def test_always_same_order(self): graph = deployment_graph.DeploymentGraph(tasks=self.tasks) # (dshulyak) order should be static self.assertEqual( [n['id'] for n in graph.topology], ['a', 'b', 'c', 'd', 'e', 'f'])
def test_simple_string_in_group(self): graph = deployment_graph.DeploymentGraph() subtasks = copy.deepcopy(self.subtasks) subtasks[0]['groups'] = ['controller'] graph.add_tasks(self.tasks + subtasks) self.assertItemsEqual( graph.succ['setup_something'], {'deploy_end': {}, 'controller': {}})
def validate_update(cls, data, instance): parsed = cls.validate(data) cls.validate_schema(parsed, tasks.TASKS_SCHEMA) graph = deployment_graph.DeploymentGraph() graph.add_tasks(parsed) if not graph.is_acyclic(): raise errors.InvalidData( "Tasks can not be processed because it contains cycles in it.") return parsed
def test_support_for_all_groups(self): graph = deployment_graph.DeploymentGraph() subtasks = copy.deepcopy(self.subtasks) subtasks[0]['groups'] = ['/.*/'] graph.add_tasks(self.tasks + subtasks) self.assertItemsEqual( graph.succ['setup_something'], {'deploy_end': {}, 'primary-controller': {}, 'network': {}, 'cinder': {}, 'compute': {}, 'controller': {}})
def GET(self, obj_id): """:returns: Deployment tasks :http: * 200 OK * 404 (release object not found) """ obj = self.get_object_or_404(self.single, obj_id) end = web.input(end=None).end tasks = self.single.get_deployment_tasks(obj) if end: graph = deployment_graph.DeploymentGraph(tasks) return graph.find_subgraph(end).node.values() return tasks
def GET(self, obj_id): """:returns: Deployment tasks :http: * 200 OK * 404 (release object not found) """ obj = self.get_object_or_404(self.single, obj_id) end = web.input(end=None).end start = web.input(start=None).start # web.py depends on [] to understand that there will be multiple inputs include = web.input(include=[]).include tasks = self.single.get_deployment_tasks(obj) if end or start: graph = deployment_graph.DeploymentGraph(tasks) return graph.filter_subgraph(end=end, start=start, include=include).node.values() return tasks
def validate_tasks(cls, tasks, cluster): """Check that passed tasks are present in deployment graph :param tasks: list of tasks :param cluster: Cluster DB object :returns: list of tasks """ cls.validate_schema(tasks, base_types.STRINGS_ARRAY) deployment_tasks = objects.Cluster.get_deployment_tasks(cluster) graph = deployment_graph.DeploymentGraph() graph.add_tasks(deployment_tasks) non_existent_tasks = set(tasks) - set(graph.nodes()) if non_existent_tasks: raise errors.InvalidData( 'Tasks {0} are not present in deployment graph'.format( ','.join(non_existent_tasks))) return tasks
def GET(self, cluster_id): """:returns: DOT representation of deployment graph. :http: * 200 (graph returned) * 404 (cluster not found in db) * 400 (failed to get graph) """ web.header('Content-Type', 'text/vnd.graphviz', unique=True) cluster = self.get_object_or_404(objects.Cluster, cluster_id) tasks = objects.Cluster.get_deployment_tasks(cluster) graph = deployment_graph.DeploymentGraph(tasks) tasks = web.input(tasks=None).tasks parents_for = web.input(parents_for=None).parents_for remove = web.input(remove=None).remove if tasks: tasks = self.checked_data(self.validator.validate, data=tasks, cluster=cluster) logger.debug('Tasks used in dot graph %s', tasks) if parents_for: parents_for = self.checked_data( self.validator.validate_task_presence, data=parents_for, graph=graph) logger.debug('Graph with predecessors for %s', parents_for) if remove: remove = list(set(remove.split(','))) remove = self.checked_data(self.validator.validate_tasks_types, data=remove) logger.debug('Types to remove %s', remove) visualization = graph_visualization.GraphVisualization(graph) dotgraph = visualization.get_dotgraph(tasks=tasks, parents_for=parents_for, remove=remove) return dotgraph.to_string()
def validate_deployment(cls, data, cluster): """Used to validate attributes used for validate_deployment_attributes :param data: raw json data, usually web.data() :returns: loaded json or empty array """ data = cls.validate_json(data) if data: cls.validate_schema(data, base_types.STRINGS_ARRAY) tasks = objects.Cluster.get_deployment_tasks(cluster) graph = deployment_graph.DeploymentGraph() graph.add_tasks(tasks) non_existent_tasks = set(data) - set(graph.nodes()) if non_existent_tasks: raise errors.InvalidData( 'Tasks %s are not present in deployment graph', list(non_existent_tasks)) else: raise errors.InvalidData('Tasks list must be specified.') return data
def setUp(self): super(TestFindGraph, self).setUp() self.tasks = yaml.load(COMPLEX_DEPENDENCIES) self.graph = deployment_graph.DeploymentGraph() self.graph.add_tasks(self.tasks)
def setUp(self): super(TestGraphDependencies, self).setUp() self.tasks = yaml.load(TASKS) self.subtasks = yaml.load(SUBTASKS) self.graph = deployment_graph.DeploymentGraph()
def setUp(self): super(TestIncludeSkipped, self).setUp() self.tasks = yaml.load(self.TASKS) self.graph = deployment_graph.DeploymentGraph(tasks=self.tasks)
def get_dotgraph_with_tasks(self, tasks): graph = deployment_graph.DeploymentGraph() graph.add_tasks(tasks) visualization = graph_visualization.GraphVisualization(graph) dotgraph = visualization.get_dotgraph() return dotgraph.to_string()
def test_groups_regexp_resolution(self): graph = deployment_graph.DeploymentGraph() graph.add_tasks(self.tasks + self.subtasks) self.assertItemsEqual( graph.succ['setup_something'], {'deploy_end': {}, 'cinder': {}, 'compute': {}, 'controller': {}})
def setUp(self): super(TestGraphDependencies, self).setUp() self.tasks = yaml.load(TASKS) self.subtasks = yaml.load(SUBTASKS) self.subtasks_with_regexp = yaml.load(SUBTASKS_WITH_REGEXP) self.graph = deployment_graph.DeploymentGraph()
def get_tasks(self, cluster): tasks = objects.Cluster.get_deployment_tasks(cluster) graph = deployment_graph.DeploymentGraph() graph.add_tasks(tasks) subgraph = graph.find_subgraph(end='generate_vms') return [task['id'] for task in subgraph.topology]