示例#1
0
    def setup_action_models(cls):
        action_db = ActionDB()
        action_db.name = 'action-1'
        action_db.description = 'awesomeness'
        action_db.enabled = True
        action_db.pack = 'wolfpack'
        action_db.entry_point = ''
        action_db.runner_type = {'name': 'test-runner'}
        action_db.parameters = {
            'actionstr': {'type': 'string', 'required': True},
            'actionint': {'type': 'number', 'default': 10},
            'runnerdummy': {'type': 'string', 'default': 'actiondummy'},
            'runnerimmutable': {'type': 'string', 'default': 'failed_override'},
            'actionimmutable': {'type': 'string', 'default': 'actionimmutable', 'immutable': True}
        }
        RunnerContainerTest.action_db = Action.add_or_update(action_db)

        action_db = ActionDB()
        action_db.name = 'action-2'
        action_db.description = 'awesomeness'
        action_db.enabled = True
        action_db.pack = 'wolfpack'
        action_db.entry_point = ''
        action_db.runner_type = {'name': 'test-failingrunner'}
        action_db.parameters = {}
        RunnerContainerTest.failingaction_db = Action.add_or_update(action_db)
    def _register_action(self, pack, action):
        content = self._meta_loader.load(action)
        action_ref = ResourceReference(pack=pack, name=str(content['name']))
        model = action_utils.get_action_by_ref(action_ref)
        if not model:
            model = ActionDB()
        model.name = content['name']
        model.description = content['description']
        model.enabled = content['enabled']
        model.pack = pack
        model.entry_point = content['entry_point']
        model.parameters = content.get('parameters', {})
        runner_type = str(content['runner_type'])
        valid_runner_type, runner_type_db = self._has_valid_runner_type(runner_type)
        if valid_runner_type:
            model.runner_type = {'name': runner_type_db.name}
        else:
            LOG.exception('Runner type %s doesn\'t exist.', runner_type)
            raise

        try:
            model = Action.add_or_update(model)
            LOG.audit('Action created. Action %s from %s.', model, action)
        except Exception:
            LOG.exception('Failed to write action to db %s.', model.name)
            raise
示例#3
0
 def _setup_action_models(cls):
     action_db = ActionDB()
     action_db.name = 'action-1'
     action_db.description = 'awesomeness'
     action_db.enabled = True
     action_db.pack = 'wolfpack'
     action_db.entry_point = ''
     action_db.runner_type = {'name': 'test-runner'}
     action_db.parameters = {
         'actionstr': {
             'type': 'string',
             'required': True
         },
         'actionint': {
             'type': 'number',
             'default': 10
         },
         'runnerdummy': {
             'type': 'string',
             'default': 'actiondummy',
             'immutable': True
         },
         'runnerimmutable': {
             'type': 'string',
             'default': 'failed_override'
         },
         'actionimmutable': {
             'type': 'string',
             'default': 'actionimmutable',
             'immutable': True
         }
     }
     ParamsUtilsTest.action_db = action_db
示例#4
0
    def setup_action_models(cls):
        action_db = ActionDB()
        action_db.name = 'action-1'
        action_db.description = 'awesomeness'
        action_db.enabled = True
        action_db.pack = 'wolfpack'
        action_db.ref = ResourceReference(name=action_db.name, pack=action_db.pack).ref
        action_db.entry_point = ''
        action_db.runner_type = {'name': 'test-runner'}
        action_db.parameters = {
            'actionstr': {'type': 'string', 'position': 1, 'required': True},
            'actionint': {'type': 'number', 'default': 10, 'position': 0},
            'runnerdummy': {'type': 'string', 'default': 'actiondummy'}
        }
        ActionDBUtilsTestCase.action_db = Action.add_or_update(action_db)

        liveaction_db = LiveActionDB()
        liveaction_db.status = 'initializing'
        liveaction_db.start_timestamp = get_datetime_utc_now()
        liveaction_db.action = ActionDBUtilsTestCase.action_db.ref
        params = {
            'actionstr': 'foo',
            'some_key_that_aint_exist_in_action_or_runner': 'bar',
            'runnerint': 555
        }
        liveaction_db.parameters = params
        ActionDBUtilsTestCase.liveaction_db = LiveAction.add_or_update(liveaction_db)
示例#5
0
    def _register_action(self, pack, action):
        with open(action, 'r') as fd:
            try:
                content = json.load(fd)
            except ValueError:
                LOG.exception('Failed loading action json from %s.', action)
                raise

            try:
                model = Action.get_by_name(str(content['name']))
            except ValueError:
                model = ActionDB()
            model.name = content['name']
            model.description = content['description']
            model.enabled = content['enabled']
            model.pack = pack
            model.entry_point = content['entry_point']
            model.parameters = content.get('parameters', {})
            runner_type = str(content['runner_type'])
            valid_runner_type, runner_type_db = self._has_valid_runner_type(runner_type)
            if valid_runner_type:
                model.runner_type = {'name': runner_type_db.name}
            else:
                LOG.exception('Runner type %s doesn\'t exist.')
                raise

            try:
                model = Action.add_or_update(model)
                LOG.audit('Action created. Action %s from %s.', model, action)
            except Exception:
                LOG.exception('Failed to write action to db %s.', model.name)
                raise
示例#6
0
 def _create_save_action(runnertype, metadata=False):
     created = ActionDB()
     created.name = 'action-1'
     created.description = 'awesomeness'
     created.enabled = True
     created.entry_point = '/tmp/action.py'
     created.pack = 'wolfpack'
     created.ref = ResourceReference(pack=created.pack,
                                     name=created.name).ref
     created.runner_type = {'name': runnertype.name}
     if not metadata:
         created.parameters = {'p1': None, 'p2': None, 'p3': None}
     else:
         created.parameters = {
             'p1': {
                 'type': 'string',
                 'required': True
             },
             'p2': {
                 'type': 'number',
                 'default': 2868
             },
             'p3': {
                 'type': 'boolean',
                 'default': False
             }
         }
     return Action.add_or_update(created)
示例#7
0
    def _register_action(self, pack, action):
        content = self._meta_loader.load(action)
        try:
            model = Action.get_by_name(str(content['name']))
        except ValueError:
            model = ActionDB()
        model.name = content['name']
        model.description = content['description']
        model.enabled = content['enabled']
        model.pack = pack
        model.entry_point = content['entry_point']
        model.parameters = content.get('parameters', {})
        runner_type = str(content['runner_type'])
        valid_runner_type, runner_type_db = self._has_valid_runner_type(
            runner_type)
        if valid_runner_type:
            model.runner_type = {'name': runner_type_db.name}
        else:
            LOG.exception('Runner type %s doesn\'t exist.', runner_type)
            raise

        try:
            model = Action.add_or_update(model)
            LOG.audit('Action created. Action %s from %s.', model, action)
        except Exception:
            LOG.exception('Failed to write action to db %s.', model.name)
            raise
示例#8
0
 def _setup_action_models(cls):
     action_db = ActionDB()
     action_db.name = 'action-1'
     action_db.description = 'awesomeness'
     action_db.enabled = True
     action_db.pack = 'wolfpack'
     action_db.entry_point = ''
     action_db.runner_type = {'name': 'test-runner'}
     action_db.parameters = {
         'actionstr': {'type': 'string', 'required': True},
         'actionint': {'type': 'number', 'default': 10},
         'runnerdummy': {'type': 'string', 'default': 'actiondummy', 'immutable': True},
         'runnerimmutable': {'type': 'string', 'default': 'failed_override'},
         'actionimmutable': {'type': 'string', 'default': 'actionimmutable', 'immutable': True}
     }
     ParamsUtilsTest.action_db = action_db
示例#9
0
文件: test_db.py 项目: srenatus/st2
 def _create_save_action(runnertype, metadata=False):
     created = ActionDB()
     created.name = 'action-1'
     created.description = 'awesomeness'
     created.enabled = True
     created.entry_point = '/tmp/action.py'
     created.pack = 'wolfpack'
     created.ref = ResourceReference(pack=created.pack, name=created.name).ref
     created.runner_type = {'name': runnertype.name}
     if not metadata:
         created.parameters = {'p1': None, 'p2': None, 'p3': None}
     else:
         created.parameters = {
             'p1': {'type': 'string', 'required': True},
             'p2': {'type': 'number', 'default': 2868},
             'p3': {'type': 'boolean', 'default': False}
         }
     return Action.add_or_update(created)
示例#10
0
    def test_format_secret_action_parameters_are_masked(self):
        formatter = ConsoleLogFormatter()

        mock_message = 'test message 1'

        mock_action_db = ActionDB()
        mock_action_db.name = 'test.action'
        mock_action_db.pack = 'testpack'
        mock_action_db.parameters = {
            'parameter1': {
                'type': 'string',
                'required': False
            },
            'parameter2': {
                'type': 'string',
                'required': False,
                'secret': True
            }
        }

        mock_action_execution_db = ActionExecutionDB()
        mock_action_execution_db.action = mock_action_db.to_serializable_dict()
        mock_action_execution_db.parameters = {
            'parameter1': 'value1',
            'parameter2': 'value2'
        }

        record = MockRecord()
        record.msg = mock_message

        # Add "extra" attributes
        record._action_execution_db = mock_action_execution_db

        expected_msg_part = "'parameters': {'parameter1': 'value1', 'parameter2': '********'}"

        message = formatter.format(record=record)
        self.assertTrue('test message 1' in message)
        self.assertTrue(expected_msg_part in message)