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:
parent
38e10514d3
commit
21c87f35a0
@ -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)
|
||||
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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.
|
Loading…
x
Reference in New Issue
Block a user