mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #31488 from isbm/isbm-zypper-ut-removepurge
Unit Test for Zypper's "remove" and "purge"
This commit is contained in:
commit
e68a0947b7
2 changed files with 40 additions and 6 deletions
|
@ -891,7 +891,7 @@ def upgrade(refresh=True):
|
|||
|
||||
def _uninstall(name=None, pkgs=None):
|
||||
'''
|
||||
remove and purge do identical things but with different zypper commands,
|
||||
Remove and purge do identical things but with different Zypper commands,
|
||||
this function performs the common logic.
|
||||
'''
|
||||
try:
|
||||
|
@ -900,16 +900,16 @@ def _uninstall(name=None, pkgs=None):
|
|||
raise CommandExecutionError(exc)
|
||||
|
||||
old = list_pkgs()
|
||||
targets = [x for x in pkg_params if x in old]
|
||||
targets = [target for target in pkg_params if target in old]
|
||||
if not targets:
|
||||
return {}
|
||||
|
||||
while targets:
|
||||
cmd = _zypper('remove', *targets[:500])
|
||||
__salt__['cmd.run'](cmd, output_loglevel='trace')
|
||||
__salt__['cmd.run'](_zypper('remove', *targets[:500]), output_loglevel='trace')
|
||||
targets = targets[500:]
|
||||
__context__.pop('pkg.list_pkgs', None)
|
||||
new = list_pkgs()
|
||||
return salt.utils.compare_dicts(old, new)
|
||||
|
||||
return salt.utils.compare_dicts(old, list_pkgs())
|
||||
|
||||
|
||||
def remove(name=None, pkgs=None, **kwargs): # pylint: disable=unused-argument
|
||||
|
|
|
@ -284,6 +284,40 @@ class ZypperTestCase(TestCase):
|
|||
assert pkgs.get(pkg_name)
|
||||
assert pkgs[pkg_name] == pkg_version
|
||||
|
||||
def test_remove_purge(self):
|
||||
'''
|
||||
Test package removal
|
||||
:return:
|
||||
'''
|
||||
class ListPackages(object):
|
||||
def __init__(self):
|
||||
self._packages = ['vim', 'pico']
|
||||
self._pkgs = {
|
||||
'vim': '0.18.0',
|
||||
'emacs': '24.0.1',
|
||||
'pico': '0.1.1',
|
||||
}
|
||||
|
||||
def __call__(self):
|
||||
pkgs = self._pkgs.copy()
|
||||
for target in self._packages:
|
||||
if self._pkgs.get(target):
|
||||
del self._pkgs[target]
|
||||
|
||||
return pkgs
|
||||
|
||||
parsed_targets = [{'vim': None, 'pico': None}, None]
|
||||
|
||||
with patch.dict(zypper.__salt__, {'cmd.run': MagicMock(return_value=False)}):
|
||||
with patch.dict(zypper.__salt__, {'pkg_resource.parse_targets': MagicMock(return_value=parsed_targets)}):
|
||||
with patch.dict(zypper.__salt__, {'pkg_resource.stringify': MagicMock()}):
|
||||
with patch('salt.modules.zypper.list_pkgs', ListPackages()):
|
||||
diff = zypper.remove(name='vim,pico')
|
||||
for pkg_name in ['vim', 'pico']:
|
||||
assert diff.get(pkg_name)
|
||||
assert diff[pkg_name]['old']
|
||||
assert not diff[pkg_name]['new']
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
|
Loading…
Add table
Reference in a new issue