Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2018.3] Do not report patches as installed when not all the related pkgs are installed (yumpkg) #52657

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions salt/modules/yumpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3117,12 +3117,18 @@ def _get_patches(installed_only=False):
for line in salt.utils.itertools.split(ret, os.linesep):
inst, advisory_id, sev, pkg = re.match(r'([i|\s]) ([^\s]+) +([^\s]+) +([^\s]+)',
line).groups()
if inst != 'i' and installed_only:
continue
patches[advisory_id] = {
'installed': True if inst == 'i' else False,
'summary': pkg
}
if not advisory_id in patches:
patches[advisory_id] = {
'installed': True if inst == 'i' else False,
'summary': [pkg]
}
else:
patches[advisory_id]['summary'].append(pkg)
if inst != 'i':
patches[advisory_id]['installed'] = False

if installed_only:
patches = {k: v for k, v in patches.items() if v['installed']}
return patches


Expand Down
48 changes: 48 additions & 0 deletions tests/unit/modules/test_yumpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,54 @@ def _add_data(data, key, value):
self.assertTrue(pkgs.get(pkg_name))
self.assertEqual(pkgs[pkg_name], [pkg_attr])

def test_list_patches(self):
'''
Test patches listing.

:return:
'''
def _add_data(data, key, value):
data.setdefault(key, []).append(value)

yum_out = [
'i my-fake-patch-not-installed-1234 recommended spacewalk-usix-2.7.5.2-2.2.noarch',
' my-fake-patch-not-installed-1234 recommended spacewalksd-5.0.26.2-21.2.x86_64',
'i my-fake-patch-not-installed-1234 recommended suseRegisterInfo-3.1.1-18.2.x86_64',
'i my-fake-patch-installed-1234 recommended my-package-one-1.1-0.1.x86_64',
'i my-fake-patch-installed-1234 recommended my-package-two-1.1-0.1.x86_64',
]

expected_patches = {
'my-fake-patch-not-installed-1234': {
'installed': False,
'summary': [
'spacewalk-usix-2.7.5.2-2.2.noarch',
'spacewalksd-5.0.26.2-21.2.x86_64',
'suseRegisterInfo-3.1.1-18.2.x86_64',
]
},
'my-fake-patch-installed-1234': {
'installed': True,
'summary': [
'my-package-one-1.1-0.1.x86_64',
'my-package-two-1.1-0.1.x86_64',
]
}
}

with patch.dict(yumpkg.__grains__, {'osarch': 'x86_64'}), \
patch.dict(yumpkg.__salt__, {'cmd.run_stdout': MagicMock(return_value=os.linesep.join(yum_out))}):
patches = yumpkg.list_patches()
self.assertFalse(patches['my-fake-patch-not-installed-1234']['installed'])
self.assertTrue(len(patches['my-fake-patch-not-installed-1234']['summary']) == 3)
for _patch in expected_patches['my-fake-patch-not-installed-1234']['summary']:
self.assertTrue(_patch in patches['my-fake-patch-not-installed-1234']['summary'])

self.assertTrue(patches['my-fake-patch-installed-1234']['installed'])
self.assertTrue(len(patches['my-fake-patch-installed-1234']['summary']) == 2)
for _patch in expected_patches['my-fake-patch-installed-1234']['summary']:
self.assertTrue(_patch in patches['my-fake-patch-installed-1234']['summary'])

def test_latest_version_with_options(self):
with patch.object(yumpkg, 'list_pkgs', MagicMock(return_value={})):

Expand Down