[test-API][PATCH] Add 2 methods to generate cdrom & floppy XML for test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



add the following 2 functions to utils/Python/xmlbuilder.py
* build_cdrom()
* build_floppy()
---
 utils/Python/xmlbuilder.py   |   47 +++++++++++++++++++++++++++++++++++++++++-
 utils/Python/xmlgenerator.py |   15 +++++++------
 2 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/utils/Python/xmlbuilder.py b/utils/Python/xmlbuilder.py
index 78230da..5a0f8c8 100644
--- a/utils/Python/xmlbuilder.py
+++ b/utils/Python/xmlbuilder.py
@@ -112,6 +112,33 @@ class XmlBuilder:
             self.write_toxml(disk)
         return disk.toxml()
 
+    def build_cdrom(self, params):
+        if params.get('hdmodel', None) == None:
+            params['hdmodel'] = 'ide'
+
+        if params['hdmodel'] == 'ide':
+            target_dev = 'hdc'
+        elif params['hdmodel'] == 'scsi':
+            target_dev = 'sdc'
+        else:
+            print 'Wrong cdrom model.'
+
+        cdrom = xmlgenerator.disk_xml(params, True)
+        if params['guesttype'] == 'xenpv':
+            cdrom.getElementsByTagName("target")[0].setAttribute("dev", "xvdc")
+        else:
+            cdrom.getElementsByTagName("target")[0].setAttribute("dev",
+                                                                target_dev)
+        if __DEBUG__:
+            self.write_toxml(cdrom)
+        return cdrom.toxml()
+
+    def build_floppy(self, params):
+        floppy = xmlgenerator.floppy_xml(params)
+        if __DEBUG__:
+            self.write_toxml(floppy)
+        return floppy.toxml()
+
     def build_interface(self, params):
         interface = xmlgenerator.interface_xml(params)
         if __DEBUG__:
@@ -177,11 +204,29 @@ if __name__ == "__main__":
     print '=' * 30, 'disk xml', '=' * 30
     params['guesttype'] = 'kvm'
     params['guestname'] = 'foo'
-    params['imagepath'] = '/images'
     params['hdmodel'] = 'virtio'
 
     diskxml = xmlobj.build_disk(params)
 
+    #---------------------
+    # get cdrom xml string
+    #---------------------
+    print '=' * 30, 'cdrom xml', '=' * 30
+    params['guesttype'] = 'kvm'
+    params['guestname'] = 'foo'
+    params['hdmodel'] = 'ide'
+    params['bootcd'] = '/tmp/cdrom.img'
+
+    cdromxml = xmlobj.build_cdrom(params)
+
+    #---------------------
+    # get floppy xml string
+    #---------------------
+    print '=' * 30, 'floppy xml', '=' * 30
+    params['floppysource'] = '/tmp/floppy.img'
+
+    floppyxml = xmlobj.build_floppy(params)
+
     #--------------------------
     # get interface xml string
     #--------------------------
diff --git a/utils/Python/xmlgenerator.py b/utils/Python/xmlgenerator.py
index c59ca9e..d57dd33 100644
--- a/utils/Python/xmlgenerator.py
+++ b/utils/Python/xmlgenerator.py
@@ -308,7 +308,7 @@ def disk_xml(params, cdrom = False):
                                       params['guestname']
         elif hypertype == 'xen':
             params['imagepath'] = '/var/lib/xen/images'
-            params['fullimagepath'] = '/var/lib/xen/images' + '/' + \
+            params['fullimagepath'] = params['imagepath'] + '/' + \
                                       params['guestname']
         else:
             print 'DO NOT supported hypervisor.'
@@ -367,14 +367,15 @@ def disk_xml(params, cdrom = False):
 def floppy_xml(params):
     # Disk element
     floppy = xml.dom.minidom.Document()
-    disk_element = floppy.createElement('disk')
-    disk_element.setAttribute('device', 'floppy')
-    floppy.appendChild(disk_element)
+    floppy_element = floppy.createElement('disk')
+    floppy_element.setAttribute('type', 'file')
+    floppy_element.setAttribute('device', 'floppy')
+    floppy.appendChild(floppy_element)
 
     # Source element
     source_element = floppy.createElement('source')
     source_element.setAttribute('file', params['floppysource'])
-    disk_element.appendChild(source_element)
+    floppy_element.appendChild(source_element)
 
     # Target element
     target_element = floppy.createElement('target')
@@ -384,11 +385,11 @@ def floppy_xml(params):
         target_element.setAttribute('dev', 'fda')
 
     target_element.setAttribute('bus', 'fdc')
-    disk_element.appendChild(target_element)
+    floppy_element.appendChild(target_element)
 
     # Readonly
     readonly = floppy.createElement('readonly')
-    disk_element.appendChild(readonly)
+    floppy_element.appendChild(readonly)
 
     return floppy
 
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]