Ejemplo 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='' "))
Ejemplo n.º 2
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),
        )
Ejemplo n.º 3
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)
Ejemplo n.º 4
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),
        )
Ejemplo n.º 5
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
     )
Ejemplo n.º 6
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='' ")
     )
Ejemplo n.º 7
0
 def test_update_disks_xml(self):
     """
     Replace one disk, moving from file to block; no changes to CDROM
     """
     dom, disk_devs = self._make_env()
     domxml_preprocess.update_disks_xml_from_objs(FakeVM(self.log), dom,
                                                  disk_devs)
     self.assertXMLEqual(extract_device_snippet('disk', dom=dom),
                         read_data('disk_updated_snippet.xml'))
Ejemplo n.º 8
0
 def test_update_disks_xml(self):
     """
     Replace one disk, moving from file to block; no changes to CDROM
     """
     dom, disk_devs = self._make_env()
     domxml_preprocess.update_disks_xml_from_objs(
         FakeVM(self.log), dom, disk_devs)
     self.assertXMLEqual(
         extract_device_snippet(
             'disk',
             dom=dom),
         read_data('disk_updated_snippet.xml')
     )