def test_vm_created_event(self): domainObj = libvirt.virDomain() self.mox.StubOutWithMock(api, 'vm_save') api.vm_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mox.StubOutWithMock( InventoryCacheManager, 'get_object_from_cache') InventoryCacheManager.get_object_from_cache( domainObj.UUIDString(), Constants.Vm).AndReturn(None) self.mox.ReplayAll() self.libvirtVM._processVm(domainObj) 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_VM_CREATED) 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'], domainObj.UUIDString())
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_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_process_updates_for_updated_VM_exception(self): domainObj = libvirt.virDomain() self.libvirtVM.vmHost = None self.libvirtVM.process_updates_for_updated_VM(domainObj) self.assertRaises(Exception, LibvirtVM) self.mock.stubs.UnsetAll() self.mock.VerifyAll()
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 _mapLibvirtvmToVm(self): '''Create a libvirt Domain object and map it to a healthmon Vm object for it ''' domainObj = libvirt.virDomain() self.libvirtVM.domainObj = domainObj self.libvirtVM.domainUuid = domainObj.UUIDString() self.libvirtVM.Vm = Vm() self.libvirtVM._mapVmProperties() return (domainObj, self.libvirtVM.Vm)
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 test_vm_created_event(self): domainObj = libvirt.virDomain() self.mox.StubOutWithMock(api, 'vm_save') api.vm_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mox.StubOutWithMock(InventoryCacheManager, 'get_object_from_cache') InventoryCacheManager.get_object_from_cache( domainObj.UUIDString(), Constants.Vm).AndReturn(None) self.mox.ReplayAll() self.libvirtVM._processVm(domainObj) 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_VM_CREATED) 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'], domainObj.UUIDString())
def test_processStorageException(self): self.assertEquals(self.LibvirtStorageVolume._processStorage( libvirt.virDomain()), None) self.assertRaises(Exception, self.LibvirtStorageVolume)