Browse Source

Now cluster-template-update works for "labels"

Now we are handling the label values converting them as a dictionary.
But as magnum-api only accepts the input as string. We are converting
the dictionary into string and passing to magnum-api. It is parsing
the string to dictionary and storing the label value a dictionary.

Change-Id: I2cec19e24c6dd32e209ca65a26a2f1999d8289e0
Depends-on: I4d64da78dc4ed4d5599533b54861b65bce609c28
Closes-Bug: #1659189
tags/2.10.0
M V P Nitesh 1 year ago
parent
commit
c165071ff8

+ 7
- 1
magnumclient/common/utils.py View File

@@ -78,7 +78,13 @@ def args_array_to_patch(op, attributes):
78 78
             attr = '/' + attr
79 79
         if op in ['add', 'replace']:
80 80
             path, value = split_and_deserialize(attr)
81
-            patch.append({'op': op, 'path': path, 'value': value})
81
+            if path == "/labels":
82
+                a = []
83
+                a.append(value)
84
+                value = str(handle_labels(a))
85
+                patch.append({'op': op, 'path': path, 'value': value})
86
+            else:
87
+                patch.append({'op': op, 'path': path, 'value': value})
82 88
 
83 89
         elif op == "remove":
84 90
             # For remove only the key is needed

+ 9
- 0
magnumclient/tests/v1/test_clustertemplates_shell.py View File

@@ -679,6 +679,15 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
679 679
                  {'op': 'add', 'path': '/test1', 'value': 'test1'}]
680 680
         mock_update.assert_called_once_with('test', patch)
681 681
 
682
+    @mock.patch(
683
+        'magnumclient.v1.cluster_templates.ClusterTemplateManager.update')
684
+    def test_cluster_template_update_label(self, mock_update):
685
+        self._test_arg_success('cluster-template-update test '
686
+                               'replace labels=key1=val1')
687
+        patch = [{'op': 'replace', 'path': '/labels',
688
+                 'value': "{'key1': 'val1'}"}]
689
+        mock_update.assert_called_once_with('test', patch)
690
+
682 691
     @mock.patch(
683 692
         'magnumclient.v1.cluster_templates.ClusterTemplateManager.update')
684 693
     def test_cluster_template_update_failure_wrong_op(self, mock_update):

Loading…
Cancel
Save