def test_container_action_get_by_container_and_request(self): """Ensure we can get an action by container UUID and request_id""" uuid1 = uuidutils.generate_uuid() action_values = self._create_action_values(uuid1) dbapi.action_start(self.context, action_values) request_id = action_values['request_id'] # An other action using a different req id action_values['action'] = 'test-action' action_values['request_id'] = 'req-00000000-7522-4d99-7ff-111111111111' dbapi.action_start(self.context, action_values) action = dbapi.action_get_by_request_id(self.context, uuid1, request_id) self.assertEqual('create_container', action['action']) self.assertEqual(self.context.request_id, action['request_id'])
def test_container_action_get_by_container_and_request(self, mock_write, mock_read): """Ensure we can get an action by container UUID and request_id""" mock_read.side_effect = etcd.EtcdKeyNotFound uuid1 = uuidutils.generate_uuid() action_values = self._create_action_values(uuid1) action = dbapi.action_start(self.context, action_values) request_id = action_values['request_id'] # An other action using a different req id action_values['action'] = 'test-action' action_values['request_id'] = 'req-00000000-7522-4d99-7ff-111111111111' dbapi.action_start(self.context, action_values) mock_read.side_effect = lambda *args: FakeEtcdMultipleResult([action]) action = dbapi.action_get_by_request_id(self.context, uuid1, request_id) self.assertEqual('create_container', action['action']) self.assertEqual(self.context.request_id, action['request_id'])
def test_container_action_event_finish_success(self): """Finish a container action event.""" uuid = uuidutils.generate_uuid() action = dbapi.action_start(self.context, self._create_action_values(uuid)) dbapi.action_event_start(self.context, self._create_event_values(uuid)) event_values = { 'finish_time': timeutils.utcnow() + datetime.timedelta(seconds=5), 'result': 'Success' } event_values = self._create_event_values(uuid, extra=event_values) event = dbapi.action_event_finish(self.context, event_values) self._assertActionEventSaved(event, action['id']) action = dbapi.action_get_by_request_id(self.context, uuid, self.context.request_id) self.assertNotEqual('Error', action['message'])
def test_container_action_event_finish_success(self): """Finish a container action event.""" uuid = uuidutils.generate_uuid() action = dbapi.action_start(self.context, self._create_action_values(uuid)) dbapi.action_event_start(self.context, self._create_event_values(uuid)) event_values = { 'finish_time': timeutils.utcnow() + timedelta(seconds=5), 'result': 'Success' } event_values = self._create_event_values(uuid, extra=event_values) event = dbapi.action_event_finish(self.context, event_values) self._assertActionEventSaved(event, action['id']) action = dbapi.action_get_by_request_id(self.context, uuid, self.context.request_id) self.assertNotEqual('Error', action['message'])
def test_container_action_event_finish_success( self, mock_db_inst, mock_get_event_by_name, mock__action_get_by_request_id, mock_update, mock_write, mock_read): """Finish a container action event.""" mock_db_inst.return_value = etcdapi.get_backend() mock_read.side_effect = etcd.EtcdKeyNotFound uuid = uuidutils.generate_uuid() action = dbapi.action_start(self.context, self._create_action_values(uuid)) event_values = self._create_event_values(uuid) event_values['action_uuid'] = action['uuid'] mock__action_get_by_request_id.return_value = action mock_read.side_effect = etcd.EtcdKeyNotFound event = dbapi.action_event_start(self.context, event_values) event_values = { 'finish_time': timeutils.utcnow() + timedelta(seconds=5), 'result': 'Success' } event_values = self._create_event_values(uuid, extra=event_values) mock__action_get_by_request_id.return_value = action mock_get_event_by_name.return_value = event mock_read.side_effect = lambda *args: FakeEtcdResult(event) event = dbapi.action_event_finish(self.context, event_values) event['start_time'] = datetime.isoformat(event['start_time']) mock_read.side_effect = lambda *args: FakeEtcdMultipleResult([event]) self._assertActionEventSaved(event, action['uuid']) mock_read.side_effect = lambda *args: FakeEtcdMultipleResult([action]) action = dbapi.action_get_by_request_id(self.context, uuid, self.context.request_id) self.assertNotEqual('Error', action['message'])
def get_by_request_id(cls, context, container_uuid, request_id): db_action = dbapi.action_get_by_request_id(context, container_uuid, request_id) if db_action: return cls._from_db_object(context, cls(context), db_action)
def get_by_request_id(cls, context, container_uuid, request_id): db_action = dbapi.action_get_by_request_id(context, container_uuid, request_id) if db_action: return cls._from_db_object(context, cls(context), db_action)