예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
파일: vmlab.py 프로젝트: hsavolai/vmlab
def main(argv=None):

    model = VMCatalog()
    view = VirtLabView(model)
    VirtLabControl(view, model)
    model.set_view(view)
    view.show()
    gtk.main()
예제 #4
0
    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())
예제 #5
0
    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()))
예제 #6
0
    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())
예제 #7
0
    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()))
예제 #8
0
    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())
예제 #9
0
    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())
예제 #10
0
 def testExeptionLibVirtdConnectionNotFound(self):
     static_stub = staticmethod(lambda *args, **kwargs: self.throw_ex())
     LibVirtDao.get_libvirt = static_stub
     vmcatalog = VMCatalog()
     # TODO: Add check exception should include vme_id with correct value
     self.assertRaises(VMLabException, vmcatalog.get_conn)