mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #33088 from isbm/isbm-zypper-fix-booleans
Bugfix: Restore boolean values from the repo configuration
This commit is contained in:
commit
6d604926d3
4 changed files with 40 additions and 7 deletions
|
@ -608,12 +608,14 @@ def _get_repo_info(alias, repos_cfg=None):
|
|||
Get one repo meta-data.
|
||||
'''
|
||||
try:
|
||||
ret = dict((repos_cfg or _get_configured_repos()).items(alias))
|
||||
ret['alias'] = alias
|
||||
for key, val in six.iteritems(ret):
|
||||
if val == 'NONE':
|
||||
ret[key] = None
|
||||
return ret
|
||||
meta = dict((repos_cfg or _get_configured_repos()).items(alias))
|
||||
meta['alias'] = alias
|
||||
for key, val in six.iteritems(meta):
|
||||
if val in ['0', '1']:
|
||||
meta[key] = int(meta[key]) == 1
|
||||
elif val == 'NONE':
|
||||
meta[key] = None
|
||||
return meta
|
||||
except (ValueError, configparser.NoSectionError):
|
||||
return {}
|
||||
|
||||
|
@ -781,7 +783,7 @@ def mod_repo(repo, **kwargs):
|
|||
cmd_opt.append('--gpg-auto-import-keys')
|
||||
|
||||
if 'priority' in kwargs:
|
||||
cmd_opt.append("--priority='{0}'".format(kwargs.get('priority', DEFAULT_PRIORITY)))
|
||||
cmd_opt.append("--priority={0}".format(kwargs.get('priority', DEFAULT_PRIORITY)))
|
||||
|
||||
if 'humanname' in kwargs:
|
||||
cmd_opt.append("--name='{0}'".format(kwargs.get('humanname')))
|
||||
|
|
5
tests/unit/modules/zypp/zypper-repo-1.cfg
Normal file
5
tests/unit/modules/zypp/zypper-repo-1.cfg
Normal file
|
@ -0,0 +1,5 @@
|
|||
[SLE12-SP1-x86_64-Update]
|
||||
enabled=1
|
||||
autorefresh=1
|
||||
baseurl=http://somehost.com/SUSE/Updates/SLE-SERVER/12-SP1/x86_64/update/
|
||||
type=NONE
|
5
tests/unit/modules/zypp/zypper-repo-2.cfg
Normal file
5
tests/unit/modules/zypp/zypper-repo-2.cfg
Normal file
|
@ -0,0 +1,5 @@
|
|||
[SLE12-SP1-x86_64-Update-disabled]
|
||||
enabled=0
|
||||
autorefresh=0
|
||||
baseurl=http://somehost.com/SUSE/Updates/SLE-SERVER/12-SP1/x86_64/update/
|
||||
type=NONE
|
|
@ -17,6 +17,8 @@ from salttesting.mock import (
|
|||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
import os
|
||||
from salt.ext.six.moves import configparser
|
||||
import StringIO
|
||||
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
|
||||
|
@ -391,6 +393,25 @@ class ZypperTestCase(TestCase):
|
|||
self.assertTrue(diff[pkg_name]['old'])
|
||||
self.assertFalse(diff[pkg_name]['new'])
|
||||
|
||||
def test_repo_value_info(self):
|
||||
'''
|
||||
Tests if repo info is properly parsed.
|
||||
|
||||
:return:
|
||||
'''
|
||||
repos_cfg = configparser.ConfigParser()
|
||||
for cfg in ['zypper-repo-1.cfg', 'zypper-repo-2.cfg']:
|
||||
repos_cfg.readfp(StringIO.StringIO(get_test_data(cfg)))
|
||||
|
||||
for alias in repos_cfg.sections():
|
||||
r_info = zypper._get_repo_info(alias, repos_cfg=repos_cfg)
|
||||
self.assertEqual(type(r_info['type']), type(None))
|
||||
self.assertEqual(type(r_info['enabled']), bool)
|
||||
self.assertEqual(type(r_info['autorefresh']), bool)
|
||||
self.assertEqual(type(r_info['baseurl']), str)
|
||||
self.assertEqual(r_info['type'], None)
|
||||
self.assertEqual(r_info['enabled'], alias == 'SLE12-SP1-x86_64-Update')
|
||||
self.assertEqual(r_info['autorefresh'], alias == 'SLE12-SP1-x86_64-Update')
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
|
Loading…
Add table
Reference in a new issue