From eb60a2a128cd59fd675d726e61434f250da33cab Mon Sep 17 00:00:00 2001 From: Kirill Bespalov Date: Thu, 19 Jan 2017 09:03:58 +0300 Subject: [flavor update] Fixing a flavor comparation issue A flavor attributes keys from UpdateFlavorInfo.contributes does not match with attributes of flavor instance which returned by novaclient. swap_mb != swap, memory_mb != ram, etc so, is_equals() method always return False. Change-Id: Ic1c2b83fdcca6b7eab9e3b964b8d9becbdca2d3c --- .../dashboards/admin/flavors/workflows.py | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/openstack_dashboard/dashboards/admin/flavors/workflows.py b/openstack_dashboard/dashboards/admin/flavors/workflows.py index eff2d74f6..1642bf9f5 100644 --- a/openstack_dashboard/dashboards/admin/flavors/workflows.py +++ b/openstack_dashboard/dashboards/admin/flavors/workflows.py @@ -298,11 +298,14 @@ class UpdateFlavor(workflows.Workflow): flavor_projects = data["flavor_access"] is_public = not flavor_projects - def is_equals(a, b, keys): - for k in keys: - if getattr(a, k, None) != getattr(b, k, None): - return False - return True + def is_changed(flavor): + return not (data['name'] == flavor.name and + data['memory_mb'] == flavor.ram and + data['vcpus'] == flavor.vcpus and + data['disk_gb'] == flavor.disk and + data['swap_mb'] == (flavor.swap or 0) and + data['rxtx_factor'] == flavor.rxtx_factor and + data['eph_gb'] == flavor.ephemeral) def setup_access(): for project in flavor_projects: @@ -312,20 +315,17 @@ class UpdateFlavor(workflows.Workflow): # Update flavor information try: - flavor_id = data['flavor_id'] flavor = api.nova.flavor_get(self.request, flavor_id) # Check if the flavor info is not actually changed - if is_equals(flavor, data, UpdateFlavorInfo.contributes): - if is_public: - return True - else: - # In this case info like cpu, ram, etc not changed - # so, just set the access without any flavor changing - # this behavior coincides with nova cli + if not is_changed(flavor): + try: setup_access() - return True + except Exception: + exceptions.handle(request, + _('Unable to modify flavor access.')) + return True # Grab any existing extra specs, because flavor edit is currently # implemented as a delete followed by a create. -- cgit v1.2.1