diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-10-11 18:48:50 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-10-11 18:48:50 -0700 |
commit | 66f6d2d4fd1e8c1b397c9533ee0596d7b09e9824 (patch) | |
tree | c0deb0a9c6c973d1ca24b0835b037f399b992195 /tests/unittests/test_distros | |
parent | 059a4c45ab2b4439872d138452d6296bfe82be07 (diff) | |
download | vyos-cloud-init-66f6d2d4fd1e8c1b397c9533ee0596d7b09e9824.tar.gz vyos-cloud-init-66f6d2d4fd1e8c1b397c9533ee0596d7b09e9824.zip |
Update to use pipes.quote to ensure that
variables adjusted in sysconfig files are
properly quoted for there common use case,
that being sourced into shell scripts.
Diffstat (limited to 'tests/unittests/test_distros')
-rw-r--r-- | tests/unittests/test_distros/test_sysconfig.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/tests/unittests/test_distros/test_sysconfig.py b/tests/unittests/test_distros/test_sysconfig.py index 196d090d..a07a251e 100644 --- a/tests/unittests/test_distros/test_sysconfig.py +++ b/tests/unittests/test_distros/test_sysconfig.py @@ -1,5 +1,7 @@ from mocker import MockerTestCase +import re + from cloudinit.distros.parsers.sys_conf import SysConf @@ -7,6 +9,11 @@ from cloudinit.distros.parsers.sys_conf import SysConf # http://content.hccfl.edu/pollock/AUnix1/SysconfigFilesDesc.txt class TestSysConfHelper(MockerTestCase): + def assertRegexpMatches(self, text, regexp): + regexp = re.compile(regexp) + self.assertTrue(regexp.search(text), + msg="%s must match %s!" % (text, regexp.pattern)) + def test_parse_no_change(self): contents = '''# A comment USESMBAUTH=no @@ -16,8 +23,8 @@ HOSTNAME=blahblah NETMASK0=255.255.255.0 # Inline comment LIST=$LOGROOT/incremental-list -IPV6TO4_ROUTING="eth0-:0004::1/64 eth1-:0005::1/64" -ETHTOOL_OPTS="-K ${DEVICE} tso on; -G ${DEVICE} rx 256 tx 256" +IPV6TO4_ROUTING='eth0-:0004::1/64 eth1-:0005::1/64' +ETHTOOL_OPTS='-K ${DEVICE} tso on; -G ${DEVICE} rx 256 tx 256' USEMD5=no''' conf = SysConf(contents.splitlines()) self.assertEquals(conf['HOSTNAME'], 'blahblah') @@ -25,6 +32,7 @@ USEMD5=no''' # Should be unquoted self.assertEquals(conf['ETHTOOL_OPTS'], ('-K ${DEVICE} tso on; ' '-G ${DEVICE} rx 256 tx 256')) + # This is harmless convertion self.assertEquals(contents, str(conf)) def test_parse_adjust(self): @@ -36,7 +44,7 @@ USEMD5=no''' conf['IPV6TO4_ROUTING'] = "blah \tblah" contents2 = str(conf).strip() # Should be requoted due to whitespace - self.assertEquals('IPV6TO4_ROUTING="blah \tblah"', contents2) + self.assertRegexpMatches(contents2, r'IPV6TO4_ROUTING=["\']blah \tblah["\']') def test_parse_no_adjust_shell(self): conf = SysConf(''.splitlines()) |