Exemplo n.º 1
0
    def _execute(self,
                 env=None,
                 use_sudo=False,
                 hide_output=None,
                 process=None,
                 custom_input='',
                 test_operations=None,
                 commands=None):
        process = process or {}
        if env:
            process.setdefault('env', {}).update(env)

        test_operations = test_operations or [self.test_name]

        local_script_path = os.path.join(resources.DIR, 'scripts',
                                         'test_ssh.sh')
        script_path = os.path.basename(local_script_path)
        self._upload(local_script_path, script_path)

        if commands:
            operation = operations.run_commands_with_ssh
        else:
            operation = operations.run_script_with_ssh

        @workflow
        def mock_workflow(ctx, graph):
            op = 'test.op'
            node_instance = ctx.model.node_instance.get_by_name(
                mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
            node_instance.node.operations[op] = {
                'operation':
                '{0}.{1}'.format(operations.__name__, operation.__name__)
            }
            graph.sequence(*[
                api.task.OperationTask.node_instance(
                    instance=node_instance,
                    name=op,
                    inputs={
                        'script_path': script_path,
                        'fabric_env': _FABRIC_ENV,
                        'process': process,
                        'use_sudo': use_sudo,
                        'hide_output': hide_output,
                        'custom_env_var': custom_input,
                        'test_operation': test_operation,
                        'commands': commands
                    }) for test_operation in test_operations
            ])
            return graph

        tasks_graph = mock_workflow(ctx=self._workflow_context)  # pylint: disable=no-value-for-parameter
        eng = engine.Engine(executor=self._executor,
                            workflow_context=self._workflow_context,
                            tasks_graph=tasks_graph)
        eng.execute()
        return self._workflow_context.model.node_instance.get_by_name(
            mock.models.DEPENDENCY_NODE_INSTANCE_NAME).runtime_properties
Exemplo n.º 2
0
    def _execute(self,
                 env=None,
                 use_sudo=False,
                 hide_output=None,
                 process=None,
                 custom_input='',
                 test_operations=None,
                 commands=None):
        process = process or {}
        if env:
            process.setdefault('env', {}).update(env)

        test_operations = test_operations or [self.test_name]

        local_script_path = os.path.join(resources.DIR, 'scripts',
                                         'test_ssh.sh')
        script_path = os.path.basename(local_script_path)
        self._upload(local_script_path, script_path)

        if commands:
            operation = operations.run_commands_with_ssh
        else:
            operation = operations.run_script_with_ssh

        node = self._workflow_context.model.node.get_by_name(
            mock.models.DEPENDENCY_NODE_NAME)
        arguments = {
            'script_path': script_path,
            'fabric_env': _FABRIC_ENV,
            'process': process,
            'use_sudo': use_sudo,
            'custom_env_var': custom_input,
            'test_operation': '',
        }
        if hide_output:
            arguments['hide_output'] = hide_output
        if commands:
            arguments['commands'] = commands
        interface = mock.models.create_interface(
            node.service,
            'test',
            'op',
            operation_kwargs=dict(function='{0}.{1}'.format(
                operations.__name__, operation.__name__),
                                  arguments=arguments))
        node.interfaces[interface.name] = interface

        @workflow
        def mock_workflow(ctx, graph):
            ops = []
            for test_operation in test_operations:
                op_arguments = arguments.copy()
                op_arguments['test_operation'] = test_operation
                ops.append(
                    api.task.OperationTask(node,
                                           interface_name='test',
                                           operation_name='op',
                                           arguments=op_arguments))

            graph.sequence(*ops)
            return graph

        tasks_graph = mock_workflow(ctx=self._workflow_context)  # pylint: disable=no-value-for-parameter
        graph_compiler.GraphCompiler(
            self._workflow_context,
            self._executor.__class__).compile(tasks_graph)
        eng = engine.Engine({self._executor.__class__: self._executor})
        eng.execute(self._workflow_context)
        return self._workflow_context.model.node.get_by_name(
            mock.models.DEPENDENCY_NODE_NAME).attributes