diff --git a/magnumclient/common/utils.py b/magnumclient/common/utils.py index 57ce02e9..af5642fa 100644 --- a/magnumclient/common/utils.py +++ b/magnumclient/common/utils.py @@ -78,7 +78,13 @@ def args_array_to_patch(op, attributes): attr = '/' + attr if op in ['add', 'replace']: path, value = split_and_deserialize(attr) - patch.append({'op': op, 'path': path, 'value': value}) + if path == "/labels": + a = [] + a.append(value) + value = str(handle_labels(a)) + patch.append({'op': op, 'path': path, 'value': value}) + else: + patch.append({'op': op, 'path': path, 'value': value}) elif op == "remove": # For remove only the key is needed diff --git a/magnumclient/tests/v1/test_clustertemplates_shell.py b/magnumclient/tests/v1/test_clustertemplates_shell.py index bb53ff67..67bce87a 100644 --- a/magnumclient/tests/v1/test_clustertemplates_shell.py +++ b/magnumclient/tests/v1/test_clustertemplates_shell.py @@ -679,6 +679,15 @@ class ShellTest(shell_test_base.TestCommandLineArgument): {'op': 'add', 'path': '/test1', 'value': 'test1'}] mock_update.assert_called_once_with('test', patch) + @mock.patch( + 'magnumclient.v1.cluster_templates.ClusterTemplateManager.update') + def test_cluster_template_update_label(self, mock_update): + self._test_arg_success('cluster-template-update test ' + 'replace labels=key1=val1') + patch = [{'op': 'replace', 'path': '/labels', + 'value': "{'key1': 'val1'}"}] + mock_update.assert_called_once_with('test', patch) + @mock.patch( 'magnumclient.v1.cluster_templates.ClusterTemplateManager.update') def test_cluster_template_update_failure_wrong_op(self, mock_update):