Fix Zypper module and tests for Carbon

This commit is contained in:
Pablo Suárez Hernández 2016-10-25 11:07:19 +01:00
parent f3e2148f94
commit 32f44b43ee
2 changed files with 14 additions and 17 deletions

View File

@ -1171,6 +1171,7 @@ def upgrade(refresh=True,
old = list_pkgs()
__zypper__(systemd_scope=_systemd_scope()).noraise.call(*cmd_update)
__context__.pop('pkg.list_pkgs', None)
new = list_pkgs()
ret = salt.utils.compare_dicts(old, new)
@ -1187,8 +1188,8 @@ def upgrade(refresh=True,
info={'changes': ret, 'result': result}
)
if dryrun or not ret['result']:
ret['comment'] = (__zypper__.stdout() + os.linesep + __zypper__.stderr()).strip()
if dryrun:
ret = (__zypper__.stdout + os.linesep + __zypper__.stderr).strip()
return ret

View File

@ -356,27 +356,22 @@ class ZypperTestCase(TestCase):
with patch('salt.modules.zypper.__zypper__.noraise.call', MagicMock()) as zypper_mock:
with patch('salt.modules.zypper.list_pkgs', MagicMock(side_effect=[{"vim": "1.1"}, {"vim": "1.2"}])):
ret = zypper.upgrade()
self.assertTrue(ret['result'])
self.assertDictEqual(ret['changes'], {"vim": {"old": "1.1", "new": "1.2"}})
self.assertDictEqual(ret, {"vim": {"old": "1.1", "new": "1.2"}})
zypper_mock.assert_any_call('update', '--auto-agree-with-licenses')
with patch('salt.modules.zypper.list_pkgs', MagicMock(side_effect=[{"vim": "1.1"}, {"vim": "1.2"}])):
ret = zypper.upgrade(dist_upgrade=True)
self.assertTrue(ret['result'])
self.assertDictEqual(ret['changes'], {"vim": {"old": "1.1", "new": "1.2"}})
self.assertDictEqual(ret, {"vim": {"old": "1.1", "new": "1.2"}})
zypper_mock.assert_any_call('dist-upgrade', '--auto-agree-with-licenses')
with patch('salt.modules.zypper.list_pkgs', MagicMock(side_effect=[{"vim": "1.1"}, {"vim": "1.1"}])):
ret = zypper.upgrade(dist_upgrade=True, dryrun=True)
self.assertTrue(ret['result'])
self.assertDictEqual(ret['changes'], {})
zypper_mock.assert_any_call('dist-upgrade', '--auto-agree-with-licenses', '--dry-run')
zypper_mock.assert_any_call('dist-upgrade', '--auto-agree-with-licenses', '--dry-run', '--debug-solver')
with patch('salt.modules.zypper.list_pkgs', MagicMock(side_effect=[{"vim": "1.1"}, {"vim": "1.2"}])):
ret = zypper.upgrade(dist_upgrade=True, fromrepo=["Dummy", "Dummy2"], novendorchange=True)
self.assertTrue(ret['result'])
self.assertDictEqual(ret['changes'], {"vim": {"old": "1.1", "new": "1.2"}})
self.assertDictEqual(ret, {"vim": {"old": "1.1", "new": "1.2"}})
zypper_mock.assert_any_call('dist-upgrade', '--auto-agree-with-licenses', '--from', "Dummy", '--from', 'Dummy2', '--no-allow-vendor-change')
@patch('salt.modules.zypper.refresh_db', MagicMock(return_value=True))
@ -398,9 +393,10 @@ Repository 'DUMMY' not found by its alias, number, or URI.
class FailingZypperDummy(object):
def __init__(self):
self.stdout = MagicMock(return_value=zypper_out)
self.stderr = MagicMock(return_value="")
self.exit_code = MagicMock(return_value=555)
self.stdout = zypper_out
self.stderr = ""
self.pid = 1234
self.exit_code = 555
self.noraise = MagicMock()
self.SUCCESS_EXIT_CODES = [0]
@ -410,10 +406,10 @@ Repository 'DUMMY' not found by its alias, number, or URI.
with patch('salt.modules.zypper.__zypper__', FailingZypperDummy()) as zypper_mock:
zypper_mock.noraise.call = MagicMock()
with patch('salt.modules.zypper.list_pkgs', MagicMock(side_effect=[{"vim": "1.1"}, {"vim": "1.1"}])):
ret = zypper.upgrade(dist_upgrade=True, fromrepo=["DUMMY"])
self.assertFalse(ret['result'])
self.assertEqual(ret['comment'], zypper_out.strip())
self.assertDictEqual(ret['changes'], {})
with self.assertRaises(CommandExecutionError) as cmd_exc:
ret = zypper.upgrade(dist_upgrade=True, fromrepo=["DUMMY"])
self.assertEqual(cmd_exc.exception.info['changes'], {})
self.assertEqual(cmd_exc.exception.info['result']['stdout'], zypper_out)
zypper_mock.noraise.call.assert_called_with('dist-upgrade', '--auto-agree-with-licenses', '--from', 'DUMMY')
@patch('salt.modules.zypper.refresh_db', MagicMock(return_value=True))