summaryrefslogtreecommitdiff
path: root/tests/unittests/test_handler/test_handler_yum_add_repo.py
diff options
context:
space:
mode:
authorDylan Perry <dylan.perry@messagemedia.com.au>2017-04-07 15:43:35 +1000
committerScott Moser <smoser@brickies.net>2017-04-21 15:45:40 -0400
commitd16632ad8dfd1844d265d93ab00b54d419626019 (patch)
tree19ba536395b2d80a7aa1b48dcdffa96d1de50170 /tests/unittests/test_handler/test_handler_yum_add_repo.py
parent2775622cda53da14d6609c864b5888d54c9b6eea (diff)
downloadvyos-cloud-init-d16632ad8dfd1844d265d93ab00b54d419626019.tar.gz
vyos-cloud-init-d16632ad8dfd1844d265d93ab00b54d419626019.zip
Fix yum repo config where keys contain array values
ConfigObj produces configuration files that are incompatible with yum if multiple values are listed for a configuration key. Switch to the builtin configparser, and ConfigParser (Python 2) which correctly handles this case. Add additional test case for array values in yum_repos definition LP: #1592150
Diffstat (limited to 'tests/unittests/test_handler/test_handler_yum_add_repo.py')
-rw-r--r--tests/unittests/test_handler/test_handler_yum_add_repo.py56
1 files changed, 50 insertions, 6 deletions
diff --git a/tests/unittests/test_handler/test_handler_yum_add_repo.py b/tests/unittests/test_handler/test_handler_yum_add_repo.py
index 3feba86c..4815bdb6 100644
--- a/tests/unittests/test_handler/test_handler_yum_add_repo.py
+++ b/tests/unittests/test_handler/test_handler_yum_add_repo.py
@@ -5,10 +5,13 @@ from cloudinit import util
from .. import helpers
-import configobj
+try:
+ from configparser import ConfigParser
+except ImportError:
+ from ConfigParser import ConfigParser
import logging
import shutil
-from six import BytesIO
+from six import StringIO
import tempfile
LOG = logging.getLogger(__name__)
@@ -54,9 +57,9 @@ class TestConfig(helpers.FilesystemMockingTestCase):
}
self.patchUtils(self.tmp)
cc_yum_add_repo.handle('yum_add_repo', cfg, None, LOG, [])
- contents = util.load_file("/etc/yum.repos.d/epel_testing.repo",
- decode=False)
- contents = configobj.ConfigObj(BytesIO(contents))
+ contents = util.load_file("/etc/yum.repos.d/epel_testing.repo")
+ parser = ConfigParser()
+ parser.readfp(StringIO(contents))
expected = {
'epel_testing': {
'name': 'Extra Packages for Enterprise Linux 5 - Testing',
@@ -67,6 +70,47 @@ class TestConfig(helpers.FilesystemMockingTestCase):
'gpgcheck': '1',
}
}
- self.assertEqual(expected, dict(contents))
+ for section in expected:
+ self.assertTrue(parser.has_section(section),
+ "Contains section {}".format(section))
+ for k, v in expected[section].items():
+ self.assertEqual(parser.get(section, k), v)
+
+ def test_write_config_array(self):
+ cfg = {
+ 'yum_repos': {
+ 'puppetlabs-products': {
+ 'name': 'Puppet Labs Products El 6 - $basearch',
+ 'baseurl':
+ 'http://yum.puppetlabs.com/el/6/products/$basearch',
+ 'gpgkey': [
+ 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs',
+ 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppet',
+ ],
+ 'enabled': True,
+ 'gpgcheck': True,
+ }
+ }
+ }
+ self.patchUtils(self.tmp)
+ cc_yum_add_repo.handle('yum_add_repo', cfg, None, LOG, [])
+ contents = util.load_file("/etc/yum.repos.d/puppetlabs_products.repo")
+ parser = ConfigParser()
+ parser.readfp(StringIO(contents))
+ expected = {
+ 'puppetlabs_products': {
+ 'name': 'Puppet Labs Products El 6 - $basearch',
+ 'baseurl': 'http://yum.puppetlabs.com/el/6/products/$basearch',
+ 'gpgkey': 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs\n'
+ 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppet',
+ 'enabled': '1',
+ 'gpgcheck': '1',
+ }
+ }
+ for section in expected:
+ self.assertTrue(parser.has_section(section),
+ "Contains section {}".format(section))
+ for k, v in expected[section].items():
+ self.assertEqual(parser.get(section, k), v)
# vi: ts=4 expandtab