6fe4934941
see https://docs.saltstack.com/en/latest/topics/releases/2016.3.0.html * backwards-incompatible changes: - The default path for the extension_modules master config option has been changed. - add 0014-Fix-crashing-Maintenence-process.patch see release notes OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=71
326 lines
12 KiB
Diff
326 lines
12 KiB
Diff
From 9d5f4b9de1a98890d5cdccbc2672d7ac720f3af2 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Mihai=20Dinc=C4=83?= <dincamihai@users.noreply.github.com>
|
|
Date: Mon, 23 May 2016 23:15:29 +0200
|
|
Subject: [PATCH 12/13] Fix pkgrepo.managed gpgkey argument (bsc#979448)
|
|
|
|
* Call zypper refresh after adding/modifying a repository
|
|
|
|
* Calling `zypper --gpg-auto-import-keys refresh` is required after
|
|
adding/modifying a repository because `--gpg-auto-import-keys` doesn't
|
|
do anything when called with `zypper ar` or `zypper mr`.
|
|
Without calling `zypper --gpg-auto-import-keys refresh` here, calling
|
|
`zypper ref` after adding/removing would still ask for
|
|
accepting/rejecting the gpg key.
|
|
|
|
* Update test method names to pass pylint
|
|
|
|
* Reduce dicts and lists to one line where possible
|
|
|
|
* Reverse if conditions and rename variable
|
|
|
|
* Assert only gpgautoimport: True works
|
|
|
|
* Improve zypper_patcher_config looks
|
|
|
|
* DRY test
|
|
---
|
|
salt/modules/zypper.py | 24 +++--
|
|
tests/unit/modules/zypper_test.py | 213 ++++++++++++++++++++++++++++++++++++++
|
|
2 files changed, 229 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/salt/modules/zypper.py b/salt/modules/zypper.py
|
|
index 03ca6e6a1fcd..b42eec824ccb 100644
|
|
--- a/salt/modules/zypper.py
|
|
+++ b/salt/modules/zypper.py
|
|
@@ -770,6 +770,8 @@ def mod_repo(repo, **kwargs):
|
|
|
|
# Modify added or existing repo according to the options
|
|
cmd_opt = []
|
|
+ global_cmd_opt = []
|
|
+ call_refresh = False
|
|
|
|
if 'enabled' in kwargs:
|
|
cmd_opt.append(kwargs['enabled'] and '--enable' or '--disable')
|
|
@@ -785,21 +787,27 @@ def mod_repo(repo, **kwargs):
|
|
if 'gpgcheck' in kwargs:
|
|
cmd_opt.append(kwargs['gpgcheck'] and '--gpgcheck' or '--no-gpgcheck')
|
|
|
|
- if kwargs.get('gpgautoimport') is True:
|
|
- cmd_opt.append('--gpg-auto-import-keys')
|
|
-
|
|
if 'priority' in kwargs:
|
|
cmd_opt.append("--priority={0}".format(kwargs.get('priority', DEFAULT_PRIORITY)))
|
|
|
|
if 'humanname' in kwargs:
|
|
cmd_opt.append("--name='{0}'".format(kwargs.get('humanname')))
|
|
|
|
- if cmd_opt:
|
|
- cmd_opt.append(repo)
|
|
- __zypper__.refreshable.xml.call('mr', *cmd_opt)
|
|
+ if kwargs.get('gpgautoimport') is True:
|
|
+ global_cmd_opt.append('--gpg-auto-import-keys')
|
|
+ call_refresh = True
|
|
|
|
- # If repo nor added neither modified, error should be thrown
|
|
- if not added and not cmd_opt:
|
|
+ if cmd_opt:
|
|
+ cmd_opt = global_cmd_opt + ['mr'] + cmd_opt + [repo]
|
|
+ __zypper__.refreshable.xml.call(*cmd_opt)
|
|
+
|
|
+ if call_refresh:
|
|
+ # when used with "zypper ar --refresh" or "zypper mr --refresh"
|
|
+ # --gpg-auto-import-keys is not doing anything
|
|
+ # so we need to specifically refresh here with --gpg-auto-import-keys
|
|
+ refresh_opts = global_cmd_opt + ['refresh'] + [repo]
|
|
+ __zypper__.xml.call(*refresh_opts)
|
|
+ elif not added and not cmd_opt:
|
|
raise CommandExecutionError(
|
|
'Specified arguments did not result in modification of repo'
|
|
)
|
|
diff --git a/tests/unit/modules/zypper_test.py b/tests/unit/modules/zypper_test.py
|
|
index 9ec2b83deb4f..c4f7597bb96c 100644
|
|
--- a/tests/unit/modules/zypper_test.py
|
|
+++ b/tests/unit/modules/zypper_test.py
|
|
@@ -9,7 +9,9 @@ from __future__ import absolute_import
|
|
# Import Salt Testing Libs
|
|
from salttesting import TestCase, skipIf
|
|
from salttesting.mock import (
|
|
+ Mock,
|
|
MagicMock,
|
|
+ call,
|
|
patch,
|
|
NO_MOCK,
|
|
NO_MOCK_REASON
|
|
@@ -54,10 +56,26 @@ zypper.rpm = None
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
|
class ZypperTestCase(TestCase):
|
|
+
|
|
'''
|
|
Test cases for salt.modules.zypper
|
|
'''
|
|
|
|
+ def setUp(self):
|
|
+ self.new_repo_config = dict(
|
|
+ name='mock-repo-name',
|
|
+ url='http://repo.url/some/path'
|
|
+ )
|
|
+ side_effect = [
|
|
+ Mock(**{'sections.return_value': []}),
|
|
+ Mock(**{'sections.return_value': [self.new_repo_config['name']]})
|
|
+ ]
|
|
+ self.zypper_patcher_config = {
|
|
+ '_get_configured_repos': Mock(side_effect=side_effect),
|
|
+ '__zypper__': Mock(),
|
|
+ 'get_repo': Mock()
|
|
+ }
|
|
+
|
|
def test_list_upgrades(self):
|
|
'''
|
|
List package upgrades
|
|
@@ -438,6 +456,201 @@ class ZypperTestCase(TestCase):
|
|
self.assertEqual(r_info['enabled'], alias == 'SLE12-SP1-x86_64-Update')
|
|
self.assertEqual(r_info['autorefresh'], alias == 'SLE12-SP1-x86_64-Update')
|
|
|
|
+ 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()
|
|
+
|
|
+ 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()
|
|
+
|
|
+ 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
|
|
+ )
|
|
+
|
|
+ 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
|
|
+ )
|
|
+
|
|
+ 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()
|
|
+
|
|
+ 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()
|
|
+
|
|
+ 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
|
|
+ )
|
|
+
|
|
+ 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
|
|
+ )
|
|
+
|
|
if __name__ == '__main__':
|
|
from integration import run_tests
|
|
run_tests(ZypperTestCase, needs_daemon=False)
|
|
--
|
|
2.8.3
|
|
|