def blockInfo(self, source): if not self._has_disk_block: raise fake.Error(libvirt.VIR_ERR_INTERNAL_ERROR, "no such disk in this VM") # capacity, allocation, physical info = self._block_disk.info() return [info[1], info[2], info[1]]
def test_set_new_threshold_when_state_unset_but_fails(self): with make_env(events_enabled=True, drive_infos=self.DRIVE_INFOS) as (testvm, dom, drives): for drive in drives: self.assertEqual(drive.threshold_state, BLOCK_THRESHOLD.UNSET) # Simulate setBlockThreshold failure testvm._dom.errors["setBlockThreshold"] = fake.Error( libvirt.VIR_ERR_OPERATION_FAILED, "fake error") # first run: does nothing but set the block thresholds testvm.monitor_drives() for drive in drives: self.assertEqual(drive.threshold_state, BLOCK_THRESHOLD.UNSET)
def test_block_threshold_set_failure_after_drive_extended(self): with make_env( events_enabled=True, drive_infos=self.DRIVE_INFOS) as (testvm, dom, drives): # first run: does nothing but set the block thresholds testvm.monitor_drives() # Simulate write on drive vdb vdb = dom.block_info['/virtio/1'] # The BLOCK_THRESHOLD event contains the highest allocated # block... alloc = allocation_threshold_for_resize_mb( vdb, drives[1]) + 1 * MB # ... but we repeat the check in monitor_drives(), # so we need to set both locations to the correct value. vdb['allocation'] = alloc # Simulating block threshold event testvm.drive_monitor.on_block_threshold( 'vdb', '/virtio/1', alloc, 1 * MB) # Simulating periodic check testvm.monitor_drives() self.assertEqual(len(testvm.cif.irs.extensions), 1) # Simulate completed extend operation, invoking callback # Simulate setBlockThreshold failure testvm._dom.errors["setBlockThreshold"] = fake.Error( libvirt.VIR_ERR_OPERATION_FAILED, "fake error") simulate_extend_callback(testvm.cif.irs, extension_id=0) drv = drives[1] self.assertEqual(drv.threshold_state, BLOCK_THRESHOLD.UNSET)
def lookupByIDFailure(id): raise fake.Error(libvirt.VIR_ERR_NO_DOMAIN, 'Domain not exists')
def lookupByNameFailure(name): raise fake.Error(libvirt.VIR_ERR_NO_DOMAIN, 'Domain not exists')
def legacylistAllDomainsWrongRaise(): raise fake.Error(libvirt.VIR_ERR_NO_DOMAIN, 'Domain not exists')
def legacylistAllDomains(): raise fake.Error(libvirt.VIR_ERR_NO_SUPPORT, 'Method not supported')
def internal_error(name): raise fake.Error(libvirt.VIR_ERR_INTERNAL_ERROR)
def internal_error(flags=0): raise fake.Error(libvirt.VIR_ERR_INTERNAL_ERROR)
def lookupByID(self, id): for vm in self._vms: if vm.ID() == id: return vm raise fake.Error(libvirt.VIR_ERR_NO_DOMAIN, 'virDomainLookupByID() failed')
def lookupByName(self, name): for vm in self._vms: if vm.name() == name: return vm raise fake.Error(libvirt.VIR_ERR_NO_DOMAIN, 'virDomainLookupByName() failed')
def fail(uuid): raise vmfakelib.Error(libvirt.VIR_ERR_INTERNAL_ERROR)
def fail(*args): raise fake.Error(libvirt.VIR_ERR_NO_DOMAIN)
def fail(*args): raise fake.Error(errcode)
def storageVolLookupByPath(self, name): if not any([vm._has_disk_volume for vm in self._vms]): raise fake.Error(libvirt.VIR_ERR_INTERNAL_ERROR, "no volume in storage") return FakeVolume()
def blockPeek(self, disk, pos, size): if not self._has_disk_block: raise fake.Error(libvirt.VIR_ERR_INTERNAL_ERROR, "no such disk in this VM") self._block_disk.seek(pos) return self._block_disk.read(size)