class test_LibvirtInventoryMonitor(unittest.TestCase): connection.libvirt = libvirt def setUp(self): self.mock = mox.Mox() self.connection = LibvirtConnection(False) self.connection._wrapped_conn = libvirt.open('qemu:///system') vmHost = VmHost() InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection.compute_rmcontext = \ ComputeRMContext(rmType='fake', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') InventoryCacheManager.get_all_compute_inventory()['1'] = \ ComputeInventory(self.connection.compute_rmcontext) self.mock.StubOutWithMock(LibvirtConnection, '_connect') self.connection._connect( mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(libvirt.libvirtError) self.mock.ReplayAll() self.inventoryMonitor = LibvirtInventoryMonitor() # self.libvirtVmHost = LibvirtVmHost(self.connection, '1') cfg.CONF.set_override('healthnmon_notification_drivers', ['healthnmon.notifier.log_notifier']) self.libvirtInventoryMonitor = LibvirtInventoryMonitor() def test_collectInventory(self): self.mock.StubOutWithMock(api, 'vm_host_save') api.vm_host_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.ReplayAll() self.libvirtInventoryMonitor.collectInventory( self.connection._wrapped_conn, '1') self.mock.stubs.UnsetAll() def test_collectInventory_conn_none(self): self.libvirtInventoryMonitor.collectInventory(None, '1') self.mock.stubs.UnsetAll() def test_collectInventory_conn_exception(self): self.libvirtInventoryMonitor.collectInventory(self.connection, '1') self.mock.stubs.UnsetAll()
class test_LibvirtInventoryMonitor(unittest.TestCase): connection.libvirt = libvirt def setUp(self): self.mock = mox.Mox() self.connection = LibvirtConnection(False) self.connection._wrapped_conn = libvirt.open('qemu:///system') vmHost = VmHost() InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection.compute_rmcontext = \ ComputeRMContext(rmType='fake', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') InventoryCacheManager.get_all_compute_inventory()['1'] = \ ComputeInventory(self.connection.compute_rmcontext) self.mock.StubOutWithMock(LibvirtConnection, '_connect') self.connection._connect(mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(libvirt.libvirtError) self.mock.ReplayAll() self.inventoryMonitor = LibvirtInventoryMonitor() # self.libvirtVmHost = LibvirtVmHost(self.connection, '1') cfg.CONF.set_override('healthnmon_notification_drivers', ['healthnmon.notifier.log_notifier']) self.libvirtInventoryMonitor = LibvirtInventoryMonitor() def test_collectInventory(self): self.mock.StubOutWithMock(api, 'vm_host_save') api.vm_host_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.ReplayAll() self.libvirtInventoryMonitor.collectInventory( self.connection._wrapped_conn, '1') self.mock.stubs.UnsetAll() def test_collectInventory_conn_none(self): self.libvirtInventoryMonitor.collectInventory(None, '1') self.mock.stubs.UnsetAll() def test_collectInventory_conn_exception(self): self.libvirtInventoryMonitor.collectInventory(self.connection, '1') self.mock.stubs.UnsetAll()
class test_LibvirtVmHostDisconnected(unittest.TestCase): connection.libvirt = libvirt def setUp(self): self.mock = mox.Mox() self.connection = LibvirtConnection(False) vmHost = VmHost() vmHost.set_virtualMachineIds([]) InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection._wrapped_conn = None self.connection.compute_rmcontext = \ ComputeRMContext(rmType='fake', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') InventoryCacheManager.get_all_compute_inventory()['1'] = \ ComputeInventory(self.connection.compute_rmcontext) self.mock.StubOutWithMock(LibvirtConnection, '_connect') self.connection._connect( mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(libvirt.libvirtError) self.mock.ReplayAll() self.inventoryMonitor = LibvirtInventoryMonitor() libvirtEvents = LibvirtEvents() self.libvirtVmHost = LibvirtVmHost( self.connection._wrapped_conn, '1', libvirtEvents) cfg.CONF.set_override('healthnmon_notification_drivers', ['healthnmon.notifier.log_notifier']) def testProcessUpdatesNoOp(self): self.mock.StubOutWithMock(api, 'vm_host_save') api.vm_host_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.ReplayAll() InventoryCacheManager.delete_object_in_cache('1', Constants.VmHost) self.assertEquals(self.libvirtVmHost.processUpdates(), None) self.assertEquals(self.libvirtVmHost.vmHost, None) self.mock.stubs.UnsetAll() def testProcessUpdates(self): 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()) self.mock.ReplayAll() self.assertEquals(self.libvirtVmHost.processUpdates(), None) self.assertEquals(self.libvirtVmHost.vmHost.get_connectionState(), 'Disconnected') self.mock.stubs.UnsetAll() def testProcessUpdates_compute_stopped(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()).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 tearDown(self): cfg.CONF.set_override('healthnmon_notification_drivers', None)
class test_LibvirtVmHostDisconnected(unittest.TestCase): connection.libvirt = libvirt def setUp(self): self.mock = mox.Mox() self.connection = LibvirtConnection(False) vmHost = VmHost() vmHost.set_virtualMachineIds([]) InventoryCacheManager.update_object_in_cache('1', vmHost) self.connection._wrapped_conn = None self.connection.compute_rmcontext = \ ComputeRMContext(rmType='fake', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') InventoryCacheManager.get_all_compute_inventory()['1'] = \ ComputeInventory(self.connection.compute_rmcontext) self.mock.StubOutWithMock(LibvirtConnection, '_connect') self.connection._connect(mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(libvirt.libvirtError) self.mock.ReplayAll() self.inventoryMonitor = LibvirtInventoryMonitor() libvirtEvents = LibvirtEvents() self.libvirtVmHost = LibvirtVmHost( self.connection._wrapped_conn, '1', libvirtEvents) cfg.CONF.set_override('healthnmon_notification_drivers', ['healthnmon.notifier.log_notifier']) def testProcessUpdatesNoOp(self): self.mock.StubOutWithMock(api, 'vm_host_save') api.vm_host_save(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None) self.mock.ReplayAll() InventoryCacheManager.delete_object_in_cache('1', Constants.VmHost) self.assertEquals(self.libvirtVmHost.processUpdates(), None) self.assertEquals(self.libvirtVmHost.vmHost, None) self.mock.stubs.UnsetAll() def testProcessUpdates(self): 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()) self.mock.ReplayAll() self.assertEquals(self.libvirtVmHost.processUpdates(), None) self.assertEquals(self.libvirtVmHost.vmHost.get_connectionState(), 'Disconnected') self.mock.stubs.UnsetAll() def testProcessUpdates_compute_stopped(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()).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 tearDown(self): cfg.CONF.set_override('healthnmon_notification_drivers', None)