def _getAllDomains(self, arch, channelName=None): for conf, rawXml in self._CONFS[arch]: if channelName is not None: conf = conf.copy() conf['agentChannelName'] = channelName domXml = rawXml % conf yield fake.Domain(domXml, vmId=conf['vmId']), domXml
def _verifyDeviceUpdate(self, device, allDevices, domXml, devXml): with fake.VM(devices=allDevices) as testvm: testvm._dom = fake.Domain(domXml) self._updateGraphicsDevice(testvm, device['device']) self.assertEquals(testvm._dom.devXml, devXml)
def listAllDomains(self): for conf, rawXml in self.CONFS[self.arch]: if self.channel_name is not None: conf = conf.copy() conf['agentChannelName'] = self.channel_name domXml = rawXml % conf yield fake.Domain(domXml, vmId=conf['vmId'])
def test_interface_update(self): devices = [{'nicModel': 'virtio', 'network': 'ovirtmgmt', 'macAddr': '52:54:00:59:F5:3F', 'device': 'bridge', 'type': 'interface', 'alias': 'net1', 'name': 'net1', 'linkActive': 'true', 'specParams': {'inbound': {'average': 1000, 'peak': 5000, 'burst': 1024}, 'outbound': {'average': 128, 'burst': 256}}, }] params = {'linkActive': 'true', 'alias': 'net1', 'deviceType': 'interface', 'network': 'ovirtmgmt2', 'specParams': {'inbound': {}, 'outbound': {}}} updated_xml = ''' <interface type="bridge"> <mac address="52:54:00:59:F5:3F"/> <model type="virtio"/> <source bridge="ovirtmgmt2"/> <virtualport type="openvswitch"/> <link state="up"/> <alias name="net1"/> <bandwidth/> </interface> ''' with fake.VM(devices=devices, create_device_objects=True) as testvm: testvm._dom = fake.Domain() res = testvm.updateDevice(params) self.assertIn('vmList', res) self.assertXMLEqual(testvm._dom.devXml, updated_xml)
def testSetSaslPasswordInFips(self): graphics_params = dict(_GRAPHICS_DEVICE_PARAMS) del graphics_params['existingConnAction'] device = self.GRAPHIC_DEVICES[1] # VNC graphics_xml = ('<graphics type="%s" port="5900"/>' % (device['device'], )) device_xml = '<devices>%s</devices>' '' % (graphics_xml, ) with fake.VM(xmldevices=graphics_xml) as testvm: def _fake_set_vnc_pwd(username, pwd): testvm.pwd = pwd testvm.username = username testvm._dom = fake.Domain(device_xml) testvm.pwd = "invalid" params = {'graphicsType': device['device']} params.update(graphics_params) params['params']['fips'] = 'true' params['params']['vncUsername'] = '******' with MonkeyPatchScope([(saslpasswd2, 'set_vnc_password', _fake_set_vnc_pwd)]): testvm.updateDevice(params) self.assertEqual(password.unprotect(params['password']), testvm.pwd) self.assertEqual(params['params']['vncUsername'], testvm.username)
def testReadPauseCodeDomainPausedCrash(self): with fake.VM() as testvm: # if paused for different reason we must not extend the disk # so anything else is ok dom = fake.Domain(domState=libvirt.VIR_DOMAIN_PAUSED, domReason=libvirt.VIR_DOMAIN_PAUSED_CRASHED) testvm._dom = dom self.assertNotEqual(testvm._readPauseCode(), 'ENOSPC')
def testReadPauseCodeDomainPausedEIO(self): with fake.VM() as testvm: dom = fake.Domain(domState=libvirt.VIR_DOMAIN_PAUSED, domReason=libvirt.VIR_DOMAIN_PAUSED_IOERROR) dom.setDiskErrors({'vda': libvirt.VIR_DOMAIN_DISK_ERROR_NONE, 'hdc': libvirt.VIR_DOMAIN_DISK_ERROR_UNSPEC}) testvm._dom = dom self.assertEqual(testvm._readPauseCode(), 'EOTHER')
def _buildAllDomains(self, arch, channelName=None): for conf, _ in self._CONFS[arch]: if channelName is not None: conf = conf.copy() conf['agentChannelName'] = channelName with fake.VM(conf, arch=arch) as v: domXml = v._buildDomainXML() yield fake.Domain(domXml, vmId=v.id), domXml
def _verifyDeviceUpdate(self, device, allDevices, domXml, devXml, graphics_params): with fake.VM(xmldevices=allDevices) as testvm: testvm._dom = fake.Domain(domXml) self._updateGraphicsDevice(testvm, device['device'], graphics_params) self.assertXMLEqual(testvm._dom.devXml, devXml)
def testIgnoreKnownErrors(self, code, text): def _fail(*args): raise_libvirt_error(code, text) with fake.VM() as testvm: dom = fake.Domain() dom.controlInfo = _fail testvm._dom = dom self.assertFalse(testvm.isDomainReadyForCommands())
def testDomainDisappearedNotReadyForCommands(self): def _fail(*args): raise_libvirt_error(libvirt.VIR_ERR_NO_DOMAIN, "Disappeared domain") with fake.VM() as testvm: dom = fake.Domain() dom.controlInfo = _fail testvm._dom = dom self.assertFalse(testvm.isDomainReadyForCommands())
def setUp(self): devices = [{'nicModel': 'virtio', 'network': 'ovirtmgmt', 'macAddr': "11:22:33:44:55:66", 'device': 'bridge', 'type': 'interface', 'alias': 'net1', 'name': 'net1', 'linkActive': 'true', }] with fake.VM(devices=devices, create_device_objects=True) as vm: vm._dom = fake.Domain(vm=vm) self.vm = vm self.supervdsm = fake.SuperVdsm()
def _make_domains_collection(vm_uuids): return { vm_uuid: fake.Domain( vmId=vm_uuid, xml=_make_domain_xml( vm_uuid, external=external ), ) for vm_uuid, external in vm_uuids }
def testReadPauseCodeDomainPausedCrash(self): # REQUIRED_FOR: el6 if not hasattr(libvirt, 'VIR_DOMAIN_PAUSED_CRASHED'): raise SkipTest('libvirt.VIR_DOMAIN_PAUSED_CRASHED undefined') with fake.VM() as testvm: # if paused for different reason we must not extend the disk # so anything else is ok dom = fake.Domain(domState=libvirt.VIR_DOMAIN_PAUSED, domReason=libvirt.VIR_DOMAIN_PAUSED_CRASHED) testvm._dom = dom self.assertNotEqual(testvm._readPauseCode(), 'ENOSPC')
def testReadyForCommandsRaisesLibvirtError(self): def _fail(*args): # anything != NO_DOMAIN is good raise_libvirt_error(libvirt.VIR_ERR_INTERNAL_ERROR, "Fake internal error") with fake.VM() as testvm: dom = fake.Domain() dom.controlInfo = _fail testvm._dom = dom self.assertRaises(libvirt.libvirtError, testvm.isDomainReadyForCommands)
def _update_downtime_repeatedly(downtime, steps): dom = fake.Domain() with fake.VM({'memSize': 1024}) as testvm: testvm._dom = dom cfg = make_config([('vars', 'migration_downtime_delay', '0')]) with MonkeyPatchScope([(migration, 'config', cfg)]): dt = migration.DowntimeThread(testvm, downtime, steps) dt.start() dt.join() return dom.getDowntimes()
def test_get_mapping_vcpu_to_pcpu(self): # stolen from real libvirt vcpu_output = ([(0, 1, 20050000000, 0), (1, 1, 11300000000, 1)], [(True, True, True, True), (True, True, True, True)]) mapping = {0: 0, 1: 1} with fake.VM() as testvm: testvm._dom = fake.Domain() testvm._dom.vcpus = lambda: vcpu_output self.assertEqual( numa._get_mapping_vcpu_to_pcpu( numa._get_vcpu_positioning(testvm)), mapping)
def testSetNumberOfVcpusFailed(self, virt_error, vdsm_error, error_message): def _fail(*args): raise_libvirt_error(virt_error, error_message) with MonkeyPatchScope([(hooks, 'before_set_num_of_cpus', lambda: None) ]): with fake.VM() as testvm: dom = fake.Domain() dom.setVcpusFlags = _fail testvm._dom = dom res = testvm.setNumberOfCpus(4) # random value self.assertEqual(res, response.error(vdsm_error))
def setUp(self): devices = ''' <interface type="bridge"> <mac address="11:22:33:44:55:66"/> <model type="virtio"/> <source bridge="ovirtmgmt"/> <virtualport type="openvswitch"/> <link state="down"/> <alias name="net1"/> <target dev="net1"/> </interface> ''' with fake.VM(xmldevices=devices, create_device_objects=True) as vm: vm._dom = fake.Domain(vm=vm) self.vm = vm self.supervdsm = fake.SuperVdsm()
def test_interface_update(self): devices = ''' <interface type="bridge"> <mac address="52:54:00:59:F5:3F"/> <model type="virtio"/> <source bridge="ovirtmgmt"/> <virtualport type="openvswitch"/> <link state="up"/> <alias name="ua-net1"/> <target dev="net1"/> <bandwidth> <inbound average="1000" peak="5000" burst="1024"/> <inbound average="128" burst="256"/> </bandwidth> </interface> ''' params = { 'linkActive': 'true', 'alias': 'ua-net1', 'name': 'net1', 'deviceType': 'interface', 'network': 'ovirtmgmt2', 'specParams': { 'inbound': {}, 'outbound': {} } } updated_xml = ''' <interface type="bridge"> <mac address="52:54:00:59:F5:3F"/> <model type="virtio"/> <source bridge="ovirtmgmt2"/> <virtualport type="openvswitch"/> <link state="up"/> <alias name="ua-net1"/> <bandwidth/> </interface> ''' with fake.VM(xmldevices=devices, create_device_objects=True) as testvm: testvm._dom = fake.Domain() res = testvm.updateDevice(params) self.assertIn('vmList', res) self.assertXMLEqual(testvm._dom.devXml, updated_xml)
def testUpdateDeviceGraphicsFailed(self): with fake.VM(devices=self.GRAPHIC_DEVICES) as testvm: message = 'fake timeout while setting ticket' device = 'spice' domXml = ''' <devices> <graphics type="%s" port="5900" /> </devices>''' % device def _fail(*args): raise virdomain.TimeoutError(defmsg=message) domain = fake.Domain(domXml) domain.updateDeviceFlags = _fail testvm._dom = domain res = self._updateGraphicsDevice(testvm, device) self.assertEqual(res, response.error('ticketErr', message))
def testUpdateDeviceGraphicsFailed(self): with fake.VM(devices=self.GRAPHIC_DEVICES) as testvm: message = 'fake timeout while setting ticket' device = 'spice' domXml = ''' <devices> <graphics type="%s" port="5900" /> </devices>''' % device def _fail(*args): raise virdomain.TimeoutError(defmsg=message) domain = fake.Domain(domXml) domain.updateDeviceFlags = _fail testvm._dom = domain self.assertRaises(exception.SpiceTicketError, self._updateGraphicsDevice, testvm, device, _GRAPHICS_DEVICE_PARAMS)
def test_memory_info_committed(self): vm_uuid = str(uuid.uuid4()) memory_mb = 128 minimal_xml = u"""<?xml version="1.0" encoding="utf-8"?> <domain type="kvm" xmlns:ovirt="http://ovirt.org/vm/tune/1.0"> <name>testVm</name> <uuid>{vm_uuid}</uuid> <memory unit='KiB'>{vm_memory}</memory> <maxMemory unit='KiB'>{vm_memory}</maxMemory> </domain>""".format(vm_uuid=vm_uuid, vm_memory=memory_mb * define.Kbytes) vm_params = { 'vmId': vm_uuid, 'memSize': memory_mb, 'xml': minimal_xml, } with fake.VM(params=vm_params) as testvm: testvm._dom = fake.Domain(xml=minimal_xml, vmId=vm_uuid) mem_info = testvm.memory_info() self.assertEqual(_mem_committed(memory_mb), mem_info['commit'] * define.Kbytes)
def testClearSaslPasswordNoFips(self): graphics_params = dict(_GRAPHICS_DEVICE_PARAMS) del graphics_params['existingConnAction'] device = self.GRAPHIC_DEVICES[1] # VNC domXml = ''' <devices> <graphics type="%s" port="5900" /> </devices>''' % device['device'] with fake.VM(devices=domXml) as testvm: def _fake_remove_pwd(username): testvm.username = username testvm._dom = fake.Domain(domXml) params = {'graphicsType': device['device']} params.update(graphics_params) params['params']['vncUsername'] = '******' with MonkeyPatchScope([(saslpasswd2, 'remove_vnc_password', _fake_remove_pwd)]): testvm.updateDevice(params) self.assertEqual(params['params']['vncUsername'], testvm.username)
def _build_domain_xml(self, arch): for conf, rawXml in self._CONFS[arch]: domXml = rawXml % conf yield fake.Domain(domXml, vmId=conf['vmId']), domXml
def _getAllDomains(self, arch): for conf, rawXml in self._CONFS[arch]: domXml = rawXml % conf yield fake.Domain(domXml, vmId=conf['vmId']), domXml
def testAcpiRebootConnected(self): with fake.VM() as testvm: testvm._dom = fake.Domain(vmId='testvm') self.assertFalse(response.is_error(testvm.acpiReboot()))
def testReadPauseCodeDomainRunning(self): with fake.VM() as testvm: testvm._dom = fake.Domain(domState=libvirt.VIR_DOMAIN_RUNNING) self.assertEqual(testvm._readPauseCode(), 'NOERR')
def _buildAllDomains(self, arch): for conf, _ in self._CONFS[arch]: with fake.VM(conf, arch=arch) as v: domXml = v._buildDomainXML() yield fake.Domain(domXml, vmId=v.id), domXml
def testDomainIsReadyForCommands(self): with fake.VM() as testvm: testvm._dom = fake.Domain() self.assertTrue(testvm.isDomainReadyForCommands())