From 7f0b4f3001575d1419c5020e007ce2c841c88f2f Mon Sep 17 00:00:00 2001 From: Jens Harbott Date: Mon, 1 Apr 2019 11:43:28 +0000 Subject: [PATCH] Fix double quoting issue when writing localconf When [0] introduced quoting all arguments, it broke existing consumers that already quote their value themselves. Fix this by avoiding to add additional quotes to the value when it already starts with a double quote. [0] https://review.openstack.org/636078 Change-Id: I92146e04731efc6dcc632ae6c3a7c374e783cdba Closes-Bug: 1822453 --- .../library/devstack_local_conf.py | 6 +++++- .../write-devstack-local-conf/library/test.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/roles/write-devstack-local-conf/library/devstack_local_conf.py b/roles/write-devstack-local-conf/library/devstack_local_conf.py index 3a8cd588b9..2f97d0e355 100644 --- a/roles/write-devstack-local-conf/library/devstack_local_conf.py +++ b/roles/write-devstack-local-conf/library/devstack_local_conf.py @@ -252,7 +252,11 @@ class LocalConf(object): if localrc: vg = VarGraph(localrc) for k, v in vg.getVars(): - self.localrc.append('{}="{}"'.format(k, v)) + # Avoid double quoting + if len(v) and v[0]=='"': + self.localrc.append('{}={}'.format(k, v)) + else: + self.localrc.append('{}="{}"'.format(k, v)) if k == 'LIBS_FROM_GIT': lfg = True elif k == 'TEMPEST_PLUGINS': diff --git a/roles/write-devstack-local-conf/library/test.py b/roles/write-devstack-local-conf/library/test.py index 22bf2da55d..7c526b34c8 100644 --- a/roles/write-devstack-local-conf/library/test.py +++ b/roles/write-devstack-local-conf/library/test.py @@ -187,6 +187,24 @@ class TestDevstackLocalConf(unittest.TestCase): lfg = line.strip().split('=')[1] self.assertEqual('"oslo.db"', lfg) + def test_avoid_double_quote(self): + "Test that there a no duplicated quotes" + localrc = {'TESTVAR': '"quoted value"'} + p = dict(localrc=localrc, + base_services=[], + base_dir='./test', + path=os.path.join(self.tmpdir, 'test.local.conf'), + projects={}) + lc = self._init_localconf(p) + lc.write(p['path']) + + testvar = None + with open(p['path']) as f: + for line in f: + if line.startswith('TESTVAR'): + testvar = line.strip().split('=')[1] + self.assertEqual('"quoted value"', testvar) + def test_plugin_circular_deps(self): "Test that plugins with circular dependencies fail" os.makedirs(os.path.join(self.tmpdir, 'foo-plugin', 'devstack'))