Merge pull request #34056 from vutny/rpmbuild-support-debian

Make rpmbuild module work on non-RPM based GNU/Linux systems
This commit is contained in:
Thomas S Hatch 2016-06-17 09:14:51 -06:00 committed by GitHub
commit 52b852216a
2 changed files with 39 additions and 17 deletions

View file

@ -7,7 +7,7 @@ RPM Package builder system
This system allows for all of the components to build rpms safely in chrooted
environments. This also provides a function to generate yum repositories
This module impliments the pkgbuild interface
This module implements the pkgbuild interface
'''
# Import python libs
@ -23,9 +23,9 @@ import traceback
import functools
# Import salt libs
import salt.utils
from salt.exceptions import SaltInvocationError
from salt.ext.six.moves.urllib.parse import urlparse as _urlparse # pylint: disable=no-name-in-module,import-error
from salt.exceptions import SaltInvocationError
import salt.utils
HAS_LIBS = False
@ -43,21 +43,23 @@ __virtualname__ = 'pkgbuild'
def __virtual__():
'''
Confirm this module is on a Redhat/CentOS based system, and has required utilities
Confirm this module is on a RPM based system, and has required utilities
'''
if __grains__.get('os_family', False) == 'RedHat':
missing_util = False
utils_reqd = ['gpg', 'rpm', 'rpmbuild', 'mock', 'createrepo']
for named_util in utils_reqd:
if not salt.utils.which(named_util):
missing_util = True
break
if HAS_LIBS and not missing_util:
missing_util = False
utils_reqd = ['gpg', 'rpm', 'rpmbuild', 'mock', 'createrepo']
for named_util in utils_reqd:
if not salt.utils.which(named_util):
missing_util = True
break
if HAS_LIBS and not missing_util:
if __grains__.get('os_family', False) in ('RedHat', 'Suse'):
return __virtualname__
else:
return False, 'The rpmbuild module could not be loaded: requires python-gnupg, gpg, rpm, rpmbuild, mock and createrepo utilities to be installed'
# The module will be exposed as `rpmbuild` on non-rpm based systems
return 'rpmbuild'
else:
return False
return False, 'The rpmbuild module could not be loaded: requires python-gnupg, gpg, rpm, rpmbuild, mock and createrepo utilities to be installed'
def _create_rpmmacros():

View file

@ -215,7 +215,14 @@ def built(name,
ret['result'] = False
return ret
ret['changes'] = __salt__['pkgbuild.build'](
func = 'pkgbuild.build'
if __grains__.get('os_family', False) not in ('RedHat', 'Suse'):
for res in results:
if res.endswith('.rpm'):
func = 'rpmbuild.build'
break
ret['changes'] = __salt__[func](
runas,
tgt,
dest_dir,
@ -237,7 +244,12 @@ def built(name,
return ret
def repo(name, keyid=None, env=None, use_passphrase=False, gnupghome='/etc/salt/gpgkeys', runas='builder'):
def repo(name,
keyid=None,
env=None,
use_passphrase=False,
gnupghome='/etc/salt/gpgkeys',
runas='builder'):
'''
Make a package repository and optionally sign it and packages present,
the name is directory to turn into a repo. This state is best used
@ -330,6 +342,7 @@ def repo(name, keyid=None, env=None, use_passphrase=False, gnupghome='/etc/salt/
'changes': {},
'comment': '',
'result': True}
if __opts__['test'] is True:
ret['result'] = None
ret['comment'] = 'Package repo at {0} will be rebuilt'.format(name)
@ -342,6 +355,13 @@ def repo(name, keyid=None, env=None, use_passphrase=False, gnupghome='/etc/salt/
'documentation.')
return ret
__salt__['pkgbuild.make_repo'](name, keyid, env, use_passphrase, gnupghome, runas)
func = 'pkgbuild.make_repo'
if __grains__.get('os_family', False) not in ('RedHat', 'Suse'):
for file in os.listdir(name):
if file.endswith('.rpm'):
func = 'rpmbuild.make_repo'
break
__salt__[func](name, keyid, env, use_passphrase, gnupghome, runas)
ret['changes'] = {'refresh': True}
return ret