Esempio n. 1
0
    def test_repo_noadd_mod_ref(self):
        '''
        Test mod_repo detects the repo already exists,
        calls modify to update 'autorefresh' and refreshes the repo with
            `zypper --gpg-auto-import-keys refresh <repo-name>`

        :return:
        '''
        url = self.new_repo_config['url']
        name = self.new_repo_config['name']
        self.zypper_patcher_config['_get_configured_repos'] = Mock(
            **{'return_value.sections.return_value': [name]}
        )
        zypper_patcher = patch.multiple(
            'salt.modules.zypper', **self.zypper_patcher_config)

        with zypper_patcher:
            zypper.mod_repo(
                name,
                **{'url': url, 'refresh': True, 'gpgautoimport': True}
            )
            self.assertEqual(
                zypper.__zypper__.xml.call.call_args_list,
                [call('--gpg-auto-import-keys', 'refresh', name)]
            )
            zypper.__zypper__.refreshable.xml.call.assert_called_once_with(
                '--gpg-auto-import-keys', 'mr', '--refresh', name
            )
Esempio n. 2
0
    def test_repo_add_mod_ref(self):
        '''
        Test mod_repo adds the new repo,
        calls modify to update 'autorefresh' and refreshes the repo with
            `zypper --gpg-auto-import-keys refresh <repo-name>`

        :return:
        '''
        zypper_patcher = patch.multiple(
            'salt.modules.zypper', **self.zypper_patcher_config)

        url = self.new_repo_config['url']
        name = self.new_repo_config['name']
        with zypper_patcher:
            zypper.mod_repo(
                name,
                **{'url': url, 'refresh': True, 'gpgautoimport': True}
            )
            self.assertEqual(
                zypper.__zypper__.xml.call.call_args_list,
                [
                    call('ar', url, name),
                    call('--gpg-auto-import-keys', 'refresh', name)
                ]
            )
            zypper.__zypper__.refreshable.xml.call.assert_called_once_with(
                '--gpg-auto-import-keys', 'mr', '--refresh', name
            )
Esempio n. 3
0
 def test_autoremove(self):
     '''
     Test - Remove packages not required by another package.
     '''
     patch_kwargs = {
         '__salt__': {
             'config.get': MagicMock(return_value=True),
             'cmd.run': MagicMock(return_value=AUTOREMOVE)
         }
     }
     with patch.multiple(aptpkg, **patch_kwargs):
         self.assertEqual(aptpkg.autoremove(), dict())
         self.assertEqual(aptpkg.autoremove(purge=True), dict())
         self.assertEqual(aptpkg.autoremove(list_only=True), list())
         self.assertEqual(aptpkg.autoremove(list_only=True, purge=True), list())
Esempio n. 4
0
 def test_upgrade(self):
     '''
     Test - Upgrades all packages.
     '''
     mock_cmd = MagicMock(return_value={
         'retcode': 0,
         'stdout': UPGRADE
     })
     patch_kwargs = {
         '__salt__': {
             'config.get': MagicMock(return_value=True),
             'cmd.run_all': mock_cmd
         }
     }
     with patch.multiple(aptpkg, **patch_kwargs):
         self.assertEqual(aptpkg.upgrade(), dict())
Esempio n. 5
0
    def test_repo_add_nomod_noref(self):
        '''
        Test mod_repo adds the new repo and nothing else

        :return:
        '''
        zypper_patcher = patch.multiple('salt.modules.zypper',
                                        **self.zypper_patcher_config)

        url = self.new_repo_config['url']
        name = self.new_repo_config['name']
        with zypper_patcher:
            zypper.mod_repo(name, **{'url': url})
            self.assertEqual(zypper.__zypper__.xml.call.call_args_list,
                             [call('ar', url, name)])
            zypper.__zypper__.refreshable.xml.call.assert_not_called()
Esempio n. 6
0
    def test_repo_add_mod_noref(self):
        '''
        Test mod_repo adds the new repo and call modify to update autorefresh

        :return:
        '''
        zypper_patcher = patch.multiple('salt.modules.zypper',
                                        **self.zypper_patcher_config)

        url = self.new_repo_config['url']
        name = self.new_repo_config['name']
        with zypper_patcher:
            zypper.mod_repo(name, **{'url': url, 'refresh': True})
            self.assertEqual(zypper.__zypper__.xml.call.call_args_list,
                             [call('ar', url, name)])
            zypper.__zypper__.refreshable.xml.call.assert_called_once_with(
                'mr', '--refresh', name)
Esempio n. 7
0
    def test_repo_noadd_mod_noref(self):
        '''
        Test mod_repo detects the repository exists,
        calls modify to update 'autorefresh' but does not call refresh

        :return:
        '''
        url = self.new_repo_config['url']
        name = self.new_repo_config['name']
        self.zypper_patcher_config['_get_configured_repos'] = Mock(
            **{'return_value.sections.return_value': [name]})
        zypper_patcher = patch.multiple('salt.modules.zypper',
                                        **self.zypper_patcher_config)
        with zypper_patcher:
            zypper.mod_repo(name, **{'url': url, 'refresh': True})
            zypper.__zypper__.xml.call.assert_not_called()
            zypper.__zypper__.refreshable.xml.call.assert_called_once_with(
                'mr', '--refresh', name)
Esempio n. 8
0
    def test_repo_add_nomod_noref(self):
        '''
        Test mod_repo adds the new repo and nothing else

        :return:
        '''
        zypper_patcher = patch.multiple(
            'salt.modules.zypper', **self.zypper_patcher_config)

        url = self.new_repo_config['url']
        name = self.new_repo_config['name']
        with zypper_patcher:
            zypper.mod_repo(name, **{'url': url})
            self.assertEqual(
                zypper.__zypper__.xml.call.call_args_list,
                [call('ar', url, name)]
            )
            zypper.__zypper__.refreshable.xml.call.assert_not_called()
Esempio n. 9
0
    def test_repo_add_nomod_ref(self):
        '''
        Test mod_repo adds the new repo and refreshes the repo with
            `zypper --gpg-auto-import-keys refresh <repo-name>`

        :return:
        '''
        zypper_patcher = patch.multiple('salt.modules.zypper',
                                        **self.zypper_patcher_config)

        url = self.new_repo_config['url']
        name = self.new_repo_config['name']
        with zypper_patcher:
            zypper.mod_repo(name, **{'url': url, 'gpgautoimport': True})
            self.assertEqual(zypper.__zypper__.xml.call.call_args_list, [
                call('ar', url, name),
                call('--gpg-auto-import-keys', 'refresh', name)
            ])
            zypper.__zypper__.refreshable.xml.call.assert_not_called()
Esempio n. 10
0
    def test_repo_noadd_mod_noref(self):
        '''
        Test mod_repo detects the repository exists,
        calls modify to update 'autorefresh' but does not call refresh

        :return:
        '''
        url = self.new_repo_config['url']
        name = self.new_repo_config['name']
        self.zypper_patcher_config['_get_configured_repos'] = Mock(
            **{'return_value.sections.return_value': [name]})
        zypper_patcher = patch.multiple(
            'salt.modules.zypper', **self.zypper_patcher_config)
        with zypper_patcher:
            zypper.mod_repo(name, **{'url': url, 'refresh': True})
            zypper.__zypper__.xml.call.assert_not_called()
            zypper.__zypper__.refreshable.xml.call.assert_called_once_with(
                'mr', '--refresh', name
            )
Esempio n. 11
0
    def setUp(self):
        loader_module = getattr(self, 'loader_module', None)
        if loader_module is not None:
            if NO_MOCK:
                self.skipTest(NO_MOCK_REASON)

            loader_module_name = loader_module.__name__
            loader_module_globals = getattr(self, 'loader_module_globals', None)
            loader_module_blacklisted_dunders = getattr(self, 'loader_module_blacklisted_dunders', ())
            if loader_module_globals is None:
                loader_module_globals = {}
            elif callable(loader_module_globals):
                loader_module_globals = loader_module_globals()
            else:
                loader_module_globals = copy.deepcopy(loader_module_globals)

            salt_dunders = (
                '__opts__', '__salt__', '__runner__', '__context__', '__utils__',
                '__ext_pillar__', '__thorium__', '__states__', '__serializers__', '__ret__',
                '__grains__', '__pillar__', '__sdb__',
                # Proxy is commented out on purpose since some code in salt expects a NameError
                # and is most of the time not a required dunder
                # '__proxy__'
            )
            for dunder_name in salt_dunders:
                if dunder_name not in loader_module_globals:
                    if dunder_name in loader_module_blacklisted_dunders:
                        continue
                    loader_module_globals[dunder_name] = {}

            for key in loader_module_globals:
                if not hasattr(loader_module, key):
                    if key in salt_dunders:
                        setattr(loader_module, key, {})
                    else:
                        setattr(loader_module, key, None)

            if loader_module_globals:
                patcher = patch.multiple(loader_module_name, **loader_module_globals)
                patcher.start()
                self.addCleanup(patcher.stop)
        super(LoaderModuleMockMixin, self).setUp()
Esempio n. 12
0
    def test_repo_noadd_nomod_ref(self):
        '''
        Test mod_repo detects the repo already exists,
        has nothing to modify and refreshes the repo with
            `zypper --gpg-auto-import-keys refresh <repo-name>`

        :return:
        '''
        url = self.new_repo_config['url']
        name = self.new_repo_config['name']
        self.zypper_patcher_config['_get_configured_repos'] = Mock(
            **{'return_value.sections.return_value': [name]})
        zypper_patcher = patch.multiple('salt.modules.zypper',
                                        **self.zypper_patcher_config)

        with zypper_patcher:
            zypper.mod_repo(name, **{'url': url, 'gpgautoimport': True})
            self.assertEqual(zypper.__zypper__.xml.call.call_args_list,
                             [call('--gpg-auto-import-keys', 'refresh', name)])
            zypper.__zypper__.refreshable.xml.call.assert_not_called()
Esempio n. 13
0
    def test_repo_noadd_nomod_noref(self):
        '''
        Test mod_repo detects the repo already exists,
        no modification was requested and no refresh requested either

        :return:
        '''
        url = self.new_repo_config['url']
        name = self.new_repo_config['name']
        self.zypper_patcher_config['_get_configured_repos'] = Mock(
            **{'return_value.sections.return_value': [name]}
        )
        zypper_patcher = patch.multiple(
            'salt.modules.zypper', **self.zypper_patcher_config)

        with zypper_patcher:
            self.assertEqual(zypper.mod_repo(name, **{'url': url}),
                             {'comment': 'Specified arguments did not result in modification of repo'})
            zypper.__zypper__.xml.call.assert_not_called()
            zypper.__zypper__.refreshable.xml.call.assert_not_called()
Esempio n. 14
0
    def test_repo_add_mod_noref(self):
        '''
        Test mod_repo adds the new repo and call modify to update autorefresh

        :return:
        '''
        zypper_patcher = patch.multiple(
            'salt.modules.zypper', **self.zypper_patcher_config)

        url = self.new_repo_config['url']
        name = self.new_repo_config['name']
        with zypper_patcher:
            zypper.mod_repo(name, **{'url': url, 'refresh': True})
            self.assertEqual(
                zypper.__zypper__.xml.call.call_args_list,
                [call('ar', url, name)]
            )
            zypper.__zypper__.refreshable.xml.call.assert_called_once_with(
                'mr', '--refresh', name
            )
Esempio n. 15
0
    def test_repo_noadd_nomod_noref(self):
        '''
        Test mod_repo detects the repo already exists,
        no modification was requested and no refresh requested either

        :return:
        '''
        url = self.new_repo_config['url']
        name = self.new_repo_config['name']
        self.zypper_patcher_config['_get_configured_repos'] = Mock(
            **{'return_value.sections.return_value': [name]}
        )
        zypper_patcher = patch.multiple(
            'salt.modules.zypper', **self.zypper_patcher_config)

        with zypper_patcher:
            self.assertEqual(zypper.mod_repo(name, **{'url': url}),
                             {'comment': 'Specified arguments did not result in modification of repo'})
            zypper.__zypper__.xml.call.assert_not_called()
            zypper.__zypper__.refreshable.xml.call.assert_not_called()