From 895e5095c35ffe5c9c9688339c5da05f437893d5 Mon Sep 17 00:00:00 2001 From: Feilong Wang Date: Tue, 25 Sep 2018 16:17:44 +1200 Subject: [PATCH] Limit cluster update properties Magnum only allows the node count of cluster being updated. And in mangum ui, cluster and cluster template are sharing same function to generating the patch json dict, which is causing lots of bugs before. So let's define a set for cluster update allowed properties and use it to restrict the patch json dict. Task: 26699 Story: 2003865 Change-Id: I2f0126fbf2f7396dda504b988ee11659824fcde8 --- magnum_ui/api/magnum.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/magnum_ui/api/magnum.py b/magnum_ui/api/magnum.py index 839c96de..6d406be8 100644 --- a/magnum_ui/api/magnum.py +++ b/magnum_ui/api/magnum.py @@ -35,6 +35,7 @@ CLUSTER_TEMPLATE_CREATE_ATTRS = cluster_templates.CREATION_ATTRIBUTES CLUSTER_CREATE_ATTRS = clusters.CREATION_ATTRIBUTES CERTIFICATE_CREATE_ATTRS = certificates.CREATION_ATTRIBUTES QUOTA_CREATION_ATTRIBUTES = quotas.CREATION_ATTRIBUTES +CLUSTER_UPDATE_ALLOWED_PROPERTIES = set(['/node_count']) def _cleanup_params(attrs, create, **params): @@ -138,6 +139,11 @@ def cluster_template_update(request, id, **kwargs): old = magnumclient(request).cluster_templates.get(id).to_dict() old = _cleanup_params(CLUSTER_TEMPLATE_CREATE_ATTRS, False, **old) patch = _create_patches(old, new) + # NOTE(flwang): Now Magnum only support updating the node count for + # cluster upddate action. So let's simplify it by only passing the + # /node_count dict which can avoid many potential bugs. + patch = [d for d in patch if d['path'] + in CLUSTER_UPDATE_ALLOWED_PROPERTIES] return magnumclient(request).cluster_templates.update(id, patch)