Exemplo n.º 1
0
    def validate_tasks(cls, tasks, cluster, graph_type):
        """Check that passed tasks are present in deployment graph.

        :param tasks: list of tasks
        :type tasks: list[dict]
        :param cluster: Cluster DB object
        :type cluster: models.Cluster
        :param graph_type: Deployment graph type
        :type graph_type: basestring
        :returns: list of tasks
        :rtype: list[dict]
        """
        cls.validate_schema(tasks, base_types.STRINGS_ARRAY)

        deployment_tasks = objects.Cluster.get_deployment_tasks(
            cluster, graph_type)
        graph = orchestrator_graph.GraphSolver()
        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
Exemplo n.º 2
0
 def test_simple_string_in_group(self):
     graph = orchestrator_graph.GraphSolver()
     subtasks = copy.deepcopy(self.subtasks)
     subtasks[0]['groups'] = ['controller']
     graph.add_tasks(self.tasks + subtasks)
     self.assertItemsEqual(graph.succ['setup_something'], {
         'deploy_end': {},
         'controller': {}
     })
Exemplo n.º 3
0
 def test_groups_regexp_resolution(self):
     graph = orchestrator_graph.GraphSolver()
     graph.add_tasks(self.tasks + self.subtasks)
     self.assertItemsEqual(graph.succ['setup_something'], {
         'deploy_end': {},
         'cinder': {},
         'compute': {},
         'controller': {}
     })
Exemplo n.º 4
0
 def test_support_for_all_groups(self):
     graph = orchestrator_graph.GraphSolver()
     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': {}
         })
Exemplo n.º 5
0
    def get_tasks(self, cluster, graph_type):
        """Get deployment tasks for VMs spawning.

        :param cluster: models.Cluster instance
        :type cluster: models.Cluster
        :param graph_type: Deployment graph type
        :type graph_type: basestring
        :returns: list of tasks ids
        :rtype: list[basestring]
        """
        tasks = objects.Cluster.get_deployment_tasks(cluster, graph_type)
        graph = orchestrator_graph.GraphSolver()
        graph.add_tasks(tasks)
        subgraph = graph.find_subgraph(end='generate_vms')
        return [task['id'] for task in subgraph.topology]
Exemplo n.º 6
0
    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)
        graph_type = web.input(graph_type=None).graph_type or None

        cluster = self.get_object_or_404(objects.Cluster, cluster_id)
        tasks = objects.Cluster.get_deployment_tasks(cluster, graph_type)
        graph = orchestrator_graph.GraphSolver(tasks)

        tasks = self.get_param_as_set('tasks', default=[])
        parents_for = web.input(parents_for=None).parents_for
        remove = self.get_param_as_set('remove')

        if tasks:
            tasks = self.checked_data(self.validator.validate,
                                      data=list(tasks),
                                      cluster=cluster,
                                      graph_type=graph_type)
            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(remove)
            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()
Exemplo n.º 7
0
    def GET(self, obj_id):
        """:returns: Deployment tasks

        :http: * 200 OK
               * 404 (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
        graph_type = web.input(graph_type=None).graph_type
        # web.py depends on [] to understand that there will be multiple inputs
        include = web.input(include=[]).include

        # merged (cluster + plugins + release) tasks is returned for cluster
        # but the own release tasks is returned for release
        tasks = self.single.get_deployment_tasks(obj, graph_type=graph_type)
        if end or start:
            graph = orchestrator_graph.GraphSolver(tasks)
            return graph.filter_subgraph(
                end=end, start=start, include=include).node.values()
        return tasks
Exemplo n.º 8
0
    def GET(self, obj_id):
        """:returns: Deployment tasks

        :http: * 200 OK
               * 404 (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
        graph_type = web.input(graph_type=None).graph_type or None
        # web.py depends on [] to understand that there will be multiple inputs
        include = web.input(include=[]).include

        # merged (cluster + plugins + release) tasks is returned for cluster
        # but the own release tasks is returned for release
        tasks = self.single.get_deployment_tasks(obj, graph_type=graph_type)

        if end or start:
            graph = orchestrator_graph.GraphSolver(tasks)

            for t in tasks:
                if StrictVersion(t.get('version')) >= \
                        StrictVersion(consts.TASK_CROSS_DEPENDENCY):
                    raise self.http(
                        400,
                        ('Both "start" and "end" parameters are not allowed '
                         'for task-based deployment.'))

            try:
                return graph.filter_subgraph(end=end,
                                             start=start,
                                             include=include).node.values()
            except errors.TaskNotFound as e:
                raise self.http(
                    400, 'Cannot find task {0} by its '
                    'name.'.format(e.task_name))
        return tasks
Exemplo n.º 9
0
 def get_dotgraph_with_tasks(self, tasks):
     graph = orchestrator_graph.GraphSolver()
     graph.add_tasks(tasks)
     visualization = graph_visualization.GraphVisualization(graph)
     dotgraph = visualization.get_dotgraph()
     return dotgraph.to_string()
Exemplo n.º 10
0
 def setUp(self):
     super(TestIncludeSkipped, self).setUp()
     self.tasks = yaml.load(self.TASKS)
     self.graph = orchestrator_graph.GraphSolver(tasks=self.tasks)
Exemplo n.º 11
0
    def test_always_same_order(self):

        graph = orchestrator_graph.GraphSolver(tasks=self.tasks)
        # (dshulyak) order should be static
        self.assertEqual([n['id'] for n in graph.topology],
                         ['a', 'b', 'c', 'd', 'e', 'f'])
Exemplo n.º 12
0
 def setUp(self):
     super(TestFindGraph, self).setUp()
     self.tasks = yaml.load(COMPLEX_DEPENDENCIES)
     self.graph = orchestrator_graph.GraphSolver()
     self.graph.add_tasks(self.tasks)
Exemplo n.º 13
0
 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 = orchestrator_graph.GraphSolver()
Exemplo n.º 14
0
 def get_tasks(self, cluster):
     tasks = objects.Cluster.get_deployment_tasks(cluster)
     graph = orchestrator_graph.GraphSolver()
     graph.add_tasks(tasks)
     subgraph = graph.find_subgraph(end='generate_vms')
     return [task['id'] for task in subgraph.topology]