def test_container_action_events_get_in_order(self): """Ensure retrived action events are in order.""" uuid1 = uuidutils.generate_uuid() action = dbapi.action_start(self.context, self._create_action_values(uuid1)) extra1 = { 'created_at': timeutils.utcnow() } extra2 = { 'created_at': timeutils.utcnow() + timedelta(seconds=5) } event_val1 = self._create_event_values(uuid1, 'fake1', extra=extra1) event_val2 = self._create_event_values(uuid1, 'fake2', extra=extra1) event_val3 = self._create_event_values(uuid1, 'fake3', extra=extra2) event1 = dbapi.action_event_start(self.context, event_val1) event2 = dbapi.action_event_start(self.context, event_val2) event3 = dbapi.action_event_start(self.context, event_val3) events = dbapi.action_events_get(self.context, action['id']) self.assertEqual(3, len(events)) self._assertEqualOrderedListOfObjects([event3, event2, event1], events, ['container_uuid', 'request_id'])
def test_container_action_events_get_in_order( self, mock_db_inst, mock__action_get_by_request_id, mock_write, mock_read): mock_db_inst.return_value = etcdapi.get_backend() mock_read.side_effect = etcd.EtcdKeyNotFound uuid1 = uuidutils.generate_uuid() action = dbapi.action_start(self.context, self._create_action_values(uuid1)) extra1 = { 'action_uuid': action['uuid'], 'created_at': timeutils.utcnow() } extra2 = { 'action_uuid': action['uuid'], 'created_at': timeutils.utcnow() + timedelta(seconds=5) } event_val1 = self._create_event_values(uuid1, 'fake1', extra=extra1) event_val2 = self._create_event_values(uuid1, 'fake2', extra=extra1) event_val3 = self._create_event_values(uuid1, 'fake3', extra=extra2) mock__action_get_by_request_id.return_value = action mock_read.side_effect = etcd.EtcdKeyNotFound event1 = dbapi.action_event_start(self.context, event_val1) event1['start_time'] = datetime.isoformat(event1['start_time']) mock__action_get_by_request_id.return_value = action mock_read.side_effect = etcd.EtcdKeyNotFound event2 = dbapi.action_event_start(self.context, event_val2) event2['start_time'] = datetime.isoformat(event2['start_time']) mock__action_get_by_request_id.return_value = action mock_read.side_effect = etcd.EtcdKeyNotFound event3 = dbapi.action_event_start(self.context, event_val3) event3['start_time'] = datetime.isoformat(event3['start_time']) mock_read.side_effect = lambda *args: FakeEtcdMultipleResult( [event1, event2, event3]) events = dbapi.action_events_get(self.context, action['uuid']) self.assertEqual(3, len(events)) self._assertEqualOrderedListOfObjects([event3, event2, event1], events, ['container_uuid', 'request_id'])
def get_by_action(cls, context, action_id): db_events = dbapi.action_events_get(context, action_id) return ContainerActionEvent._from_db_object_list( context, cls, db_events)
def _assertActionEventSaved(self, event, action_id): """Retrieve the event to ensure it was successfully added.""" events = dbapi.action_events_get(self.context, action_id) self.assertEqual(1, len(events)) self._assertEqualObjects(event, events[0], ['container_uuid', 'request_id'])
def get_by_action(cls, context, action_id): db_events = dbapi.action_events_get(context, action_id) return ContainerActionEvent._from_db_object_list(context, cls, db_events)