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()
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()