Merge "Unable to add classless-static-route in extra_dhcp_opt extension"

This commit is contained in:
Jenkins 2017-04-01 17:14:20 +00:00 committed by Gerrit Code Review
commit ef93a52c2b
2 changed files with 18 additions and 0 deletions

View File

@ -129,7 +129,18 @@ def str2dict(strdict, required_keys=None, optional_keys=None):
"""
result = {}
if strdict:
i = 0
kvlist = []
for kv in strdict.split(','):
if '=' in kv:
kvlist.append(kv)
i += 1
elif i == 0:
msg = _("missing value for key '%s'")
raise argparse.ArgumentTypeError(msg % kv)
else:
kvlist[i-1] = "%s,%s" % (kvlist[i-1], kv)
for kv in kvlist:
key, sep, value = kv.partition('=')
if not sep:
msg = _("invalid key-value '%s', expected format: key=value")

View File

@ -51,6 +51,13 @@ class TestUtils(testtools.TestCase):
self.assertRaises(argparse.ArgumentTypeError,
utils.str2dict, input_str)
def test_string_with_comma_value_to_dictionary(self):
input_str = ('opt_name=classless-static-route,'
'opt_value=169.254.169.254/32,10.0.0.1')
expected = {'opt_name': 'classless-static-route',
'opt_value': '169.254.169.254/32,10.0.0.1'}
self.assertEqual(expected, utils.str2dict(input_str))
def test_str2dict_optional_keys(self):
self.assertDictEqual({'key1': 'value1'},
utils.str2dict('key1=value1',