mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Merge remote-tracking branch 'upstream/develop' into develop
This commit is contained in:
commit
95e5ce6033
@ -802,8 +802,8 @@ def list_repos():
|
||||
repo['disabled'] = source.disabled
|
||||
repo['dist'] = source.dist
|
||||
repo['type'] = source.type
|
||||
repo['uri'] = source.uri
|
||||
repo['line'] = source.line.strip()
|
||||
repo['uri'] = source.uri.rstrip('/')
|
||||
repo['line'] = _strip_uri(source.line.strip())
|
||||
repo['architectures'] = getattr(source, 'architectures', [])
|
||||
repos.setdefault(source.uri, []).append(repo)
|
||||
return repos
|
||||
@ -822,8 +822,9 @@ def get_repo(repo, **kwargs):
|
||||
salt '*' pkg.get_repo "myrepo definition"
|
||||
'''
|
||||
if not apt_support:
|
||||
msg = 'Error: aptsources.sourceslist python module not found'
|
||||
raise Exception(msg)
|
||||
raise CommandExecutionError(
|
||||
'Error: aptsources.sourceslist python module not found'
|
||||
)
|
||||
|
||||
ppa_auth = kwargs.get('ppa_auth', None)
|
||||
# we have to be clever about this since the repo definition formats
|
||||
@ -858,8 +859,10 @@ def get_repo(repo, **kwargs):
|
||||
ppa_auth,
|
||||
uri_match.group(2))
|
||||
except SyntaxError:
|
||||
error_str = 'Error: repo {0!r} is not a well formatted definition'
|
||||
raise Exception(error_str.format(repo))
|
||||
raise CommandExecutionError(
|
||||
'Error: repo {0!r} is not a well formatted definition'
|
||||
.format(repo)
|
||||
)
|
||||
|
||||
for source in repos.values():
|
||||
for sub in source:
|
||||
@ -874,7 +877,7 @@ def get_repo(repo, **kwargs):
|
||||
if comp in sub.get('comps', []):
|
||||
return sub
|
||||
|
||||
raise Exception('repo {0!r} was not found'.format(repo))
|
||||
raise CommandExecutionError('repo {0!r} was not found'.format(repo))
|
||||
|
||||
|
||||
def del_repo(repo, **kwargs):
|
||||
@ -1048,7 +1051,7 @@ def mod_repo(repo, **kwargs):
|
||||
'Expected format "<PPA_OWNER>/<PPA_NAME>" ' \
|
||||
'(e.g. saltstack/salt) not found. Received ' \
|
||||
'{0!r} instead.'
|
||||
raise Exception(err_str.format(repo[4:]))
|
||||
raise CommandExecutionError(err_str.format(repo[4:]))
|
||||
dist = __grains__['lsb_distrib_codename']
|
||||
# ppa has a lot of implicit arguments. Make them explicit.
|
||||
# These will defer to any user-defined variants
|
||||
@ -1068,17 +1071,21 @@ def mod_repo(repo, **kwargs):
|
||||
if 'keyid' not in kwargs:
|
||||
error_str = 'Private PPAs require a ' \
|
||||
'keyid to be specified: {0}/{1}'
|
||||
raise Exception(error_str.format(owner_name,
|
||||
ppa_name))
|
||||
raise CommandExecutionError(
|
||||
error_str.format(owner_name, ppa_name)
|
||||
)
|
||||
except urllib2.HTTPError as exc:
|
||||
error_str = 'Launchpad does not know about {0}/{1}: {2}'
|
||||
raise Exception(error_str.format(owner_name, ppa_name,
|
||||
exc))
|
||||
raise CommandExecutionError(
|
||||
error_str.format(owner_name, ppa_name, exc)
|
||||
)
|
||||
except IndexError as e:
|
||||
error_str = 'Launchpad knows about {0}/{1} but did not ' \
|
||||
'return a fingerprint. Please set keyid ' \
|
||||
'manually: {2}'
|
||||
raise Exception(error_str.format(owner_name, ppa_name, e))
|
||||
raise CommandExecutionError(
|
||||
error_str.format(owner_name, ppa_name, e)
|
||||
)
|
||||
|
||||
if 'keyserver' not in kwargs:
|
||||
kwargs['keyserver'] = 'keyserver.ubuntu.com'
|
||||
@ -1086,7 +1093,7 @@ def mod_repo(repo, **kwargs):
|
||||
if not launchpad_ppa_info['private']:
|
||||
error_str = 'PPA is not private but auth ' \
|
||||
'credentials passed: {0}'
|
||||
raise Exception(error_str.format(repo))
|
||||
raise CommandExecutionError(error_str.format(repo))
|
||||
# assign the new repo format to the "repo" variable
|
||||
# so we can fall through to the "normal" mechanism
|
||||
# here.
|
||||
@ -1097,8 +1104,10 @@ def mod_repo(repo, **kwargs):
|
||||
else:
|
||||
repo = LP_SRC_FORMAT.format(owner_name, ppa_name, dist)
|
||||
else:
|
||||
error_str = 'cannot parse "ppa:" style repo definitions: {0}'
|
||||
raise Exception(error_str.format(repo))
|
||||
raise CommandExecutionError(
|
||||
'cannot parse "ppa:" style repo definitions: {0}'
|
||||
.format(repo)
|
||||
)
|
||||
|
||||
sources = sourceslist.SourcesList()
|
||||
if kwargs.get('consolidate', False):
|
||||
@ -1142,8 +1151,10 @@ def mod_repo(repo, **kwargs):
|
||||
ret = __salt__['cmd.run_all'](cmd.format(ks, keyid),
|
||||
**kwargs)
|
||||
if ret['retcode'] != 0:
|
||||
error_str = 'Error: key retrieval failed: {0}'
|
||||
raise Exception(error_str.format(ret['stdout']))
|
||||
raise CommandExecutionError(
|
||||
'Error: key retrieval failed: {0}'
|
||||
.format(ret['stdout'])
|
||||
)
|
||||
|
||||
elif 'key_url' in kwargs:
|
||||
key_url = kwargs['key_url']
|
||||
@ -1151,8 +1162,9 @@ def mod_repo(repo, **kwargs):
|
||||
cmd = 'apt-key add {0}'.format(fn_)
|
||||
out = __salt__['cmd.run_stdout'](cmd, **kwargs)
|
||||
if not out.upper().startswith('OK'):
|
||||
error_str = 'Error: key retrieval failed: {0}'
|
||||
raise Exception(error_str.format(cmd.format(key_url)))
|
||||
raise CommandExecutionError(
|
||||
'Error: key retrieval failed: {0}'.format(cmd.format(key_url))
|
||||
)
|
||||
|
||||
if 'comps' in kwargs:
|
||||
kwargs['comps'] = kwargs['comps'].split(',')
|
||||
@ -1265,6 +1277,18 @@ def file_dict(*packages):
|
||||
return __salt__['lowpkg.file_dict'](*packages)
|
||||
|
||||
|
||||
def _strip_uri(repo):
|
||||
'''
|
||||
Remove the trailing slash from the URI in a repo definition
|
||||
'''
|
||||
splits = repo.split()
|
||||
for idx in xrange(len(splits)):
|
||||
if any(splits[idx].startswith(x)
|
||||
for x in ('http://', 'https://', 'ftp://')):
|
||||
splits[idx] = splits[idx].rstrip('/')
|
||||
return ' '.join(splits)
|
||||
|
||||
|
||||
def expand_repo_def(repokwargs):
|
||||
'''
|
||||
Take a repository definition and expand it to the full pkg repository dict
|
||||
@ -1276,10 +1300,11 @@ def expand_repo_def(repokwargs):
|
||||
sanitized = {}
|
||||
|
||||
if not apt_support:
|
||||
msg = 'Error: aptsources.sourceslist python module not found'
|
||||
raise Exception(msg)
|
||||
raise CommandExecutionError(
|
||||
'Error: aptsources.sourceslist python module not found'
|
||||
)
|
||||
|
||||
repo = repokwargs['repo']
|
||||
repo = _strip_uri(repokwargs['repo'])
|
||||
|
||||
if repo.startswith('ppa:') and __grains__['os'] == 'Ubuntu':
|
||||
dist = __grains__['lsb_distrib_codename']
|
||||
@ -1310,7 +1335,7 @@ def expand_repo_def(repokwargs):
|
||||
sanitized['disabled'] = source_entry.disabled
|
||||
sanitized['dist'] = source_entry.dist
|
||||
sanitized['type'] = source_entry.type
|
||||
sanitized['uri'] = source_entry.uri
|
||||
sanitized['uri'] = source_entry.uri.rstrip('/')
|
||||
sanitized['line'] = source_entry.line.strip()
|
||||
sanitized['architectures'] = getattr(source_entry, 'architectures', [])
|
||||
|
||||
|
@ -41,6 +41,9 @@ Package repositories can be managed with the pkgrepo state:
|
||||
- refresh: True
|
||||
'''
|
||||
|
||||
# Import salt libs
|
||||
from salt.modules.apt import _strip_uri
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
@ -108,7 +111,7 @@ def managed(name, **kwargs):
|
||||
components (i.e. 'main') which can be added/modified with the
|
||||
"comps" option.
|
||||
|
||||
EXAMPLE: name: deb http://us.archive.ubuntu.com/ubuntu/ precise main
|
||||
EXAMPLE: name: deb http://us.archive.ubuntu.com/ubuntu precise main
|
||||
|
||||
disabled
|
||||
On apt-based systems, disabled toggles whether or not the repo is
|
||||
@ -196,6 +199,8 @@ def managed(name, **kwargs):
|
||||
# to use. Most package providers will simply return the data provided
|
||||
# it doesn't require any "specialized" data massaging.
|
||||
sanitizedkwargs = __salt__['pkg.expand_repo_def'](kwargs)
|
||||
if __grains__['os_family'] == 'Debian':
|
||||
kwargs['repo'] = _strip_uri(kwargs['repo'])
|
||||
|
||||
if repo:
|
||||
notset = False
|
||||
@ -220,10 +225,12 @@ def managed(name, **kwargs):
|
||||
notset = True
|
||||
if notset is False:
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'Package repo {0} already configured'.format(name)
|
||||
ret['comment'] = ('Package repo {0!r} already configured'
|
||||
.format(name))
|
||||
return ret
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'Package repo {0} needs to be configured'.format(name)
|
||||
ret['comment'] = ('Package repo {0!r} needs to be configured'
|
||||
.format(name))
|
||||
return ret
|
||||
try:
|
||||
__salt__['pkg.mod_repo'](**kwargs)
|
||||
@ -231,8 +238,8 @@ def managed(name, **kwargs):
|
||||
# This is another way to pass information back from the mod_repo
|
||||
# function.
|
||||
ret['result'] = False
|
||||
ret['comment'] = 'Failed to configure repo "{0}": {1}'.format(name,
|
||||
str(e))
|
||||
ret['comment'] = ('Failed to configure repo {0!r}: {1}'
|
||||
.format(name, str(e)))
|
||||
return ret
|
||||
try:
|
||||
repodict = __salt__['pkg.get_repo'](kwargs['repo'],
|
||||
@ -248,10 +255,10 @@ def managed(name, **kwargs):
|
||||
ret['changes'] = {'repo': kwargs['repo']}
|
||||
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'Configured package repo {0}'.format(name)
|
||||
ret['comment'] = 'Configured package repo {0!r}'.format(name)
|
||||
except Exception as e:
|
||||
ret['result'] = False
|
||||
ret['comment'] = 'Failed to confirm config of repo {0}: {1}'.format(
|
||||
ret['comment'] = 'Failed to confirm config of repo {0!r}: {1}'.format(
|
||||
name, str(e))
|
||||
return ret
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user