From ec2805db426cc8a1817d3d0339dfd42cc2279b50 Mon Sep 17 00:00:00 2001 From: Xicheng Chang Date: Thu, 10 Dec 2015 15:11:15 -0800 Subject: [PATCH] Enable patched_roles cleanup after patch action is sent. Change-Id: I34b73e6725455a70912272e744d5f85586ffe8e8 --- compass/actions/patch.py | 10 ++++++++++ compass/db/api/cluster.py | 3 ++- compass/db/models.py | 19 ++++++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/compass/actions/patch.py b/compass/actions/patch.py index 80082e19..6d29be67 100644 --- a/compass/actions/patch.py +++ b/compass/actions/patch.py @@ -15,6 +15,7 @@ """Module to patch an existing cluster """ import logging +import simplejson as json from compass.actions import util from compass.db.api import cluster as cluster_db @@ -56,4 +57,13 @@ def patch(cluster_id, username=None): patch_successful = False if patch_successful: + clean_payload = '{"patched_roles": []}' + clean_payload = json.loads(clean_payload) + for cluster_host in cluster_hosts: + cluster_db.update_cluster_host( + cluster_id, cluster_host['id'], user, **clean_payload) + logging.info( + "cleaning up patched roles for host id: %s", + cluster_host['id'] + ) logging.info("Patch successful: %s", patched_config) diff --git a/compass/db/api/cluster.py b/compass/db/api/cluster.py index eb4be1c4..639c54c2 100644 --- a/compass/db/api/cluster.py +++ b/compass/db/api/cluster.py @@ -107,7 +107,7 @@ OPTIONAL_ADDED_FIELDS = ['flavor_id'] UPDATED_FIELDS = ['name', 'reinstall_distributed_system'] ADDED_HOST_FIELDS = ['machine_id'] UPDATED_HOST_FIELDS = ['name', 'reinstall_os'] -UPDATED_CLUSTERHOST_FIELDS = ['roles'] +UPDATED_CLUSTERHOST_FIELDS = ['roles', 'patched_roles'] PATCHED_CLUSTERHOST_FIELDS = ['patched_roles'] UPDATED_CONFIG_FIELDS = [ 'put_os_config', 'put_package_config', 'config_step' @@ -1021,6 +1021,7 @@ def update_cluster_host( session=None, **kwargs ): """Update clusterhost by cluster id and host id.""" + logging.info('updating kwargs: %s', kwargs) clusterhost = _get_cluster_host( cluster_id, host_id, session=session ) diff --git a/compass/db/models.py b/compass/db/models.py index 86c5a4bf..b27cd3c8 100644 --- a/compass/db/models.py +++ b/compass/db/models.py @@ -572,13 +572,18 @@ class ClusterHost(BASE, TimestampMixin, HelperMixin): @patched_roles.setter def patched_roles(self, value): """value should be a list of role name.""" - roles = list(self._roles) - roles.extend(value) - self._roles = roles - patched_roles = list(self._patched_roles) - patched_roles.extend(value) - self._patched_roles = patched_roles - self.config_validated = False + # if value is an empty list, we empty the field + if value: + roles = list(self._roles) + roles.extend(value) + self._roles = roles + patched_roles = list(self._patched_roles) + patched_roles.extend(value) + self._patched_roles = patched_roles + self.config_validated = False + else: + self._patched_roles = list(value) + self.config_validated = False @hybrid_property def owner(self):