mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #40638 from rallytime/bp-40571
Back-port #40571 to 2016.3
This commit is contained in:
commit
2ae9eaa176
3 changed files with 45 additions and 7 deletions
|
@ -35,6 +35,7 @@ from salt.ext.six.moves.urllib.request import Request as _Request, urlopen as _u
|
|||
# Import salt libs
|
||||
from salt.modules.cmdmod import _parse_env
|
||||
import salt.utils
|
||||
import salt.utils.pkg.deb
|
||||
import salt.utils.systemd
|
||||
from salt.exceptions import (
|
||||
CommandExecutionError, MinionError, SaltInvocationError
|
||||
|
@ -1788,8 +1789,9 @@ def mod_repo(repo, saltenv='base', **kwargs):
|
|||
|
||||
comments
|
||||
Sometimes you want to supply additional information, but not as
|
||||
enabled configuration. Anything supplied for this list will be saved
|
||||
in the repo configuration with a comment marker (#) in front.
|
||||
enabled configuration. All comments provided here will be joined
|
||||
into a single string and appended to the repo configuration with a
|
||||
comment marker (#) before it.
|
||||
|
||||
.. versionadded:: 2015.8.9
|
||||
|
||||
|
@ -2014,13 +2016,17 @@ def mod_repo(repo, saltenv='base', **kwargs):
|
|||
if mod_source:
|
||||
break
|
||||
|
||||
if 'comments' in kwargs:
|
||||
kwargs['comments'] = \
|
||||
salt.utils.pkg.deb.combine_comments(kwargs['comments'])
|
||||
|
||||
if not mod_source:
|
||||
mod_source = sourceslist.SourceEntry(repo)
|
||||
if 'comments' in kwargs:
|
||||
mod_source.comment = " ".join(str(c) for c in kwargs['comments'])
|
||||
mod_source.comment = kwargs['comments']
|
||||
sources.list.append(mod_source)
|
||||
elif 'comments' in kwargs:
|
||||
mod_source.comment = " ".join(str(c) for c in kwargs['comments'])
|
||||
mod_source.comment = kwargs['comments']
|
||||
|
||||
for key in kwargs:
|
||||
if key in _MODIFY_OK and hasattr(mod_source, key):
|
||||
|
|
|
@ -97,6 +97,7 @@ from salt.exceptions import CommandExecutionError, SaltInvocationError
|
|||
from salt.modules.aptpkg import _strip_uri
|
||||
from salt.state import STATE_INTERNAL_KEYWORDS as _STATE_INTERNAL_KEYWORDS
|
||||
import salt.utils
|
||||
import salt.utils.pkg.deb
|
||||
|
||||
|
||||
def __virtual__():
|
||||
|
@ -388,13 +389,16 @@ def managed(name, ppa=None, **kwargs):
|
|||
# split the line and sort everything after the URL
|
||||
sanitizedsplit = sanitizedkwargs[kwarg].split()
|
||||
sanitizedsplit[3:] = sorted(sanitizedsplit[3:])
|
||||
reposplit = pre[kwarg].split()
|
||||
reposplit, _, pre_comments = \
|
||||
[x.strip() for x in pre[kwarg].partition('#')]
|
||||
reposplit = reposplit.split()
|
||||
reposplit[3:] = sorted(reposplit[3:])
|
||||
if sanitizedsplit != reposplit:
|
||||
break
|
||||
if 'comments' in kwargs:
|
||||
_line = pre[kwarg].split('#')
|
||||
if str(kwargs['comments']) not in _line:
|
||||
post_comments = \
|
||||
salt.utils.pkg.deb.combine_comments(kwargs['comments'])
|
||||
if pre_comments != post_comments:
|
||||
break
|
||||
else:
|
||||
if os_family in ('redhat', 'suse') \
|
||||
|
|
28
salt/utils/pkg/deb.py
Normal file
28
salt/utils/pkg/deb.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Common functions for working with RPM packages
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.ext import six
|
||||
from salt.ext.six.moves import range # pylint: disable=redefined-builtin
|
||||
|
||||
|
||||
def combine_comments(comments):
|
||||
'''
|
||||
Given a list of comments, or a comment submitted as a string, return a
|
||||
single line of text containing all of the comments.
|
||||
'''
|
||||
if isinstance(comments, list):
|
||||
for idx in range(len(comments)):
|
||||
if not isinstance(comments[idx], six.string_types):
|
||||
comments[idx] = str(comments[idx])
|
||||
else:
|
||||
if not isinstance(comments, six.string_types):
|
||||
comments = [str(comments)]
|
||||
else:
|
||||
comments = [comments]
|
||||
return ' '.join(comments).strip()
|
Loading…
Add table
Reference in a new issue