def test_create(self, mock_create_action): mock_create_action.return_value = self.fake_action action = objects.Action(self.context, **self.fake_action) action.create() expected_action = self.fake_action.copy() expected_action['created_at'] = expected_action['created_at'].replace( tzinfo=iso8601.iso8601.Utc()) mock_create_action.assert_called_once_with(expected_action) self.assertEqual(self.context, action._context)
def test_create(self): with mock.patch.object(self.dbapi, 'create_action', autospec=True) as mock_create_action: mock_create_action.return_value = self.fake_action action = objects.Action(self.context, **self.fake_action) action.create() mock_create_action.assert_called_once_with(self.fake_action) self.assertEqual(self.context, action._context)
def _create_action(self, context, _action): try: LOG.debug("Creating the %s in the Watcher database", _action.get("action_type")) new_action = objects.Action(context, **_action) new_action.create() return new_action except Exception as exc: LOG.exception(exc) raise
def create_action(self, action_type, parameters, next): action = { 'uuid': utils.generate_uuid(), 'action_plan_id': 0, 'action_type': action_type, 'input_parameters': parameters, 'state': objects.action.State.PENDING, 'alarm': None, 'next': next, } new_action = objects.Action(self.context, **action) new_action.create(self.context) new_action.save() return new_action
def create_action(self, action_type, parameters, parents=None, uuid=None): action = { 'uuid': uuid or utils.generate_uuid(), 'action_plan_id': 0, 'action_type': action_type, 'input_parameters': parameters, 'state': objects.action.State.PENDING, 'parents': parents or [], } new_action = objects.Action(self.context, **action) with mock.patch.object(notifications.action, 'send_create'): new_action.create() return new_action
def get_test_action(context, **kw): """Return a Action object with appropriate attributes. NOTE: The object leaves the attributes marked as changed, such that a create() could be used to commit it to the DB. """ db_action = db_utils.get_test_action(**kw) # Let DB generate ID if it isn't specified explicitly if 'id' not in kw: del db_action['id'] action = objects.Action(context) for key in db_action: setattr(action, key, db_action[key]) return action
def create_action(self, action_type, parameters, parents, uuid=None): action = { 'uuid': uuid or utils.generate_uuid(), 'action_plan_id': 0, 'action_type': action_type, 'input_parameters': parameters, 'state': objects.action.State.PENDING, 'parents': parents, } new_action = objects.Action(self.context, **action) new_action.create() new_action.save() return new_action
def get_sorted_actions_by_weight(self, context, action_plan, solution): # We need to make them immutable to add them to the graph action_objects = list([ objects.Action( context, uuid=utils.generate_uuid(), parents=[], action_plan_id=action_plan.id, **a) for a in solution.actions]) # This is a dict of list with each being a weight and the list being # all the actions associated to this weight weighted_actions = collections.defaultdict(list) for action in action_objects: action_weight = self.config.weights[action.action_type] weighted_actions[action_weight].append(action) return reversed(sorted(weighted_actions.items(), key=lambda x: x[0]))
def post(self, action): """Create a new action. :param action: a action within the request body. """ if self.from_actions: raise exception.OperationNotPermitted action_dict = action.as_dict() context = pecan.request.context new_action = objects.Action(context, **action_dict) new_action.create(context) # Set the HTTP Location Header pecan.response.location = link.build_url('actions', new_action.uuid) return Action.convert_with_links(new_action)
def _create_action(self, context, _action, parent_action): try: LOG.debug("Creating the %s in watcher db", _action.get("action_type")) new_action = objects.Action(context, **_action) new_action.create(context) new_action.save() if parent_action: parent_action.next = new_action.id parent_action.save() return new_action except Exception as exc: LOG.exception(exc) raise
def post(self, action): """Create a new action. :param action: a action within the request body. """ # FIXME: blueprint edit-action-plan-flow raise exception.OperationNotPermitted( _("Cannot create an action directly")) if self.from_actions: raise exception.OperationNotPermitted action_dict = action.as_dict() context = pecan.request.context new_action = objects.Action(context, **action_dict) new_action.create() # Set the HTTP Location Header pecan.response.location = link.build_url('actions', new_action.uuid) return Action.convert_with_links(new_action)