def test_vm_deleted_event(self): self.mox.StubOutWithMock(api, 'vm_delete_by_ids') api.vm_delete_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) deleted_vm_id = '25f04dd3-e924-02b2-9eac-876e3c943123' deleted_vm = Vm() deleted_vm.id = deleted_vm_id self.mox.StubOutWithMock( InventoryCacheManager, 'get_object_from_cache') InventoryCacheManager.get_object_from_cache( deleted_vm_id, Constants.Vm).AndReturn(deleted_vm) self.mox.ReplayAll() cachedList = ['25f04dd3-e924-02b2-9eac-876e3c943262', deleted_vm_id] updatedList = ['25f04dd3-e924-02b2-9eac-876e3c943262'] self.libvirtVM.processVmDeletes(cachedList, updatedList) self.assertTrue(len(test_notifier.NOTIFICATIONS) == 1) msg = test_notifier.NOTIFICATIONS[0] self.assertTrue(msg is not None) self.assertEquals(msg['priority'], notifier_api.INFO) event_type = \ event_metadata.get_EventMetaData( event_metadata.EVENT_TYPE_VM_DELETED) self.assertEquals(msg['event_type'], event_type.get_event_fully_qal_name()) payload = msg['payload'] self.assertEquals(payload['entity_type'], 'Vm') self.assertEquals(payload['entity_id'], deleted_vm_id)
def test_vm_save_update(self): ''' Update an existing object in db ''' vm = Vm() vm.id = 'VM1-id' healthnmon_db_api.vm_save(get_admin_context(), vm) vmGlobalSettings = VmGlobalSettings() vmGlobalSettings.set_id(vm.id) vmGlobalSettings.set_autoStartAction('autoStartAction') vmGlobalSettings.set_autoStopAction('autoStopAction') vm.set_vmGlobalSettings(vmGlobalSettings) healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm.id]) self.assertTrue(vms is not None) self.assertTrue(len(vms) == 1) vm = vms[0] self.assertEqual(vm.get_id(), 'VM1-id', "VM id is not same") vmGlobalSets = vm.get_vmGlobalSettings() self.assertTrue(vmGlobalSets is not None) self.assertEqual(vmGlobalSets.get_id(), 'VM1-id', "VM id is not same") self.assertEqual(vmGlobalSets.get_autoStartAction(), 'autoStartAction', "autoStartAction is not same") self.assertEqual(vmGlobalSets.get_autoStopAction(), 'autoStopAction', "autoStopAction is not same")
def test_vm_host_get_all_for_vm(self): host_id = 'VH1' vmhost = VmHost() vmhost.id = host_id healthnmon_db_api.vm_host_save(get_admin_context(), vmhost) vm = Vm() vm.id = 'VM11' vm.set_vmHostId(host_id) healthnmon_db_api.vm_save(get_admin_context(), vm) vmhosts = \ healthnmon_db_api.vm_host_get_all(get_admin_context()) self.assertFalse(vmhosts is None, 'Host get by id returned a none list') self.assertTrue(len(vmhosts) > 0, 'Host get by id returned invalid number of list' ) self.assertTrue(vmhosts[0].id == host_id) vmids = vmhosts[0].get_virtualMachineIds() self.assert_(vmids is not None) self.assert_(len(vmids) == 1) self.assert_(vm.id in vmids) healthnmon_db_api.vm_delete_by_ids(get_admin_context(), [vm.id]) vmhosts = \ healthnmon_db_api.vm_host_get_all(get_admin_context()) self.assertTrue(vmhosts[0].id == host_id) vmids = vmhosts[0].get_virtualMachineIds() self.assert_((vmids is None) or (len(vmids) == 0))
def test_vm_host_get_all_for_vm(self): host_id = 'VH1' vmhost = VmHost() vmhost.id = host_id healthnmon_db_api.vm_host_save(get_admin_context(), vmhost) vm = Vm() vm.id = 'VM11' vm.set_vmHostId(host_id) healthnmon_db_api.vm_save(get_admin_context(), vm) vmhosts = \ healthnmon_db_api.vm_host_get_all(get_admin_context()) self.assertFalse(vmhosts is None, 'Host get by id returned a none list') self.assertTrue( len(vmhosts) > 0, 'Host get by id returned invalid number of list') self.assertTrue(vmhosts[0].id == host_id) vmids = vmhosts[0].get_virtualMachineIds() self.assert_(vmids is not None) self.assert_(len(vmids) == 1) self.assert_(vm.id in vmids) healthnmon_db_api.vm_delete_by_ids(get_admin_context(), [vm.id]) vmhosts = \ healthnmon_db_api.vm_host_get_all(get_admin_context()) self.assertTrue(vmhosts[0].id == host_id) vmids = vmhosts[0].get_virtualMachineIds() self.assert_((vmids is None) or (len(vmids) == 0))
def test_processVmDeletes(self): self.mock.StubOutWithMock(api, 'vm_delete_by_ids') api.vm_delete_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic') nova_db.service_get_all_by_topic( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.StubOutWithMock(InventoryCacheManager, 'get_object_from_cache') deleted_vm_id = '25f04dd3-e924-02b2-9eac-876e3c943123' deleted_vm = Vm() deleted_vm.id = deleted_vm_id InventoryCacheManager.get_object_from_cache( deleted_vm_id, Constants.Vm).AndReturn(deleted_vm) self.mock.ReplayAll() cachedList = ['25f04dd3-e924-02b2-9eac-876e3c943262', deleted_vm_id] updatedList = ['25f04dd3-e924-02b2-9eac-876e3c943262'] self.assertEquals(self.libvirtVM.processVmDeletes(cachedList, updatedList), None) self.assertTrue(deleted_vm_id not in InventoryCacheManager.get_inventory_cache().keys()) self.mock.stubs.UnsetAll()
def test_vm_deleted_event(self): self.mox.StubOutWithMock(api, 'vm_delete_by_ids') api.vm_delete_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) deleted_vm_id = '25f04dd3-e924-02b2-9eac-876e3c943123' deleted_vm = Vm() deleted_vm.id = deleted_vm_id self.mox.StubOutWithMock(InventoryCacheManager, 'get_object_from_cache') InventoryCacheManager.get_object_from_cache( deleted_vm_id, Constants.Vm).AndReturn(deleted_vm) self.mox.ReplayAll() cachedList = ['25f04dd3-e924-02b2-9eac-876e3c943262', deleted_vm_id] updatedList = ['25f04dd3-e924-02b2-9eac-876e3c943262'] self.libvirtVM.processVmDeletes(cachedList, updatedList) self.assertTrue(len(test_notifier.NOTIFICATIONS) == 1) msg = test_notifier.NOTIFICATIONS[0] self.assertTrue(msg is not None) self.assertEquals(msg['priority'], notifier_api.INFO) event_type = \ event_metadata.get_EventMetaData( event_metadata.EVENT_TYPE_VM_DELETED) self.assertEquals(msg['event_type'], event_type.get_event_fully_qal_name()) payload = msg['payload'] self.assertEquals(payload['entity_type'], 'Vm') self.assertEquals(payload['entity_id'], deleted_vm_id)
def test_vm_host_get_by_id(self): host_id = 'VH1' vmhost = VmHost() vmhost.id = host_id healthnmon_db_api.vm_host_save(get_admin_context(), vmhost) vm = Vm() vm.id = 'VM11' vm.set_vmHostId(host_id) healthnmon_db_api.vm_save(get_admin_context(), vm) mntPnt = HostMountPoint() mntPnt.set_vmHostId(host_id) mntPnt.set_path('/path') volume = StorageVolume() volume.set_id('SV11') volume.add_mountPoints(mntPnt) healthnmon_db_api.storage_volume_save(get_admin_context(), volume) vmhosts = \ healthnmon_db_api.vm_host_get_by_ids(get_admin_context(), [host_id]) self.assertFalse(vmhosts is None, 'Host get by id returned a none list') self.assertTrue( len(vmhosts) > 0, 'Host get by id returned invalid number of list') self.assertTrue(vmhosts[0].id == host_id)
def test_vm_save(self): ''' Insert a vm object into db and check whether we are getting proper values after retrieval ''' vm = Vm() vm.id = 'VM1-id' vm.name = 'VM1-Name' vmScsiController = VmScsiController() vmScsiController.set_id('VM_CTRL_1') vmScsiController.set_id('some_type') vm.add_vmScsiControllers(vmScsiController) healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm.id]) self.assertTrue(vms is not None) self.assertTrue(len(vms) == 1) self.assertEqual(vms[0].get_id(), 'VM1-id', "VM id is not same") self.assertEqual(vms[0].get_name(), 'VM1-Name', "VM name is not same") self.assert_( len(vms[0].get_vmScsiControllers()) == 1, "vmScsiController len mismatch") self.assert_( vms[0].get_vmScsiControllers()[0].get_id() == vmScsiController.get_id(), "vmScsiController id mismatch") self.assert_( vms[0].get_vmScsiControllers()[0].get_type() == vmScsiController.get_type(), "vmScsiController type mismatch")
def test_vm_save_update(self): ''' Update an existing object in db ''' vm = Vm() vm.id = 'VM1-id' healthnmon_db_api.vm_save(get_admin_context(), vm) vmGlobalSettings = VmGlobalSettings() vmGlobalSettings.set_id(vm.id) vmGlobalSettings.set_autoStartAction('autoStartAction') vmGlobalSettings.set_autoStopAction('autoStopAction') vm.set_vmGlobalSettings(vmGlobalSettings) healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm.id]) self.assertTrue(vms is not None) self.assertTrue(len(vms) == 1) vm = vms[0] self.assertEqual(vm.get_id(), 'VM1-id', "VM id is not same") vmGlobalSets = vm.get_vmGlobalSettings() self.assertTrue(vmGlobalSets is not None) self.assertEqual(vmGlobalSets.get_id(), 'VM1-id', "VM id is not same") self.assertEqual(vmGlobalSets.get_autoStartAction(), 'autoStartAction', "autoStartAction is not same") self.assertEqual(vmGlobalSets.get_autoStopAction(), 'autoStopAction', "autoStopAction is not same")
def test_vm_netadpater_save(self): vm = Vm() vm.id = 'VM1' vmNetAdapter = VmNetAdapter() vmNetAdapter.set_id('netAdapter-01') vmNetAdapter.set_name('netAdapter-01') vmNetAdapter.set_addressType('assigned') vmNetAdapter.set_adapterType('E1000') vmNetAdapter.set_switchType('vSwitch') vmNetAdapter.set_macAddress('00:50:56:81:1c:d0') vmNetAdapter.add_ipAddresses('1.1.1.1') vmNetAdapter.set_networkName('br100') vmNetAdapter.set_vlanId(0) vm.add_vmNetAdapters(vmNetAdapter) healthnmon_db_api.vm_save(get_admin_context(), vm) virual_machines = \ healthnmon_db_api.vm_get_by_ids(get_admin_context(), ['VM1' ]) vm_from_db = virual_machines[0] netAdapters = vm_from_db.get_vmNetAdapters() netAdapter = netAdapters[0] self.assertTrue(vmNetAdapter.get_id() == netAdapter.get_id()) healthnmon_db_api.vm_delete_by_ids(get_admin_context(), [vm.id]) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm.id]) self.assertTrue(vms is None or len(vms) == 0, 'VM not deleted')
def test_vm_save(self): ''' Insert a vm object into db and check whether we are getting proper values after retrieval ''' vm = Vm() vm.id = 'VM1-id' vm.name = 'VM1-Name' vmScsiController = VmScsiController() vmScsiController.set_id('VM_CTRL_1') vmScsiController.set_id('some_type') vm.add_vmScsiControllers(vmScsiController) healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm.id]) self.assertTrue(vms is not None) self.assertTrue(len(vms) == 1) self.assertEqual(vms[0].get_id(), 'VM1-id', "VM id is not same") self.assertEqual(vms[0].get_name(), 'VM1-Name', "VM name is not same") self.assert_(len(vms[0].get_vmScsiControllers( )) == 1, "vmScsiController len mismatch") self.assert_(vms[0].get_vmScsiControllers()[0].get_id( ) == vmScsiController.get_id(), "vmScsiController id mismatch") self.assert_(vms[0].get_vmScsiControllers()[0].get_type() == vmScsiController.get_type(), "vmScsiController type mismatch")
def test_vm_netadpater_save(self): vm = Vm() vm.id = 'VM1' vmNetAdapter = VmNetAdapter() vmNetAdapter.set_id('netAdapter-01') vmNetAdapter.set_name('netAdapter-01') vmNetAdapter.set_addressType('assigned') vmNetAdapter.set_adapterType('E1000') vmNetAdapter.set_switchType('vSwitch') vmNetAdapter.set_macAddress('00:50:56:81:1c:d0') vmNetAdapter.add_ipAddresses('1.1.1.1') vmNetAdapter.set_networkName('br100') vmNetAdapter.set_vlanId(0) vm.add_vmNetAdapters(vmNetAdapter) healthnmon_db_api.vm_save(get_admin_context(), vm) virual_machines = \ healthnmon_db_api.vm_get_by_ids(get_admin_context(), ['VM1' ]) vm_from_db = virual_machines[0] netAdapters = vm_from_db.get_vmNetAdapters() netAdapter = netAdapters[0] self.assertTrue(vmNetAdapter.get_id() == netAdapter.get_id()) healthnmon_db_api.vm_delete_by_ids(get_admin_context(), [vm.id]) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm.id]) self.assertTrue(vms is None or len(vms) == 0, 'VM not deleted')
def test_vm_host_get_by_id(self): host_id = 'VH1' vmhost = VmHost() vmhost.id = host_id healthnmon_db_api.vm_host_save(get_admin_context(), vmhost) vm = Vm() vm.id = 'VM11' vm.set_vmHostId(host_id) healthnmon_db_api.vm_save(get_admin_context(), vm) mntPnt = HostMountPoint() mntPnt.set_vmHostId(host_id) mntPnt.set_path('/path') volume = StorageVolume() volume.set_id('SV11') volume.add_mountPoints(mntPnt) healthnmon_db_api.storage_volume_save(get_admin_context(), volume) vmhosts = \ healthnmon_db_api.vm_host_get_by_ids(get_admin_context(), [host_id]) self.assertFalse(vmhosts is None, 'Host get by id returned a none list') self.assertTrue(len(vmhosts) > 0, 'Host get by id returned invalid number of list' ) self.assertTrue(vmhosts[0].id == host_id)
def test_processVmDeletes(self): self.mock.StubOutWithMock(api, 'vm_delete_by_ids') api.vm_delete_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic') nova_db.service_get_all_by_topic(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.StubOutWithMock(InventoryCacheManager, 'get_object_from_cache' ) deleted_vm_id = '25f04dd3-e924-02b2-9eac-876e3c943123' deleted_vm = Vm() deleted_vm.id = deleted_vm_id InventoryCacheManager.get_object_from_cache(deleted_vm_id, Constants.Vm).AndReturn(deleted_vm) self.mock.ReplayAll() cachedList = ['25f04dd3-e924-02b2-9eac-876e3c943262', deleted_vm_id] updatedList = ['25f04dd3-e924-02b2-9eac-876e3c943262'] self.assertEquals(self.libvirtVM.processVmDeletes(cachedList, updatedList), None) self.assertTrue(deleted_vm_id not in InventoryCacheManager.get_inventory_cache().keys()) self.mock.stubs.UnsetAll()
def test_vm_get_by_id(self): vm_id = 'VM1' vm = Vm() vm.id = vm_id healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm_id]) self.assertFalse(vms is None, 'VM get by id returned a none list') self.assertTrue( len(vms) > 0, 'VM get by id returned invalid number of list') self.assertTrue(vms[0].id == 'VM1')
def test_vm_get_by_id(self): vm_id = 'VM1' vm = Vm() vm.id = vm_id healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm_id]) self.assertFalse(vms is None, 'VM get by id returned a none list') self.assertTrue(len(vms) > 0, 'VM get by id returned invalid number of list') self.assertTrue(vms[0].id == 'VM1')
def test_vm_save_none(self): #Initially insert a vm into db and check the length vm = Vm() vm.id = 'VM1-id' healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_all(get_admin_context()) self.assertTrue(vms is not None) self.assertTrue(len(vms) == 1) #Now try to save the none and check the length is same as previous healthnmon_db_api.vm_save(get_admin_context(), None) vmsaved = healthnmon_db_api.vm_get_all(get_admin_context()) self.assertTrue(vmsaved is not None) self.assertTrue(len(vmsaved) == 1)
def test_vm_delete_none(self): # Initially insert a vm into db and check the length vm = Vm() vm.id = 'VM1-id' healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_all(get_admin_context()) self.assertTrue(vms is not None) self.assertTrue(len(vms) == 1) # Now delete the None from db healthnmon_db_api.vm_delete_by_ids(get_admin_context(), None) vms = healthnmon_db_api.vm_get_all(get_admin_context()) self.assertTrue(vms is not None) self.assertTrue(len(vms) == 1)
def test_vm_save_none(self): # Initially insert a vm into db and check the length vm = Vm() vm.id = 'VM1-id' healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_all(get_admin_context()) self.assertTrue(vms is not None) self.assertTrue(len(vms) == 1) # Now try to save the none and check the length is same as previous healthnmon_db_api.vm_save(get_admin_context(), None) vmsaved = healthnmon_db_api.vm_get_all(get_admin_context()) self.assertTrue(vmsaved is not None) self.assertTrue(len(vmsaved) == 1)
def test_vm_delete_none(self): #Initially insert a vm into db and check the length vm = Vm() vm.id = 'VM1-id' healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_all(get_admin_context()) self.assertTrue(vms is not None) self.assertTrue(len(vms) == 1) #Now delete the None from db healthnmon_db_api.vm_delete_by_ids(get_admin_context(), None) vms = healthnmon_db_api.vm_get_all(get_admin_context()) self.assertTrue(vms is not None) self.assertTrue(len(vms) == 1)
def test_vm_get_all(self): ''' Inserts more than one vm object and try to get them all and validates the values ''' vm = Vm() vm.id = 'VM1-id' vm.name = 'VM1-Name' healthnmon_db_api.vm_save(get_admin_context(), vm) vm = Vm() vm.id = 'VM2-id' vm.name = 'VM2-Name' healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_all(get_admin_context()) self.assertFalse(vms is None, 'vm_get_all returned None') self.assertTrue(len(vms) == 2, 'vm_get_all does not returned expected number of vms') self.assertEqual(vms[0].get_id(), 'VM1-id', "VM id is not same") self.assertEqual(vms[1].get_id(), 'VM2-id', "VM id is not same") self.assertEqual(vms[0].get_name(), 'VM1-Name', "VM Name is not same") self.assertEqual(vms[1].get_name(), 'VM2-Name', "VM Name is not same")
def test_vm_get_all(self): ''' Inserts more than one vm object and try to get them all and validates the values ''' vm = Vm() vm.id = 'VM1-id' vm.name = 'VM1-Name' healthnmon_db_api.vm_save(get_admin_context(), vm) vm = Vm() vm.id = 'VM2-id' vm.name = 'VM2-Name' healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_all(get_admin_context()) self.assertFalse(vms is None, 'vm_get_all returned None') self.assertTrue( len(vms) == 2, 'vm_get_all does not returned expected number of vms') self.assertEqual(vms[0].get_id(), 'VM1-id', "VM id is not same") self.assertEqual(vms[1].get_id(), 'VM2-id', "VM id is not same") self.assertEqual(vms[0].get_name(), 'VM1-Name', "VM Name is not same") self.assertEqual(vms[1].get_name(), 'VM2-Name', "VM Name is not same")
def test_vm_delete(self): vm = Vm() vm_id = 'VM1' vm.id = vm_id vmGlobalSettings = VmGlobalSettings() vmGlobalSettings.set_id(vm_id) vm.set_vmGlobalSettings(vmGlobalSettings) healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm_id]) self.assertFalse(vms is None, 'VM get by id returned a none list') self.assertTrue( len(vms) > 0, 'VM get by id returned invalid number of list') healthnmon_db_api.vm_delete_by_ids(get_admin_context(), [vm_id]) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm_id]) self.assertTrue(vms is None or len(vms) == 0, 'VM not deleted')
def test_vm_delete(self): vm = Vm() vm_id = 'VM1' vm.id = vm_id vmGlobalSettings = VmGlobalSettings() vmGlobalSettings.set_id(vm_id) vm.set_vmGlobalSettings(vmGlobalSettings) healthnmon_db_api.vm_save(get_admin_context(), vm) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm_id]) self.assertFalse(vms is None, 'VM get by id returned a none list') self.assertTrue(len(vms) > 0, 'VM get by id returned invalid number of list') healthnmon_db_api.vm_delete_by_ids(get_admin_context(), [vm_id]) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm_id]) self.assertTrue(vms is None or len(vms) == 0, 'VM not deleted')
def test_vm_host_get_all(self): ''' Inserts more than one host with vms and storage volumes. Also validates the data retrieved from the vmhost, vm, storage volumes. ''' vmhost = VmHost() vmhost.id = 'VH1-id' healthnmon_db_api.vm_host_save(get_admin_context(), vmhost) vmhost = VmHost() vmhost.id = 'VH2-id' healthnmon_db_api.vm_host_save(get_admin_context(), vmhost) vm = Vm() vm.id = 'VM1-id' vm.set_vmHostId('VH1-id') vmGlobalSettings = VmGlobalSettings() vmGlobalSettings.set_id(vm.id) vmGlobalSettings.set_autoStartAction('autoStartAction') vmGlobalSettings.set_autoStopAction('autoStopAction') vm.set_vmGlobalSettings(vmGlobalSettings) healthnmon_db_api.vm_save(get_admin_context(), vm) mntPnt = HostMountPoint() mntPnt.set_vmHostId('VH1-id') mntPnt.set_path('/path') volume = StorageVolume() sv_id = 'SV1-id' volume.set_id(sv_id) volume.add_mountPoints(mntPnt) healthnmon_db_api.storage_volume_save(get_admin_context(), volume) vmhosts = healthnmon_db_api.vm_host_get_all(get_admin_context()) self.assertFalse(vmhosts is None, 'vm_host_get_all returned a None') self.assertTrue( len(vmhosts) == 2, 'vm_host_get_all does not returned expected number of hosts') self.assertEqual(vmhosts[0].get_id(), 'VH1-id', "VMHost id is not same") self.assertEqual(vmhosts[1].get_id(), 'VH2-id', "VMHost id is not same") vmlist = vmhosts[0].get_virtualMachineIds() self.assertFalse(vmlist is None, "virtual machines from the host returned None") self.assertTrue( len(vmlist) == 1, "length of virtual machines list is not returned as expected") self.assertTrue(vm.id in vmlist, "VmId is not in host") vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), ['VM1-id']) self.assertTrue(vms is not None) self.assertTrue(len(vms) == 1) vm = vms[0] self.assertEqual(vm.get_id(), 'VM1-id', "VM id is not same") vmGlobalSets = vm.get_vmGlobalSettings() self.assertTrue(vmGlobalSets is not None) self.assertEqual(vmGlobalSets.get_id(), 'VM1-id', "VM id is not same") self.assertEqual(vmGlobalSets.get_autoStartAction(), 'autoStartAction', "autoStartAction is not same") self.assertEqual(vmGlobalSets.get_autoStopAction(), 'autoStopAction', "autoStopAction is not same") svlist = vmhosts[0].get_storageVolumeIds() self.assertFalse(svlist is None, "Storage Volumes from the host returned None") self.assertTrue( len(svlist) >= 1, "length of storage volumes list is not returned as expected") self.assertTrue(sv_id in svlist, "Storage Volume Id is not host") storagevolumes = \ healthnmon_db_api.storage_volume_get_by_ids(get_admin_context(), ['SV1-id']) self.assertFalse(storagevolumes is None, 'Storage volume get by id returned a none list') self.assertTrue( len(storagevolumes) > 0, 'Storage volume get by id returned invalid number of list') self.assertEquals(storagevolumes[0].id, 'SV1-id', "Storage volume id is not same") hostMountPoints = storagevolumes[0].get_mountPoints() self.assertEquals(hostMountPoints[0].get_path(), '/path', "Host mount point path is not same") self.assertEquals( hostMountPoints[0].get_vmHostId(), 'VH1-id', "VmHost id is not same for storage volumes")
def test_vm_host_get_all(self): ''' Inserts more than one host with vms and storage volumes. Also validates the data retrieved from the vmhost, vm, storage volumes. ''' vmhost = VmHost() vmhost.id = 'VH1-id' healthnmon_db_api.vm_host_save(get_admin_context(), vmhost) vmhost = VmHost() vmhost.id = 'VH2-id' healthnmon_db_api.vm_host_save(get_admin_context(), vmhost) vm = Vm() vm.id = 'VM1-id' vm.set_vmHostId('VH1-id') vmGlobalSettings = VmGlobalSettings() vmGlobalSettings.set_id(vm.id) vmGlobalSettings.set_autoStartAction('autoStartAction') vmGlobalSettings.set_autoStopAction('autoStopAction') vm.set_vmGlobalSettings(vmGlobalSettings) healthnmon_db_api.vm_save(get_admin_context(), vm) mntPnt = HostMountPoint() mntPnt.set_vmHostId('VH1-id') mntPnt.set_path('/path') volume = StorageVolume() sv_id = 'SV1-id' volume.set_id(sv_id) volume.add_mountPoints(mntPnt) healthnmon_db_api.storage_volume_save(get_admin_context(), volume) vmhosts = healthnmon_db_api.vm_host_get_all(get_admin_context()) self.assertFalse(vmhosts is None, 'vm_host_get_all returned a None') self.assertTrue( len(vmhosts) == 2, 'vm_host_get_all does not returned expected number of hosts') self.assertEqual(vmhosts[0].get_id(), 'VH1-id', "VMHost id is not same") self.assertEqual(vmhosts[1].get_id(), 'VH2-id', "VMHost id is not same") vmlist = vmhosts[0].get_virtualMachineIds() self.assertFalse(vmlist is None, "virtual machines from the host returned None") self.assertTrue( len(vmlist) == 1, "length of virtual machines list is not returned as expected") self.assertTrue(vm.id in vmlist, "VmId is not in host") vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), ['VM1-id']) self.assertTrue(vms is not None) self.assertTrue(len(vms) == 1) vm = vms[0] self.assertEqual(vm.get_id(), 'VM1-id', "VM id is not same") vmGlobalSets = vm.get_vmGlobalSettings() self.assertTrue(vmGlobalSets is not None) self.assertEqual(vmGlobalSets.get_id(), 'VM1-id', "VM id is not same") self.assertEqual(vmGlobalSets.get_autoStartAction(), 'autoStartAction', "autoStartAction is not same") self.assertEqual(vmGlobalSets.get_autoStopAction(), 'autoStopAction', "autoStopAction is not same") svlist = vmhosts[0].get_storageVolumeIds() self.assertFalse(svlist is None, "Storage Volumes from the host returned None") self.assertTrue( len(svlist) >= 1, "length of storage volumes list is not returned as expected") self.assertTrue(sv_id in svlist, "Storage Volume Id is not host") storagevolumes = \ healthnmon_db_api.storage_volume_get_by_ids(get_admin_context(), ['SV1-id']) self.assertFalse(storagevolumes is None, 'Storage volume get by id returned a none list') self.assertTrue( len(storagevolumes) > 0, 'Storage volume get by id returned invalid number of list') self.assertEquals(storagevolumes[0].id, 'SV1-id', "Storage volume id is not same") hostMountPoints = storagevolumes[0].get_mountPoints() self.assertEquals(hostMountPoints[0].get_path(), '/path', "Host mount point path is not same") self.assertEquals(hostMountPoints[0].get_vmHostId(), 'VH1-id', "VmHost id is not same for storage volumes")