Merge "Add ability to get refreshable tasks from cluster"

This commit is contained in:
Jenkins 2015-11-10 16:50:35 +00:00 committed by Gerrit Code Review
commit fe7fe7d082
3 changed files with 56 additions and 0 deletions

View File

@ -360,6 +360,8 @@ INTERNAL_TASKS = (ORCHESTRATOR_TASK_TYPES.group,
ORCHESTRATOR_TASK_TYPES.stage,
ORCHESTRATOR_TASK_TYPES.skipped)
TASK_REFRESH_FIELD = 'refresh_on'
ROLE_NAME_MAX_SIZE = 64
EXTENSION_NAME_MAX_SIZE = 64

View File

@ -817,6 +817,29 @@ class Cluster(NailgunObject):
PluginManager.get_plugins_deployment_tasks(instance)
return release_deployment_tasks + plugin_deployment_tasks
@classmethod
def get_refreshable_tasks(cls, instance, filter_by_configs=None):
"""Return list of refreshable tasks
If 'filter_by_configs' specified then only tasks needed to update
these config resources will be returned as a result, otherwise
all refreshable tasks will be returned
:param instance: a Cluster instance
:param filter_by_configs: a list with configs resources
:return: list of tasks
"""
if filter_by_configs:
filter_by_configs = set(filter_by_configs)
tasks = []
for task in cls.get_deployment_tasks(instance):
refresh_on = task.get(consts.TASK_REFRESH_FIELD)
if (refresh_on
and (filter_by_configs is None
or filter_by_configs.intersection(set(refresh_on)))):
tasks.append(task)
return tasks
@classmethod
def get_volumes_metadata(cls, instance):
"""Return proper volumes metadata for cluster

View File

@ -1125,6 +1125,37 @@ class TestClusterObject(BaseTestCase):
expected_message):
objects.Cluster.get_deployment_tasks(cluster)
def test_get_refreshable_tasks(self):
deployment_tasks = [
self.env.get_default_plugin_deployment_tasks(**{
'id': 'refreshable_task_on_keystone',
consts.TASK_REFRESH_FIELD: ['keystone_config']
})[0],
self.env.get_default_plugin_deployment_tasks(**{
'id': 'refreshable_task_on_nova',
consts.TASK_REFRESH_FIELD: ['nova_config']
})[0],
]
plugin_metadata = self.env.get_default_plugin_metadata(
deployment_tasks=deployment_tasks
)
cluster = self._create_cluster_with_plugins([plugin_metadata])
refreshable_tasks = \
objects.Cluster.get_refreshable_tasks(cluster)
tasks_ids = [t['id'] for t in refreshable_tasks]
self.assertIn(deployment_tasks[1]['id'], tasks_ids)
self.assertIn(deployment_tasks[0]['id'], tasks_ids)
refreshable_tasks_on_nova = \
objects.Cluster.get_refreshable_tasks(
cluster, filter_by_configs=('nova_config',))
tasks_ids = [t['id'] for t in refreshable_tasks_on_nova]
self.assertIn(deployment_tasks[1]['id'], tasks_ids)
self.assertNotIn(deployment_tasks[0]['id'], tasks_ids)
def test_get_plugin_network_roles(self):
network_roles = [self._get_network_role_metadata()]
plugin_data = self.env.get_default_plugin_metadata(