コード例 #1
0
    def test_create_mistral_http_action_with_no_headers(self):
        db_task = copy.copy(DB_TASK)
        db_task['task_spec']['action'] = 'std.mistral_http'

        del db_task['parameters']['headers']

        action = a_f.create_action(db_task)

        self.assertIsNotNone(action)

        task_params = db_task['parameters']

        self.assertEqual(task_params['url'], action.url)
        self.assertDictEqual(task_params['params'], action.params)
        self.assertEqual(task_params['method'], action.method)
        self.assertDictEqual(task_params['body'], json.loads(action.body))

        self.assertIsNotNone(action.headers)

        self.assertEqual(db_task['workbook_name'],
                         action.headers['Mistral-Workbook-Name'])
        self.assertEqual(db_task['execution_id'],
                         action.headers['Mistral-Execution-Id'])
        self.assertEqual(db_task['id'],
                         action.headers['Mistral-Task-Id'])
コード例 #2
0
ファイル: executor.py プロジェクト: dmitryilyin/mistral
    def _do_task_action(self, task):
        """Executes the action defined by the task and return result.

        :param task: a task definition
        :type task: dict
        """
        LOG.info("Starting task action [task_id=%s, "
                 "action='%s', action_spec='%s'" %
                 (task['id'], task['task_spec']['action'],
                  task['action_spec']))

        action = a_f.create_action(task)

        if action.is_sync():
            try:
                state, result = states.SUCCESS, action.run()
            except exc.ActionException:
                state, result = states.ERROR, None

            self.engine.convey_task_result(task['workbook_name'],
                                           task['execution_id'],
                                           task['id'],
                                           state, result)
        else:
            try:
                action.run()

            except exc.ActionException:
                self.engine.convey_task_result(task['workbook_name'],
                                               task['execution_id'],
                                               task['id'],
                                               states.ERROR, None)
コード例 #3
0
ファイル: server.py プロジェクト: TimurNurlygayanov/mistral
    def _do_task_action(self, task):
        """Executes the action defined by the task and return result.

        :param task: a task definition
        :type task: dict
        """
        LOG.info(
            "Starting task action [task_id=%s, "
            "action='%s', action_spec='%s'" %
            (task['id'], task['task_spec']['action'], task['action_spec']))

        action = a_f.create_action(task)

        if action.is_sync():
            try:
                state, result = states.SUCCESS, action.run()
            except exc.ActionException:
                state, result = states.ERROR, None

            self.engine.convey_task_result(task['workbook_name'],
                                           task['execution_id'], task['id'],
                                           state, result)
        else:
            try:
                action.run()

            except exc.ActionException:
                self.engine.convey_task_result(task['workbook_name'],
                                               task['execution_id'],
                                               task['id'], states.ERROR, None)
コード例 #4
0
    def test_create_adhoc_action_no_openstack_context(self):
        db_task = copy.copy(DB_TASK_ADHOC)
        db_task['action_spec']['output'] = {'res': '{$}'}
        db_task['in_context'].update({
            'openstack': None
        })
        base_parameters = db_task['action_spec']['base-parameters']
        base_parameters['output'] = "$.openstack.auth_token"

        action = a_f.create_action(db_task)

        self.assertEqual({'res': "$.openstack.auth_token"}, action.run())
コード例 #5
0
    def test_create_http_action(self):
        action = a_f.create_action(DB_TASK)

        self.assertIsNotNone(action)

        task_params = DB_TASK['parameters']

        self.assertEqual(task_params['url'], action.url)
        self.assertDictEqual(task_params['params'], action.params)
        self.assertEqual(task_params['method'], action.method)
        self.assertEqual(task_params['headers'], action.headers)
        self.assertDictEqual(task_params['body'], json.loads(action.body))
コード例 #6
0
    def test_create_http_action(self):
        action = a_f.create_action(DB_TASK)

        self.assertIsNotNone(action)

        task_params = DB_TASK['parameters']

        self.assertEqual(task_params['url'], action.url)
        self.assertDictEqual(task_params['params'], action.params)
        self.assertEqual(task_params['method'], action.method)
        self.assertEqual(task_params['headers'], action.headers)
        self.assertDictEqual(task_params['body'], json.loads(action.body))
コード例 #7
0
    def test_adhoc_echo_action(self):
        db_task = copy.copy(DB_TASK_ADHOC)
        action_spec = db_task['action_spec']

        # With dic-like output formatter.
        action = a_f.create_action(db_task)

        self.assertDictEqual({'res': 'Tango and Cash'}, action.run())

        # With list-like output formatter.
        action_spec['output'] = ['$', '$']

        action = a_f.create_action(db_task)

        self.assertListEqual(['Tango and Cash', 'Tango and Cash'],
                             action.run())

        # With single-object output formatter.
        action_spec['output'] = "'{$}' is a cool movie!"

        action = a_f.create_action(db_task)

        self.assertEqual("'Tango and Cash' is a cool movie!", action.run())
コード例 #8
0
    def test_adhoc_echo_action(self):
        db_task = DB_TASK_ADHOC.copy()
        action_spec = db_task['action_spec']

        # With dic-like output formatter.
        action = a_f.create_action(db_task)

        self.assertDictEqual({'res': 'Tango and Cash'}, action.run())

        # With list-like output formatter.
        action_spec['output'] = ['$', '$']

        action = a_f.create_action(db_task)

        self.assertListEqual(['Tango and Cash', 'Tango and Cash'],
                             action.run())

        # With single-object output formatter.
        action_spec['output'] = "'{$}' is a cool movie!"

        action = a_f.create_action(db_task)

        self.assertEqual("'Tango and Cash' is a cool movie!", action.run())
コード例 #9
0
    def test_create_adhoc_action_with_openstack_context(self):
        db_task = copy.copy(DB_TASK_ADHOC)
        db_task['action_spec']['output'] = {'res': '{$}'}
        db_task['in_context'].update({
            'openstack': {
                'auth_token': '123',
                'project_id': '321'
            }
        })
        base_parameters = db_task['action_spec']['base-parameters']
        base_parameters['output'] = ("{$.openstack.auth_token}"
                                     "{$.openstack.project_id}")

        action = a_f.create_action(db_task)

        self.assertEqual({'res': "123321"}, action.run())
コード例 #10
0
    def test_create_no_adhoc_action_with_openstack_context(self):
        db_task = copy.copy(DB_TASK)
        db_task['task_spec']['action'] = 'std.http'
        db_task['in_context'].update({
            'openstack': {
                'auth_token': '123',
                'project_id': '321'
            }
        })
        ## In case of no-adhoc action we should evaluate task parameters
        ## to see what we need.
        task_spec = db_task['task_spec']
        task_spec['parameters'] = {
            'url': "http://some/{$.openstack.project_id}/servers",
        }

        db_task['parameters'] = data_flow.evaluate_task_parameters(
            db_task, db_task['in_context'])

        action = a_f.create_action(db_task)

        self.assertEqual("http://some/321/servers", action.url)
コード例 #11
0
    def test_get_ssh_action(self):
        db_task = copy.copy(DB_TASK)
        db_task['task_spec'] = {
            'name': 'my_task',
            'action': 'std.ssh',
            'parameters': {
                'host': '10.0.0.1',
                'cmd': 'ls -l',
                'username': '******',
                'password': '******'
            }
        }
        db_task['parameters'] = {'host': '10.0.0.1',
                                 'cmd': 'ls -l',
                                 'username': '******',
                                 'password': '******'}

        action = a_f.create_action(db_task)

        self.assertEqual("ubuntu", action.username)
        self.assertEqual("ubuntu_password", action.password)
        self.assertEqual("ls -l", action.cmd)
        self.assertEqual("10.0.0.1", action.host)
コード例 #12
0
    def test_get_ssh_action(self):
        db_task = copy.copy(DB_TASK)
        db_task['task_spec'] = {
            'name': 'my_task',
            'action': 'std.ssh',
            'parameters': {
                'host': '10.0.0.1',
                'cmd': 'ls -l',
                'username': '******',
                'password': '******'
            }
        }
        db_task['parameters'] = {'host': '10.0.0.1',
                                 'cmd': 'ls -l',
                                 'username': '******',
                                 'password': '******'}

        action = a_f.create_action(db_task)

        self.assertEqual("ubuntu", action.username)
        self.assertEqual("ubuntu_password", action.password)
        self.assertEqual("ls -l", action.cmd)
        self.assertEqual("10.0.0.1", action.host)
コード例 #13
0
    def test_create_mistral_http_action(self):
        db_task = copy.copy(DB_TASK)
        db_task['task_spec']['action'] = 'std.mistral_http'

        action = a_f.create_action(db_task)

        self.assertIsNotNone(action)

        task_params = db_task['parameters']

        self.assertEqual(task_params['url'], action.url)
        self.assertDictEqual(task_params['params'], action.params)
        self.assertEqual(task_params['method'], action.method)
        self.assertEqual(task_params['headers'], action.headers)
        self.assertDictEqual(task_params['body'], json.loads(action.body))

        headers = task_params['headers']

        self.assertEqual(db_task['workbook_name'],
                         headers['Mistral-Workbook-Name'])
        self.assertEqual(db_task['execution_id'],
                         headers['Mistral-Execution-Id'])
        self.assertEqual(db_task['id'],
                         headers['Mistral-Task-Id'])