From 1fca63bc07f1484179e99c295b26a807fc1577dc Mon Sep 17 00:00:00 2001 From: nicholasmhughes Date: Sun, 29 Mar 2020 16:34:23 -0400 Subject: [PATCH 1/6] fixes #56476 --- salt/modules/yumpkg.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/salt/modules/yumpkg.py b/salt/modules/yumpkg.py index f7e4ac9753c..d017863b931 100644 --- a/salt/modules/yumpkg.py +++ b/salt/modules/yumpkg.py @@ -2418,10 +2418,10 @@ def group_list(): return ret -def group_info(name, expand=False): +def group_info(name, expand=False, ignore_groups=None): ''' .. versionadded:: 2014.1.0 - .. versionchanged:: 2016.3.0,2015.8.4,2015.5.10 + .. versionchanged:: Sodium,2015.8.4,2015.5.10 The return data has changed. A new key ``type`` has been added to distinguish environment groups from package groups. Also, keys for the group name and group ID have been added. The ``mandatory packages``, @@ -2442,6 +2442,13 @@ def group_info(name, expand=False): .. versionadded:: 2016.3.0 + ignore_groups : None + This parameter can be used to pass a list of groups to ignore when + expanding subgroups. It is used during recursion in order to prevent + expanding the same group multiple times. + + .. versionadded:: Sodium + CLI Example: .. code-block:: bash @@ -2460,6 +2467,8 @@ def group_info(name, expand=False): python_shell=False ) + log.trace('Output from "%s": %s', cmd, out) + g_info = {} for line in salt.utils.itertools.split(out, '\n'): try: @@ -2480,6 +2489,7 @@ def group_info(name, expand=False): ret['description'] = g_info.get('description', '') + completed_groups = ignore_groups or [] pkgtypes_capturegroup = '(' + '|'.join(pkgtypes) + ')' for pkgtype in pkgtypes: target_found = False @@ -2500,7 +2510,11 @@ def group_info(name, expand=False): continue if target_found: if expand and ret['type'] == 'environment group': - expanded = group_info(line, expand=True) + if not line or line in completed_groups: + continue + log.trace('Adding group "%s" to completed list: %s', line, completed_groups) + completed_groups.append(line) + expanded = group_info(line, expand=True, ignore_groups=completed_groups) # Don't shadow the pkgtype variable from the outer loop for p_type in pkgtypes: ret[p_type].update(set(expanded[p_type])) From b2f573e7e52d8cf3de9c95c0fbcb8fe7dfd3a784 Mon Sep 17 00:00:00 2001 From: nicholasmhughes Date: Sun, 29 Mar 2020 16:36:45 -0400 Subject: [PATCH 2/6] fix issue with multiple groups returned --- salt/modules/yumpkg.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/salt/modules/yumpkg.py b/salt/modules/yumpkg.py index d017863b931..9d1c7642330 100644 --- a/salt/modules/yumpkg.py +++ b/salt/modules/yumpkg.py @@ -2514,7 +2514,9 @@ def group_info(name, expand=False, ignore_groups=None): continue log.trace('Adding group "%s" to completed list: %s', line, completed_groups) completed_groups.append(line) - expanded = group_info(line, expand=True, ignore_groups=completed_groups) + # Using the @ prefix on the group here in order to prevent multiple matches + # being returned, such as with gnome-desktop + expanded = group_info('@' + line, expand=True, ignore_groups=completed_groups) # Don't shadow the pkgtype variable from the outer loop for p_type in pkgtypes: ret[p_type].update(set(expanded[p_type])) From 599f8d2ece66cfd5e076ea64eb0ade28a9c0571b Mon Sep 17 00:00:00 2001 From: nicholasmhughes Date: Sun, 29 Mar 2020 18:04:28 -0400 Subject: [PATCH 3/6] adding yumpkg.group_info test --- tests/unit/modules/test_yumpkg.py | 232 ++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) diff --git a/tests/unit/modules/test_yumpkg.py b/tests/unit/modules/test_yumpkg.py index 5e652b7e535..ed545801ad6 100644 --- a/tests/unit/modules/test_yumpkg.py +++ b/tests/unit/modules/test_yumpkg.py @@ -844,6 +844,238 @@ class YumTestCase(TestCase, LoaderModuleMockMixin): with pytest.raises(CommandExecutionError): yumpkg._get_yum_config() + def test_group_info(self): + ''' + Test yumpkg.group_info parsing + ''' + expected = { + 'conditional': [], + 'default': ['qgnomeplatform', 'xdg-desktop-portal-gtk'], + 'description': 'GNOME is a highly intuitive and user friendly desktop environment.', + 'group': 'GNOME', + 'id': 'gnome-desktop', + 'mandatory': ['NetworkManager-libreswan-gnome', + 'PackageKit-command-not-found', + 'PackageKit-gtk3-module', + 'abrt-desktop', + 'at-spi2-atk', + 'at-spi2-core', + 'avahi', + 'baobab', + 'caribou', + 'caribou-gtk2-module', + 'caribou-gtk3-module', + 'cheese', + 'chrome-gnome-shell', + 'compat-cheese314', + 'control-center', + 'dconf', + 'empathy', + 'eog', + 'evince', + 'evince-nautilus', + 'file-roller', + 'file-roller-nautilus', + 'firewall-config', + 'firstboot', + 'fprintd-pam', + 'gdm', + 'gedit', + 'glib-networking', + 'gnome-bluetooth', + 'gnome-boxes', + 'gnome-calculator', + 'gnome-classic-session', + 'gnome-clocks', + 'gnome-color-manager', + 'gnome-contacts', + 'gnome-dictionary', + 'gnome-disk-utility', + 'gnome-font-viewer', + 'gnome-getting-started-docs', + 'gnome-icon-theme', + 'gnome-icon-theme-extras', + 'gnome-icon-theme-symbolic', + 'gnome-initial-setup', + 'gnome-packagekit', + 'gnome-packagekit-updater', + 'gnome-screenshot', + 'gnome-session', + 'gnome-session-xsession', + 'gnome-settings-daemon', + 'gnome-shell', + 'gnome-software', + 'gnome-system-log', + 'gnome-system-monitor', + 'gnome-terminal', + 'gnome-terminal-nautilus', + 'gnome-themes-standard', + 'gnome-tweak-tool', + 'gnome-user-docs', + 'gnome-weather', + 'gucharmap', + 'gvfs-afc', + 'gvfs-afp', + 'gvfs-archive', + 'gvfs-fuse', + 'gvfs-goa', + 'gvfs-gphoto2', + 'gvfs-mtp', + 'gvfs-smb', + 'initial-setup-gui', + 'libcanberra-gtk2', + 'libcanberra-gtk3', + 'libproxy-mozjs', + 'librsvg2', + 'libsane-hpaio', + 'metacity', + 'mousetweaks', + 'nautilus', + 'nautilus-sendto', + 'nm-connection-editor', + 'orca', + 'redhat-access-gui', + 'sane-backends-drivers-scanners', + 'seahorse', + 'setroubleshoot', + 'sushi', + 'totem', + 'totem-nautilus', + 'vinagre', + 'vino', + 'xdg-user-dirs-gtk', + 'yelp'], + 'optional': ['', + 'alacarte', + 'dconf-editor', + 'dvgrab', + 'fonts-tweak-tool', + 'gconf-editor', + 'gedit-plugins', + 'gnote', + 'libappindicator-gtk3', + 'seahorse-nautilus', + 'seahorse-sharing', + 'vim-X11', + 'xguest'], + 'type': 'package group' + } + cmd_out = '''Group: GNOME + Group-Id: gnome-desktop + Description: GNOME is a highly intuitive and user friendly desktop environment. + Mandatory Packages: + =NetworkManager-libreswan-gnome + =PackageKit-command-not-found + =PackageKit-gtk3-module + abrt-desktop + =at-spi2-atk + =at-spi2-core + =avahi + =baobab + -caribou + -caribou-gtk2-module + -caribou-gtk3-module + =cheese + =chrome-gnome-shell + =compat-cheese314 + =control-center + =dconf + =empathy + =eog + =evince + =evince-nautilus + =file-roller + =file-roller-nautilus + =firewall-config + =firstboot + fprintd-pam + =gdm + =gedit + =glib-networking + =gnome-bluetooth + =gnome-boxes + =gnome-calculator + =gnome-classic-session + =gnome-clocks + =gnome-color-manager + =gnome-contacts + =gnome-dictionary + =gnome-disk-utility + =gnome-font-viewer + =gnome-getting-started-docs + =gnome-icon-theme + =gnome-icon-theme-extras + =gnome-icon-theme-symbolic + =gnome-initial-setup + =gnome-packagekit + =gnome-packagekit-updater + =gnome-screenshot + =gnome-session + =gnome-session-xsession + =gnome-settings-daemon + =gnome-shell + =gnome-software + =gnome-system-log + =gnome-system-monitor + =gnome-terminal + =gnome-terminal-nautilus + =gnome-themes-standard + =gnome-tweak-tool + =gnome-user-docs + =gnome-weather + =gucharmap + =gvfs-afc + =gvfs-afp + =gvfs-archive + =gvfs-fuse + =gvfs-goa + =gvfs-gphoto2 + =gvfs-mtp + =gvfs-smb + initial-setup-gui + =libcanberra-gtk2 + =libcanberra-gtk3 + =libproxy-mozjs + =librsvg2 + =libsane-hpaio + =metacity + =mousetweaks + =nautilus + =nautilus-sendto + =nm-connection-editor + =orca + -redhat-access-gui + =sane-backends-drivers-scanners + =seahorse + =setroubleshoot + =sushi + =totem + =totem-nautilus + =vinagre + =vino + =xdg-user-dirs-gtk + =yelp + Default Packages: + =qgnomeplatform + =xdg-desktop-portal-gtk + Optional Packages: + alacarte + dconf-editor + dvgrab + fonts-tweak-tool + gconf-editor + gedit-plugins + gnote + libappindicator-gtk3 + seahorse-nautilus + seahorse-sharing + vim-X11 + xguest + ''' + with patch.dict(yumpkg.__salt__, {'cmd.run_stdout': MagicMock(return_value=cmd_out)}): + info = yumpkg.group_info('@gnome-desktop') + self.assertDictEqual(info, expected) + @skipIf(pytest is None, 'PyTest is missing') class YumUtilsTestCase(TestCase, LoaderModuleMockMixin): From 7a04ffeda47f21382141dfa92d14575c043ea4fd Mon Sep 17 00:00:00 2001 From: nicholasmhughes Date: Sun, 29 Mar 2020 18:06:05 -0400 Subject: [PATCH 4/6] already have trace output from cmd module --- salt/modules/yumpkg.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/salt/modules/yumpkg.py b/salt/modules/yumpkg.py index 9d1c7642330..7fb83aad7c4 100644 --- a/salt/modules/yumpkg.py +++ b/salt/modules/yumpkg.py @@ -2467,8 +2467,6 @@ def group_info(name, expand=False, ignore_groups=None): python_shell=False ) - log.trace('Output from "%s": %s', cmd, out) - g_info = {} for line in salt.utils.itertools.split(out, '\n'): try: From 54af825d2d66df4a4ebb093c1d5d4e9e398393f9 Mon Sep 17 00:00:00 2001 From: Nicholas Hughes Date: Tue, 14 Apr 2020 18:17:12 -0400 Subject: [PATCH 5/6] updates for black --- salt/modules/yumpkg.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/salt/modules/yumpkg.py b/salt/modules/yumpkg.py index e61c8872740..a489bc2138f 100644 --- a/salt/modules/yumpkg.py +++ b/salt/modules/yumpkg.py @@ -2456,7 +2456,7 @@ def group_list(): def group_info(name, expand=False, ignore_groups=None): """ .. versionadded:: 2014.1.0 - .. versionchanged:: Sodium,2015.8.4,2015.5.10 + .. versionchanged:: Sodium,2016.3.0,2015.8.4,2015.5.10 The return data has changed. A new key ``type`` has been added to distinguish environment groups from package groups. Also, keys for the group name and group ID have been added. The ``mandatory packages``, @@ -2540,11 +2540,17 @@ def group_info(name, expand=False, ignore_groups=None): if expand and ret["type"] == "environment group": if not line or line in completed_groups: continue - log.trace("Adding group \"%s\" to completed list: %s", line, completed_groups) + log.trace( + 'Adding group "%s" to completed list: %s', + line, + completed_groups, + ) completed_groups.append(line) # Using the @ prefix on the group here in order to prevent multiple matches # being returned, such as with gnome-desktop - expanded = group_info('@' + line, expand=True, ignore_groups=completed_groups) + expanded = group_info( + "@" + line, expand=True, ignore_groups=completed_groups + ) # Don't shadow the pkgtype variable from the outer loop for p_type in pkgtypes: ret[p_type].update(set(expanded[p_type])) From 0b4e741196cf93af084747e468b7ede0ec357a88 Mon Sep 17 00:00:00 2001 From: Nicholas Hughes Date: Tue, 14 Apr 2020 18:22:42 -0400 Subject: [PATCH 6/6] updates for black --- tests/unit/modules/test_yumpkg.py | 218 +++++++++++++++--------------- 1 file changed, 112 insertions(+), 106 deletions(-) diff --git a/tests/unit/modules/test_yumpkg.py b/tests/unit/modules/test_yumpkg.py index 4deecc544ff..5e596d33f20 100644 --- a/tests/unit/modules/test_yumpkg.py +++ b/tests/unit/modules/test_yumpkg.py @@ -1311,111 +1311,115 @@ class YumTestCase(TestCase, LoaderModuleMockMixin): "description": "GNOME is a highly intuitive and user friendly desktop environment.", "group": "GNOME", "id": "gnome-desktop", - "mandatory": ["NetworkManager-libreswan-gnome", - "PackageKit-command-not-found", - "PackageKit-gtk3-module", - "abrt-desktop", - "at-spi2-atk", - "at-spi2-core", - "avahi", - "baobab", - "caribou", - "caribou-gtk2-module", - "caribou-gtk3-module", - "cheese", - "chrome-gnome-shell", - "compat-cheese314", - "control-center", - "dconf", - "empathy", - "eog", - "evince", - "evince-nautilus", - "file-roller", - "file-roller-nautilus", - "firewall-config", - "firstboot", - "fprintd-pam", - "gdm", - "gedit", - "glib-networking", - "gnome-bluetooth", - "gnome-boxes", - "gnome-calculator", - "gnome-classic-session", - "gnome-clocks", - "gnome-color-manager", - "gnome-contacts", - "gnome-dictionary", - "gnome-disk-utility", - "gnome-font-viewer", - "gnome-getting-started-docs", - "gnome-icon-theme", - "gnome-icon-theme-extras", - "gnome-icon-theme-symbolic", - "gnome-initial-setup", - "gnome-packagekit", - "gnome-packagekit-updater", - "gnome-screenshot", - "gnome-session", - "gnome-session-xsession", - "gnome-settings-daemon", - "gnome-shell", - "gnome-software", - "gnome-system-log", - "gnome-system-monitor", - "gnome-terminal", - "gnome-terminal-nautilus", - "gnome-themes-standard", - "gnome-tweak-tool", - "gnome-user-docs", - "gnome-weather", - "gucharmap", - "gvfs-afc", - "gvfs-afp", - "gvfs-archive", - "gvfs-fuse", - "gvfs-goa", - "gvfs-gphoto2", - "gvfs-mtp", - "gvfs-smb", - "initial-setup-gui", - "libcanberra-gtk2", - "libcanberra-gtk3", - "libproxy-mozjs", - "librsvg2", - "libsane-hpaio", - "metacity", - "mousetweaks", - "nautilus", - "nautilus-sendto", - "nm-connection-editor", - "orca", - "redhat-access-gui", - "sane-backends-drivers-scanners", - "seahorse", - "setroubleshoot", - "sushi", - "totem", - "totem-nautilus", - "vinagre", - "vino", - "xdg-user-dirs-gtk", - "yelp"], - "optional": ["", - "alacarte", - "dconf-editor", - "dvgrab", - "fonts-tweak-tool", - "gconf-editor", - "gedit-plugins", - "gnote", - "libappindicator-gtk3", - "seahorse-nautilus", - "seahorse-sharing", - "vim-X11", - "xguest"], - "type": "package group" + "mandatory": [ + "NetworkManager-libreswan-gnome", + "PackageKit-command-not-found", + "PackageKit-gtk3-module", + "abrt-desktop", + "at-spi2-atk", + "at-spi2-core", + "avahi", + "baobab", + "caribou", + "caribou-gtk2-module", + "caribou-gtk3-module", + "cheese", + "chrome-gnome-shell", + "compat-cheese314", + "control-center", + "dconf", + "empathy", + "eog", + "evince", + "evince-nautilus", + "file-roller", + "file-roller-nautilus", + "firewall-config", + "firstboot", + "fprintd-pam", + "gdm", + "gedit", + "glib-networking", + "gnome-bluetooth", + "gnome-boxes", + "gnome-calculator", + "gnome-classic-session", + "gnome-clocks", + "gnome-color-manager", + "gnome-contacts", + "gnome-dictionary", + "gnome-disk-utility", + "gnome-font-viewer", + "gnome-getting-started-docs", + "gnome-icon-theme", + "gnome-icon-theme-extras", + "gnome-icon-theme-symbolic", + "gnome-initial-setup", + "gnome-packagekit", + "gnome-packagekit-updater", + "gnome-screenshot", + "gnome-session", + "gnome-session-xsession", + "gnome-settings-daemon", + "gnome-shell", + "gnome-software", + "gnome-system-log", + "gnome-system-monitor", + "gnome-terminal", + "gnome-terminal-nautilus", + "gnome-themes-standard", + "gnome-tweak-tool", + "gnome-user-docs", + "gnome-weather", + "gucharmap", + "gvfs-afc", + "gvfs-afp", + "gvfs-archive", + "gvfs-fuse", + "gvfs-goa", + "gvfs-gphoto2", + "gvfs-mtp", + "gvfs-smb", + "initial-setup-gui", + "libcanberra-gtk2", + "libcanberra-gtk3", + "libproxy-mozjs", + "librsvg2", + "libsane-hpaio", + "metacity", + "mousetweaks", + "nautilus", + "nautilus-sendto", + "nm-connection-editor", + "orca", + "redhat-access-gui", + "sane-backends-drivers-scanners", + "seahorse", + "setroubleshoot", + "sushi", + "totem", + "totem-nautilus", + "vinagre", + "vino", + "xdg-user-dirs-gtk", + "yelp", + ], + "optional": [ + "", + "alacarte", + "dconf-editor", + "dvgrab", + "fonts-tweak-tool", + "gconf-editor", + "gedit-plugins", + "gnote", + "libappindicator-gtk3", + "seahorse-nautilus", + "seahorse-sharing", + "vim-X11", + "xguest", + ], + "type": "package group", } cmd_out = """Group: GNOME Group-Id: gnome-desktop @@ -1529,7 +1533,9 @@ class YumTestCase(TestCase, LoaderModuleMockMixin): vim-X11 xguest """ - with patch.dict(yumpkg.__salt__, {"cmd.run_stdout": MagicMock(return_value=cmd_out)}): + with patch.dict( + yumpkg.__salt__, {"cmd.run_stdout": MagicMock(return_value=cmd_out)} + ): info = yumpkg.group_info("@gnome-desktop") self.assertDictEqual(info, expected)