def testProcessUpdates_compute_stopped_exception(self): vmHost = VmHost() vmHost.set_id('1') vmHost.set_connectionState(Constants.VMHOST_CONNECTED) InventoryCacheManager.update_object_in_cache('1', vmHost) self.mock.StubOutWithMock(api, 'vm_host_save') api.vm_host_save( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.StubOutWithMock( InventoryCacheManager, 'get_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( self.libvirtVmHost.compute_id, Constants.VmHost).AndReturn(fake.get_connection()) fake_computes = [{'id': '1', 'service': {'created_at': 'created', 'updated_at':'updated'}}] self.mock.StubOutWithMock(novadb, 'compute_node_get_all') novadb.compute_node_get_all(mox.IgnoreArg()).AndReturn(fake_computes) self.mock.StubOutWithMock(hnm_utils, 'is_service_alive') hnm_utils.is_service_alive( mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(False) self.mock.StubOutWithMock(event_api, 'notify_host_update') event_api.notify_host_update( mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(Exception()) self.mock.ReplayAll() self.assertEquals(self.libvirtVmHost.processUpdates(), None) self.mock.stubs.UnsetAll()
def skiptestProcessUpdates_network_stopped(self): vmHost = VmHost() vmHost.set_id('1') vmHost.set_connectionState(Constants.VMHOST_CONNECTED) InventoryCacheManager.update_object_in_cache('1', vmHost) self.mock.StubOutWithMock( self.libvirtVmHost, '_get_compute_running_status') self.libvirtVmHost._get_compute_running_status().AndReturn( (True, 'host')) self.mock.StubOutWithMock(api, 'vm_host_save') api.vm_host_save( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) fake_networks = { 'id': '1', 'created_at': 'created', 'updated_at': 'updated'} self.mock.StubOutWithMock(novadb, 'service_get_by_host_and_topic') novadb.service_get_by_host_and_topic( mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(fake_networks) self.mock.StubOutWithMock(hnm_utils, 'is_service_alive') hnm_utils.is_service_alive( mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(False) self.mock.StubOutWithMock(event_api, 'notify_host_update') event_api.notify_host_update( mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(None) self.mock.ReplayAll() self.assertEquals(self.libvirtVmHost.processUpdates(), None) self.assertEquals( self.libvirtVmHost.cachedvmHost.get_connectionState(), 'Disconnected') self.mock.stubs.UnsetAll()
def testProcessUpdates_compute_stopped_exception(self): vmHost = VmHost() vmHost.set_id('1') vmHost.set_connectionState(Constants.VMHOST_CONNECTED) InventoryCacheManager.update_object_in_cache('1', vmHost) self.mock.StubOutWithMock(api, 'vm_host_save') api.vm_host_save( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.StubOutWithMock( InventoryCacheManager, 'get_compute_conn_driver') InventoryCacheManager.get_compute_conn_driver( self.libvirtVmHost.compute_id, Constants.VmHost).AndReturn(fake.get_connection()) fake_computes = [{'id': '1', 'service': {'created_at': 'created', 'updated_at':'updated'}}] self.mock.StubOutWithMock(novadb, 'compute_node_get_all') novadb.compute_node_get_all(mox.IgnoreArg()).AndReturn(fake_computes) self.mock.StubOutWithMock(hnm_utils, 'is_service_alive') hnm_utils.is_service_alive( mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(False) self.mock.StubOutWithMock(event_api, 'notify_host_update') event_api.notify_host_update( mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(Exception()) self.mock.ReplayAll() self.assertEquals(self.libvirtVmHost.processUpdates(), None) self.mock.stubs.UnsetAll()
def createInvCache(self, vmrunning, hostconnection='Connected'): vmhost = VmHost() vmhost.set_id(self.vmhost_id) vmhost.set_connectionState(hostconnection) vm = Vm() vm.set_id(self.vm_id) if vmrunning: vm.set_powerState(Constants.VM_POWER_STATES[1]) else: vm.set_powerState(Constants.VM_POWER_STATES[0]) vm.set_vmHostId(self.vmhost_id) vmhost.set_virtualMachineIds([self.vm_id]) vmhost.set_processorSpeedMhz(2100) vmhost.set_processorCoresCount(4) vmhost.set_processorCount('2') vmhost.set_memorySize(2097152) vmhost.set_memoryConsumed(2097152) InventoryCacheManager.update_object_in_cache(self.vmhost_id, vmhost) InventoryCacheManager.update_object_in_cache(self.vm_id, vm)
def createInvCache(self, vmrunning, hostconnection='Connected'): vmhost = VmHost() vmhost.set_id(self.vmhost_id) vmhost.set_connectionState(hostconnection) vm = Vm() vm.set_id(self.vm_id) if vmrunning: vm.set_powerState(Constants.VM_POWER_STATES[1]) else: vm.set_powerState(Constants.VM_POWER_STATES[0]) vm.set_vmHostId(self.vmhost_id) vmhost.set_virtualMachineIds([self.vm_id ]) vmhost.set_processorSpeedMhz(2100) vmhost.set_processorCoresCount(4) vmhost.set_processorCount('2') vmhost.set_memorySize(2097152) vmhost.set_memoryConsumed(2097152) InventoryCacheManager.update_object_in_cache(self.vmhost_id, vmhost) InventoryCacheManager.update_object_in_cache( self.vm_id, vm)