salt/0016-Bugfix-Restore-boolean-values-from-the-repo-configur.patch

119 lines
4.3 KiB
Diff

From e52b55979bdc0734c2e452dd2fd67fb56a3fb37b Mon Sep 17 00:00:00 2001
From: Bo Maryniuk <bo@suse.de>
Date: Fri, 6 May 2016 12:29:48 +0200
Subject: [PATCH 16/16] Bugfix: Restore boolean values from the repo
configuration
* Add test data for repos
* Add repo config test
* Bugfix (follow-up): setting priority requires non-positive integer
---
salt/modules/zypper.py | 16 +++++++++-------
tests/unit/modules/zypp/zypper-repo-1.cfg | 5 +++++
tests/unit/modules/zypp/zypper-repo-2.cfg | 5 +++++
tests/unit/modules/zypper_test.py | 21 +++++++++++++++++++++
4 files changed, 40 insertions(+), 7 deletions(-)
create mode 100644 tests/unit/modules/zypp/zypper-repo-1.cfg
create mode 100644 tests/unit/modules/zypp/zypper-repo-2.cfg
diff --git a/salt/modules/zypper.py b/salt/modules/zypper.py
index 53b5d9f..c37b382 100644
--- a/salt/modules/zypper.py
+++ b/salt/modules/zypper.py
@@ -602,12 +602,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 {}
@@ -769,7 +771,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')))
diff --git a/tests/unit/modules/zypp/zypper-repo-1.cfg b/tests/unit/modules/zypp/zypper-repo-1.cfg
new file mode 100644
index 0000000..958718c
--- /dev/null
+++ b/tests/unit/modules/zypp/zypper-repo-1.cfg
@@ -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
diff --git a/tests/unit/modules/zypp/zypper-repo-2.cfg b/tests/unit/modules/zypp/zypper-repo-2.cfg
new file mode 100644
index 0000000..f55cf18
--- /dev/null
+++ b/tests/unit/modules/zypp/zypper-repo-2.cfg
@@ -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
diff --git a/tests/unit/modules/zypper_test.py b/tests/unit/modules/zypper_test.py
index 16e8542..4e735cd 100644
--- a/tests/unit/modules/zypper_test.py
+++ b/tests/unit/modules/zypper_test.py
@@ -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
--
2.8.1