Merge "Custom graph support for OpenstackConfigExecuteHandler"

This commit is contained in:
Jenkins 2016-05-12 08:10:43 +00:00 committed by Gerrit Code Review
commit e53540d019
7 changed files with 70 additions and 7 deletions

View File

@ -116,6 +116,7 @@ class OpenstackConfigExecuteHandler(BaseHandler):
* 400 (Invalid data)
* 404 (Object dependencies not found)
"""
graph_type = web.input(graph_type=None).graph_type
filters = self.checked_data(self.validator.validate_execute)
cluster = self.get_object_or_404(
@ -124,7 +125,7 @@ class OpenstackConfigExecuteHandler(BaseHandler):
# Execute upload task for nodes
task_manager = self.task_manager(cluster_id=cluster.id)
try:
task = task_manager.execute(filters)
task = task_manager.execute(filters, graph_type=graph_type)
except Exception as exc:
logger.warn(
u'Cannot execute %s task nodes: %s',

View File

@ -1138,7 +1138,8 @@ class Cluster(NailgunObject):
return PluginManager.get_legacy_tasks_for_cluster(instance)
@classmethod
def get_refreshable_tasks(cls, instance, filter_by_configs=None):
def get_refreshable_tasks(cls, instance, filter_by_configs=None,
graph_type=None):
"""Return list of refreshable tasks
If 'filter_by_configs' specified then only tasks needed to update
@ -1147,12 +1148,13 @@ class Cluster(NailgunObject):
:param instance: a Cluster instance
:param filter_by_configs: a list with configs resources
:param graph_type: deployment graph type
:return: list of tasks
"""
if filter_by_configs:
filter_by_configs = set(filter_by_configs)
tasks = []
for task in cls.get_deployment_tasks(instance):
for task in cls.get_deployment_tasks(instance, graph_type):
refresh_on = task.get(consts.TASK_REFRESH_FIELD)
if (refresh_on
and (filter_by_configs is None

View File

@ -1317,7 +1317,7 @@ class OpenstackConfigTaskManager(TaskManager):
return tasks.ClusterTransaction
return tasks.UpdateOpenstackConfigTask
def execute(self, filters, force=False, **kwargs):
def execute(self, filters, force=False, graph_type=None, **kwargs):
self.check_running_task(consts.TASK_NAMES.deployment)
task = Task(name=consts.TASK_NAMES.deployment,
@ -1332,6 +1332,7 @@ class OpenstackConfigTaskManager(TaskManager):
task,
self.get_deployment_task(),
nodes_to_update,
graph_type=graph_type,
method_name='message',
force=force
)

View File

@ -2114,7 +2114,7 @@ class UpdateOpenstackConfigTask(BaseDeploymentTask):
})
@classmethod
def message(cls, task, nodes, **kwargs):
def message(cls, task, nodes, graph_type, **kwargs):
configs = objects.OpenstackConfigCollection.find_configs_for_nodes(
task.cluster, nodes)
updated_configs = set()
@ -2127,10 +2127,11 @@ class UpdateOpenstackConfigTask(BaseDeploymentTask):
raise errors.NoChanges()
refreshable_tasks = objects.Cluster.get_refreshable_tasks(
task.cluster, updated_configs
task.cluster, updated_configs, graph_type
)
task_ids = {t['id'] for t in refreshable_tasks}
deployment_tasks = objects.Cluster.get_deployment_tasks(task.cluster)
deployment_tasks = objects.Cluster.get_deployment_tasks(
task.cluster, graph_type)
return cls.call_deployment_method(
task, tasks=deployment_tasks, nodes=nodes, task_ids=task_ids
)[1]

View File

@ -16,6 +16,7 @@ from mock import patch
from nailgun import consts
from nailgun.db.sqlalchemy.models import DeploymentGraphTask
from nailgun import objects
from nailgun.orchestrator.tasks_templates import make_generic_task
from nailgun.task.manager import OpenstackConfigTaskManager
from nailgun.test import base
@ -119,6 +120,28 @@ class TestOpenstackConfigTaskManager80(base.BaseIntegrationTest):
self.assertItemsEqual(deployment_tasks, [
make_generic_task([self.nodes[0].uid], self.refreshable_task)])
@patch('nailgun.rpc.cast')
def test_configuration_execute_w_custom_graph(self, mocked_rpc):
custom_tasks = [
{
'id': 'custom-task',
'type': 'puppet',
'roles': '*'
}
]
objects.DeploymentGraph.create_for_model(
{'tasks': custom_tasks}, self.cluster, 'custom-graph')
task_manager = OpenstackConfigTaskManager(self.cluster.id)
task = task_manager.execute(
{'cluster_id': self.cluster.id}, graph_type='custom-graph')
self.assertEqual(task.status, consts.TASK_STATUSES.pending)
self.assertEqual(
mocked_rpc.call_args[0][1]['args']['tasks'][0]['task_name'],
'custom-task'
)
@patch('nailgun.rpc.cast')
def test_configuration_execute_by_node_id(self, mocked_rpc):
task_manager = OpenstackConfigTaskManager(self.cluster.id)

View File

@ -1413,6 +1413,26 @@ class TestClusterObject(BaseTestCase):
self.assertIn(deployment_tasks[1]['id'], tasks_ids)
self.assertNotIn(deployment_tasks[0]['id'], tasks_ids)
def test_get_refreshable_tasks_w_custom_graph(self):
deployment_tasks = [
self.env.get_default_plugin_deployment_tasks(**{
'id': 'refreshable_task_on_keystone',
consts.TASK_REFRESH_FIELD: ['keystone_config']
})[0]
]
cluster = self.cluster
release_graph = objects.DeploymentGraph.get_for_model(cluster.release)
release_tasks = objects.DeploymentGraph.get_tasks(release_graph)
objects.DeploymentGraph.create_for_model(
{'tasks': release_tasks}, cluster.release, 'custom-graph')
objects.DeploymentGraph.create_for_model(
{'tasks': deployment_tasks}, cluster, 'custom-graph')
refreshable_tasks = objects.Cluster.get_refreshable_tasks(
cluster, None, 'custom-graph')
tasks_ids = [t['id'] for t in refreshable_tasks]
self.assertIn(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(

View File

@ -473,6 +473,21 @@ class TestOpenstackConfigHandlers(BaseIntegrationTest):
expect_errors=True)
self.check_fail_deploy_running(deploy_task_id, resp)
@mock.patch('objects.Cluster.get_deployment_tasks')
@mock.patch('nailgun.task.task.rpc.cast')
def test_execute_update_open_stack_config_w_custom_graph(
self, mock_rpc, tasks_mock):
data = {'cluster_id': self.clusters[0].id}
resp = self.app.put(
reverse('OpenstackConfigExecuteHandler') +
'?graph_type=custom-graph',
jsonutils.dumps(data),
headers=self.default_headers,
expect_errors=False
)
self.assertEqual(202, resp.status_code)
self.assertIn('custom-graph', tasks_mock.call_args[0])
@classmethod
def _make_filter_url(cls, **kwargs):
return '{0}?{1}'.format(