Skip to content

Commit

Permalink
Merge pull request #55582 from meaksh/master-yumpkg-do-not-report-uni…
Browse files Browse the repository at this point in the history
…nstalled-patches-as-installed

[master] Do not report patches as installed when not all the related pkgs are installed (yumpkg)
  • Loading branch information
dwoz authored Jan 11, 2020
2 parents 40e55b5 + d07999c commit 8d52ccd
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
18 changes: 12 additions & 6 deletions salt/modules/yumpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3180,12 +3180,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 advisory_id not 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 @@ -236,6 +236,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

0 comments on commit 8d52ccd

Please sign in to comment.