예제 #1
0
 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"/>
           <bandwidth/>
         </interface>
     '''
     with fake.VM(devices=devices, create_device_objects=True) as testvm:
         testvm._dom = fake.Domain()
         res = testvm.updateDevice(params)
         self.assertFalse(response.is_error(res))
         self.assertXMLEqual(testvm._dom.devXml, updated_xml)
예제 #2
0
    def test_correct_disk_and_metadata(self):
        vmParams = {
            'vmId': '627f1f31-752b-4e7c-bfb5-4313d191ed7b',  # from XML
            'restoreState': '/dev/null',  # unused here
            'restoreFromSnapshot': True,
            '_srcDomXML': read_data('vm_replace_md_base.xml'),
            'xml': read_data('vm_replace_md_update.xml'),
        }
        with fake.VM(vmParams) as testvm:
            updated_dom_xml = testvm.conf['xml']

        # shortcut
        make_params = vmdevices.common.storage_device_params_from_domain_xml

        dom_desc = domain_descriptor.DomainDescriptor(updated_dom_xml)
        with dom_desc.metadata_descriptor() as md_desc:

            disk_params = make_params(dom_desc.id, dom_desc, md_desc,
                                      self._log)

        sda = find_drive_conf_by_name(disk_params, 'sda')

        self.assertIsNotNone(sda)
        self.assertEqual(sda['path'], '/rhev/data-center/path/updated')
        self.assertEqual(sda['imageID'], 'imageID_updated')
        self.assertEqual(sda['poolID'], 'poolID_updated')
        self.assertEqual(sda['domainID'], 'domainID_updated')
        self.assertEqual(sda['volumeID'], 'volumeID_updated')
예제 #3
0
 def testSetCpuTunePeriod(self, period, offset):
     with fake.VM() as testvm:
         # same as per testSetCpuTuneQuota
         testvm._dom = ChangingSchedulerDomain(offset)
         testvm.setCpuTunePeriod(period)
         self.assertEqual(period + offset,
                          testvm._vcpuTuneInfo['vcpu_period'])
예제 #4
0
    def testGetChunkedDrives(self, disk_conf, expected):
        with fake.VM() as testvm:
            vda = storage.Drive(self.log, **drive_config(**disk_conf))
            testvm._devices[hwclass.DISK] = [vda]

            drives = [drive.name for drive in testvm.getChunkedDrives()]
            self.assertEqual(drives, expected)
예제 #5
0
 def testVmNumaNodeRuntimeInfo(self):
     VM_PARAMS = {
         'guestNumaNodes': [{
             'cpus': '0,1',
             'memory': '1024',
             'nodeIndex': 0
         }, {
             'cpus': '2,3',
             'memory': '1024',
             'nodeIndex': 1
         }]
     }
     with fake.VM(VM_PARAMS) as testvm:
         expectedResult = {'0': [0, 1], '1': [0, 1]}
         self.assertTrue(testvm.hasGuestNumaNode)
         sample = [
             (0, 1, 19590000000, 1),
             (1, 1, 10710000000, 1),
             (2, 1, 19590000000, 0),
             (3, 1, 19590000000, 2),
             # CPU not assigned by Engine, should be ignored:
             (4, 1, 10710000000, 0)
         ]
         with MonkeyPatchScope([(numa, "_get_vcpu_positioning",
                                 lambda vm: sample)]):
             vm_numa_info = numa.getVmNumaNodeRuntimeInfo(testvm)
             self.assertEqual(expectedResult, vm_numa_info)
예제 #6
0
    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)
예제 #7
0
 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')
예제 #8
0
    def testGraphicsDisplayNetworkFromVmConf(self):
        conf = {'displayNetwork': 'vmDisplayConf'}
        conf.update(self.conf)
        with fake.VM(conf) as testvm:
            graphDev = vmdevices.graphics.Graphics(testvm.conf, testvm.log)

            self.assertEqual(graphDev.specParams['displayNetwork'],
                             'vmDisplayConf')
예제 #9
0
 def testTimeOffsetUpdateIfPresent(self, exitCode):
     with fake.VM({'timeOffset': self.BASE_OFFSET}) as testvm:
         for offset in self.UPDATE_OFFSETS:
             testvm.onRTCUpdate(offset)
         # beware of type change!
         testvm.setDownStatus(exitCode, vmexitreason.GENERIC_ERROR)
         self.assertEqual(testvm.getStats()['timeOffset'],
                          str(self.BASE_OFFSET + self.UPDATE_OFFSETS[-1]))
예제 #10
0
    def testGraphicsDisplayNetworkFromSpecParams(self):
        with fake.VM() as testvm:
            graphDev = vmdevices.graphics.Graphics(
                testvm.log,
                specParams={'displayNetwork': 'vmDisplaySpecParams'})

            self.assertEqual(graphDev.specParams['displayNetwork'],
                             'vmDisplaySpecParams')
예제 #11
0
 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
예제 #12
0
 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')
예제 #13
0
 def test_migrate_from_status(self, vm_status, is_error, error_code):
     with MonkeyPatchScope([(migration, 'SourceThread',
                             fake.MigrationSourceThread)]):
         with fake.VM(status=vm_status, cif=self.cif) as testvm:
             res = testvm.migrate({})  # no params needed
             self.assertEquals(
                 response.is_error(res, error_code),
                 is_error,
             )
예제 #14
0
    def test_sriov_vm(self):
        params = {
            'nicModel': 'rtl8139,pv',
            'name': 'SRiovVm',
            'displaySecurePort': '-1',
            'memSize': '256',
            'displayPort': '-1',
            'display': 'qxl'
        }

        devices = [
            {
                'device': 'virtio-serial',
                'type': 'controller'
            },
            {
                'device': 'memballoon',
                'specParams': {
                    'model': 'virtio'
                },
                'type': 'balloon'
            },
            {
                'device': 'bridge',
                'nicModel': 'virtio',
                'macAddr': '52:54:00:59:FF:FF',
                'type': 'interface',
                'network': ''
            },
            {
                'device': 'hostdev',
                'type': hwclass.NIC,
                'alias': 'hostdev2',
                'hostdev': 'pci_0000_05_00_1',
                'deviceId': '6940d5e7-9814-4ae0-94ef-f78e68229e76',
                'macAddr': '00:00:00:00:00:43',
                'specParams': {
                    'vlanid': 12
                }
            },
        ]

        test_path = os.path.realpath(__file__)
        dir_name = os.path.split(test_path)[0]
        api_path = os.path.join(dir_name, '..', 'data', 'testSRiovVm.xml')

        domain = None
        with open(api_path, 'r') as domxml:
            domain = domxml.read()
        with fake.VM(params=params,
                     devices=devices,
                     create_device_objects=True) as vm:
            vm._domain = domain_descriptor.DomainDescriptor(domain)
            vm._getUnderlyingVmDevicesInfo()
            self.verifyDevicesConf(vm.conf['devices'])
            self._assert_guest_device_adress_is_reported(vm)
            self._assert_host_address_is_reported(devices, vm)
예제 #15
0
    def testGraphicsDeviceMultiple(self, primary, secondary):
        devices = '\n'.join([
            '''
<graphics type="{type_}" port="-1">
  <listen type="network" network="vdsm-ovirtmgmt"/>
</graphics>'''.format(type_=type_) for type_ in (primary, secondary)
        ])
        with fake.VM(xmldevices=devices, create_device_objects=True) as testvm:
            self.assertEqual(len(testvm._devices['graphics']), 2)
예제 #16
0
 def testSetCpuTuneQuote(self, quota, offset):
     with fake.VM() as testvm:
         # we need a different behaviour with respect to
         # plain fake.Domain. Seems simpler to just add
         # a new special-purpose trivial fake here.
         testvm._dom = ChangingSchedulerDomain(offset)
         testvm.setCpuTuneQuota(quota)
         self.assertEqual(quota + offset,
                          testvm._vcpuTuneInfo['vcpu_quota'])
예제 #17
0
 def testGraphicsDisplayNetworkFromVmConf(self):
     conf = {'displayNetwork': 'vmDisplayConf'}
     conf.update(self.conf)
     with fake.VM(conf) as testvm:
         dev = {'type': hwclass.GRAPHICS, 'specParams': {}}
         testvm._dev_spec_update_with_vm_conf(dev)
         graphDev = vmdevices.graphics.Graphics(testvm.log, **dev)
         self.assertEqual(graphDev.specParams['displayNetwork'],
                          'vmDisplayConf')
예제 #18
0
    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)
예제 #19
0
    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())
예제 #20
0
 def testTimeOffsetUpdateIfAbsent(self, exitCode):
     # bz956741 (-like, simpler case)
     with fake.VM() as testvm:
         for offset in self.UPDATE_OFFSETS:
             testvm.onRTCUpdate(offset)
         # beware of type change!
         testvm.setDownStatus(exitCode, vmexitreason.GENERIC_ERROR)
         self.assertEqual(testvm.getStats()['timeOffset'],
                          str(self.UPDATE_OFFSETS[-1]))
예제 #21
0
 def test_restore_paths(self):
     xml = self.XML
     second_disk_path = '/path/secondary-drive'
     snapshot_params = {'path': '/path/snapshot-path',
                        'volume_id': 'aaa',
                        'device': '/dev/random',
                        'second_disk_path': second_disk_path,
                        }
     engine_params = {'path': '/path/engine-path',
                      'volume_id': 'bbb',
                      'device': '/dev/urandom',
                      'second_disk_path': second_disk_path,
                      }
     snapshot_xml = xml.format(**snapshot_params)
     engine_xml = xml.format(**engine_params)
     params = {'_srcDomXML': snapshot_xml,
               'xml': engine_xml,
               'restoreState': {
                   'device': 'disk',
                   'imageID': u'111',
                   'poolID': u'222',
                   'domainID': u'333',
                   'volumeID': u'bbb',
               },
               'restoreFromSnapshot': True,
               }
     with fake.VM(params) as vm:
         vm._normalizeVdsmImg = lambda *args: None
         devices = vm._make_devices()
         vm_xml = vm.conf['xml']
     # Check that unrelated devices are taken from the snapshot untouched,
     # not from the XML provided from Engine:
     for d in devices[hwclass.RNG]:
         self.assertEqual(d.specParams['source'],
                          os.path.basename(snapshot_params['device']))
         break
     else:
         raise Exception('RNG device not found')
     tested_drives = (('1234', engine_params['path'],),
                      ('5678', second_disk_path,),)
     for serial, path in tested_drives:
         for d in devices[hwclass.DISK]:
             if d.serial == serial:
                 self.assertEqual(d.path, path)
                 break
         else:
             raise Exception('Tested drive not found', serial)
     dom = xmlutils.fromstring(vm_xml)
     random = vmxml.find_first(dom, 'backend')
     self.assertEqual(random.text, snapshot_params['device'])
     for serial, path in tested_drives:
         for d in dom.findall(".//disk[serial='{}']".format(serial)):
             self.assertEqual(vmxml.find_attr(d, 'source', 'file'), path)
             break
         else:
             raise Exception('Tested drive not found', serial)
     self.assertEqual(vm_xml, vm._domain.xml)
예제 #22
0
 def testGraphicsDeviceDuplicated(self, devType):
     devices = [{
         'type': 'graphics',
         'device': devType
     }, {
         'type': 'graphics',
         'device': devType
     }]
     with fake.VM(self.conf, devices) as testvm:
         self.assertRaises(ValueError, testvm.devSpecMapFromConf)
예제 #23
0
    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())
예제 #24
0
 def testGraphicsDeviceMultiple(self, primary, secondary):
     devices = [{
         'type': 'graphics',
         'device': primary
     }, {
         'type': 'graphics',
         'device': secondary
     }]
     with fake.VM(self.conf, devices) as testvm:
         devs = testvm.devSpecMapFromConf()
         self.assertTrue(len(devs['graphics']) == 2)
예제 #25
0
 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()
예제 #26
0
 def testTimeOffsetRoundtriupAcrossInstances(self, exitCode):
     # bz956741
     lastOffset = 0
     for offset in self.UPDATE_OFFSETS:
         with fake.VM({'timeOffset': lastOffset}) as testvm:
             testvm.onRTCUpdate(offset)
             testvm.setDownStatus(exitCode, vmexitreason.GENERIC_ERROR)
             vmOffset = testvm.getStats()['timeOffset']
             self.assertEqual(vmOffset, str(lastOffset + offset))
             # the field in getStats is str, not int
             lastOffset = int(vmOffset)
예제 #27
0
 def test_createXmlElem(self):
     dev = {'type': 'graphics', 'device': 'spice'}
     expected_xml = '''<?xml version=\'1.0\' encoding=\'utf-8\'?>
     <graphics device="spice" type="test" />'''
     with fake.VM(self.conf, devices=(dev,),
                  create_device_objects=True) as testvm:
         graphics = testvm._devices[hwclass.GRAPHICS][0]
         element = graphics.createXmlElem('graphics', 'test',
                                          attributes=('device', 'foo',))
         result = xmlutils.tostring(element)
         self.assertXMLEqual(result, expected_xml)
예제 #28
0
    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')
예제 #29
0
 def testVmNumaNodeRuntimeInfo(self):
     VM_PARAMS = {'guestNumaNodes': [{'cpus': '0,1',
                                      'memory': '1024',
                                      'nodeIndex': 0},
                                     {'cpus': '2,3',
                                      'memory': '1024',
                                      'nodeIndex': 1}]}
     with fake.VM(VM_PARAMS) as testvm:
         testvm._vmStats = fake.VmStatsThread(testvm)
         expectedResult = {'0': [0, 1], '1': [0, 1]}
         vmNumaNodeRuntimeMap = numaUtils.getVmNumaNodeRuntimeInfo(testvm)
         self.assertEqual(expectedResult, vmNumaNodeRuntimeMap)
예제 #30
0
    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)