本文整理汇总了Python中healthnmon.tests.FakeLibvirt类的典型用法代码示例。如果您正苦于以下问题:Python FakeLibvirt类的具体用法?Python FakeLibvirt怎么用?Python FakeLibvirt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FakeLibvirt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_broken_connection_cover
def test_broken_connection_cover(self):
global libvirt
libvirt = libvirt = __import__('libvirt')
error = 38
domain = 13
conn = connection.get_connection(False)
# self.mox.StubOutWithMock(libvirt,'openReadOnly')
# libvirt.openReadOnly(mox.IgnoreArg()).AndReturn(self.fakeConn)
# conn._wrapped_conn=self.fakeConn
self.mox.StubOutWithMock(conn, '_wrapped_conn')
self.mox.StubOutWithMock(conn._wrapped_conn, 'getCapabilities')
self.mox.StubOutWithMock(libvirt.libvirtError, 'get_error_code')
self.mox.StubOutWithMock(libvirt.libvirtError,
'get_error_domain')
conn._wrapped_conn.getCapabilities().AndRaise(
FakeLibvirt.libvirtError('fake failure'
))
libvirt.libvirtError.get_error_code().MultipleTimes(). \
AndReturn(error)
libvirt.libvirtError.get_error_domain().MultipleTimes(). \
AndReturn(domain)
self.mox.ReplayAll()
try:
self.assertFalse(conn._test_connection())
except:
print 'error'
示例2: test_update_inventory
def test_update_inventory(self):
self.mox.StubOutWithMock(libvirt, 'openReadOnly')
libvirt.openReadOnly(mox.IgnoreArg()).AndReturn(self.fakeConn)
self.mox.StubOutWithMock(api, 'vm_save')
self.mox.StubOutWithMock(api, 'vm_host_save')
self.mox.StubOutWithMock(api, 'storage_volume_save')
api.storage_volume_save(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
api.vm_host_save(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
api.vm_save(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mox.ReplayAll()
conn = connection.get_connection(True)
compute_rmcontext = ComputeRMContext(rmType='QEMU',
rmIpAddress='10.10.155.165', rmUserName='openstack',
rmPassword='password')
InventoryCacheManager.get_all_compute_inventory()['1'] = \
ComputeInventory(compute_rmcontext)
conn.init_rmcontext(compute_rmcontext)
conn._wrapped_conn = self.fakeConn
conn.update_inventory('1')
示例3: test_get_connection_with_conn_static
def test_get_connection_with_conn_static(self):
self.mox.StubOutWithMock(libvirt, 'openReadOnly')
libvirt.openReadOnly(mox.IgnoreArg()).AndReturn(self.fakeConn)
self.mox.ReplayAll()
con = self.libvirt_connection_cls._connect('uri', True)
self.assertEquals("ubuntu164.vmm.hp.com", con.getHostname())
self.assertTrue("ReleaseBDevEnv" in con.listDefinedDomains())
self.assertTrue("1" in str(con.listDomainsID()))
示例4: test_get_connection_with_conn_static_exception
def test_get_connection_with_conn_static_exception(self):
self.mox.StubOutWithMock(libvirt, 'openReadOnly')
libvirt.openReadOnly(mox.IgnoreArg()).AndRaise(libvirt.libvirtError)
self.mox.ReplayAll()
try:
self.libvirt_connection_cls._connect('uri', True)
except Exception as e:
self.assertTrue(isinstance(e, libvirt.libvirtError))
示例5: test__get_connection_with_invalid_conn
def test__get_connection_with_invalid_conn(self):
self.mox.StubOutWithMock(libvirt, 'openReadOnly')
libvirt.openReadOnly(mox.IgnoreArg()).AndReturn(self.fakeConn)
self.mox.ReplayAll()
conn = connection.get_connection(True)
compute_rmcontext = ComputeRMContext(
rmType='QEMU',
rmIpAddress='10.10.155.165', rmUserName='openstack',
rmPassword='password')
conn.init_rmcontext(compute_rmcontext)
conn._wrapped_conn = 'Invalid'
self.assertRaises(Exception, conn._get_connection)
self.mox.UnsetStubs()
示例6: test_update_perfdata
def test_update_perfdata(self):
conn = connection.get_connection(True)
self.mox.StubOutWithMock(connection.LibvirtConnection, 'uri')
conn.uri().AndReturn(None)
self.mox.StubOutWithMock(libvirt, 'openReadOnly')
libvirt.openReadOnly(mox.IgnoreArg()).AndReturn(self.fakeConn)
self.mox.ReplayAll()
conn.update_perfdata('uuid', 'perfmon_type')
self.assertTrue(conn.libvirt_perfmon.perfDataCache is not None)
conn.update_perfdata('uuid', 'perfmon_type1')
self.assertTrue(conn.libvirt_perfmon.perfDataCache is not None)
示例7: test_processVmForIPAddress
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')
示例8: test_process_updates_for_updated_VM_exception
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()
示例9: test_storage_added_event
def test_storage_added_event(self):
storagePool = libvirt.virStoragePool()
self.mox.StubOutWithMock(api, 'storage_volume_save')
api.storage_volume_save(
mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mox.StubOutWithMock(
InventoryCacheManager, 'get_object_from_cache')
InventoryCacheManager.get_object_from_cache(
storagePool.UUIDString(),
Constants.StorageVolume).AndReturn(None)
self.mox.ReplayAll()
self.LibvirtStorageVolume._processStorage(storagePool)
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_STORAGE_ADDED)
self.assertEquals(msg['event_type'],
event_type.get_event_fully_qal_name())
payload = msg['payload']
self.assertEquals(payload['entity_type'], 'StorageVolume')
self.assertEquals(payload['entity_id'],
storagePool.UUIDString())
示例10: setUp
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='openstack',
rmPassword='password')
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)
示例11: test_storage_no_state_change
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)
示例12: setUp
def setUp(self):
self.fakeConn = libvirt.open('qemu:///system')
self.libvirt_connection_cls = connection.LibvirtConnection
super(Test_virt_connection, self).setUp()
self.flags(
healthnmon_notification_drivers=['healthnmon.notifier.log_notifier']
)
示例13: test_deregister_libvirt_events
def test_deregister_libvirt_events(self):
libvirtEvents = libvirt_event_monitor.LibvirtEvents()
libvirtEvents.registered = True
libvirtEvents.call_back_ids['domain_events'] = [1]
libvirtEvents.libvirt_con = libvirt.open("fake:///system")
libvirtEvents.deregister_libvirt_events()
self.mock.VerifyAll()
示例14: setUpClass
def setUpClass(cls):
cls.connection = LibvirtConnection(False)
cls.mox = mox.Mox()
cls.connection._wrapped_conn = libvirt.open('qemu:///system')
cls.connection.libvirt = libvirt
cls.vm_id = '25f04dd3-e924-02b2-9eac-876e3c943262'
cls.vmhost_id = '1'
示例15: test_processVm_disk_exception_next_retry
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()