Esempio n. 1
0
 def test_replace_cdrom_withoutource_file(self):
     dom_str = read_data('vm_hibernated.xml')
     dom = xmlutils.fromstring(dom_str)
     cdrom_xml = u'''<disk device="cdrom" type="file">
         <driver error_policy="report" name="qemu" type="raw" />
         <source {file_src}startupPolicy="optional">
             <seclabel model="dac" relabel="no" type="none" />
         </source>
         <backingStore />
         <target bus="ide" dev="hdc" />
         <readonly />
         <alias name="ide0-1-0" />
         <address bus="1" controller="0" target="0"
             type="drive" unit="0" />
     </disk>'''
     cdrom_params = vmdevices.storagexml.parse(
         xmlutils.fromstring(cdrom_xml.format(file_src='')), {}
     )
     disk_devs = [
         vmdevices.storage.Drive(self.log, **cdrom_params),
     ]
     domxml_preprocess.update_disks_xml_from_objs(
         FakeVM(self.log), dom, disk_devs)
     cdrom_elem = dom.find('./devices/disk[@device="cdrom"]')
     self.assertXMLEqual(
         xmlutils.tostring(cdrom_elem, pretty=True),
         cdrom_xml.format(file_src="file='' ")
     )
Esempio n. 2
0
 def test_replace_cdrom_with_minimal_drive(self):
     dom_str = read_data('vm_hibernated_390.xml')
     dom = xmlutils.fromstring(dom_str)
     # taken from the test XML and amended manually
     # please note:
     # - the lack of empty 'backingStore' element
     # - the 'driver' elements lack name="qemu" (default)
     cdrom_xml = u'''<disk device="cdrom" type="file">
         <driver error_policy="report" type="raw" />
         <source file="" startupPolicy="optional">
             <seclabel model="dac" relabel="no" type="none" />
         </source>
         <target bus="ide" dev="hdc" />
         <readonly />
         <alias name="ua-096534a7-5fbd-4bd1-add0-65501bce51f9" />
         <address bus="1" controller="0" target="0"
             type="drive" unit="0" />
     </disk>'''
     cdrom_params = vmdevices.storagexml.parse(
         xmlutils.fromstring(cdrom_xml), {}
     )
     disk_devs = [
         vmdevices.storage.Drive(self.log, **cdrom_params),
     ]
     domxml_preprocess.update_disks_xml_from_objs(
         FakeVM(self.log), dom, disk_devs)
     cdrom_elem = dom.find('./devices/disk[@device="cdrom"]')
     self.assertXMLEqual(
         xmlutils.tostring(cdrom_elem, pretty=True),
         cdrom_xml
     )
Esempio n. 3
0
 def attachDevice(self, device_xml):
     if self._xml:
         dom = xmlutils.fromstring(self._xml)
         devices = dom.find('.//devices')
         attached_device = xmlutils.fromstring(device_xml)
         devices.append(attached_device)
         self._xml = xmlutils.tostring(dom)
Esempio n. 4
0
    def test_disk_ignore_volumeinfo_from_metadata_xml(self):
        xml_snippet = u'''<volumeInfo>
            <path>/rhev/data-center/omitted/for/brevity</path>
            <volType>path</volType>
        </volumeInfo>'''

        root = xmlutils.fromstring(_DISK_DATA.metadata_xml)
        dev = vmxml.find_first(root, 'device')
        vmxml.append_child(dev, etree_child=xmlutils.fromstring(xml_snippet))
        data = _TestData(
            copy.deepcopy(_DISK_DATA.conf), xmlutils.tostring(root))
        self._check_drive_from_metadata_xml(data)
Esempio n. 5
0
 def test_lookup_drive_by_element(self, drive_xml, dev_name, alias_name):
     # intentionally without serial and alias
     if dev_name is None:
         with pytest.raises(LookupError):
             lookup.drive_from_element(
                 self.drives, xmlutils.fromstring(drive_xml)
             )
     else:
         drive = lookup.drive_from_element(
             self.drives,
             xmlutils.fromstring(drive_xml)
         )
         assert drive.name == dev_name
Esempio n. 6
0
 def test_lookup_drive_by_element(self, drive_xml, dev_name, alias_name):
     # intentionally without serial and alias
     if dev_name is None:
         self.assertRaises(
             LookupError,
             lookup.drive_from_element,
             self.drives,
             xmlutils.fromstring(drive_xml)
         )
     else:
         drive = lookup.drive_from_element(
             self.drives,
             xmlutils.fromstring(drive_xml)
         )
         self.assertEqual(drive.name, dev_name)
Esempio n. 7
0
 def _make_env(self):
     dom_disk_file_str = read_data('domain_disk_file.xml')
     dom = xmlutils.fromstring(dom_disk_file_str)
     # taken from domain_disk_file.xml
     disk_meta = {
         'domainID': 'f3f6e278-47a1-4048-b9a5-0cf4d6ba455f',
         'imageID': 'c9865ca8-f6d2-4363-bec2-af870a87a819',
         'poolID': '59c4c3ee-0205-0227-0229-000000000155',
         'volumeID': '1dfad482-c65c-436c-aa59-87e020b63302',
     }
     disk_path = (
         '/rhev/data-center/mnt/blockSD/'
         'a67a8671-05fc-4e42-b147-f7d3a0496cd6/images/'
         'b07a37de-95d6-4682-84cd-c8c9201327e3/'
         'b3335e60-6d27-46e0-bed8-50e75cca6786'
     )
     disk_xml = u'''<disk type='block' device='disk' snapshot='no'>
         <driver name='qemu' type='qcow2' cache='none'
             error_policy='stop' io='native'/>
         <source dev='{path}'/>
       <backingStore/>
       <target dev='sda' bus='scsi'/>
       <serial>b07a37de-95d6-4682-84cd-c8c9201327e3</serial>
       <boot order='1'/>
       <alias name='scsi0-0-0-0'/>
       <address type='drive' controller='0' bus='0' target='0' unit='0'/>
     </disk>'''.format(path=disk_path)
     disk_params = vmdevices.storagexml.parse(
         xmlutils.fromstring(disk_xml), disk_meta
     )
     cdrom_xml = u'''<disk device="cdrom" type="file">
         <driver error_policy="report" name="qemu" type="raw" />
         <source startupPolicy="optional" />
         <backingStore />
         <target bus="ide" dev="hdc" />
         <readonly />
         <alias name="ide0-1-0" />
         <address bus="1" controller="0" target="0"
             type="drive" unit="0" />
     </disk>'''
     cdrom_params = vmdevices.storagexml.parse(
         xmlutils.fromstring(cdrom_xml), {}
     )
     disk_devs = [
         vmdevices.storage.Drive(self.log, **cdrom_params),
         vmdevices.storage.Drive(self.log, **disk_params)
     ]
     return dom, disk_devs
Esempio n. 8
0
 def _make_env(self):
     dom_disk_file_str = read_data('domain_disk_file.xml')
     dom = xmlutils.fromstring(dom_disk_file_str)
     # taken from domain_disk_file.xml
     disk_meta = {
         'domainID': 'f3f6e278-47a1-4048-b9a5-0cf4d6ba455f',
         'imageID': 'c9865ca8-f6d2-4363-bec2-af870a87a819',
         'poolID': '59c4c3ee-0205-0227-0229-000000000155',
         'volumeID': '1dfad482-c65c-436c-aa59-87e020b63302',
     }
     disk_path = (
         '/rhev/data-center/mnt/blockSD/'
         'a67a8671-05fc-4e42-b147-f7d3a0496cd6/images/'
         'b07a37de-95d6-4682-84cd-c8c9201327e3/'
         'b3335e60-6d27-46e0-bed8-50e75cca6786'
     )
     disk_xml = u'''<disk type='block' device='disk' snapshot='no'>
         <driver name='qemu' type='qcow2' cache='none'
             error_policy='stop' io='native'/>
         <source dev='{path}'/>
       <backingStore/>
       <target dev='sda' bus='scsi'/>
       <serial>b07a37de-95d6-4682-84cd-c8c9201327e3</serial>
       <boot order='1'/>
       <alias name='scsi0-0-0-0'/>
       <address type='drive' controller='0' bus='0' target='0' unit='0'/>
     </disk>'''.format(path=disk_path)
     disk_params = vmdevices.storagexml.parse(
         xmlutils.fromstring(disk_xml), disk_meta
     )
     cdrom_xml = u'''<disk device="cdrom" type="file">
         <driver error_policy="report" name="qemu" type="raw" />
         <source startupPolicy="optional" />
         <backingStore />
         <target bus="ide" dev="hdc" />
         <readonly />
         <alias name="ide0-1-0" />
         <address bus="1" controller="0" target="0"
             type="drive" unit="0" />
     </disk>'''
     cdrom_params = vmdevices.storagexml.parse(
         xmlutils.fromstring(cdrom_xml), {}
     )
     disk_devs = [
         vmdevices.storage.Drive(self.log, **cdrom_params),
         vmdevices.storage.Drive(self.log, **disk_params)
     ]
     return dom, disk_devs
Esempio n. 9
0
    def test_replace_device_xml_with_hook_xml_empty_custom(self):
        """
        Try to replace device XML if custom properties are declared.
        """
        # invoked even if custom properties exist, but are empty.
        dom_disk_file_str = read_data('vm_replace_md_base.xml')
        dom = xmlutils.fromstring(dom_disk_file_str)

        with MonkeyPatchScope([
            (hooks, 'before_device_create', self._hook),
        ]):
            domxml_preprocess.replace_device_xml_with_hooks_xml(
                dom, 'test', {})

        addr = (
            '<address bus="0x00" domain="0x0000"'
            ' function="0x0" slot="0x03" type="pci" />'
        )
        expected_xml = u'''<?xml version='1.0' encoding='utf-8'?>
<interface type="bridge">
    <model type="virtio" />
    <link state="up" />
    <source bridge="ovirtmgmt" />
    {addr}
    <mac address="00:1a:4a:16:01:12" />
    <filterref filter="vdsm-no-mac-spoofing" />
    <bandwidth />
</interface>
'''.format(addr=addr)
        self.assertEqual(
            self._hook_params,
            [(expected_xml, {}, {})]
        )
Esempio n. 10
0
    def test_no_leases(self):
        """
        without leases, do nothing
        """
        # any VM without leases is fine
        xml_str = read_data('vm_compat41.xml')
        self.assertXMLEqual(
            extract_device_snippet('lease', xml_str=xml_str),
            u'''<?xml version='1.0' encoding='utf-8'?><devices />'''
        )

        dom = xmlutils.fromstring(xml_str)
        disk_devs = domxml_preprocess._make_disk_devices(
            xml_str, self.log)
        disk_devs = self._inject_volume_chain(
            disk_devs, self.driveVolInfo,
            domainID='unknwonDomainID',
            volumeID='unknownVolumeID')

        domxml_preprocess.update_leases_xml_from_disk_objs(
            self.vm, dom, disk_devs)

        self.assertXMLEqual(
            extract_device_snippet('lease', dom=dom),
            u'''<?xml version='1.0' encoding='utf-8'?><devices />'''
        )
Esempio n. 11
0
 def test_load_ns(self):
     test_xml = u'''<ovirt-vm:vm xmlns:ovirt-vm="http://ovirt.org/vm/1.0">
       <ovirt-vm:version type="float">4.2</ovirt-vm:version>
     </ovirt-vm:vm>'''
     metadata_obj = metadata.Metadata('ovirt-vm', 'http://ovirt.org/vm/1.0')
     self.assertEqual(metadata_obj.load(xmlutils.fromstring(test_xml)),
                      {'version': 4.2})
Esempio n. 12
0
def parse_jobs(vm):
    """
    Parse jobs persisted in vm metadata.
    """
    root = xmlutils.fromstring(vm._dom.metadata)
    jobs = root.find("./jobs").text
    return json.loads(jobs)
Esempio n. 13
0
    def test_with_sysprep_floppy(self):
        dom_str = read_data('vm_sysprep_floppy.xml')
        dom = xmlutils.fromstring(dom_str)
        # taken and amended from vm_sysprep_floppy.xml
        floppy_params = {
            'index': 0,
            'iface': 'fdc',
            'name': 'fda',
            'alias': 'ua-cc9acd76-7b44-4adf-881d-e98e1cf4e639',
            'vmid': 'e9252f48-6b22-4c9b-8d9a-8531fcf71f4c',
            'diskType': 'file',
            'readonly': True,
            'device': 'floppy',
            'path': 'PAYLOAD:',
            'propagateErrors': 'off',
            'type': 'disk'
        }
        floppy_obj = vmdevices.storage.Drive(self.log, **floppy_params)
        disk_devs = [floppy_obj]
        domxml_preprocess.update_disks_xml_from_objs(
            FakeVM(self.log), dom, disk_devs)

        floppy_elem = dom.find('./devices/disk[@device="floppy"]')
        self.assertXMLEqual(
            xmlutils.tostring(floppy_elem, pretty=True),
            xmlutils.tostring(floppy_obj.getXML(), pretty=True),
        )
Esempio n. 14
0
    def test_no_leases(self):
        """
        without leases, do nothing
        """
        # any VM without leases is fine
        xml_str = read_data('vm_compat41.xml')
        self.assertXMLEqual(
            extract_device_snippet('lease', xml_str=xml_str),
            u'''<?xml version='1.0' encoding='utf-8'?><devices />'''
        )

        dom = xmlutils.fromstring(xml_str)
        disk_devs = domxml_preprocess._make_disk_devices(
            xml_str, self.log)
        disk_devs = self._inject_volume_chain(
            disk_devs, self.driveVolInfo,
            domainID='unknwonDomainID',
            volumeID='unknownVolumeID')

        domxml_preprocess.update_leases_xml_from_disk_objs(
            self.vm, dom, disk_devs)

        self.assertXMLEqual(
            extract_device_snippet('lease', dom=dom),
            u'''<?xml version='1.0' encoding='utf-8'?><devices />'''
        )
Esempio n. 15
0
 def setUp(self):
     self.drives = [
         FakeDrive(
             name='sda',
             serial='scsi0000',
             alias='ua-0000'
         ),
         FakeDrive(
             name='vdb',
             serial='virtio0000',
             alias='ua-2001'
         ),
     ]
     self.devices_conf = [
         {'alias': 'dimm0', 'type': 'memory', 'size': 1024},
         {'alias': 'ac97', 'type': 'sound'}
     ]
     self.devices = common.empty_dev_map()
     self.device_xml = xmlutils.fromstring("""
         <devices>
           <disk><alias name='ua-1'/></disk>
           <hostdev><alias name='ua-2'/></hostdev>
           <interface><alias name='ua-3'/></interface>
         </devices>
     """)
Esempio n. 16
0
def extract_device_snippet(device_type, xml_str=None, dom=None):
    if dom is None:
        dom = xmlutils.fromstring(xml_str)
    devs = vmxml.Element('devices')
    for dev in dom.findall('./devices/%s' % device_type):
        vmxml.append_child(devs, etree_child=dev)
    return xmlutils.tostring(devs, pretty=True)
Esempio n. 17
0
    def load(self, dom):
        """
        Reads the content of the metadata section from the given libvirt
        domain. This will fully overwrite any existing content stored in the
        Descriptor. The data in the libvirt domain is not changed at all.

        :param dom: domain to access
        :type dom: libvirt.Domain
        """
        md_xml = "<{tag}/>".format(tag=self._name)
        try:
            md_xml = dom.metadata(
                libvirt.VIR_DOMAIN_METADATA_ELEMENT,
                self._namespace_uri,
                0
            )
        except libvirt.libvirtError as e:
            if e.get_error_code() != libvirt.VIR_ERR_NO_DOMAIN_METADATA:
                raise
            # else `md_xml` not reassigned, so we will parse empty section
            # and that's exactly what we want.

        self._log.debug(
            'loading metadata for %s: %s', dom.UUIDString(), md_xml)
        self._load(xmlutils.fromstring(md_xml))
Esempio n. 18
0
 def test_storage_from_incomplete_xml(self):
     storage_xml = '''<disk device="disk" snapshot="no" type="file">
         <source>
             <seclabel model="dac" relabel="no" type="none" />
         </source>
         <target bus="virtio" dev="vda"/>
         <serial>54-a672-23e5b495a9ea</serial>
         <driver cache="none" error_policy="stop"
                 io="threads" name="qemu" type="raw"/>
     </disk>'''
     expected_xml = '''<disk device="disk" snapshot="no" type="file">
         <source file="">
             <seclabel model="dac" relabel="no" type="none" />
         </source>
         <target bus="virtio" dev="vda"/>
         <serial>54-a672-23e5b495a9ea</serial>
         <driver cache="none" error_policy="stop"
                 io="threads" name="qemu" type="raw"/>
     </disk>'''
     dev = vmdevices.storage.Drive(
         self.log, **vmdevices.storagexml.parse(
             xmlutils.fromstring(storage_xml),
             {}
         )
     )
     self._check_device_xml(dev, expected_xml)
Esempio n. 19
0
 def test_missing_address_alias(self):
     XML = u"<device type='fake' />"
     dev = xmlutils.fromstring(XML)
     found_addr = vmdevices.core.find_device_guest_address(dev)
     found_alias = vmdevices.core.find_device_alias(dev)
     assert found_addr is None
     assert found_alias == ''
Esempio n. 20
0
 def test_storage_from_xml(self, storage_xml, meta):
     dev = vmdevices.storage.Drive(
         self.log, **vmdevices.storagexml.parse(
             xmlutils.fromstring(storage_xml),
             {} if meta is None else meta
         )
     )
     self._check_device_xml(dev, storage_xml)
Esempio n. 21
0
 def test_transient_storage_from_xml(self, storage_xml, meta):
     dev = vmdevices.storage.Drive(
         self.log, **vmdevices.storagexml.parse(
             xmlutils.fromstring(storage_xml),
             {} if meta is None else meta
         )
     )
     assert dev.shared == vmdevices.storage.DRIVE_SHARED_TYPE.TRANSIENT
Esempio n. 22
0
 def _check_roundtrip(self, klass, dev_xml, meta=None, expected_xml=None):
     dev = klass.from_xml_tree(
         self.log,
         xmlutils.fromstring(dev_xml),
         {} if meta is None else meta
     )
     self._check_device_attrs(dev)
     self._check_device_xml(dev, dev_xml, expected_xml)
Esempio n. 23
0
 def test_missing_address(self):
     XML = u"""<device type='fake'>
       <alias name='{alias}'/>
     </device>""".format(alias=self.ALIAS)
     dev = xmlutils.fromstring(XML)
     found_addr = vmdevices.core.find_device_guest_address(dev)
     found_alias = vmdevices.core.find_device_alias(dev)
     assert found_addr is None
     assert found_alias == self.ALIAS
Esempio n. 24
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)
Esempio n. 25
0
    def _check_leases(self, xml_str, vol_infos):
        xml_dom = xmlutils.fromstring(xml_str)
        lease_elems = xml_dom.findall('./devices/lease')
        assert len(lease_elems) == len(vol_infos)

        for lease_elem, vol_info in zip(lease_elems, vol_infos):
            target = vmxml.find_first(lease_elem, 'target')
            assert target.attrib['path'] == str(vol_info['leasePath'])
            assert target.attrib['offset'] == str(vol_info['leaseOffset'])
Esempio n. 26
0
File: common.py Progetto: nirs/vdsm
def dev_elems_from_xml(vm, xml):
    """
    Return device instance building elements from provided XML.

    The XML must contain <devices> element with a single device subelement, the
    one to create the instance for.  Depending on the device kind <metadata>
    element may be required to provide device metadata; the element may and
    needn't contain unrelated metadata.  This function is used in device
    hot(un)plugs.

    Example `xml` value (top element tag may be arbitrary):

      <?xml version='1.0' encoding='UTF-8'?>
      <hotplug>
        <devices>
          <interface type="bridge">
            <mac address="66:55:44:33:22:11"/>
            <model type="virtio" />
            <source bridge="ovirtmgmt" />
            <filterref filter="vdsm-no-mac-spoofing" />
            <link state="up" />
            <bandwidth />
          </interface>
        </devices>
        <metadata xmlns:ns0="http://ovirt.org/vm/tune/1.0"
                  xmlns:ovirt-vm="http://ovirt.org/vm/1.0">
          <ovirt-vm:vm xmlns:ovirt-vm="http://ovirt.org/vm/1.0">
            <ovirt-vm:device mac_address='66:55:44:33:22:11'>
              <ovirt-vm:network>test</ovirt-vm:network>
              <ovirt-vm:portMirroring>
                <ovirt-vm:network>network1</ovirt-vm:network>
                <ovirt-vm:network>network2</ovirt-vm:network>
              </ovirt-vm:portMirroring>
            </ovirt-vm:device>
          </ovirt-vm:vm>
        </metadata>
      </hotplug>

    :param xml: XML specifying the device as described above.
    :type xml: basestring
    :returns: Triplet (device_class, device_element, device_meta) where
      `device_class` is the class to be used to create the device instance;
      `device_element` and `device_meta` are objects to be passed as arguments
      to device_class `from_xml_tree` method.
    """
    dom = xmlutils.fromstring(xml)
    devices = vmxml.find_first(dom, 'devices')
    dev_elem = next(vmxml.children(devices))
    _dev_type, dev_class = identify_from_xml_elem(dev_elem)
    meta = vmxml.find_first(dom, 'metadata', None)
    if meta is None:
        md_desc = metadata.Descriptor()
    else:
        md_desc = metadata.Descriptor.from_xml(xmlutils.tostring(meta))
    dev_meta = _get_metadata_from_elem_xml(vm.id, md_desc, dev_class, dev_elem)
    return dev_class, dev_elem, dev_meta
Esempio n. 27
0
    def _check_leases(self, xml_str, vol_infos):
        xml_dom = xmlutils.fromstring(xml_str)
        lease_elems = xml_dom.findall('./devices/lease')
        self.assertEqual(len(lease_elems), len(vol_infos))

        for lease_elem, vol_info in zip(lease_elems, vol_infos):
            target = vmxml.find_first(lease_elem, 'target')
            self.assertEqual(
                target.attrib['path'], str(vol_info['leasePath']))
            self.assertEqual(
                target.attrib['offset'], str(vol_info['leaseOffset']))
Esempio n. 28
0
 def test_replace_values(self):
     xml_str = read_data('sysinfo_snippet_template.xml')
     dom = xmlutils.fromstring(xml_str)
     with MonkeyPatchScope([
         (osinfo, 'version', self._version),
         (constants, 'SMBIOS_OSNAME', 'test-product'),
     ]):
         domxml_preprocess.replace_placeholders(
             dom, cpuarch.X86_64, serial='test-serial')
     self.assertXMLEqual(
         xmlutils.tostring(dom, pretty=True),
         read_data('sysinfo_snippet_filled.xml')
     )
Esempio n. 29
0
    def _assertDeviceCorrect(self, dev_class, dev_xml, dev_conf, dev_meta):
        dev = dev_class.from_xml_tree(
            self.log,
            xmlutils.fromstring(dev_xml),
            dev_meta
        )
        self.assertEqual(dev.vmid, 'testvm')
        self.assertEqual(dev.config(), dev_conf)

        self.assertEqual(
            dev.config(),
            dev_class(self.log, **dev_conf).config()
        )
Esempio n. 30
0
 def test_skip_without_placeholders(self):
     # any domain without placeholders is fine, picked random one
     xml_str = read_data('vm_hosted_engine_42.xml')
     dom = xmlutils.fromstring(xml_str)
     with MonkeyPatchScope([
         (osinfo, 'version', self._version),
     ]):
         domxml_preprocess.replace_placeholders(
             dom, cpuarch.X86_64, serial='test-serial')
     self.assertXMLEqual(
         xmlutils.tostring(dom, pretty=True),
         xml_str
     )
Esempio n. 31
0
    def test_replace_device_xml_with_hook_xml_no_custom(self):
        """
        Don't replace devices if they lack custom properties
        """
        dom = xmlutils.fromstring(read_data('domain_disk_file.xml'))

        with MonkeyPatchScope([
            (hooks, 'before_device_create', self._hook),
        ]):
            domxml_preprocess.replace_device_xml_with_hooks_xml(
                dom, 'test', {})

        self.assertEqual(self._hook_params, [])
Esempio n. 32
0
    def test_drive(self):
        dev_xml = u'''<disk snapshot="no" type="block" device="disk">
            <address bus="0" controller="0" unit="0" type="drive" target="0"/>
            <source dev="/rhev/data-center/mnt/blockSD/a/images/b/c"/>
            <target dev="sda" bus="scsi"/>
            <serial>d591482b-eb24-47bd-be07-082c115d11f4</serial>
            <boot order="1"/>
            <driver name="qemu" io="native" type="qcow2"
              error_policy="stop" cache="none"/>
            <alias name="ua-58ca6050-0134-00d6-0053-000000000388"/>
        </disk>'''
        dev_conf = {
            'address': {
                'bus': '0',
                'controller': '0',
                'target': '0',
                'type': 'drive',
                'unit': '0'
            },
            'alias': 'ua-58ca6050-0134-00d6-0053-000000000388',
            'bootOrder': '1',
            'cache': 'none',
            'device': 'disk',
            'discard': 'False',
            'diskType': 'block',
            'format': 'cow',
            'iface': 'scsi',
            'index': '0',
            'name': 'sda',
            'path': '/rhev/data-center/mnt/blockSD/a/images/b/c',
            'propagateErrors': 'off',
            'serial': 'd591482b-eb24-47bd-be07-082c115d11f4',
            'specParams': {},
            'type': 'disk',
            'volumeChain': [],
            'volumeInfo': {}
        }
        dev_meta = {}
        dev = vmdevices.storage.Drive(
            self.log,
            **vmdevices.storagexml.parse(
                xmlutils.fromstring(dev_xml),
                dev_meta
            )
        )
        self.assertEqual(dev.config(), dev_conf)

        self.assertEqual(
            dev.config(),
            vmdevices.storage.Drive(self.log, **dev_conf).config()
        )
Esempio n. 33
0
    def test_interface_update_disappear_queues(self):
        interface_xml = """<interface type="bridge">
          <model type="virtio" />
          <link state="up" />
          <source bridge="ovirtmgmt" />
          <driver name="vhost" queues="1" />
          <alias name="ua-604c7957-9aaf-4e86-bcaa-87e12571449b" />
          <mac address="00:1a:4a:16:01:50" />
          <mtu size="1500" />
          <filterref filter="vdsm-no-mac-spoofing" />
          <bandwidth />
        </interface>
        """
        updated_xml = """<?xml version="1.0" encoding="utf-8"?>
        <domain type="kvm"
          xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">
          <devices>
            <interface type='bridge'>
              <mac address='00:1a:4a:16:01:50'/>
              <source bridge='ovirtmgmt'/>
              <target dev='vnet0'/>
              <model type='virtio'/>
              <driver name='vhost'/>
              <filterref filter='vdsm-no-mac-spoofing'/>
              <link state='up'/>
              <mtu size='1500'/>
              <alias name='ua-604c7957-9aaf-4e86-bcaa-87e12571449b'/>
              <address type='pci' domain='0x0000'
                       bus='0x00' slot='0x03' function='0x0'/>
            </interface>
          </devices>
        </domain>"""
        meta = {'vmid': 'VMID'}  # noone cares about the actual ID
        with fake.VM() as testvm:
            nic = vmdevices.network.Interface.from_xml_tree(
                self.log, xmlutils.fromstring(interface_xml), meta=meta
            )
            saved_driver = nic.driver.copy()
            testvm._devices[hwclass.NIC].append(nic)
            testvm._domain = DomainDescriptor(updated_xml)

            vmdevices.network.Interface.update_device_info(
                testvm, testvm._devices[hwclass.NIC]
            )

            self.assertEqual(nic.driver, saved_driver)
Esempio n. 34
0
    def setUp(self):
        self.vm = FakeVM(self.log)
        self.cif = fake.ClientIF()
        self.xml_str = read_data('hostedengine_lease.xml')
        self.dom = xmlutils.fromstring(self.xml_str)
        self.disk_devs = domxml_preprocess._make_disk_devices(
            self.xml_str, self.log)

        self.driveVolInfo = {
            'leasePath': '/fake/drive/lease/path',
            'leaseOffset': 42,
        }
        self.vmVolInfo = {
            # from XML
            'leasePath': 'LEASE-PATH:'
                         '9eaa286e-37d6-429e-a46b-63bec1dd4868:'
                         '4f0a775f-ed16-4832-ab9f-f0427f33ab92',
            'leaseOffset': 'LEASE-OFFSET:'
                           '9eaa286e-37d6-429e-a46b-63bec1dd4868:'
                           '4f0a775f-ed16-4832-ab9f-f0427f33ab92',
        }
Esempio n. 35
0
def is_vnc_secure(vmParams, log):
    """
    This function checks if VNC is not mis-configured to offer insecure,
    free-for-all access. The engine can send the XML with empty password,
    but it's acceptable IFF qemu uses SASL as the authentication mechanism.

    is_vnc_secure returns False in such case (i.e. no password and no SASL),
    otherwise VNC connection is considered secure.
    """
    parsed = xmlutils.fromstring(vmParams['xml'])
    graphics = vmxml.find_all(parsed, 'graphics')
    for g in graphics:
        if vmxml.attr(g, 'type') == 'vnc':
            # When the XML does not contain 'passwordValidTo' attribute
            # this is a way to say 'don't use password auth'.
            no_password_auth = vmxml.attr(g, 'passwdValidTo') == ''
            if no_password_auth and not utils.sasl_enabled():
                log.warning("VNC not secure: passwdValidTo empty or missing"
                            " and SASL not configured")
                return False
    return True
Esempio n. 36
0
File: lookup.py Progetto: nirs/vdsm
def device_from_xml_alias(devices, device_xml):
    dev = xmlutils.fromstring(device_xml)
    alias = core.find_device_alias(dev)
    return device_by_alias(devices, alias)
Esempio n. 37
0
 def _parse_xml(self, xml_str):
     self._parse_tree(xmlutils.fromstring(xml_str))
Esempio n. 38
0
 def detachDevice(self, device_xml):
     if self.vm is not None:
         dev = xmlutils.fromstring(device_xml)
         alias = core.find_device_alias(dev)
         self.vm.onDeviceRemoved(alias)