Merge pull request #41986 from rallytime/bp-41820

Back-port #41820 to 2016.11
This commit is contained in:
Nicole Thomas 2017-06-28 14:18:42 -06:00 committed by GitHub
commit bd9090c0bf
4 changed files with 34 additions and 4 deletions

View file

@ -2350,8 +2350,9 @@ def del_repo(repo, basedir=None, **kwargs): # pylint: disable=W0613
if stanza == repo:
continue
comments = ''
if 'comments' in filerepos[stanza]:
comments = '\n'.join(filerepos[stanza]['comments'])
if 'comments' in six.iterkeys(filerepos[stanza]):
comments = salt.utils.pkg.rpm.combine_comments(
filerepos[stanza]['comments'])
del filerepos[stanza]['comments']
content += '\n[{0}]'.format(stanza)
for line in filerepos[stanza]:
@ -2486,7 +2487,8 @@ def mod_repo(repo, basedir=None, **kwargs):
for stanza in six.iterkeys(filerepos):
comments = ''
if 'comments' in six.iterkeys(filerepos[stanza]):
comments = '\n'.join(filerepos[stanza]['comments'])
comments = salt.utils.pkg.rpm.combine_comments(
filerepos[stanza]['comments'])
del filerepos[stanza]['comments']
content += '\n[{0}]'.format(stanza)
for line in six.iterkeys(filerepos[stanza]):

View file

@ -96,6 +96,7 @@ 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
import salt.utils.pkg.rpm
def __virtual__():
@ -403,6 +404,12 @@ def managed(name, ppa=None, **kwargs):
salt.utils.pkg.deb.combine_comments(kwargs['comments'])
if pre_comments != post_comments:
break
elif kwarg == 'comments' and os_family == 'redhat':
precomments = salt.utils.pkg.rpm.combine_comments(pre[kwarg])
kwargcomments = salt.utils.pkg.rpm.combine_comments(
sanitizedkwargs[kwarg])
if precomments != kwargcomments:
break
else:
if os_family in ('redhat', 'suse') \
and any(isinstance(x, bool) for x in

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
'''
Common functions for working with RPM packages
Common functions for working with deb packages
'''
# Import python libs

View file

@ -11,6 +11,10 @@ import logging
# Import salt libs
from salt._compat import subprocess
# Import 3rd-party libs
from salt.ext import six
from salt.ext.six.moves import range # pylint: disable=redefined-builtin
log = logging.getLogger(__name__)
# These arches compiled from the rpmUtils.arch python module source
@ -100,3 +104,20 @@ def parse_pkginfo(line, osarch=None):
version = ':'.join((epoch, version))
return pkginfo(name, version, arch, repoid)
def combine_comments(comments):
'''
Given a list of comments, strings, a single comment or a single string,
return a single string of text containing all of the comments, prepending
the '#' and joining with newlines as necessary.
'''
if not isinstance(comments, list):
comments = [comments]
for idx in range(len(comments)):
if not isinstance(comments[idx], six.string_types):
comments[idx] = str(comments[idx])
comments[idx] = comments[idx].strip()
if not comments[idx].startswith('#'):
comments[idx] = '#' + comments[idx]
return '\n'.join(comments)