[Libvirt-cim] [PATCH] [TEST]4# bundles of patch for LXC support

yunguol at cn.ibm.com yunguol at cn.ibm.com
Fri May 23 10:14:35 UTC 2008


# HG changeset patch
# User Guolian Yun <yunguol at cn.ibm.com>
# Date 1211537668 -28800
# Node ID 0a4ecb2ab4c495e8f52dfbaf2a0ce6a22d54a8b7
# Parent  2039130968f0c4e19234dcfbba9940eddbcd7325
[TEST]4# bundles of patch for LXC support

Move the init_path file to be part of undefine and destroy step

Signed-off-by: Guolian Yun <yunguol at cn.ibm.com>

diff -r 2039130968f0 -r 0a4ecb2ab4c4 lib/CimTest/Globals.py
--- a/lib/CimTest/Globals.py	Wed May 21 06:37:47 2008 -0700
+++ b/lib/CimTest/Globals.py	Fri May 23 18:14:28 2008 +0800
@@ -66,8 +66,8 @@
 parser.add_option("-i", "--ip", dest="ip", default="localhost", 
                   help="IP address of machine to test, default: localhost")
 parser.add_option("-v", "--virt", dest="virt", type="choice",
-                  choices=platform_sup, default="Xen",
-                  help="Virt type, select from: 'Xen' & 'KVM' & 'XenFV', default: Xen")
+                  choices=['Xen', 'KVM', 'XenFV', 'LXC'], default="Xen",
+                  help="Virt type, select from: 'Xen' & 'KVM' & 'XenFV' & 'LXC', default: Xen")
 parser.add_option("-d", "--debug-output", action="store_true", dest="debug",
                   help="Duplicate the output to stderr")
 
diff -r 2039130968f0 -r 0a4ecb2ab4c4 lib/VirtLib/utils.py
--- a/lib/VirtLib/utils.py	Wed May 21 06:37:47 2008 -0700
+++ b/lib/VirtLib/utils.py	Fri May 23 18:14:28 2008 +0800
@@ -161,5 +161,7 @@
         return "xen:///"
     if virt == "KVM":
         return "qemu:///system"
+    if virt == "LXC":
+        return "lxc:///system"
     return ""
 
diff -r 2039130968f0 -r 0a4ecb2ab4c4 suites/libvirt-cim/cimtest/ComputerSystem/03_defineVS.py
--- a/suites/libvirt-cim/cimtest/ComputerSystem/03_defineVS.py	Wed May 21 06:37:47 2008 -0700
+++ b/suites/libvirt-cim/cimtest/ComputerSystem/03_defineVS.py	Fri May 23 18:14:28 2008 +0800
@@ -35,7 +35,7 @@
 from CimTest.Globals import do_main
 from CimTest.ReturnCodes import PASS, FAIL
 
-sup_types = ['Xen', 'KVM', 'XenFV']
+sup_types = ['Xen', 'KVM', 'XenFV', 'LXC']
 test_dom = "domU1"
 
 @do_main(sup_types)
diff -r 2039130968f0 -r 0a4ecb2ab4c4 suites/libvirt-cim/lib/XenKvmLib/classes.py
--- a/suites/libvirt-cim/lib/XenKvmLib/classes.py	Wed May 21 06:37:47 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/classes.py	Fri May 23 18:14:28 2008 +0800
@@ -19,7 +19,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 #
 
-virt_types = ['Xen', 'KVM', 'XenFV']
+virt_types = ['Xen', 'KVM', 'XenFV', 'LXC']
 
 def get_typed_class(virt, basename):
     if virt not in virt_types:
diff -r 2039130968f0 -r 0a4ecb2ab4c4 suites/libvirt-cim/lib/XenKvmLib/computersystem.py
--- a/suites/libvirt-cim/lib/XenKvmLib/computersystem.py	Wed May 21 06:37:47 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/computersystem.py	Fri May 23 18:14:28 2008 +0800
@@ -69,6 +69,9 @@
 class KVM_ComputerSystem(CIM_System):
     pass
 
+class LXC_ComputerSystem(CIM_System):
+    pass
+
 def get_cs_class(virt):
     if virt in virt_types:
         return eval(get_typed_class(virt, 'ComputerSystem'))
diff -r 2039130968f0 -r 0a4ecb2ab4c4 suites/libvirt-cim/lib/XenKvmLib/const.py
--- a/suites/libvirt-cim/lib/XenKvmLib/const.py	Wed May 21 06:37:47 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/const.py	Fri May 23 18:14:28 2008 +0800
@@ -81,3 +81,7 @@
 XenFV_default_disk_dev = 'hda'
 XenFV_default_mac = '00:16:3e:5d:c7:9e'
 XenFV_default_net_type = 'bridge'
+
+#vxml.LXCXML
+LXC_init_path = os.path.join(_image_dir, 'cimtest_lxc_init')
+LXC_default_tty = '/dev/ptmx'
diff -r 2039130968f0 -r 0a4ecb2ab4c4 suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Wed May 21 06:37:47 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Fri May 23 18:14:28 2008 +0800
@@ -141,6 +141,8 @@
             self.vuri = 'xen:///'
         elif vir_type == 'kvm':
             self.vuri = 'qemu:///system'
+        elif vir_type == 'lxc':
+            self.vuri = 'lxc:///system'
 
     def run(self, ip, vcmd, param):
         file_arg_cmds = ['define', 'create', 'net-create', 'pool-create', 'pool-destroy']
@@ -280,7 +282,7 @@
         raise NotImplementedError('virtual method, implement your own')
     
     def issubinstance(self):
-        return isinstance(self, (XenXML, KVMXML, XenFVXML))
+        return isinstance(self, (XenXML, KVMXML, XenFVXML, LXCXML))
 
     def set_memory(self, mem):
         self.set_cdata('/domain/memory', mem * 1024)
@@ -308,6 +310,8 @@
         return self.run(ip, 'define', self.xml_string)
 
     def undefine(self, ip):
+        if os.path.exists(const.LXC_init_path):
+            os.remove(const.LXC_init_path)
         return self.run(ip, 'undefine', self.dname)
 
     def start(self, ip):
@@ -317,6 +321,8 @@
         return self.run(ip, 'stop', self.dname)        
 
     def destroy(self, ip):
+        if os.path.exists(const.LXC_init_path):
+            os.remove(const.LXC_init_path)
         return self.run(ip, 'destroy', self.dname)
 
     def create(self, ip):
@@ -627,6 +633,37 @@
     def set_vbridge(self, ip):
         return self._set_vbridge(ip, 'XenFV')
 
+class LXCXML(VirtXML):
+
+    def __init__(self, test_dom=const.default_domname,
+                       mem=const.default_memory,
+                       vcpus=const.default_vcpus,
+                       tty=const.LXC_default_tty):
+        VirtXML.__init__(self, 'lxc', test_dom, set_uuid(), mem, vcpus)
+        self._os(const.LXC_init_path)
+        self._devices(const.LXC_default_tty)
+        self.create_lxc_file(CIM_IP, const.LXC_init_path)
+
+    def _os(self, os_init):
+        os = self.get_node('/domain/os')
+        self.add_sub_node(os, 'init', os_init)
+
+    def _devices(self, tty):
+        devices = self.get_node('/domain/devices')
+
+        interface = self.add_sub_node(devices, 'console', tty)
+
+    def create_lxc_file(self, ip, lxc_file):
+        try:
+            f = open(lxc_file, 'w')
+            f.write('%s' % 'exec /bin/sh')
+            cmd = 'chmod +x %s' % lxc_file
+            s, o = utils.run_remote(ip, cmd)
+            f.close()
+        except Exception:
+            logger.error("Creation of LXC file Failed")
+            return False
+
 
 def get_class(virt):
     if virt in virt_types:
diff -r 2039130968f0 -r 0a4ecb2ab4c4 suites/libvirt-cim/main.py
--- a/suites/libvirt-cim/main.py	Wed May 21 06:37:47 2008 -0700
+++ b/suites/libvirt-cim/main.py	Fri May 23 18:14:28 2008 +0800
@@ -50,8 +50,8 @@
                   action="store_true", dest="clean",
                   help="Will remove existing log files before test run")
 parser.add_option("-v", "--virt", dest="virt", type="choice",
-                  choices=platform_sup, default="Xen",
-                  help="Virt type, select from 'Xen' & 'KVM' & 'XenFV'(default: Xen). ")
+                  choices=['Xen', 'KVM', 'XenFV', 'LXC'], default="Xen",
+                  help="Virt type, select from 'Xen' & 'KVM' & 'XenFV' & 'LXC'(default: Xen). ")
 parser.add_option("-d", "--debug-output", action="store_true", dest="debug",
                   help="Duplicate the output to stderr")
 




More information about the Libvirt-cim mailing list