Enable patched_roles cleanup after patch action is sent.

Change-Id: I34b73e6725455a70912272e744d5f85586ffe8e8
This commit is contained in:
Xicheng Chang 2015-12-10 15:11:15 -08:00
parent a05ce06169
commit ec2805db42
3 changed files with 24 additions and 8 deletions

View File

@ -15,6 +15,7 @@
"""Module to patch an existing cluster """Module to patch an existing cluster
""" """
import logging import logging
import simplejson as json
from compass.actions import util from compass.actions import util
from compass.db.api import cluster as cluster_db from compass.db.api import cluster as cluster_db
@ -56,4 +57,13 @@ def patch(cluster_id, username=None):
patch_successful = False patch_successful = False
if patch_successful: 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) logging.info("Patch successful: %s", patched_config)

View File

@ -107,7 +107,7 @@ OPTIONAL_ADDED_FIELDS = ['flavor_id']
UPDATED_FIELDS = ['name', 'reinstall_distributed_system'] UPDATED_FIELDS = ['name', 'reinstall_distributed_system']
ADDED_HOST_FIELDS = ['machine_id'] ADDED_HOST_FIELDS = ['machine_id']
UPDATED_HOST_FIELDS = ['name', 'reinstall_os'] UPDATED_HOST_FIELDS = ['name', 'reinstall_os']
UPDATED_CLUSTERHOST_FIELDS = ['roles'] UPDATED_CLUSTERHOST_FIELDS = ['roles', 'patched_roles']
PATCHED_CLUSTERHOST_FIELDS = ['patched_roles'] PATCHED_CLUSTERHOST_FIELDS = ['patched_roles']
UPDATED_CONFIG_FIELDS = [ UPDATED_CONFIG_FIELDS = [
'put_os_config', 'put_package_config', 'config_step' 'put_os_config', 'put_package_config', 'config_step'
@ -1021,6 +1021,7 @@ def update_cluster_host(
session=None, **kwargs session=None, **kwargs
): ):
"""Update clusterhost by cluster id and host id.""" """Update clusterhost by cluster id and host id."""
logging.info('updating kwargs: %s', kwargs)
clusterhost = _get_cluster_host( clusterhost = _get_cluster_host(
cluster_id, host_id, session=session cluster_id, host_id, session=session
) )

View File

@ -572,13 +572,18 @@ class ClusterHost(BASE, TimestampMixin, HelperMixin):
@patched_roles.setter @patched_roles.setter
def patched_roles(self, value): def patched_roles(self, value):
"""value should be a list of role name.""" """value should be a list of role name."""
roles = list(self._roles) # if value is an empty list, we empty the field
roles.extend(value) if value:
self._roles = roles roles = list(self._roles)
patched_roles = list(self._patched_roles) roles.extend(value)
patched_roles.extend(value) self._roles = roles
self._patched_roles = patched_roles patched_roles = list(self._patched_roles)
self.config_validated = False 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 @hybrid_property
def owner(self): def owner(self):