def testGetMixedVmInstancesOrderAttached(self): self.setUpMVMock() # Setup running instance self.virConnectMock.listDomainsID().AndReturn([1]) run_vm_name = "TEST-VM-RUN" self.virDomainMock.name().AndReturn(run_vm_name) self.virConnectMock.lookupByID(1).AndReturn(self.virDomainMock) # Setup stopped instance stop_vm_name = "TEST-VM-STOP" self.virConnectMock.listDefinedDomains().AndReturn([stop_vm_name]) mox.Replay(self.virConnectMock, self.virDomainMock) vm_catalog = VMCatalog() vm_catalog.refesh() vm_catalog.get_vm(run_vm_name).set_order(1) vms = vm_catalog.get_vms() self.assertEqual(2, len(vms), "There should be two vms! / "\ + str(len(vms))) self.assertEqual(stop_vm_name, vms[1].get_name(), \ "VM name does not match! / " \ + stop_vm_name + vms[1].get_name()) self.assertEqual(c.STATE_STOPPED, vms[1].get_state().get_state_str(), \ "VM should be stopped / " + vms[1].get_state().get_state_str()) self.assertEqual(run_vm_name, vms[0].get_name(), \ "VM name does not match! / " + vms[0].get_name()) self.assertEqual(c.STATE_RUNNING, vms[0].get_state().get_state_str(), \ "VM should be running / " + vms[0].get_state().get_state_str()) self.assertEqual(1, vms[0].get_order(), \ "VM should have order / " + str(vms[0].get_order()))
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 testGetMixedVmInstancesOrderAttached(self): self.setUpMVMock() # Setup running instance self.virConnectMock.listDomainsID().AndReturn([1]) run_vm_name = "TEST-VM-RUN" self.virDomainMock.name().AndReturn(run_vm_name) self.virConnectMock.lookupByID(1).AndReturn(self.virDomainMock) # Setup stopped instance stop_vm_name = "TEST-VM-STOP" self.virConnectMock.listDefinedDomains().AndReturn([stop_vm_name]) mox.Replay(self.virConnectMock, self.virDomainMock) vm_catalog = VMCatalog() vm_catalog.refesh() vm_catalog.get_vm(run_vm_name).set_order(1) vms = vm_catalog.get_vms() self.assertEqual(2, len(vms), "There should be two vms! / "\ + str(len(vms))) self.assertEqual(stop_vm_name, vms[1].get_name(), \ "VM name does not match! / " \ + stop_vm_name + vms[1].get_name()) self.assertEqual(c.STATE_STOPPED, vms[1].get_state().get_state_str(), \ "VM should be stopped / " + vms[1].get_state().get_state_str()) self.assertEqual(run_vm_name, vms[0].get_name(), \ "VM name does not match! / " + vms[0].get_name()) self.assertEqual(c.STATE_RUNNING, vms[0].get_state().get_state_str(), \ "VM should be running / " + vms[0].get_state().get_state_str()) self.assertEqual(1, vms[0].get_order(), \ "VM should have order / " + str(vms[0].get_order()))
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 testGetSingleRunningVmInstance(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() vm_catalog.refesh() vms = vm_catalog.get_vms() vm1 = vm_catalog.get_vm(run_vm_name + "-0") vm2 = vm_catalog.get_vm(stop_vm_name + "-0") #Assert self.assertEqual(1, len(vms)) self.assertFalse(vm2) self.assertTrue(vm1) self.assertEqual(c.STATE_RUNNING, vm1.get_state().get_state_str())
def testGetSingleRunningVmInstance(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() vm_catalog.refesh() vms = vm_catalog.get_vms() vm1 = vm_catalog.get_vm(run_vm_name + "-0") vm2 = vm_catalog.get_vm(stop_vm_name + "-0") #Assert self.assertEqual(1, len(vms)) self.assertFalse(vm2) self.assertTrue(vm1) self.assertEqual(c.STATE_RUNNING, vm1.get_state().get_state_str())