def setUp(self): super(StorageVolumeEventsTest, self).setUp() self.connection = LibvirtConnection(False) vmHost = VmHost() vmHost.set_storageVolumeIds([]) InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection._wrapped_conn = libvirt.open('qemu:///system') self.LibvirtStorageVolume = \ LibvirtStorageVolume(self.connection._wrapped_conn, '1') self.LibvirtStorageVolume.vmHost = vmHost self.LibvirtStorageVolume.cur_total_storage_size = 0 self.LibvirtStorageVolume.curr_storage_free = 0 self.LibvirtStorageVolume.old_total_storage_size = 0 self.LibvirtStorageVolume.old_storage_free = 0 self.LibvirtStorageVolume.vmHost.set_id('1') self.connection.compute_rmcontext = \ ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') self.flags( healthnmon_notification_drivers=['nova.notifier.test_notifier']) test_notifier.NOTIFICATIONS = [] self.mox.StubOutWithMock(nova_db, 'service_get_all_by_topic') nova_db.service_get_all_by_topic( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)
def test_processUpdatesException(self): self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) mock_libvirtSV = LibvirtStorageVolume(self.connection, '1') self.mock.StubOutWithMock(mock_libvirtSV, 'processStorageDeletes') mock_libvirtSV.processStorageDeletes([], []).AndRaise(Exception) self.mock.ReplayAll() self.assertEquals(self.LibvirtStorageVolume.processUpdates(), None) self.assertRaises(Exception, LibvirtStorageVolume) self.mock.stubs.UnsetAll()
def setUp(self): self.connection = LibvirtConnection(False) vmHost = VmHost() vmHost.set_storageVolumeIds([]) InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection._wrapped_conn = libvirt.open('qemu:///system') self.LibvirtStorageVolume = \ LibvirtStorageVolume(self.connection._wrapped_conn, '1') self.connection.compute_rmcontext = \ ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') self.mock = mox.Mox()
def setUp(self): super(StorageVolumeEventsTest, self).setUp() self.connection = LibvirtConnection(False) vmHost = VmHost() vmHost.set_storageVolumeIds([]) InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection._wrapped_conn = libvirt.open('qemu:///system') self.LibvirtStorageVolume = \ LibvirtStorageVolume(self.connection._wrapped_conn, '1') self.LibvirtStorageVolume.vmHost = vmHost self.LibvirtStorageVolume.cur_total_storage_size = 0 self.LibvirtStorageVolume.curr_storage_free = 0 self.LibvirtStorageVolume.old_total_storage_size = 0 self.LibvirtStorageVolume.old_storage_free = 0 self.LibvirtStorageVolume.vmHost.set_id('1') self.connection.compute_rmcontext = \ ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') self.flags(healthnmon_notification_drivers=[ 'nova.notifier.test_notifier']) test_notifier.NOTIFICATIONS = [] self.mox.StubOutWithMock(nova_db, 'service_get_all_by_topic') nova_db.service_get_all_by_topic( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)
def setUp(self): super(test_LibvirtStorage, self).setUp() self.connection = LibvirtConnection(False) vmHost = VmHost() vmHost.set_storageVolumeIds([]) InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection._wrapped_conn = libvirt.open('qemu:///system') self.LibvirtStorageVolume = \ LibvirtStorageVolume(self.connection._wrapped_conn, '1') self.connection.compute_rmcontext = \ ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') cfg.CONF.set_override('healthnmon_notification_drivers', ['healthnmon.notifier.log_notifier']) self.mock = mox.Mox()
class test_LibvirtStorage(unittest.TestCase): def setUp(self): self.connection = LibvirtConnection(False) vmHost = VmHost() vmHost.set_storageVolumeIds([]) InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection._wrapped_conn = libvirt.open('qemu:///system') self.LibvirtStorageVolume = \ LibvirtStorageVolume(self.connection._wrapped_conn, '1') self.connection.compute_rmcontext = \ ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') self.mock = mox.Mox() def test_processUpdates(self): self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.ReplayAll() defaultInstancesPath = cfg.CONF.instances_path cfg.CONF.set_override('instances_path', '/var/lib/nova/instances') self.assertEquals(self.LibvirtStorageVolume.processUpdates(), None) host = InventoryCacheManager.get_object_from_cache( '1', Constants.VmHost) self.assertEquals(self.LibvirtStorageVolume._createNovaPool(), None) storage = InventoryCacheManager.get_object_from_cache( '95f7101b-892c-c388-867a-8340e5fea27x', Constants.StorageVolume) self.assertTrue('95f7101b-892c-c388-867a-8340e5fea27x', host.get_storageVolumeIds()) self.assertTrue(storage is not None) self.assertEquals('inactivePool', storage.get_name()) cfg.CONF.set_override('instances_path', defaultInstancesPath) self.mock.stubs.UnsetAll() def test_processUpdatesException(self): self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) mock_libvirtSV = LibvirtStorageVolume(self.connection, '1') self.mock.StubOutWithMock(mock_libvirtSV, 'processStorageDeletes') mock_libvirtSV.processStorageDeletes([], []).AndRaise(Exception) self.mock.ReplayAll() self.assertEquals(self.LibvirtStorageVolume.processUpdates(), None) self.assertRaises(Exception, LibvirtStorageVolume) self.mock.stubs.UnsetAll() 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_processStorageDeletes(self): self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.ReplayAll() cachedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf3be3', '3fbfbefb-17dd-07aa-2dac-13afbedf1234', '3fbfbefb-17dd-07aa-2dac-13afbedf4321'] updatedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf1234'] self.assertEquals( self.LibvirtStorageVolume.processStorageDeletes(cachedList, updatedList), None) storage = InventoryCacheManager.get_object_from_cache( '3fbfbefb-17dd-07aa-2dac-13afbedf3be3', Constants.StorageVolume) host = InventoryCacheManager.get_object_from_cache( '1', Constants.VmHost) self.assertTrue(storage is None) self.assertTrue('3fbfbefb-17dd-07aa-2dac-13afbedf1234' not in host.get_storageVolumeIds()) self.mock.stubs.UnsetAll() def test_processStorageException(self): self.assertEquals(self.LibvirtStorageVolume._processStorage( libvirt.virDomain()), None) self.assertRaises(Exception, self.LibvirtStorageVolume)
class StorageVolumeEventsTest(test.TestCase): ''' TestCase for Storage Events ''' def setUp(self): super(StorageVolumeEventsTest, self).setUp() self.connection = LibvirtConnection(False) vmHost = VmHost() vmHost.set_storageVolumeIds([]) InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection._wrapped_conn = libvirt.open('qemu:///system') self.LibvirtStorageVolume = \ LibvirtStorageVolume(self.connection._wrapped_conn, '1') self.LibvirtStorageVolume.vmHost = vmHost self.LibvirtStorageVolume.cur_total_storage_size = 0 self.LibvirtStorageVolume.curr_storage_free = 0 self.LibvirtStorageVolume.old_total_storage_size = 0 self.LibvirtStorageVolume.old_storage_free = 0 self.LibvirtStorageVolume.vmHost.set_id('1') self.connection.compute_rmcontext = \ ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') self.flags(healthnmon_notification_drivers=[ 'nova.notifier.test_notifier']) test_notifier.NOTIFICATIONS = [] self.mox.StubOutWithMock(nova_db, 'service_get_all_by_topic') nova_db.service_get_all_by_topic( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) 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_storage_deleted_event(self): self.mox.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mox.StubOutWithMock( InventoryCacheManager, 'get_object_from_cache') deleted_storage_id = '3fbfbefb-17dd-07aa-2dac-13afbedf3be3' deleted_storage = StorageVolume() deleted_storage.id = deleted_storage_id InventoryCacheManager.get_object_from_cache( deleted_storage_id, Constants.StorageVolume).AndReturn(deleted_storage) self.mox.ReplayAll() cachedList = [deleted_storage_id, '3fbfbefb-17dd-07aa-2dac-13afbedf1234'] updatedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf1234'] self.mox.ReplayAll() self.LibvirtStorageVolume.processStorageDeletes(cachedList, updatedList) self.assertEquals(len(test_notifier.NOTIFICATIONS), 1) msg = test_notifier.NOTIFICATIONS[0] self.assertEquals(msg['priority'], notifier_api.INFO) eventMetaData = \ event_metadata.get_EventMetaData( event_metadata.EVENT_TYPE_STORAGE_DELETED) event_type = eventMetaData.get_event_fully_qal_name() self.assertEquals(msg['event_type'], event_type) payload = msg['payload'] self.assertEquals(payload['entity_type'], 'StorageVolume') self.assertEquals(payload['entity_id'], deleted_storage_id) def test_storage_enabled_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_INACTIVE self.mox.StubOutWithMock( InventoryCacheManager, 'get_object_from_cache') InventoryCacheManager.get_object_from_cache( storagePool.UUIDString(), Constants.StorageVolume).AndReturn(cachedStorageVolume) 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_ENABLED) 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_ACTIVE) 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.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_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.ReplayAll() nova_db.service_get_all_by_topic(None, None) self.LibvirtStorageVolume._processStorage(storagePool) self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
class test_LibvirtStorage(test.TestCase): def setUp(self): super(test_LibvirtStorage, self).setUp() self.connection = LibvirtConnection(False) vmHost = VmHost() vmHost.set_storageVolumeIds([]) InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection._wrapped_conn = libvirt.open('qemu:///system') self.LibvirtStorageVolume = \ LibvirtStorageVolume(self.connection._wrapped_conn, '1') self.connection.compute_rmcontext = \ ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') cfg.CONF.set_override('healthnmon_notification_drivers', ['healthnmon.notifier.log_notifier']) self.mock = mox.Mox() def test_processUpdates(self): self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.ReplayAll() defaultInstancesPath = cfg.CONF.instances_path cfg.CONF.set_override('instances_path', '/var/lib/nova/instances') self.assertEquals(self.LibvirtStorageVolume.processUpdates(), None) host = InventoryCacheManager.get_object_from_cache( '1', Constants.VmHost) self.assertEquals(self.LibvirtStorageVolume._createNovaPool(), None) storage = InventoryCacheManager.get_object_from_cache( '95f7101b-892c-c388-867a-8340e5fea27x', Constants.StorageVolume) self.assertTrue('95f7101b-892c-c388-867a-8340e5fea27x', host.get_storageVolumeIds()) self.assertTrue(storage is not None) self.assertEquals('inactivePool', storage.get_name()) cfg.CONF.set_override('instances_path', defaultInstancesPath) self.mock.stubs.UnsetAll() 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_processUpdatesException(self): self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) mock_libvirtSV = LibvirtStorageVolume(self.connection, '1') self.mock.StubOutWithMock( LibvirtStorageVolume, 'processStorageDeletes') mock_libvirtSV.processStorageDeletes( mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(Exception) self.mock.ReplayAll() self.assertEquals(self.LibvirtStorageVolume.processUpdates(), None) self.assertRaises(Exception, LibvirtStorageVolume) self.mock.stubs.UnsetAll() 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_processStorageDeletes(self): self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.ReplayAll() cachedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf3be3', '3fbfbefb-17dd-07aa-2dac-13afbedf1234', '3fbfbefb-17dd-07aa-2dac-13afbedf4321'] updatedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf1234'] self.assertEquals( self.LibvirtStorageVolume.processStorageDeletes(cachedList, updatedList), None) storage = InventoryCacheManager.get_object_from_cache( '3fbfbefb-17dd-07aa-2dac-13afbedf3be3', Constants.StorageVolume) host = InventoryCacheManager.get_object_from_cache( '1', Constants.VmHost) self.assertTrue(storage is None) self.assertTrue('3fbfbefb-17dd-07aa-2dac-13afbedf1234' not in host.get_storageVolumeIds()) self.mock.stubs.UnsetAll() def test_processStorageException(self): self.assertEquals(self.LibvirtStorageVolume._processStorage( libvirt.virDomain()), None) self.assertRaises(Exception, self.LibvirtStorageVolume) def tearDown(self): cfg.CONF.set_override('healthnmon_notification_drivers', None) super(test_LibvirtStorage, self).tearDown()
class test_LibvirtStorage(unittest.TestCase): def setUp(self): self.connection = LibvirtConnection(False) vmHost = VmHost() vmHost.set_storageVolumeIds([]) InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection._wrapped_conn = libvirt.open('qemu:///system') self.LibvirtStorageVolume = \ LibvirtStorageVolume(self.connection._wrapped_conn, '1') self.connection.compute_rmcontext = \ ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') self.mock = mox.Mox() def test_processUpdates(self): self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.ReplayAll() defaultInstancesPath = cfg.CONF.instances_path cfg.CONF.set_override('instances_path', '/var/lib/nova/instances') self.assertEquals(self.LibvirtStorageVolume.processUpdates(), None) host = InventoryCacheManager.get_object_from_cache( '1', Constants.VmHost) self.assertEquals(self.LibvirtStorageVolume._createNovaPool(), None) storage = InventoryCacheManager.get_object_from_cache( '95f7101b-892c-c388-867a-8340e5fea27x', Constants.StorageVolume) self.assertTrue('95f7101b-892c-c388-867a-8340e5fea27x', host.get_storageVolumeIds()) self.assertTrue(storage is not None) self.assertEquals('inactivePool', storage.get_name()) cfg.CONF.set_override('instances_path', defaultInstancesPath) self.mock.stubs.UnsetAll() def test_processUpdatesException(self): self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) mock_libvirtSV = LibvirtStorageVolume(self.connection, '1') self.mock.StubOutWithMock(mock_libvirtSV, 'processStorageDeletes') mock_libvirtSV.processStorageDeletes([], []).AndRaise(Exception) self.mock.ReplayAll() self.assertEquals(self.LibvirtStorageVolume.processUpdates(), None) self.assertRaises(Exception, LibvirtStorageVolume) self.mock.stubs.UnsetAll() 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_processStorageDeletes(self): self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.ReplayAll() cachedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf3be3', '3fbfbefb-17dd-07aa-2dac-13afbedf1234', '3fbfbefb-17dd-07aa-2dac-13afbedf4321'] updatedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf1234'] self.assertEquals( self.LibvirtStorageVolume.processStorageDeletes(cachedList, updatedList), None) storage = InventoryCacheManager.get_object_from_cache( '3fbfbefb-17dd-07aa-2dac-13afbedf3be3', Constants.StorageVolume) host = InventoryCacheManager.get_object_from_cache( '1', Constants.VmHost) self.assertTrue(storage is None) self.assertTrue('3fbfbefb-17dd-07aa-2dac-13afbedf1234' not in host.get_storageVolumeIds()) self.mock.stubs.UnsetAll() def test_processStorageException(self): self.assertEquals(self.LibvirtStorageVolume._processStorage( libvirt.virDomain()), None) self.assertRaises(Exception, self.LibvirtStorageVolume)
class StorageVolumeEventsTest(test.TestCase): ''' TestCase for Storage Events ''' def setUp(self): super(StorageVolumeEventsTest, self).setUp() self.connection = LibvirtConnection(False) vmHost = VmHost() vmHost.set_storageVolumeIds([]) InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection._wrapped_conn = libvirt.open('qemu:///system') self.LibvirtStorageVolume = \ LibvirtStorageVolume(self.connection._wrapped_conn, '1') self.LibvirtStorageVolume.vmHost = vmHost self.LibvirtStorageVolume.cur_total_storage_size = 0 self.LibvirtStorageVolume.curr_storage_free = 0 self.LibvirtStorageVolume.old_total_storage_size = 0 self.LibvirtStorageVolume.old_storage_free = 0 self.LibvirtStorageVolume.vmHost.set_id('1') self.connection.compute_rmcontext = \ ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') self.flags( healthnmon_notification_drivers=['nova.notifier.test_notifier']) test_notifier.NOTIFICATIONS = [] self.mox.StubOutWithMock(nova_db, 'service_get_all_by_topic') nova_db.service_get_all_by_topic( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) 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_storage_deleted_event(self): self.mox.StubOutWithMock(api, 'storage_volume_delete_by_ids') api.storage_volume_delete_by_ids( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mox.StubOutWithMock(InventoryCacheManager, 'get_object_from_cache') deleted_storage_id = '3fbfbefb-17dd-07aa-2dac-13afbedf3be3' deleted_storage = StorageVolume() deleted_storage.id = deleted_storage_id InventoryCacheManager.get_object_from_cache( deleted_storage_id, Constants.StorageVolume).AndReturn(deleted_storage) self.mox.ReplayAll() cachedList = [ deleted_storage_id, '3fbfbefb-17dd-07aa-2dac-13afbedf1234' ] updatedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf1234'] self.mox.ReplayAll() self.LibvirtStorageVolume.processStorageDeletes( cachedList, updatedList) self.assertEquals(len(test_notifier.NOTIFICATIONS), 1) msg = test_notifier.NOTIFICATIONS[0] self.assertEquals(msg['priority'], notifier_api.INFO) eventMetaData = \ event_metadata.get_EventMetaData( event_metadata.EVENT_TYPE_STORAGE_DELETED) event_type = eventMetaData.get_event_fully_qal_name() self.assertEquals(msg['event_type'], event_type) payload = msg['payload'] self.assertEquals(payload['entity_type'], 'StorageVolume') self.assertEquals(payload['entity_id'], deleted_storage_id) def test_storage_enabled_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_INACTIVE 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() 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_ENABLED) 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_ACTIVE) 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_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)