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:
@@ -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
|
||||
|
||||
|
||||
@@ -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']
|
||||
|
||||
Reference in New Issue
Block a user