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
"""
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)

View File

@ -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
)

View File

@ -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):