def test_update_kpi_no_trackers(self): raw = self.mox.CreateMockAnything() raw.request_id = REQUEST_ID_1 views.STACKDB.find_request_trackers(request_id=REQUEST_ID_1)\ .AndReturn([]) self.mox.ReplayAll() views.update_kpi(None, raw) self.mox.VerifyAll()
def test_aggregate_lifecycle_end(self): event_name = 'compute.instance.create' start_event = '%s.end' % event_name end_event = '%s.end' % event_name start_when = datetime.datetime.utcnow() end_when = datetime.datetime.utcnow() start_raw = utils.create_raw(self.mox, start_when, start_event, state='building') end_raw = utils.create_raw(self.mox, end_when, end_event, old_task='build') lifecycle = utils.create_lifecycle(self.mox, INSTANCE_ID_1, 'active', '', start_raw) views.STACKDB.find_lifecycles(instance=INSTANCE_ID_1)\ .AndReturn([lifecycle]) views.STACKDB.save(lifecycle) timing = utils.create_timing(self.mox, event_name, lifecycle, start_raw=start_raw, start_when=start_when) views.STACKDB.find_timings(name=event_name, lifecycle=lifecycle)\ .AndReturn([timing]) self.mox.StubOutWithMock(views, "update_kpi") views.update_kpi(timing, end_raw) views.STACKDB.save(timing) self.mox.ReplayAll() views.aggregate_lifecycle(end_raw) self.assertEqual(lifecycle.last_raw, end_raw) self.assertEqual(lifecycle.last_state, 'active') self.assertEqual(lifecycle.last_task_state, 'build') self.assertEqual(timing.name, event_name) self.assertEqual(timing.lifecycle, lifecycle) self.assertEqual(timing.start_raw, start_raw) self.assertEqual(timing.start_when, start_when) self.assertEqual(timing.end_raw, end_raw) self.assertEqual(timing.end_when, end_when) self.assertEqual(timing.diff, end_when - start_when) self.mox.VerifyAll()
def test_aggregate_lifecycle_end(self): event_name = 'compute.instance.create' start_event = '%s.end' % event_name end_event = '%s.end' % event_name start_when = datetime.datetime.utcnow() end_when = datetime.datetime.utcnow() start_raw = utils.create_raw(self.mox, start_when, start_event, state='building') end_raw = utils.create_raw(self.mox, end_when, end_event, old_task='build') lifecycle = utils.create_lifecycle(self.mox, INSTANCE_ID_1, 'active', '', start_raw) views.STACKDB.find_lifecycles(instance=INSTANCE_ID_1)\ .AndReturn([lifecycle]) views.STACKDB.save(lifecycle) timing = utils.create_timing(self.mox, event_name, lifecycle, start_raw=start_raw, start_when=start_when) views.STACKDB.find_timings(name=event_name, lifecycle=lifecycle)\ .AndReturn([timing]) self.mox.StubOutWithMock(views, "update_kpi") views.update_kpi(timing, end_raw) views.STACKDB.save(timing) self.mox.ReplayAll() views.aggregate_lifecycle(end_raw) self.assertEqual(lifecycle.last_raw, end_raw) self.assertEqual(lifecycle.last_state, 'active') self.assertEqual(lifecycle.last_task_state, 'build') self.assertEqual(timing.name, event_name) self.assertEqual(timing.lifecycle, lifecycle) self.assertEqual(timing.start_raw, start_raw) self.assertEqual(timing.start_when, start_when) self.assertEqual(timing.end_raw, end_raw) self.assertEqual(timing.end_when, end_when) self.assertEqual(timing.diff, end_when-start_when) self.mox.VerifyAll()
def test_update_kpi(self): lifecycle = self.mox.CreateMockAnything() end = utils.decimal_utc() raw = self.mox.CreateMockAnything() raw.request_id = REQUEST_ID_1 raw.when=end timing = utils.create_timing(self.mox, 'compute.instance.create', lifecycle, end_when=end) start = utils.decimal_utc() tracker = utils.create_tracker(self.mox, REQUEST_ID_1, lifecycle, start) views.STACKDB.find_request_trackers(request_id=REQUEST_ID_1)\ .AndReturn([tracker]) views.STACKDB.save(tracker) self.mox.ReplayAll() views.update_kpi(timing, raw) self.assertEqual(tracker.request_id, REQUEST_ID_1) self.assertEqual(tracker.lifecycle, lifecycle) self.assertEqual(tracker.last_timing, timing) self.assertEqual(tracker.start, start) self.assertEqual(tracker.duration, end-start) self.mox.VerifyAll()