Make --gpg-auto-import-keys a global param when calling zypper (#33432)

This commit is contained in:
Mihai Dincă 2016-05-23 23:15:29 +02:00 committed by Mike Place
parent 0c4e38ced4
commit c8b4f338d8
2 changed files with 40 additions and 5 deletions

View file

@ -766,6 +766,7 @@ def mod_repo(repo, **kwargs):
# Modify added or existing repo according to the options
cmd_opt = []
global_cmd_opt = []
if 'enabled' in kwargs:
cmd_opt.append(kwargs['enabled'] and '--enable' or '--disable')
@ -779,18 +780,18 @@ 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 kwargs.get('gpgautoimport') is True:
global_cmd_opt.append('--gpg-auto-import-keys')
if cmd_opt:
cmd_opt.append(repo)
__zypper__.refreshable.xml.call('mr', *cmd_opt)
cmd_opt = global_cmd_opt + ['mr'] + cmd_opt + [repo]
__zypper__.refreshable.xml.call(*cmd_opt)
# If repo nor added neither modified, error should be thrown
if not added and not cmd_opt:

View file

@ -9,6 +9,7 @@ from __future__ import absolute_import
# Import Salt Testing Libs
from salttesting import TestCase, skipIf
from salttesting.mock import (
Mock,
MagicMock,
patch,
NO_MOCK,
@ -413,6 +414,39 @@ 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_modify_repo_gpg_auto_import_keys_parameter_position(self):
'''
Tests if when modifying a repo, --gpg-auto-import-keys is a global option
:return:
'''
zypper_patcher = patch.multiple(
'salt.modules.zypper',
**{
'_get_configured_repos': Mock(
**{
'return_value.sections.return_value': ['mock-repo-name']
}
),
'__zypper__': Mock(),
'get_repo': Mock()
}
)
with zypper_patcher:
zypper.mod_repo(
'mock-repo-name',
**{
'disabled': False,
'url': 'http://repo.url/some/path',
'gpgkey': 'http://repo.key',
'refresh': True,
'gpgautoimport': True
}
)
zypper.__zypper__.refreshable.xml.call.assert_called_once_with(
'--gpg-auto-import-keys', 'mr', '--refresh', 'mock-repo-name'
)
if __name__ == '__main__':
from integration import run_tests
run_tests(ZypperTestCase, needs_daemon=False)