Now user can update label values in cluster-template

In Magnum Labels are stored in the form of dictionary. previously we
are passing string value directly to store the value of label. Now we
are parsing it and storing it in the form of dictionary.

Change-Id: I4d64da78dc4ed4d5599533b54861b65bce609c28
Closes-Bug: #1638863
This commit is contained in:
M V P Nitesh 2017-08-22 12:38:06 +05:30 committed by Spyros Trigazis (strigazi)
parent 38e10514d3
commit 21c87f35a0
3 changed files with 29 additions and 0 deletions

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import ast
import jsonpatch
from oslo_utils import uuidutils
import pecan
@ -80,6 +81,14 @@ def apply_jsonpatch(doc, patch):
msg = _("The attribute %s has existed, please use "
"'replace' operation instead.") % p['path']
raise wsme.exc.ClientSideError(msg)
if p['op'] == 'replace' and p['path'] == '/labels':
try:
val = p['value']
dict_val = val if type(val) == dict else ast.literal_eval(val)
p['value'] = dict_val
except (SyntaxError, ValueError, AssertionError) as e:
raise exception.PatchError(patch=patch, reason=e)
return jsonpatch.apply_patch(doc, patch)

View File

@ -334,6 +334,19 @@ class TestPatch(api_base.FunctionalTest):
self.cluster_template.uuid)
self.assertEqual(response['public'], True)
def test_update_cluster_template_replace_labels_success(self):
cluster_template = obj_utils.create_test_cluster_template(self.context)
response = self.patch_json('/clustertemplates/%s' %
cluster_template.uuid,
[{'path': '/labels',
'value': '{\'etcd_volume_size\': \'1\'}',
'op': 'replace'}],
expect_errors=True)
self.assertEqual(200, response.status_int)
response = self.get_json('/clustertemplates/%s' %
self.cluster_template.uuid)
self.assertEqual(response['labels'], {'etcd_volume_size': '1'})
def test_update_cluster_template_with_cluster_not_allow_update(self):
cluster_template = obj_utils.create_test_cluster_template(self.context)
obj_utils.create_test_cluster(

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Now user can update labels in cluster-template. Previously string is
passed as a value to labels, but we know that labels can only hold
dictionary values. Now we are parsing the string and storing it as
dictionary for labels in cluster-template.