def testOrderPersistsOverReload(self): # Setup self.setUpMVMock() run_vm_name = "TEST-VM-RUN" stop_vm_name = "TEST-VM-STOP" self.addRunningVMs(run_vm_name, 1) self.addStoppedVMs(stop_vm_name, 0) mox.Replay(self.virConnectMock, self.virDomainMock) #Test vm_catalog = VMCatalog() assert isinstance(vm_catalog, VMCatalog) vm_catalog.refesh() vm = vm_catalog.get_vm(run_vm_name + "-0") assert isinstance(vm, VMInstance) order = 1 vm.set_order(1) #Setup mox.Reset(self.virConnectMock, self.virDomainMock) self.addRunningVMs(run_vm_name, 1) self.addStoppedVMs(stop_vm_name, 0) mox.Replay(self.virConnectMock, self.virDomainMock) vm_catalog.refesh() vm = vm_catalog.get_vm(run_vm_name + "-0") #Assert self.assertEqual(order, vm.get_order())
def testGetMixedVmInstancesHistoryChange(self): # Setup self.setUpMVMock() run_vm_name = "TEST-VM-RUN" stop_vm_name = "TEST-VM-STOP" self.addRunningVMs(run_vm_name, 1) self.addStoppedVMs(stop_vm_name, 1) mox.Replay(self.virConnectMock, self.virDomainMock) #Test vm_catalog = VMCatalog() history_changed = vm_catalog.refesh() #Assert self.assertEqual(True, history_changed) #Setup mox.Reset(self.virConnectMock, self.virDomainMock) self.addRunningVMs(run_vm_name, 0) self.addStoppedVMs(stop_vm_name, 2) mox.Replay(self.virConnectMock, self.virDomainMock) #Test history_changed = vm_catalog.refesh() #Assert self.assertEqual(True, history_changed)
def testReset(self): """Should empty all queues and put mocks in record mode.""" mock_obj = mox.MockObject(TestClass) mock_obj.ValidCall() self.assertFalse(mock_obj._replay_mode) mock_obj._Replay() self.assertTrue(mock_obj._replay_mode) self.assertEquals(1, len(mock_obj._expected_calls_queue)) mox.Reset(mock_obj) self.assertFalse(mock_obj._replay_mode) self.assertEquals(0, len(mock_obj._expected_calls_queue))
def test_process_job_should_fail_if_it_reached_max_retry_count(self): mox.Reset(self.worker) self.mox.StubOutWithMock(utils, 'generate_notification') max_retry_count = 2 self.config(max_retry=max_retry_count, group='snapshot_worker') self.job['retry_count'] = max_retry_count + 1 utils.generate_notification(None, 'qonos.job.run.start', mox.IsA(dict), mox.IsA(str)) self.worker.update_job(fakes.JOB_ID, 'MAX_RETRIED', timeout=None, error_message=mox.IsA(str))\ .AndReturn({'status': 'MAX_RETRIED', 'timeout': self.job['timeout']}) expected_payload = { 'job': { 'status': 'MAX_RETRIED', 'hard_timeout': self.job['hard_timeout'], 'created_at': self.job['created_at'], 'modified_at': self.job['modified_at'], 'retry_count': self.job['retry_count'], 'schedule_id': '33333333-3333-3333-3333-33333333', 'worker_id': '11111111-1111-1111-1111-11111111', 'timeout': self.job['timeout'], 'action': 'snapshot', 'id': '22222222-2222-2222-2222-22222222', 'tenant': '44444444-4444-4444-4444-44444444', 'metadata': { 'instance_id': '55555555-5555-5555-5555-55555555' } } } utils.generate_notification(None, 'qonos.job.failed', expected_payload, mox.IsA(str)) self.mox.ReplayAll() processor = TestableSnapshotProcessor(self.nova_client) processor.init_processor(self.worker) processor.process_job(self.job) self.mox.VerifyAll()
def doTestRunStateChanges(self, initial_runstate, end_runstate, attrname, do_selected=True): """test calling attrname with both a single and multi-selection of projects. Sets initial run state of the projects, and confirms it gets switched to end_runstate. Args: initial_runstate: the initial run state of the Projects end_runstate: the end run state of the Projects after the op attrname: call this attribute for each project do_selected: if True, do mock a SelectedProjects() call. """ plists = (self.Projects(1), self.Projects(4)) for projectlist in plists: for p in projectlist: p.runstate = initial_runstate tc = launcher.TaskController(FakeAppController()) tc.SetModelsViews(runtime=launcher.Runtime()) stateop = getattr(tc, attrname) self.assertTrue(callable(stateop)) # Override thread creation; don't want real tasks running tc._CreateTaskThreadForProject = self._CreateTaskThreadForProject # Mock out "selected projects" of the frame to return projectlist frame_mock = mox.MockObject(launcher.MainFrame) if do_selected: frame_mock.SelectedProjects().AndReturn(projectlist) mox.Replay(frame_mock) tc.SetModelsViews(frame=frame_mock) # Finally, call the method we are testing, and verify stateop(None) mox.Verify(frame_mock) self.ConfirmThreads(end_runstate) # re-run our op and make sure no threads are modified/added/removed tmlen = len(self.threads) mox.Reset(frame_mock) if do_selected: frame_mock.SelectedProjects().AndReturn(projectlist) mox.Replay(frame_mock) stateop(None) mox.Verify(frame_mock) self.assertEqual(tmlen, len(self.threads)) self.ConfirmThreads(end_runstate)
def test_process_job_should_fail_if_hard_timed_out(self): mox.Reset(self.worker) self.mox.StubOutWithMock(utils, 'generate_notification') now = timeutils.utcnow() self.job['hard_timeout'] = timeutils.strtime(at=now) utils.generate_notification(None, 'qonos.job.run.start', mox.IsA(dict), mox.IsA(str)) self.worker.update_job(fakes.JOB_ID, 'HARD_TIMED_OUT', timeout=None, error_message=mox.IsA(str))\ .AndReturn({'status': 'HARD_TIMED_OUT', 'timeout': self.job['timeout']}) expected_payload = { 'job': { 'status': 'HARD_TIMED_OUT', 'hard_timeout': self.job['hard_timeout'], 'created_at': self.job['created_at'], 'modified_at': self.job['modified_at'], 'retry_count': 1, 'schedule_id': '33333333-3333-3333-3333-33333333', 'worker_id': '11111111-1111-1111-1111-11111111', 'timeout': self.job['timeout'], 'action': 'snapshot', 'id': '22222222-2222-2222-2222-22222222', 'tenant': '44444444-4444-4444-4444-44444444', 'metadata': { 'instance_id': '55555555-5555-5555-5555-55555555' } } } utils.generate_notification(None, 'qonos.job.failed', expected_payload, mox.IsA(str)) self.mox.ReplayAll() processor = TestableSnapshotProcessor(self.nova_client) processor.init_processor(self.worker) processor.process_job(self.job) self.mox.VerifyAll()