diff --git a/salt/exceptions.py b/salt/exceptions.py index 1e5e42ddcc..2c6ac295af 100644 --- a/salt/exceptions.py +++ b/salt/exceptions.py @@ -44,3 +44,10 @@ class SaltInvocationError(SaltException): or invalid arguments are specified on the command line ''' pass + +class PkgParseError(SaltException): + ''' + Used when of the pkg modules cannot correctly parse the output from the CLI + tool (pacman, yum, apt, aptitude, etc) + ''' + pass diff --git a/salt/modules/yumpkg5.py b/salt/modules/yumpkg5.py index 37f592dbff..4fecbffd1c 100644 --- a/salt/modules/yumpkg5.py +++ b/salt/modules/yumpkg5.py @@ -1,6 +1,13 @@ ''' Support for YUM ''' +import logging +from collections import namedtuple + +from salt.exceptions import PkgParseError + +logger = logging.getLogger(__name__) + def __virtual__(): ''' Confine this module to yum based systems @@ -21,6 +28,25 @@ def __virtual__(): return False +def _parse_yum(arg): + ''' + A small helper to parse yum output; returns a list of namedtuples + ''' + cmd = 'yum -q {0}'.format(arg) + out = __salt__['cmd.run_stdout'](cmd) + YumOut = namedtuple('YumOut', ('name', 'version', 'status')) + + try: + results = map(YumOut._make, + [i.split() for i in out.split('\n') if len(i.split()) == 3]) + except TypeError as exc: + results = () + msg = "Could not parse yum output for: {0}".format(cmd) + logger.debug(msg, exc_info=exc) + + return results + + def _list_removed(old, new): ''' List the packages which have been removed between the two package objects