Ejemplo n.º 1
0
    def test_upgrade_success(self):
        '''
        Test system upgrade and dist-upgrade success.

        :return:
        '''
        with patch.dict(zypper.__grains__, {'osrelease_info': [12, 1]}), \
                patch('salt.modules.zypper.refresh_db', MagicMock(return_value=True)), \
                patch('salt.modules.zypper._systemd_scope', MagicMock(return_value=False)):
            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.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.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)
                    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.1"}])):
                    ret = zypper.upgrade(dist_upgrade=True, dryrun=True, fromrepo=["Dummy", "Dummy2"], novendorchange=True)
                    zypper_mock.assert_any_call('dist-upgrade', '--auto-agree-with-licenses', '--dry-run', '--from', "Dummy", '--from', 'Dummy2', '--no-allow-vendor-change')
                    zypper_mock.assert_any_call('dist-upgrade', '--auto-agree-with-licenses', '--dry-run', '--from', "Dummy", '--from', 'Dummy2', '--no-allow-vendor-change', '--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.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')
Ejemplo n.º 2
0
    def test_upgrade_success(self):
        '''
        Test system upgrade and dist-upgrade success.

        :return:
        '''
        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.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.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)
                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.1"}])):
                ret = zypper.upgrade(dist_upgrade=True, dryrun=True, fromrepo=["Dummy", "Dummy2"], novendorchange=True)
                zypper_mock.assert_any_call('dist-upgrade', '--auto-agree-with-licenses', '--dry-run', '--from', "Dummy", '--from', 'Dummy2', '--no-allow-vendor-change')
                zypper_mock.assert_any_call('dist-upgrade', '--auto-agree-with-licenses', '--dry-run', '--from', "Dummy", '--from', 'Dummy2', '--no-allow-vendor-change', '--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.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')
Ejemplo n.º 3
0
    def test_upgrade_failure(self):
        '''
        Test system upgrade failure.

        :return:
        '''
        zypper_out = '''
Loading repository data...
Reading installed packages...
Computing distribution upgrade...
Use 'zypper repos' to get the list of defined repositories.
Repository 'DUMMY' not found by its alias, number, or URI.
'''

        class FailingZypperDummy(object):
            def __init__(self):
                self.stdout = zypper_out
                self.stderr = ""
                self.pid = 1234
                self.exit_code = 555
                self.noraise = MagicMock()
                self.SUCCESS_EXIT_CODES = [0]

            def __call__(self, *args, **kwargs):
                return self

        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"}])):
                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')
Ejemplo n.º 4
0
    def test_upgrade_failure(self):
        '''
        Test system upgrade failure.

        :return:
        '''
        zypper_out = '''
Loading repository data...
Reading installed packages...
Computing distribution upgrade...
Use 'zypper repos' to get the list of defined repositories.
Repository 'DUMMY' not found by its alias, number, or URI.
'''

        class FailingZypperDummy(object):
            def __init__(self):
                self.stdout = zypper_out
                self.stderr = ""
                self.pid = 1234
                self.exit_code = 555
                self.noraise = MagicMock()
                self.SUCCESS_EXIT_CODES = [0]

            def __call__(self, *args, **kwargs):
                return self

        with patch.dict(zypper.__grains__, {'osrelease_info': [12, 1]}):
            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"}])):
                    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')
Ejemplo n.º 5
0
    def test_upgrade_failure(self):
        '''
        Test system upgrade failure.

        :return:
        '''
        zypper_out = '''
Loading repository data...
Reading installed packages...
Computing distribution upgrade...
Use 'zypper repos' to get the list of defined repositories.
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.noraise = MagicMock()
                self.SUCCESS_EXIT_CODES = [0]

            def __call__(self, *args, **kwargs):
                return self

        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'], {})
                zypper_mock.noraise.call.assert_called_with(
                    'dist-upgrade', '--auto-agree-with-licenses', '--from',
                    'DUMMY')
Ejemplo n.º 6
0
    def test_upgrade_success(self):
        '''
        Test system upgrade and dist-upgrade success.

        :return:
        '''
        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"
                                     }})
                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"
                                     }})
                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"
                                     }})
                zypper_mock.assert_any_call('dist-upgrade',
                                            '--auto-agree-with-licenses',
                                            '--from', "Dummy", '--from',
                                            'Dummy2',
                                            '--no-allow-vendor-change')