From eab1ba38ae45e353459ccfdc4882ccaae09c3b55 Mon Sep 17 00:00:00 2001 From: yatin Date: Sat, 6 Aug 2016 22:39:32 +0530 Subject: [PATCH] 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 --- magnumclient/common/utils.py | 4 +--- magnumclient/tests/test_utils.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/magnumclient/common/utils.py b/magnumclient/common/utils.py index 4c40bc3..9c26ac7 100644 --- a/magnumclient/common/utils.py +++ b/magnumclient/common/utils.py @@ -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 diff --git a/magnumclient/tests/test_utils.py b/magnumclient/tests/test_utils.py index d263201..7bef020 100644 --- a/magnumclient/tests/test_utils.py +++ b/magnumclient/tests/test_utils.py @@ -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']