Merge pull request #56477 from nicholasmhughes/fix-pkg-group_info

Fix pkg.group_info infinite recursion
This commit is contained in:
Daniel Wozniak 2020-04-23 09:21:38 -07:00 committed by GitHub
commit 8d70836c61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 252 additions and 53 deletions

View file

@ -2453,10 +2453,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,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``,
@ -2477,6 +2477,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
@ -2511,6 +2518,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
@ -2530,7 +2538,19 @@ 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)
# 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]))

View file

@ -1301,64 +1301,243 @@ class YumTestCase(TestCase, LoaderModuleMockMixin):
with pytest.raises(CommandExecutionError):
yumpkg._get_yum_config()
def test_group_install(self):
def test_group_info(self):
"""
Test group_install uses the correct keys from group_info and installs
default and mandatory packages.
Test yumpkg.group_info parsing
"""
groupinfo_output = """
Group: Printing Client
Group-Id: print-client
Description: Tools for printing to a local printer or a remote print server.
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:
+cups
+cups-pk-helper
+enscript
+ghostscript-cups
=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:
+colord
+gutenprint
+gutenprint-cups
+hpijs
+paps
+pnm2ppa
+python-smbc
+system-config-printer
+system-config-printer-udev
=qgnomeplatform
=xdg-desktop-portal-gtk
Optional Packages:
hplip
hplip-gui
samba-krb5-printing
alacarte
dconf-editor
dvgrab
fonts-tweak-tool
gconf-editor
gedit-plugins
gnote
libappindicator-gtk3
seahorse-nautilus
seahorse-sharing
vim-X11
xguest
"""
install = MagicMock()
with patch.dict(
yumpkg.__salt__,
{"cmd.run_stdout": MagicMock(return_value=groupinfo_output)},
yumpkg.__salt__, {"cmd.run_stdout": MagicMock(return_value=cmd_out)}
):
with patch.dict(yumpkg.__salt__, {"cmd.run": MagicMock(return_value="")}):
with patch.dict(
yumpkg.__salt__,
{"pkg_resource.format_pkg_list": MagicMock(return_value={})},
):
with patch.object(yumpkg, "install", install):
yumpkg.group_install("Printing Client")
install.assert_called_once_with(
pkgs=[
"cups",
"cups-pk-helper",
"enscript",
"ghostscript-cups",
"colord",
"gutenprint",
"gutenprint-cups",
"hpijs",
"paps",
"pnm2ppa",
"python-smbc",
"system-config-printer",
"system-config-printer-udev",
]
)
info = yumpkg.group_info("@gnome-desktop")
self.assertDictEqual(info, expected)
@skipIf(pytest is None, "PyTest is missing")