示例#1
0
    def test_update_liveaction_with_incorrect_output_schema(self):
        liveaction_db = LiveActionDB()
        liveaction_db.status = 'initializing'
        liveaction_db.start_timestamp = get_datetime_utc_now()
        liveaction_db.action = ResourceReference(
            name=ActionDBUtilsTestCase.action_db.name,
            pack=ActionDBUtilsTestCase.action_db.pack).ref
        params = {
            'actionstr': 'foo',
            'some_key_that_aint_exist_in_action_or_runner': 'bar',
            'runnerint': 555
        }
        liveaction_db.parameters = params
        runner = mock.MagicMock()
        runner.output_schema = {
            "notaparam": {
                "type": "boolean"
            }
        }
        liveaction_db.runner = runner
        liveaction_db = LiveAction.add_or_update(liveaction_db)
        origliveaction_db = copy.copy(liveaction_db)

        now = get_datetime_utc_now()
        status = 'succeeded'
        result = 'Work is done.'
        context = {'third_party_id': uuid.uuid4().hex}
        newliveaction_db = action_db_utils.update_liveaction_status(
            status=status, result=result, context=context, end_timestamp=now,
            liveaction_id=liveaction_db.id)

        self.assertEqual(origliveaction_db.id, newliveaction_db.id)
        self.assertEqual(newliveaction_db.status, status)
        self.assertEqual(newliveaction_db.result, result)
        self.assertDictEqual(newliveaction_db.context, context)
        self.assertEqual(newliveaction_db.end_timestamp, now)
示例#2
0
    def _get_one(self, ref_or_id, exclude_fields=None, from_model_kwargs=None):
        LOG.info('GET %s with ref_or_id=%s', pecan.request.path, ref_or_id)

        try:
            instance = self._get_by_ref_or_id(ref_or_id=ref_or_id,
                                              exclude_fields=exclude_fields)
        except Exception as e:
            LOG.exception(e.message)
            pecan.abort(http_client.NOT_FOUND, e.message)
            return

        from_model_kwargs = from_model_kwargs or {}
        from_model_kwargs.update(
            self._get_from_model_kwargs_for_request(request=pecan.request))
        result = self.model.from_model(instance, **from_model_kwargs)
        if result and self.include_reference:
            pack = getattr(result, 'pack', None)
            name = getattr(result, 'name', None)
            result.ref = ResourceReference(pack=pack, name=name).ref

        LOG.debug('GET %s with ref_or_id=%s, client_result=%s',
                  pecan.request.path, ref_or_id, result)

        return result
示例#3
0
 def test_req_nonexistent_action(self):
     parameters = {'hosts': '127.0.0.1', 'cmd': 'uname -a'}
     action_ref = ResourceReference(name='i.action', pack='default').ref
     ex = LiveActionDB(action=action_ref, parameters=parameters)
     self.assertRaises(ValueError, action_service.request, ex)
示例#4
0
ACTION_OVR_PARAM_BAD_ATTR_NOOP = {
    'name': 'my.sudo.invalid.noop.action',
    'description': 'my test',
    'enabled': True,
    'entry_point': '/tmp/test/action.sh',
    'pack': 'default',
    'runner_type': 'local-shell-script',
    'parameters': {
        'sudo': {
            'type': 'boolean'
        }
    }
}

PACK = 'default'
ACTION_REF = ResourceReference(name='my.action', pack=PACK).ref
ACTION_WORKFLOW_REF = ResourceReference(name='my.wf_action', pack=PACK).ref
ACTION_OVR_PARAM_REF = ResourceReference(name='my.sudo.default.action',
                                         pack=PACK).ref
ACTION_OVR_PARAM_MUTABLE_REF = ResourceReference(name='my.sudo.mutable.action',
                                                 pack=PACK).ref
ACTION_OVR_PARAM_IMMUTABLE_REF = ResourceReference(
    name='my.sudo.immutable.action', pack=PACK).ref
ACTION_OVR_PARAM_BAD_ATTR_REF = ResourceReference(
    name='my.sudo.invalid.action', pack=PACK).ref
ACTION_OVR_PARAM_BAD_ATTR_NOOP_REF = ResourceReference(
    name='my.sudo.invalid.noop.action', pack=PACK).ref

USERNAME = '******'

示例#5
0
 def test_req_nonexistent_action(self):
     parameters = {"hosts": "127.0.0.1", "cmd": "uname -a"}
     action_ref = ResourceReference(name="i.action", pack="default").ref
     ex = LiveActionDB(action=action_ref, parameters=parameters)
     self.assertRaises(ValueError, action_service.request, ex)
    def setup_action_models(cls):
        pack = 'wolfpack'
        name = 'action-1'
        parameters = {
            'actionint': {
                'type': 'number',
                'default': 10,
                'position': 0
            },
            'actionfloat': {
                'type': 'float',
                'required': False,
                'position': 1
            },
            'actionstr': {
                'type': 'string',
                'required': True,
                'position': 2
            },
            'actionbool': {
                'type': 'boolean',
                'required': False,
                'position': 3
            },
            'actionlist': {
                'type': 'list',
                'required': False,
                'position': 4
            },
            'actionobject': {
                'type': 'object',
                'required': False,
                'position': 5
            },
            'actionnull': {
                'type': 'null',
                'required': False,
                'position': 6
            },
            'runnerdummy': {
                'type': 'string',
                'default': 'actiondummy'
            }
        }
        action_db = ActionDB(pack=pack,
                             name=name,
                             description='awesomeness',
                             enabled=True,
                             ref=ResourceReference(name=name, pack=pack).ref,
                             entry_point='',
                             runner_type={'name': 'test-runner'},
                             parameters=parameters)
        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)
示例#7
0
 def test_schedule_nonexistent_action(self):
     parameters = {'hosts': 'localhost', 'cmd': 'uname -a'}
     action_ref = ResourceReference(name='i.action', pack='default').ref
     execution = LiveActionDB(action=action_ref, parameters=parameters)
     self.assertRaises(ValueError, action_service.schedule, execution)
示例#8
0
    'runner_type': 'run-local',
    'parameters': {
        'a': {
            'type': 'string',
            'default': 'abc'
        }
    },
    'notify': {
        'on_complete': {
            'message': 'My awesome action is complete. Party time!!!',
            'channels': ['notify.slack']
        }
    }
}

ACTION_REF = ResourceReference(name='my.action', pack='default').ref
USERNAME = '******'


@mock.patch.object(PoolPublisher, 'publish', mock.MagicMock())
class TestActionExecutionService(DbTestCase):
    @classmethod
    def setUpClass(cls):
        super(TestActionExecutionService, cls).setUpClass()
        cls.runner = RunnerTypeAPI(**RUNNER)
        cls.runnerdb = RunnerType.add_or_update(
            RunnerTypeAPI.to_model(cls.runner))
        cls.action = ActionAPI(**ACTION)
        cls.actiondb = Action.add_or_update(ActionAPI.to_model(cls.action))

    @classmethod
示例#9
0
    def setup_action_models(cls):
        pack = "wolfpack"
        name = "action-1"
        parameters = {
            "actionint": {
                "type": "number",
                "default": 10,
                "position": 0
            },
            "actionfloat": {
                "type": "float",
                "required": False,
                "position": 1
            },
            "actionstr": {
                "type": "string",
                "required": True,
                "position": 2
            },
            "actionbool": {
                "type": "boolean",
                "required": False,
                "position": 3
            },
            "actionarray": {
                "type": "array",
                "required": False,
                "position": 4
            },
            "actionlist": {
                "type": "list",
                "required": False,
                "position": 5
            },
            "actionobject": {
                "type": "object",
                "required": False,
                "position": 6
            },
            "actionnull": {
                "type": "null",
                "required": False,
                "position": 7
            },
            "runnerdummy": {
                "type": "string",
                "default": "actiondummy"
            },
        }
        action_db = ActionDB(
            pack=pack,
            name=name,
            description="awesomeness",
            enabled=True,
            ref=ResourceReference(name=name, pack=pack).ref,
            entry_point="",
            runner_type={"name": "test-runner"},
            parameters=parameters,
        )
        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)