def test_timestamp_columns(self): """ Test the time stamp columns createEpoch, modifiedEpoch and deletedEpoch """ vol = StorageVolume() vol.set_id('vol-01') # Check for createEpoch epoch_before = utils.get_current_epoch_ms() healthnmon_db_api.storage_volume_save(self.admin_context, vol) epoch_after = utils.get_current_epoch_ms() vol_queried = healthnmon_db_api.storage_volume_get_by_ids( self.admin_context, [vol.get_id()])[0] self.assert_( test_utils.is_timestamp_between(epoch_before, epoch_after, vol_queried.get_createEpoch())) # Check for lastModifiedEpoch vol_modified = vol_queried test_utils.unset_timestamp_fields(vol_modified) vol_modified.set_name('changed_name') epoch_before = utils.get_current_epoch_ms() healthnmon_db_api.storage_volume_save(self.admin_context, vol_modified) epoch_after = utils.get_current_epoch_ms() vol_queried = healthnmon_db_api.storage_volume_get_by_ids( self.admin_context, [vol.get_id()])[0] self.assert_( vol_modified.get_createEpoch() == vol_queried.get_createEpoch()) self.assert_( test_utils.is_timestamp_between( epoch_before, epoch_after, vol_queried.get_lastModifiedEpoch()))
def __create_volume(self, **kwargs): vol = StorageVolume() if kwargs is not None: for field in kwargs: setattr(vol, field, kwargs[field]) healthnmon_db_api.storage_volume_save(self.admin_context, vol) return vol
def test_storage_volume_get_all_by_filters_changessince(self): # Create StorageVolumes vol_ids = ('V1', 'V2', 'V3') vol_names = ('name1', 'name2', 'name3') for i in range(len(vol_ids)): self.__create_volume(id=vol_ids[i], name=vol_names[i]) created_time = long(time.time() * 1000L) # Wait for 1 sec and update second vol and delete third vol time.sleep(1) second_vol = healthnmon_db_api.storage_volume_get_by_ids( self.admin_context, [vol_ids[1]])[0] second_vol.name = 'New name' healthnmon_db_api.storage_volume_save(self.admin_context, second_vol) healthnmon_db_api.storage_volume_delete_by_ids(self.admin_context, [vol_ids[2]]) # Query with filter expected_updated_ids = [vol_ids[1], vol_ids[2]] filters = {'changes-since': created_time} vols = healthnmon_db_api.storage_volume_get_all_by_filters( self.admin_context, filters, None, None) self.assert_(vols is not None) self.assert_(len(vols) == 2) for vol in vols: self.assert_(vol is not None) self.assert_(vol.id in expected_updated_ids)
def test_vm_host_get_all_for_sv(self): host_id = 'VH1' vmhost = VmHost() vmhost.id = host_id healthnmon_db_api.vm_host_save(get_admin_context(), vmhost) 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_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) svlist = vmhosts[0].get_storageVolumeIds() self.assert_(svlist is not None) self.assert_(len(svlist) == 1) self.assert_(volume.get_id() in svlist) healthnmon_db_api.storage_volume_delete_by_ids( get_admin_context(), [volume.get_id()]) vmhosts = \ healthnmon_db_api.vm_host_get_all(get_admin_context()) self.assertTrue(vmhosts[0].id == host_id) svids = vmhosts[0].get_storageVolumeIds() self.assert_((svids is None) or (len(svids) == 0))
def test_storage_added_event(self): storagePool = libvirt.virStoragePool() self.mox.StubOutWithMock(api, 'storage_volume_save') api.storage_volume_save( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mox.StubOutWithMock(InventoryCacheManager, 'get_object_from_cache') InventoryCacheManager.get_object_from_cache( storagePool.UUIDString(), Constants.StorageVolume).AndReturn(None) self.mox.ReplayAll() self.LibvirtStorageVolume._processStorage(storagePool) self.assertEquals(len(test_notifier.NOTIFICATIONS), 1) msg = test_notifier.NOTIFICATIONS[0] self.assertEquals(msg['priority'], notifier_api.INFO) event_type = \ event_metadata.get_EventMetaData( event_metadata.EVENT_TYPE_STORAGE_ADDED) self.assertEquals(msg['event_type'], event_type.get_event_fully_qal_name()) payload = msg['payload'] self.assertEquals(payload['entity_type'], 'StorageVolume') self.assertEquals(payload['entity_id'], storagePool.UUIDString())
def test_storagevolume_save(self): storagevolume = StorageVolume() storagevolume.id = 'SV1' healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume)
def test_update_inventory(self): self.mox.StubOutWithMock(libvirt, 'openReadOnly') libvirt.openReadOnly(mox.IgnoreArg()).AndReturn(self.fakeConn) self.mox.StubOutWithMock(api, 'vm_save') self.mox.StubOutWithMock(api, 'vm_host_save') self.mox.StubOutWithMock(api, 'storage_volume_save') api.storage_volume_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) api.vm_host_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) api.vm_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mox.ReplayAll() conn = connection.get_connection(True) compute_rmcontext = ComputeRMContext(rmType='QEMU', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') InventoryCacheManager.get_all_compute_inventory()['1'] = \ ComputeInventory(compute_rmcontext) conn.init_rmcontext(compute_rmcontext) conn._wrapped_conn = self.fakeConn conn.update_inventory('1')
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_storage_no_state_change(self): storagePool = libvirt.virStoragePool() self.mox.StubOutWithMock(api, 'storage_volume_save') api.storage_volume_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) cachedStorageVolume = StorageVolume() cachedStorageVolume.id = storagePool.UUIDString() cachedStorageVolume.size = 0 cachedStorageVolume.free = 0 cachedStorageVolume.connectionState = \ Constants.STORAGE_STATE_ACTIVE self.mox.StubOutWithMock( InventoryCacheManager, 'get_object_from_cache') InventoryCacheManager.get_object_from_cache(storagePool.UUIDString(), Constants.StorageVolume).AndReturn(cachedStorageVolume) # self.mox.StubOutWithMock(InventoryCacheManager, 'get_compute_conn_driver') # # InventoryCacheManager.get_compute_conn_driver(self.LibvirtStorageVolume.compute_id, # Constants.VmHost).AndReturn(fake.get_connection()) self.mox.ReplayAll() nova_db.service_get_all_by_topic(None, None) self.LibvirtStorageVolume._processStorage(storagePool) self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
def test_storage_volume_get_all_by_filters_changessince(self): # Create StorageVolumes vol_ids = ('V1', 'V2', 'V3') vol_names = ('name1', 'name2', 'name3') for i in range(len(vol_ids)): self.__create_volume(id=vol_ids[i], name=vol_names[i]) created_time = long(time.time() * 1000L) # Wait for 1 sec and update second vol and delete third vol time.sleep(1) second_vol = healthnmon_db_api.storage_volume_get_by_ids( self.admin_context, [vol_ids[1]])[0] second_vol.name = 'New name' healthnmon_db_api.storage_volume_save(self.admin_context, second_vol) healthnmon_db_api.storage_volume_delete_by_ids( self.admin_context, [vol_ids[2]]) # Query with filter expected_updated_ids = [vol_ids[1], vol_ids[2]] filters = {'changes-since': created_time} vols = healthnmon_db_api.storage_volume_get_all_by_filters( self.admin_context, filters, None, None) self.assert_(vols is not None) self.assert_(len(vols) == 2) for vol in vols: self.assert_(vol is not None) self.assert_(vol.id in expected_updated_ids)
def test_vm_host_get_all_for_sv(self): host_id = 'VH1' vmhost = VmHost() vmhost.id = host_id healthnmon_db_api.vm_host_save(get_admin_context(), vmhost) 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_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) svlist = vmhosts[0].get_storageVolumeIds() self.assert_(svlist is not None) self.assert_(len(svlist) == 1) self.assert_(volume.get_id() in svlist) healthnmon_db_api.storage_volume_delete_by_ids(get_admin_context(), [volume.get_id()]) vmhosts = \ healthnmon_db_api.vm_host_get_all(get_admin_context()) self.assertTrue(vmhosts[0].id == host_id) svids = vmhosts[0].get_storageVolumeIds() self.assert_((svids is None) or (len(svids) == 0))
def test_storage_no_state_change(self): storagePool = libvirt.virStoragePool() self.mox.StubOutWithMock(api, 'storage_volume_save') api.storage_volume_save( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) cachedStorageVolume = StorageVolume() cachedStorageVolume.id = storagePool.UUIDString() cachedStorageVolume.size = 0 cachedStorageVolume.free = 0 cachedStorageVolume.connectionState = \ Constants.STORAGE_STATE_ACTIVE self.mox.StubOutWithMock(InventoryCacheManager, 'get_object_from_cache') InventoryCacheManager.get_object_from_cache( storagePool.UUIDString(), Constants.StorageVolume).AndReturn(cachedStorageVolume) # self.mox.StubOutWithMock(InventoryCacheManager, 'get_compute_conn_driver') # # InventoryCacheManager.get_compute_conn_driver(self.LibvirtStorageVolume.compute_id, # Constants.VmHost).AndReturn(fake.get_connection()) self.mox.ReplayAll() nova_db.service_get_all_by_topic(None, None) self.LibvirtStorageVolume._processStorage(storagePool) self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
def test_update_inventory(self): self.mox.StubOutWithMock(libvirt, 'openReadOnly') libvirt.openReadOnly(mox.IgnoreArg()).AndReturn(self.fakeConn) self.mox.StubOutWithMock(api, 'vm_save') self.mox.StubOutWithMock(api, 'vm_host_save') self.mox.StubOutWithMock(api, 'storage_volume_save') api.storage_volume_save( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) api.vm_host_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) api.vm_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mox.ReplayAll() conn = connection.get_connection(True) compute_rmcontext = ComputeRMContext(rmType='QEMU', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') InventoryCacheManager.get_all_compute_inventory()['1'] = \ ComputeInventory(compute_rmcontext) conn.init_rmcontext(compute_rmcontext) conn._wrapped_conn = self.fakeConn conn.update_inventory('1')
def test_timestamp_columns(self): """ Test the time stamp columns createEpoch, modifiedEpoch and deletedEpoch """ vol = StorageVolume() vol.set_id('vol-01') # Check for createEpoch epoch_before = utils.get_current_epoch_ms() healthnmon_db_api.storage_volume_save(self.admin_context, vol) epoch_after = utils.get_current_epoch_ms() vol_queried = healthnmon_db_api.storage_volume_get_by_ids( self.admin_context, [vol.get_id()])[0] self.assert_(test_utils.is_timestamp_between( epoch_before, epoch_after, vol_queried.get_createEpoch())) # Check for lastModifiedEpoch vol_modified = vol_queried test_utils.unset_timestamp_fields(vol_modified) vol_modified.set_name('changed_name') epoch_before = utils.get_current_epoch_ms() healthnmon_db_api.storage_volume_save(self.admin_context, vol_modified) epoch_after = utils.get_current_epoch_ms() vol_queried = healthnmon_db_api.storage_volume_get_by_ids( self.admin_context, [vol.get_id()])[0] self.assert_( vol_modified.get_createEpoch() == vol_queried.get_createEpoch()) self.assert_(test_utils.is_timestamp_between( epoch_before, epoch_after, vol_queried.get_lastModifiedEpoch()))
def test_storage_added_event(self): storagePool = libvirt.virStoragePool() self.mox.StubOutWithMock(api, 'storage_volume_save') api.storage_volume_save( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mox.StubOutWithMock( InventoryCacheManager, 'get_object_from_cache') InventoryCacheManager.get_object_from_cache( storagePool.UUIDString(), Constants.StorageVolume).AndReturn(None) self.mox.ReplayAll() self.LibvirtStorageVolume._processStorage(storagePool) self.assertEquals(len(test_notifier.NOTIFICATIONS), 1) msg = test_notifier.NOTIFICATIONS[0] self.assertEquals(msg['priority'], notifier_api.INFO) event_type = \ event_metadata.get_EventMetaData( event_metadata.EVENT_TYPE_STORAGE_ADDED) self.assertEquals(msg['event_type'], event_type.get_event_fully_qal_name()) payload = msg['payload'] self.assertEquals(payload['entity_type'], 'StorageVolume') self.assertEquals(payload['entity_id'], storagePool.UUIDString())
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_storagevolume_get_by_id(self): storagevolume_id = 'SV1' storagevolume = StorageVolume() storagevolume.id = storagevolume_id healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) storagevolumes = \ healthnmon_db_api.storage_volume_get_by_ids(self.admin_context, [storagevolume_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.assertTrue(storagevolumes[0].id == 'SV1')
def test_storagevolume_get_by_id(self): storagevolume_id = 'SV1' storagevolume = StorageVolume() storagevolume.id = storagevolume_id healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) storagevolumes = \ healthnmon_db_api.storage_volume_get_by_ids(self.admin_context, [storagevolume_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.assertTrue(storagevolumes[0].id == 'SV1')
def test_storagevolume_get_all(self): storagevolume = StorageVolume() storagevolume.id = 'SV1' healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) storagevolume = StorageVolume() storagevolume.id = 'SV2' healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) storagevolumes = \ healthnmon_db_api.storage_volume_get_all(self.admin_context) self.assertFalse(storagevolumes is None, 'storage volume all returned a none list') self.assertTrue(len(storagevolumes) == 2, 'storage volume all returned invalid number of list' ) self.assertTrue( storagevolumes[0].id == 'SV1', 'Storage volume id mismatch') self.assertTrue( storagevolumes[1].id == 'SV2', 'Storage volume id mismatch')
def test_processStorage(self): self.mock.StubOutWithMock(api, 'storage_volume_save') api.storage_volume_save( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.ReplayAll() self.assertEquals( self.LibvirtStorageVolume._processStorage( libvirt.virStoragePool()), None) host = InventoryCacheManager.get_object_from_cache( '1', Constants.VmHost) storage = InventoryCacheManager.get_object_from_cache( '95f7101b-892c-c388-867a-8340e5fea27a', Constants.StorageVolume) self.assertTrue('95f7101b-892c-c388-867a-8340e5fea27a', host.get_storageVolumeIds()) self.assertTrue(storage is not None) self.assertEquals('default', storage.get_name()) self.mock.stubs.UnsetAll()
def test_storagevolume_get_all(self): storagevolume = StorageVolume() storagevolume.id = 'SV1' healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) storagevolume = StorageVolume() storagevolume.id = 'SV2' healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) storagevolumes = \ healthnmon_db_api.storage_volume_get_all(self.admin_context) self.assertFalse(storagevolumes is None, 'storage volume all returned a none list') self.assertTrue( len(storagevolumes) == 2, 'storage volume all returned invalid number of list') self.assertTrue(storagevolumes[0].id == 'SV1', 'Storage volume id mismatch') self.assertTrue(storagevolumes[1].id == 'SV2', 'Storage volume id mismatch')
def test_processStorage(self): self.mock.StubOutWithMock(api, 'storage_volume_save') api.storage_volume_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.ReplayAll() self.assertEquals( self.LibvirtStorageVolume._processStorage( libvirt.virStoragePool()), None) host = InventoryCacheManager.get_object_from_cache( '1', Constants.VmHost) storage = InventoryCacheManager.get_object_from_cache( '95f7101b-892c-c388-867a-8340e5fea27a', Constants.StorageVolume) self.assertTrue('95f7101b-892c-c388-867a-8340e5fea27a', host.get_storageVolumeIds()) self.assertTrue(storage is not None) self.assertEquals('default', storage.get_name()) self.assertEquals('34353438-3934-434e-3738-313630323543', storage.get_resourceManagerId()) self.mock.stubs.UnsetAll()
def test_storage_disabled_event(self): storagePool = libvirt.virStoragePool() self.mox.StubOutWithMock(api, 'storage_volume_save') api.storage_volume_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) cachedStorageVolume = StorageVolume() cachedStorageVolume.id = storagePool.UUIDString() cachedStorageVolume.size = 0 cachedStorageVolume.free = 0 cachedStorageVolume.connectionState = \ Constants.STORAGE_STATE_ACTIVE self.mox.StubOutWithMock( InventoryCacheManager, 'get_object_from_cache') InventoryCacheManager.get_object_from_cache(storagePool.UUIDString(), Constants.StorageVolume).AndReturn(cachedStorageVolume) self.mox.StubOutWithMock(storagePool, 'isActive') storagePool.isActive().AndReturn(0) # self.mox.StubOutWithMock(InventoryCacheManager, 'get_compute_conn_driver') # # InventoryCacheManager.get_compute_conn_driver(self.LibvirtStorageVolume.compute_id, # Constants.VmHost).AndReturn(fake.get_connection()) self.mox.ReplayAll() self.LibvirtStorageVolume._processStorage(storagePool) self.assertEquals(len(test_notifier.NOTIFICATIONS), 1) msg = test_notifier.NOTIFICATIONS[0] self.assertEquals(msg['priority'], notifier_api.WARN) event_type = \ event_metadata.get_EventMetaData( event_metadata.EVENT_TYPE_STORAGE_DISABLED) self.assertEquals(msg['event_type'], event_type.get_event_fully_qal_name()) payload = msg['payload'] self.assertEquals(payload['entity_type'], 'StorageVolume') self.assertEquals(payload['entity_id'], storagePool.UUIDString()) self.assertEquals(payload['state'], Constants.STORAGE_STATE_INACTIVE)
def test_storagevolume_delete(self): storagevolume = StorageVolume() storagevolume_id = 'SV1' storagevolume.id = storagevolume_id vm = Vm() vm.set_id('vm-01') vmGlobalSettings = VmGlobalSettings() vmGlobalSettings.set_id('vm_01') vm.set_vmGlobalSettings(vmGlobalSettings) vmDisk = VmDisk() vmDisk.set_id('disk-01') vmDisk.set_storageVolumeId(storagevolume_id) vm.add_vmDisks(vmDisk) vmDisk = VmDisk() vmDisk.set_id('disk-02') vmDisk.set_storageVolumeId('SV2') vm.add_vmDisks(vmDisk) healthnmon_db_api.vm_save(self.admin_context, vm) healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) storagevolumes = \ healthnmon_db_api.storage_volume_get_by_ids(self.admin_context, [storagevolume_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') healthnmon_db_api.storage_volume_delete_by_ids(self.admin_context, [storagevolume_id]) storagevolumes = \ healthnmon_db_api.storage_volume_get_by_ids(self.admin_context, [storagevolume_id]) self.assertTrue(storagevolumes is None or len(storagevolumes) == 0, 'Storage volume not deleted')
def test_storagevolume_delete(self): storagevolume = StorageVolume() storagevolume_id = 'SV1' storagevolume.id = storagevolume_id vm = Vm() vm.set_id('vm-01') vmGlobalSettings = VmGlobalSettings() vmGlobalSettings.set_id('vm_01') vm.set_vmGlobalSettings(vmGlobalSettings) vmDisk = VmDisk() vmDisk.set_id('disk-01') vmDisk.set_storageVolumeId(storagevolume_id) vm.add_vmDisks(vmDisk) vmDisk = VmDisk() vmDisk.set_id('disk-02') vmDisk.set_storageVolumeId('SV2') vm.add_vmDisks(vmDisk) healthnmon_db_api.vm_save(self.admin_context, vm) healthnmon_db_api.storage_volume_save(self.admin_context, storagevolume) storagevolumes = \ healthnmon_db_api.storage_volume_get_by_ids(self.admin_context, [storagevolume_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') healthnmon_db_api.storage_volume_delete_by_ids(self.admin_context, [storagevolume_id]) storagevolumes = \ healthnmon_db_api.storage_volume_get_by_ids(self.admin_context, [storagevolume_id]) self.assertTrue(storagevolumes is None or len(storagevolumes) == 0, 'Storage volume not deleted')
def test_processUpdates_hostupdate_event(self): defaultInstancesPath = cfg.CONF.instances_path cfg.CONF.set_override('instances_path', '/var/lib/libvirt/images') storagePool = libvirt.virStoragePool() self.mock.StubOutWithMock(api, 'storage_volume_save') api.storage_volume_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().\ AndReturn(None) cachedStorageVolume = StorageVolume() cachedStorageVolume.id = storagePool.UUIDString() cachedStorageVolume.size = 0 cachedStorageVolume.free = 0 cachedStorageVolume.connectionState = \ Constants.STORAGE_STATE_INACTIVE InventoryCacheManager.update_object_in_cache( '95f7101b-892c-c388-867a-8340e5fea27x', cachedStorageVolume) self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().\ AndReturn(None) self.mock.StubOutWithMock( InventoryCacheManager, 'get_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver(None, Constants.VmHost).\ AndReturn(fake. get_connection()) self.mock.ReplayAll() self.assertEquals(self.LibvirtStorageVolume.processUpdates(), None) self.assertEquals(self.LibvirtStorageVolume._createNovaPool(), None) cfg.CONF.set_override('instances_path', defaultInstancesPath) self.mock.stubs.UnsetAll()
def test_storage_disabled_event(self): storagePool = libvirt.virStoragePool() self.mox.StubOutWithMock(api, 'storage_volume_save') api.storage_volume_save( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) cachedStorageVolume = StorageVolume() cachedStorageVolume.id = storagePool.UUIDString() cachedStorageVolume.size = 0 cachedStorageVolume.free = 0 cachedStorageVolume.connectionState = \ Constants.STORAGE_STATE_ACTIVE self.mox.StubOutWithMock(InventoryCacheManager, 'get_object_from_cache') InventoryCacheManager.get_object_from_cache( storagePool.UUIDString(), Constants.StorageVolume).AndReturn(cachedStorageVolume) self.mox.StubOutWithMock(storagePool, 'isActive') storagePool.isActive().AndReturn(0) # self.mox.StubOutWithMock(InventoryCacheManager, 'get_compute_conn_driver') # # InventoryCacheManager.get_compute_conn_driver(self.LibvirtStorageVolume.compute_id, # Constants.VmHost).AndReturn(fake.get_connection()) self.mox.ReplayAll() self.LibvirtStorageVolume._processStorage(storagePool) self.assertEquals(len(test_notifier.NOTIFICATIONS), 1) msg = test_notifier.NOTIFICATIONS[0] self.assertEquals(msg['priority'], notifier_api.WARN) event_type = \ event_metadata.get_EventMetaData( event_metadata.EVENT_TYPE_STORAGE_DISABLED) self.assertEquals(msg['event_type'], event_type.get_event_fully_qal_name()) payload = msg['payload'] self.assertEquals(payload['entity_type'], 'StorageVolume') self.assertEquals(payload['entity_id'], storagePool.UUIDString()) self.assertEquals(payload['state'], Constants.STORAGE_STATE_INACTIVE)
def test_vm_host_delete(self): vmhost_id = 'VH1' vmhost = VmHost() vmhost.id = vmhost_id vSwitch = VirtualSwitch() vSwitch.set_id('vSwitch-01') vSwitch.set_name('vSwitch-01') vSwitch.set_resourceManagerId('rmId') vSwitch.set_switchType('vSwitch') cost1 = Cost() cost1.set_value(100) cost1.set_units('USD') vSwitch.set_cost(cost1) portGroup = PortGroup() portGroup.set_id('pg-01') portGroup.set_name('pg-01') portGroup.set_resourceManagerId('rmId') portGroup.set_type('portgroup_type') portGroup.set_cost(cost1) vSwitch.add_portGroups(portGroup) vmhost.add_virtualSwitches(vSwitch) vmhost.add_portGroups(portGroup) healthnmon_db_api.vm_host_save(get_admin_context(), vmhost) vmhost2 = VmHost() vmhost2.set_id('VH2') healthnmon_db_api.vm_host_save(get_admin_context(), vmhost2) storage = StorageVolume() storage.set_id('sv-01') storage.set_name('storage-01') storage.set_resourceManagerId('rmId') storage.set_size(1234) storage.set_free(2345) storage.set_vmfsVolume(True) storage.set_shared(True) storage.set_assignedServerCount(1) storage.set_volumeType('VMFS') storage.set_volumeId('101') hostMount1 = HostMountPoint() hostMount1.set_path('test_path1') hostMount1.set_vmHostId('VH1') storage.add_mountPoints(hostMount1) hostMount2 = HostMountPoint() hostMount2.set_path('test_path2') hostMount2.set_vmHostId('VH2') storage.add_mountPoints(hostMount2) healthnmon_db_api.storage_volume_save(get_admin_context(), storage) vm = Vm() vm.set_id('vm-01') vm.set_name('vm-01') vm.set_vmHostId('VH1') healthnmon_db_api.vm_save(get_admin_context(), vm) vmhosts = \ healthnmon_db_api.vm_host_get_by_ids(get_admin_context(), [vmhost_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' ) healthnmon_db_api.vm_host_delete_by_ids(get_admin_context(), [vmhost_id]) vmhosts = \ healthnmon_db_api.vm_host_get_by_ids(get_admin_context(), [vmhost_id]) self.assertTrue(vmhosts is None or len(vmhosts) == 0, 'host not deleted')
def test_storagevolume_save_none(self): self.assertTrue( healthnmon_db_api.storage_volume_save(self.admin_context, None) is None, 'The storage volume should save nothing')
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")
def test_vm_host_delete(self): vmhost_id = 'VH1' vmhost = VmHost() vmhost.id = vmhost_id vSwitch = VirtualSwitch() vSwitch.set_id('vSwitch-01') vSwitch.set_name('vSwitch-01') vSwitch.set_resourceManagerId('rmId') vSwitch.set_switchType('vSwitch') cost1 = Cost() cost1.set_value(100) cost1.set_units('USD') vSwitch.set_cost(cost1) portGroup = PortGroup() portGroup.set_id('pg-01') portGroup.set_name('pg-01') portGroup.set_resourceManagerId('rmId') portGroup.set_type('portgroup_type') portGroup.set_cost(cost1) vSwitch.add_portGroups(portGroup) vmhost.add_virtualSwitches(vSwitch) vmhost.add_portGroups(portGroup) healthnmon_db_api.vm_host_save(get_admin_context(), vmhost) vmhost2 = VmHost() vmhost2.set_id('VH2') healthnmon_db_api.vm_host_save(get_admin_context(), vmhost2) storage = StorageVolume() storage.set_id('sv-01') storage.set_name('storage-01') storage.set_resourceManagerId('rmId') storage.set_size(1234) storage.set_free(2345) storage.set_vmfsVolume(True) storage.set_shared(True) storage.set_assignedServerCount(1) storage.set_volumeType('VMFS') storage.set_volumeId('101') hostMount1 = HostMountPoint() hostMount1.set_path('test_path1') hostMount1.set_vmHostId('VH1') storage.add_mountPoints(hostMount1) hostMount2 = HostMountPoint() hostMount2.set_path('test_path2') hostMount2.set_vmHostId('VH2') storage.add_mountPoints(hostMount2) healthnmon_db_api.storage_volume_save(get_admin_context(), storage) vm = Vm() vm.set_id('vm-01') vm.set_name('vm-01') vm.set_vmHostId('VH1') healthnmon_db_api.vm_save(get_admin_context(), vm) vmhosts = \ healthnmon_db_api.vm_host_get_by_ids(get_admin_context(), [vmhost_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.assertRaises(Exception, healthnmon_db_api.vm_host_delete_by_ids,([vmhost_id])) healthnmon_db_api.vm_host_delete_by_ids(get_admin_context(), [vmhost_id]) vmhosts = \ healthnmon_db_api.vm_host_get_by_ids(get_admin_context(), [vmhost_id]) self.assertTrue(vmhosts is None or len(vmhosts) == 0, 'host not deleted')
def test_storagevolume_save_none(self): self.assertTrue( healthnmon_db_api.storage_volume_save( self.admin_context, None) is None, 'The storage volume should save nothing')