Append value using comma if key exists in label

Magnum allows "labels" to be Dict of string, but currently
magnumclient creates a list of values if same key is specified
more than once when creating a baymodel.
Now if two labels of same key are passed to baymodel-create
the first value is joined with second using comma.

Change-Id: Idcee5c27e29b8d6889fd2c9fa839202ffb8a2f4e
Closes-Bug: #1521461
This commit is contained in:
yatin
2016-08-06 22:39:32 +05:30
parent 6dba7bc6c3
commit eab1ba38ae
2 changed files with 2 additions and 6 deletions

View File

@@ -112,9 +112,7 @@ def format_labels(lbls, parse_comma=True):
if k not in labels:
labels[k] = v
else:
if not isinstance(labels[k], list):
labels[k] = [labels[k]]
labels[k].append(v)
labels[k] += ",%s" % v
return labels

View File

@@ -191,9 +191,7 @@ class FormatLabelsTest(test_utils.BaseTestCase):
l = utils.format_labels([
'K1=V1',
'K1=V2'])
self.assertIn('K1', l)
self.assertIn('V1', l['K1'])
self.assertIn('V2', l['K1'])
self.assertEqual({'K1': 'V1,V2'}, l)
def test_format_label_special_label(self):
labels = ['K1=V1,K22.2.2.2']