# HG changeset patch
# User Guolian Yun <yunguol(a)cn.ibm.com>
# Date 1211469390 -28800
# Node ID 2845b58769cbe46f646c6f173c30945187f04778
# Parent b2b2bb6cc8d87ba0eeddcf3d361d3085104d3492
[TEST] 3# big patch for LXC support
Signed-off-by: Guolian Yun <yunguol(a)cn.ibm.com>
diff -r b2b2bb6cc8d8 -r 2845b58769cb lib/CimTest/Globals.py
--- a/lib/CimTest/Globals.py Mon May 19 10:43:33 2008 -0700
+++ b/lib/CimTest/Globals.py Thu May 22 23:16:30 2008 +0800
@@ -49,7 +49,7 @@
CIM_IP = os.getenv("CIM_IP")
CIM_PORT = "5988"
NM = "TEST LOG"
-platform_sup = ["Xen", "KVM", "XenFV"]
+platform_sup = ["Xen", "KVM", "XenFV", "LXC"]
logging.basicConfig(filename='/dev/null')
logger = logging.getLogger(NM)
logging.PRINT = logging.DEBUG + 50
@@ -67,7 +67,7 @@
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")
+ 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 b2b2bb6cc8d8 -r 2845b58769cb lib/VirtLib/utils.py
--- a/lib/VirtLib/utils.py Mon May 19 10:43:33 2008 -0700
+++ b/lib/VirtLib/utils.py Thu May 22 23:16:30 2008 +0800
@@ -161,5 +161,7 @@
return "xen:///"
if virt == "KVM":
return "qemu:///system"
+ if virt == "LXC":
+ return "lxc:///system"
return ""
diff -r b2b2bb6cc8d8 -r 2845b58769cb
suites/libvirt-cim/cimtest/ComputerSystem/03_defineVS.py
--- a/suites/libvirt-cim/cimtest/ComputerSystem/03_defineVS.py Mon May 19 10:43:33 2008
-0700
+++ b/suites/libvirt-cim/cimtest/ComputerSystem/03_defineVS.py Thu May 22 23:16:30 2008
+0800
@@ -27,15 +27,17 @@
# 26-Sep-2007
import sys
+import os
from XenKvmLib import computersystem
from XenKvmLib import vxml
from XenKvmLib.classes import get_typed_class
+from XenKvmLib.const import LXC_init_path
from VirtLib import utils
from CimTest import Globals
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)
@@ -76,6 +78,7 @@
Globals.logger.error("Error: property values are not set for VS %s" %
test_dom)
cxml.undefine(options.ip)
+ os.remove(LXC_init_path)
return status
if __name__ == "__main__":
diff -r b2b2bb6cc8d8 -r 2845b58769cb suites/libvirt-cim/lib/XenKvmLib/classes.py
--- a/suites/libvirt-cim/lib/XenKvmLib/classes.py Mon May 19 10:43:33 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/classes.py Thu May 22 23:16:30 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 b2b2bb6cc8d8 -r 2845b58769cb suites/libvirt-cim/lib/XenKvmLib/computersystem.py
--- a/suites/libvirt-cim/lib/XenKvmLib/computersystem.py Mon May 19 10:43:33 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/computersystem.py Thu May 22 23:16:30 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 b2b2bb6cc8d8 -r 2845b58769cb suites/libvirt-cim/lib/XenKvmLib/const.py
--- a/suites/libvirt-cim/lib/XenKvmLib/const.py Mon May 19 10:43:33 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/const.py Thu May 22 23:16:30 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 b2b2bb6cc8d8 -r 2845b58769cb suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Mon May 19 10:43:33 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Thu May 22 23:16:30 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)
@@ -627,6 +629,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 b2b2bb6cc8d8 -r 2845b58769cb suites/libvirt-cim/main.py
--- a/suites/libvirt-cim/main.py Mon May 19 10:43:33 2008 -0700
+++ b/suites/libvirt-cim/main.py Thu May 22 23:16:30 2008 +0800
@@ -51,7 +51,7 @@
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). ")
+ 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")