Fix quoting for devstack_localrc arguments

This is a combination of the following commits:
- "Quote devstack_localrc arguments"
  https://review.opendev.org/636078
  Ia63a53d745dfea7262bcdb5d46425f431c3ccfe5
- "Fix double quoting issue when writing localconf"
  https://review.opendev.org/648951
  I92146e04731efc6dcc632ae6c3a7c374e783cdba

They have been merged together because the first commit introduces
a bug, and it looks a bit pointless to deliberately introduce
a potentially breaking change on the process of backporting a fix.

Co-Authored-By: Ian Wienand <iwienand@redhat.com>
Co-Authored-By: Jens Harbott <j.harbott@x-ion.de>

Change-Id: Ia703af54a7131843fc2b0ae34efcfe0f5507acbf
This commit is contained in:
Ian Wienand 2019-08-01 10:22:44 +02:00 committed by Luigi Toscano
parent fb3b6e4baa
commit 2e1393621a
2 changed files with 25 additions and 3 deletions

View File

@ -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':

View File

@ -185,7 +185,25 @@ class TestDevstackLocalConf(unittest.TestCase):
for line in f:
if line.startswith('LIBS_FROM_GIT'):
lfg = line.strip().split('=')[1]
self.assertEqual('oslo.db', lfg)
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"
@ -265,7 +283,7 @@ class TestDevstackLocalConf(unittest.TestCase):
lc.write(p['path'])
tp = self._find_tempest_plugins_value(p['path'])
self.assertEqual('someplugin', tp)
self.assertEqual('"someplugin"', tp)
self.assertEqual(len(lc.warnings), 1)