[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 5/10][TOOLS][XM-TEST] Refactor code to encapsulate architecture decisions in one place
Refactor code to encapsulate architecture decisions in one place. Also includes some whitespace fixes. Signed-off-by: Tony Breeds <tony@xxxxxxxxxxxxxxxxxx> --- tools/xm-test/lib/XmTestLib/XenDomain.py | 73 +++------------ tools/xm-test/lib/XmTestLib/arch.py | 102 +++++++++++++++++++++ tools/xm-test/lib/XmTestReport/OSReport.py | 10 -- tools/xm-test/lib/XmTestReport/arch.py | 42 ++++++++ 4 files changed, 161 insertions(+), 66 deletions(-) --- a/tools/xm-test/lib/XmTestLib/XenDomain.py Thu Oct 19 11:57:29 2006 +1000 +++ b/tools/xm-test/lib/XmTestLib/XenDomain.py Thu Oct 19 11:58:17 2006 +1000 @@ -20,33 +20,22 @@ import sys import commands -import os import re import time from Xm import * +from arch import * from Test import * from config import * from Console import * from XenDevice import * -BLOCK_ROOT_DEV = "hda" - -def getDeviceModel(): - """Get the path to the device model based on - the architecture reported in uname""" - arch = os.uname()[4] - if re.search("64", arch): - return "/usr/lib64/xen/bin/qemu-dm" - else: - return "/usr/lib/xen/bin/qemu-dm" def getDefaultKernel(): - """Get the path to the default DomU kernel""" - dom0Ver = commands.getoutput("uname -r"); - domUVer = dom0Ver.replace("xen0", "xenU"); - - return "/boot/vmlinuz-" + domUVer; + return arch.getDefaultKernel() + +def getRdPath(): + return arch.getRdPath() def getUniqueName(): """Get a uniqueish name for use in a domain""" @@ -55,43 +44,8 @@ def getUniqueName(): test_name = re.sub("\.test", "", test_name) test_name = re.sub("[\/\.]", "", test_name) name = "%s-%i" % (test_name, unixtime) - + return name - -def getRdPath(): - rdpath = os.environ.get("RD_PATH") - if not rdpath: - rdpath = "../../ramdisk" - rdpath = os.path.abspath(rdpath) - - return rdpath - -ParavirtDefaults = {"memory" : 64, - "vcpus" : 1, - "kernel" : getDefaultKernel(), - "root" : "/dev/ram0", - "ramdisk" : getRdPath() + "/initrd.img" - } -HVMDefaults = {"memory" : 64, - "vcpus" : 1, - "acpi" : 0, - "apic" : 0, - "disk" : ["file:%s/disk.img,ioemu:%s,w!" % - (getRdPath(), BLOCK_ROOT_DEV)], - "kernel" : "/usr/lib/xen/boot/hvmloader", - "builder" : "hvm", - "sdl" : 0, - "vnc" : 0, - "vncviewer" : 0, - "nographic" : 1, - "serial" : "pty", - "device_model" : getDeviceModel() - } - -if ENABLE_HVM_SUPPORT: - configDefaults = HVMDefaults -else: - configDefaults = ParavirtDefaults class XenConfig: """An object to help create a xen-compliant config file""" @@ -140,7 +94,8 @@ class XenConfig: def setOpt(self, name, value): """Set an option in the config""" - if name in self.opts.keys() and isinstance(self.opts[name], list) and not isinstance(value, list): + if name in self.opts.keys() and isinstance(self.opts[name] , + list) and not isinstance(value, list): self.opts[name] = [value] else: self.opts[name] = value @@ -177,7 +132,7 @@ class DomainError(Exception): self.errorcode = int(errorcode) except Exception, e: self.errorcode = -1 - + def __str__(self): return str(self.msg) @@ -199,7 +154,7 @@ class XenDomain: self.devices = {} self.netEnv = "bridge" - # Set domain type, either PV for ParaVirt domU or HVM for + # Set domain type, either PV for ParaVirt domU or HVM for # FullVirt domain if ENABLE_HVM_SUPPORT: self.type = "HVM" @@ -332,7 +287,8 @@ class XenDomain: class XmTestDomain(XenDomain): - def __init__(self, name=None, extraConfig=None, baseConfig=configDefaults): + def __init__(self, name=None, extraConfig=None, + baseConfig=arch.configDefaults): """Create a new xm-test domain @param name: The requested domain name @param extraConfig: Additional configuration options @@ -351,11 +307,12 @@ class XmTestDomain(XenDomain): XenDomain.__init__(self, config.getOpt("name"), config=config) def minSafeMem(self): - return 32 + return arch.minSafeMem class XmTestNetDomain(XmTestDomain): - def __init__(self, name=None, extraConfig=None, baseConfig=configDefaults): + def __init__(self, name=None, extraConfig=None, + baseConfig=arch.configDefaults): """Create a new xm-test domain with one network device @param name: The requested domain name @param extraConfig: Additional configuration options diff -r 8c17d10f39c9 -r 413d8625debe tools/xm-test/lib/XmTestReport/OSReport.py --- a/tools/xm-test/lib/XmTestReport/OSReport.py Thu Oct 19 11:57:29 2006 +1000 +++ b/tools/xm-test/lib/XmTestReport/OSReport.py Thu Oct 19 11:58:17 2006 +1000 @@ -29,6 +29,7 @@ import os import os import commands import sys +import arch class Machine: @@ -89,8 +90,6 @@ class Machine: self.values = {} self.errors = 0 - cpuValues = {"model_name" : "Unknown", - "flags" : "Unknown"} xenValues = {"nr_cpus" : "Unknown", "nr_nodes" : "Unknown", "sockets_per_node" : "Unknown", @@ -100,12 +99,7 @@ class Machine: "total_memory" : "Unknown"} xen = self.__getXenInfo(xenValues) - cpu = self.__getCpuInfo(cpuValues) - - if cpu["model_name"] == "Unknown": - cpuValues={"arch" : "Unknown", - "features": "Unknown"} - cpu=self.__getCpuInfo(cpuValues) + cpu = self.__getCpuInfo(arch.cpuValues) for k in xen.keys(): self.values[k] = xen[k] diff -r 8c17d10f39c9 -r 413d8625debe tools/xm-test/lib/XmTestLib/arch.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/xm-test/lib/XmTestLib/arch.py Thu Oct 19 11:58:17 2006 +1000 @@ -0,0 +1,102 @@ +#!/usr/bin/python +""" + arch.py - Encapsulate all logic regarding what type of hardware xen + is running on to make adding new platforms easier. + + Copyright (C) 2006 Tony Breeds IBM Corporation + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; under version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +""" + +import os +import re +import config +import commands + +BLOCK_ROOT_DEV = "hda" + +# This isn't truly platform related but it makes the code tidier +def getRdPath(): + """Locate the full path to ramdisks needed by domUs""" + rdpath = os.environ.get("RD_PATH") + if not rdpath: + rdpath = "../../ramdisk" + rdpath = os.path.abspath(rdpath) + + return rdpath + +# Begin: Intel ia32 and ia64 as well as AMD 32-bit and 64-bit processors +def ia_minSafeMem(): + return 32 + +def ia_getDeviceModel(): + """Get the path to the device model based on + the architecture reported in uname""" + architecture = os.uname()[4] + if re.search("64", architecture): + return "/usr/lib64/xen/bin/qemu-dm" + else: + return "/usr/lib/xen/bin/qemu-dm" + +def ia_getDefaultKernel(): + """Get the path to the default DomU kernel""" + dom0Ver = commands.getoutput("uname -r"); + domUVer = dom0Ver.replace("xen0", "xenU"); + + return "/boot/vmlinuz-" + domUVer; + +ia_ParavirtDefaults = {"memory" : 64, + "vcpus" : 1, + "kernel" : ia_getDefaultKernel(), + "root" : "/dev/ram0", + "ramdisk" : getRdPath() + "/initrd.img", +} +ia_HVMDefaults = {"memory" : 64, + "vcpus" : 1, + "acpi" : 0, + "apic" : 0, + "disk" : ["file:%s/disk.img,ioemu:%s,w!" % + (getRdPath(), BLOCK_ROOT_DEV)], + "kernel" : "/usr/lib/xen/boot/hvmloader", + "builder" : "hvm", + "sdl" : 0, + "vnc" : 0, + "vncviewer" : 0, + "nographic" : 1, + "serial" : "pty", + "device_model" : ia_getDeviceModel(), +} +# End : Intel ia32 and ia64 as well as AMD 32-bit and 64-bit processors + +"""Convert from uname specification to a more general platform.""" +_uname_to_arch_map = { + "i386" : "x86", + "i486" : "x86", + "i586" : "x86", + "i686" : "x86", + "ia64" : "ia64", +} + +# Lookup current platform. +_arch = _uname_to_arch_map.get(os.uname()[4], "Unknown") +if _arch == "x86" or _arch == "ia64": + minSafeMem = ia_minSafeMem + getDefaultKernel = ia_getDefaultKernel + if config.ENABLE_HVM_SUPPORT: + configDefaults = ia_HVMDefaults + else: + configDefaults = ia_ParavirtDefaults +else: + raise ValueError, "Unknown architecture!" diff -r 8c17d10f39c9 -r 413d8625debe tools/xm-test/lib/XmTestReport/arch.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/xm-test/lib/XmTestReport/arch.py Thu Oct 19 11:58:17 2006 +1000 @@ -0,0 +1,42 @@ +#!/usr/bin/python +""" + arch.py - Encapsulate all logic regarding what type of hardware xen + is running on to make adding new platforms easier. + + Copyright (C) 2006 Tony Breeds IBM Corporation + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; under version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +""" + +import os + +"""Convert from uname specification to a more general platform.""" +_uname_to_arch_map = { + "i386" : "x86", + "i486" : "x86", + "i586" : "x86", + "i686" : "x86", + "ia64" : "ia64", +} + +_arch = _uname_to_arch_map.get(os.uname()[4], "Unknown") +if _arch == "x86": + cpuValues = {"model_name" : "Unknown", + "flags" : "Unknown"} +elif _arch == "ia64": + cpuValues = {"arch" : "Unknown", + "features" : "Unknown"} +else: + raise ValueError, "Unknown architecture!" _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |