def test_process_incomplete_vms(self): self.mock.StubOutWithMock(api, 'vm_save') api.vm_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) 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_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( self.libvirtVM.compute_id, Constants.VmHost).AndReturn(fake.get_connection()) self.mock.ReplayAll() libvirt_inventorymonitor.incomplete_vms = \ {self.libvirtVM.compute_id: {'25f04dd3-e924-02b2-9eac-876e3c943262': 1}} self.libvirtVM.process_incomplete_vms() vm = InventoryCacheManager.get_object_from_cache( "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm) self.assert_(vm.get_vmDisks(), "VM disks inventory not collected") self.assert_( '25f04dd3-e924-02b2-9eac-876e3c943262' not in libvirt_inventorymonitor.incomplete_vms[ self.libvirtVM.compute_id], "VM id not removed from incomplete list") self.mock.stubs.UnsetAll()
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 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_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_processVm_disk_exception_next_retry(self): self.mock.StubOutWithMock(api, 'vm_save') api.vm_save(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(novadb, 'instance_get_by_uuid') novadb.instance_get_by_uuid(mox.IgnoreArg(), mox.IgnoreArg())\ .AndReturn({'display_name': 'test_vm'}) self.mock.StubOutWithMock( self.libvirtVM.libvirtconn, 'storageVolLookupByPath') self.libvirtVM.libvirtconn.storageVolLookupByPath( mox.IgnoreArg()).AndRaise(Exception) self.mock.ReplayAll() InventoryCacheManager.delete_object_in_cache( '25f04dd3-e924-02b2-9eac-876e3c943262', Constants.Vm) libvirt_inventorymonitor.incomplete_vms = { self.libvirtVM.compute_id: {}} self.assertEquals(self.libvirtVM._processVm(libvirt.virDomain()), None) vm = InventoryCacheManager.get_object_from_cache( "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm) self.assertEqual(len( vm.get_vmDisks()), 0, "Instance disk should not exist when there \ is an exception") self.mock.VerifyAll() self.mock.stubs.UnsetAll()
def test_ProcessUpdatesException(self): self.mock.StubOutWithMock(api, 'vm_save') api.vm_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) 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_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( self.libvirtVM.compute_id, Constants.VmHost).AndReturn(fake.get_connection()) mock_libvirtVm = LibvirtVM(self.connection, '1') self.mock.StubOutWithMock(mock_libvirtVm, 'processVmDeletes') mock_libvirtVm.processVmDeletes([], []).AndRaise(Exception) self.mock.ReplayAll() self.assertEquals(self.libvirtVM.processUpdates(), None) self.assertRaises(Exception, LibvirtVM) self.mock.stubs.UnsetAll()
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_processVmForIPAddress(self): self.mock.StubOutWithMock(api, 'vm_save') api.vm_save(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_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( self.libvirtVM.compute_id, Constants.VmHost).AndReturn(fake.get_connection()) self.mock.ReplayAll() self.assertEquals(self.libvirtVM._processVm(libvirt.virDomain()), None) self.libvirtVM.processUpdates() vm = InventoryCacheManager.get_object_from_cache( "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm) ipProfileList = vm.get_ipAddresses() self.assertTrue(ipProfileList is not None) self.assertTrue(ipProfileList[0].get_ipAddress() == '10.1.1.19') self.assertTrue(ipProfileList[1].get_ipAddress() == '10.2.1.20')
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_process_updates_for_updated_VM(self): self.mock.StubOutWithMock(api, 'vm_save') api.vm_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) 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_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( self.libvirtVM.compute_id, Constants.VmHost).AndReturn(fake.get_connection()) self.mock.ReplayAll() domainObj = libvirt.virDomain() self.assertEquals( self.libvirtVM.process_updates_for_updated_VM(domainObj), None) vm = InventoryCacheManager.get_object_from_cache( "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm) # self.assertEquals("TestVirtMgrVM7", vm.get_name()) self.assertEquals("1048576", str(vm.get_memorySize())) self.assertEquals("hd", str(vm.get_bootOrder()).strip()) self.mock.stubs.UnsetAll()
def test_processVmForIPAddress(self): self.mock.StubOutWithMock(api, 'vm_save') api.vm_save(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_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( self.libvirtVM.compute_id, Constants.VmHost).AndReturn(fake.get_connection()) self.mock.ReplayAll() self.assertEquals(self.libvirtVM._processVm(libvirt.virDomain()), None) self.libvirtVM.processUpdates() vm = InventoryCacheManager.get_object_from_cache( "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm) ipProfileList = vm.get_ipAddresses() self.assertTrue(ipProfileList is not None) self.assertTrue(ipProfileList[0].get_ipAddress() == '10.1.1.19') self.assertTrue(ipProfileList[1].get_ipAddress() == '10.2.1.20')
def test_process_updates_for_updated_VM(self): self.mock.StubOutWithMock(api, 'vm_save') api.vm_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) 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_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( self.libvirtVM.compute_id, Constants.VmHost).AndReturn(fake.get_connection()) self.mock.ReplayAll() domainObj = libvirt.virDomain() self.assertEquals( self.libvirtVM.process_updates_for_updated_VM(domainObj), None) vm = InventoryCacheManager.get_object_from_cache( "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm) # self.assertEquals("TestVirtMgrVM7", vm.get_name()) self.assertEquals("1048576", str(vm.get_memorySize())) self.assertEquals("hd", str(vm.get_bootOrder()).strip()) self.mock.stubs.UnsetAll()
def test_ProcessUpdatesException(self): self.mock.StubOutWithMock(api, 'vm_save') api.vm_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) 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_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( self.libvirtVM.compute_id, Constants.VmHost).AndReturn(fake.get_connection()) mock_libvirtVm = LibvirtVM(self.connection, '1') self.mock.StubOutWithMock(mock_libvirtVm, 'processVmDeletes') mock_libvirtVm.processVmDeletes([], []).AndRaise(Exception) self.mock.ReplayAll() self.assertEquals(self.libvirtVM.processUpdates(), None) self.assertRaises(Exception, LibvirtVM) self.mock.stubs.UnsetAll()
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 testNotifyExceptionScheduler(self): nova_db.service_get_all_by_topic(mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(Exception()) self.mox.ReplayAll() self.assertEquals( events_api.notify(event_metadata.EVENT_TYPE_VM_DELETED, self.vm), None) msg = test_notifier.NOTIFICATIONS[0] 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()) self.assertEquals(msg['publisher_id'], 'healthnmon') payload = msg['payload'] self.assertEquals(payload['entity_type'], 'Vm') self.assertEquals(payload['entity_id'], self.vm.get_id())
def testNotifyExceptionScheduler(self): nova_db.service_get_all_by_topic(mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(Exception()) self.mox.ReplayAll() self.assertEquals(events_api.notify( event_metadata.EVENT_TYPE_VM_DELETED, self.vm), None) msg = test_notifier.NOTIFICATIONS[0] 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()) self.assertEquals(msg['publisher_id'], 'healthnmon') payload = msg['payload'] self.assertEquals(payload['entity_type'], 'Vm') self.assertEquals(payload['entity_id'], self.vm.get_id())
def test_processVm(self): self.mock.StubOutWithMock(api, 'vm_save') api.vm_save(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.ReplayAll() self.assertEquals(self.libvirtVM._processVm(libvirt.virDomain()), None) vm = InventoryCacheManager.get_object_from_cache( "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm) #self.assertEquals('Disconnected', vm.get_connectionState()) # self.assertEquals('TestVirtMgrVM7', str(vm.get_name())) self.assertEquals("1048576", str(vm.get_memorySize())) #self.assertEquals("hd", str(vm.get_bootOrder()).strip()) self.mock.stubs.UnsetAll()
def notify(event_type, obj, **kwargs): """Generate event for a event type id This API is used by the different healthnmon modules which need to generate event. Parameters: event_type - One of the event types declared in healthnmon.events.event_meta_data obj - Vm, VmHost or StorageVolume object for which this event is to be generated """ eventmetadata_obj = event_metadata.get_EventMetaData(event_type) payload = payload_generator.generate_payload(eventmetadata_obj, obj, **kwargs) # Set publisher_id as <nova-scheduler-service.host>.healthnmon publisher_id = None admin_ctxt = context.get_admin_context() scheduler_services = None try: scheduler_services = \ nova_db.service_get_all_by_topic(admin_ctxt, 'scheduler') except: LOG.error(_('Could not fetch scheduler service from nova db')) if scheduler_services is None or len(scheduler_services) < 1: LOG.debug(_('Scheduler service not found.')) else: if len(scheduler_services) > 1: LOG.debug(_('More than 1 entry for Scheduler service found.' )) scheduler_service = scheduler_services[0] scheduler_service_host = scheduler_service['host'] if scheduler_service_host is None \ or len(scheduler_service_host) < 1: LOG.debug(_('Invalid host name for Scheduler service entry : ' + str(scheduler_service_host))) else: publisher_id = scheduler_service_host + '.' + 'healthnmon' if publisher_id is None: publisher_id = 'healthnmon' LOG.warn(_('Could not determine host name of nova scheduler service. \ Using default publisher id %s' % publisher_id)) # Send message to notifier api LOG.debug(_('Sending notification with publisher_id: %s, name: %s,\ payload: %s') % (publisher_id, eventmetadata_obj.get_event_fully_qal_name(), payload)) notifier_api.notify(admin_ctxt, publisher_id, eventmetadata_obj.get_event_fully_qal_name(), eventmetadata_obj.priority, payload)
def testNotifyMultipleScheduler(self): scheduler_services = [{'host': 'testhost'}, {'host': 'testhost2'}] nova_db.service_get_all_by_topic( mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(scheduler_services) self.mox.ReplayAll() self.assertEquals( events_api.notify(event_metadata.EVENT_TYPE_VM_DELETED, self.vm), None) msg = test_notifier.NOTIFICATIONS[0] 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()) self.assertEquals(msg['publisher_id'], 'testhost.healthnmon') payload = msg['payload'] self.assertEquals(payload['entity_type'], 'Vm') self.assertEquals(payload['entity_id'], self.vm.get_id())
def test_process_incomplete_vms_with_retry(self): self.mock.StubOutWithMock(api, 'vm_save') api.vm_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) 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_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( self.libvirtVM.compute_id, Constants.VmHost).AndReturn(fake.get_connection()) self.mock.StubOutWithMock( self.libvirtVM.libvirtconn, 'storageVolLookupByPath') self.libvirtVM.libvirtconn.storageVolLookupByPath( mox.IgnoreArg()).AndRaise(Exception) self.mock.ReplayAll() libvirt_inventorymonitor.incomplete_vms = \ {self.libvirtVM.compute_id: { '25f04dd3-e924-02b2-9eac-876e3c943262': 1}} self.libvirtVM.process_incomplete_vms() vm = InventoryCacheManager.get_object_from_cache( "25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm) self.assert_(not(vm.get_vmDisks()), "VM disks should not be collected") self.assert_( libvirt_inventorymonitor.incomplete_vms[self.libvirtVM.compute_id][ '25f04dd3-e924-02b2-9eac-876e3c943262'] == 2, "incomplete_vms retry count not incremented") self.mock.stubs.UnsetAll()
def test_process_incomplete_vms_deletedvm(self): self.mock.StubOutWithMock(api, 'vm_save') api.vm_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) 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_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( self.libvirtVM.compute_id, Constants.VmHost).AndReturn(fake.get_connection()) self.mock.StubOutWithMock( self.libvirtVM.libvirtconn, 'listDefinedDomains') self.libvirtVM.libvirtconn.listDefinedDomains().AndReturn([]) self.mock.StubOutWithMock(self.libvirtVM.libvirtconn, 'listDomainsID') self.libvirtVM.libvirtconn.listDomainsID().AndReturn([]) self.mock.ReplayAll() libvirt_inventorymonitor.incomplete_vms = \ {self.libvirtVM.compute_id: { '25f04dd3-e924-02b2-9eac-876e3c943262': 1}} self.libvirtVM.process_incomplete_vms() self.assert_( '25f04dd3-e924-02b2-9eac-876e3c943262' not in libvirt_inventorymonitor.incomplete_vms[ self.libvirtVM.compute_id], "Deleted VM id not removed from incomplete list") self.mock.stubs.UnsetAll()
def testNotifyMultipleScheduler(self): scheduler_services = [{'host': 'testhost'}, {'host': 'testhost2' }] nova_db.service_get_all_by_topic( mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(scheduler_services) self.mox.ReplayAll() self.assertEquals(events_api.notify( event_metadata.EVENT_TYPE_VM_DELETED, self.vm), None) msg = test_notifier.NOTIFICATIONS[0] 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()) self.assertEquals(msg['publisher_id'], 'testhost.healthnmon') payload = msg['payload'] self.assertEquals(payload['entity_type'], 'Vm') self.assertEquals(payload['entity_id'], self.vm.get_id())
def notify(event_type, obj, **kwargs): """Generate event for a event type id This API is used by the different healthnmon modules which need to generate event. Parameters: event_type - One of the event types declared in healthnmon.events.event_meta_data obj - Vm, VmHost or StorageVolume object for which this event is to be generated """ eventmetadata_obj = event_metadata.get_EventMetaData(event_type) payload = payload_generator.generate_payload(eventmetadata_obj, obj, **kwargs) # Set publisher_id as <nova-scheduler-service.host>.healthnmon publisher_id = None admin_ctxt = context.get_admin_context() scheduler_services = None try: scheduler_services = \ nova_db.service_get_all_by_topic(admin_ctxt, 'scheduler') except: LOG.warn(_('Could not fetch scheduler service from nova db')) if scheduler_services is None or len(scheduler_services) < 1: LOG.warn(_('Scheduler service not found.')) else: if len(scheduler_services) > 1: LOG.warn(_('More than 1 entry for Scheduler service found.')) scheduler_service = scheduler_services[0] scheduler_service_host = scheduler_service['host'] if scheduler_service_host is None \ or len(scheduler_service_host) < 1: LOG.warn( _('Invalid host name for Scheduler service entry : ' + str(scheduler_service_host))) else: publisher_id = scheduler_service_host + '.' + 'healthnmon' if publisher_id is None: publisher_id = 'healthnmon' LOG.warn( _('Could not determine host name of nova scheduler service. Using default publisher id %s' % publisher_id)) # Send message to notifier api notifier_api.notify(admin_ctxt, publisher_id, eventmetadata_obj.get_event_fully_qal_name(), eventmetadata_obj.priority, payload)
def get_active_instances(period_length): context = RequestContext('1', '1', is_admin=True) start, end = get_previous_period(datetime.datetime.utcnow(), period_length) session = api.get_session() computes = novadb.service_get_all_by_topic(context, 'compute') active_instances = [] for compute in computes: query = session.query(novamodels.Instance) query = query.filter(api.or_(novamodels.Instance.terminated_at == None, novamodels.Instance.terminated_at > start)) query = query.filter_by(host=compute.host) for instance in query.all(): active_instances.append(instance) return active_instances
def __mock_service_get_all_by_topic(self): self.mox.StubOutWithMock(nova_db_api, 'service_get_all_by_topic') nova_db_api.service_get_all_by_topic( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)
def get_by_topic(cls, context, topic): db_services = db.service_get_all_by_topic(context, topic) return base.obj_make_list(context, cls(context), objects.Service, db_services)