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_noadd_modbaseurl_ref(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.side_effect': [[name], [], [], [name]]})
        zypper_patcher = patch.multiple('salt.modules.zypper',
                                        **self.zypper_patcher_config)

        with zypper_patcher:
            params = {'baseurl': url + "-changed", 'enabled': False}
            zypper.mod_repo(name, **params)
            expected_params = {
                'alias': 'mock-repo-name',
                'autorefresh': True,
                'baseurl': 'http://repo.url/some/path-changed',
                'enabled': False,
                'priority': 1,
                'cache': False,
                'keeppackages': False,
                'type': 'rpm-md'
            }
            assert zypper.mod_repo.call_count == 2
            assert zypper.mod_repo.mock_calls[1] == call(
                name, **expected_params)
Esempio n. 3
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. 4
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. 5
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:
            with self.assertRaisesRegexp(
                    Exception,
                    'Specified arguments did not result in modification of repo'
            ):
                zypper.mod_repo(name, **{'url': url})
            with self.assertRaisesRegexp(
                    Exception,
                    'Specified arguments did not result in modification of repo'
            ):
                zypper.mod_repo(name, **{'url': url, 'gpgautoimport': 'a'})

            zypper.__zypper__.xml.call.assert_not_called()
            zypper.__zypper__.refreshable.xml.call.assert_not_called()
Esempio n. 6
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. 7
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. 8
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. 9
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. 10
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. 11
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. 12
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. 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_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:
            out = zypper.mod_repo(name, alias='new-alias')
            self.assertEqual(
                out['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()