aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xm-test/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tools/xm-test/lib')
-rwxr-xr-xtools/xm-test/lib/XmTestLib/Console.py5
-rw-r--r--tools/xm-test/lib/XmTestLib/XenDomain.py81
-rw-r--r--tools/xm-test/lib/XmTestLib/acm.py91
-rw-r--r--tools/xm-test/lib/XmTestLib/arch.py148
-rw-r--r--tools/xm-test/lib/XmTestLib/block_utils.py2
-rw-r--r--tools/xm-test/lib/XmTestReport/OSReport.py10
-rw-r--r--tools/xm-test/lib/XmTestReport/arch.py52
7 files changed, 323 insertions, 66 deletions
diff --git a/tools/xm-test/lib/XmTestLib/Console.py b/tools/xm-test/lib/XmTestLib/Console.py
index 5507d3b1ec..b92f32bb3b 100755
--- a/tools/xm-test/lib/XmTestLib/Console.py
+++ b/tools/xm-test/lib/XmTestLib/Console.py
@@ -31,6 +31,7 @@ import termios
import fcntl
import select
+import arch
from Test import *
TIMEDOUT = 1
@@ -120,6 +121,7 @@ class XmConsole:
def __getprompt(self, fd):
timeout = 0
bytes = 0
+ buffer = ""
while timeout < 180:
# eat anything while total bytes less than limit else raise RUNAWAY
while (not self.limit) or (bytes < self.limit):
@@ -130,6 +132,7 @@ class XmConsole:
if self.debugMe:
sys.stdout.write(foo)
bytes += 1
+ buffer += foo
except Exception, exn:
raise ConsoleError(str(exn))
else:
@@ -137,6 +140,8 @@ class XmConsole:
else:
raise ConsoleError("Console run-away (exceeded %i bytes)"
% self.limit, RUNAWAY)
+ # Check to see if the buffer contains anything interetsing
+ arch.checkBuffer(buffer)
# press enter
os.write(self.consoleFd, "\n")
# look for prompt
diff --git a/tools/xm-test/lib/XmTestLib/XenDomain.py b/tools/xm-test/lib/XmTestLib/XenDomain.py
index cbe93f805d..40aaebf9b4 100644
--- a/tools/xm-test/lib/XmTestLib/XenDomain.py
+++ b/tools/xm-test/lib/XmTestLib/XenDomain.py
@@ -20,33 +20,23 @@
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 *
+from acm 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 +45,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
+ return name
class XenConfig:
"""An object to help create a xen-compliant config file"""
@@ -102,6 +57,9 @@ class XenConfig:
self.defaultOpts["disk"] = []
self.defaultOpts["vif"] = []
self.defaultOpts["vtpm"] = []
+ if isACMEnabled():
+ #A default so every VM can start with ACM enabled
+ self.defaultOpts["access_control"] = ['policy=xm-test,label=red']
self.opts = self.defaultOpts
@@ -129,6 +87,7 @@ class XenConfig:
output = file(filename, "w")
output.write(self.toString())
output.close()
+ ACMPrepareSystem(self.opts)
def __str__(self):
"""When used as a string, we represent ourself by a config
@@ -140,8 +99,12 @@ 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]
+ # "extra" is special so append to it.
+ elif name == "extra" and name in self.opts.keys():
+ self.opts[name] += " %s" % (value)
else:
self.opts[name] = value
@@ -177,7 +140,7 @@ class DomainError(Exception):
self.errorcode = int(errorcode)
except Exception, e:
self.errorcode = -1
-
+
def __str__(self):
return str(self.msg)
@@ -199,7 +162,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 +295,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 +315,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 --git a/tools/xm-test/lib/XmTestLib/acm.py b/tools/xm-test/lib/XmTestLib/acm.py
new file mode 100644
index 0000000000..a0d8a43c09
--- /dev/null
+++ b/tools/xm-test/lib/XmTestLib/acm.py
@@ -0,0 +1,91 @@
+#!/usr/bin/python
+"""
+ Copyright (C) International Business Machines Corp., 2006
+ Author: Stefan Berger <stefanb@us.ibm.com>
+
+ 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
+
+"""
+from Test import *
+from xen.util import security
+
+try:
+ from acm_config import *
+except:
+ ACM_LABEL_RESOURCES = False
+
+labeled_resources = {}
+acm_verbose = False
+
+def isACMEnabled():
+ return security.on()
+
+
+def ACMLoadPolicy(policy='xm-test'):
+ s, o = traceCommand("xm makepolicy %s" % (policy))
+ if s != 0:
+ FAIL("Need to be able to do 'xm makepolicy %s' but could not" %
+ (policy))
+ s, o = traceCommand("xm loadpolicy %s" % (policy))
+ if s != 0:
+ FAIL("Could not load the required policy '%s'.\n"
+ "Start the system without any policy.\n%s" %
+ (policy, o))
+
+def ACMPrepareSystem(resources):
+ if isACMEnabled():
+ ACMLoadPolicy()
+ ACMLabelResources(resources)
+
+def ACMLabelResources(resources):
+ for k, v in resources.items():
+ if k == "disk":
+ for vv in v:
+ res = vv.split(',')[0]
+ ACMLabelResource(res)
+
+# Applications may label resources explicitly by calling this function
+def ACMLabelResource(resource, label='red'):
+ if acm_verbose:
+ print "labeling resource %s with label %s" % (resource, label)
+ if not ACM_LABEL_RESOURCES:
+ SKIP("Skipping test since not allowed to label resources in "
+ "test suite")
+ if not isACMResourceLabeled(resource):
+ ACMUnlabelResource(resource)
+ s, o = traceCommand("xm addlabel %s res %s" % (label, resource))
+ if s != 0:
+ FAIL("Could not add label to resource")
+ else:
+ labeled_resources["%s" % resource] = 1
+
+
+# Application may remove a label from a resource. It has to call this
+# function and must do so once a resource for re-labeling a resource
+def ACMUnlabelResource(resource):
+ s, o = traceCommand("xm rmlabel res %s" % (resource))
+ labeled_resources["%s" % resource] = 0
+
+
+def isACMResourceLabeled(resource):
+ """ Check whether a resource has been labeled using this API
+ and while running the application """
+ try:
+ if labeled_resources["%s" % resource] == 1:
+ if acm_verbose:
+ print "resource %s already labeled!" % resource
+ return True
+ except:
+ return False
+ return False
diff --git a/tools/xm-test/lib/XmTestLib/arch.py b/tools/xm-test/lib/XmTestLib/arch.py
new file mode 100644
index 0000000000..331ede5414
--- /dev/null
+++ b/tools/xm-test/lib/XmTestLib/arch.py
@@ -0,0 +1,148 @@
+#!/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
+
+from Test import *
+
+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_checkBuffer(buffer):
+ return
+
+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,
+ "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
+
+# Begin: PowerPC
+def ppc_checkBuffer(buffer):
+ checks = [
+ {"pattern" : re.compile("^\d+:mon>\s*$", re.MULTILINE),
+ "message" : "domain trapped into XMON"},
+ ]
+
+ for i in range(0, len(checks)):
+ check=checks[i]
+ if check.get('pattern').search(buffer):
+ FAIL(check.get('message'))
+
+ return
+
+def ppc_minSafeMem():
+ return 64
+
+def ppc_getDefaultKernel():
+ """Get the path to the default DomU kernel"""
+ dom0Ver = commands.getoutput("uname -r");
+ domUVer = dom0Ver.replace("xen0", "xenU");
+
+ return "/boot/vmlinux-" + domUVer;
+
+ppc_ParavirtDefaults = {"memory" : 64,
+ "vcpus" : 1,
+ "kernel" : ppc_getDefaultKernel(),
+ "root" : "/dev/ram0",
+ "ramdisk" : getRdPath() + "/initrd.img",
+ "extra" : "xencons=tty128 console=tty128",
+}
+# End : PowerPC
+
+"""Convert from uname specification to a more general platform."""
+_uname_to_arch_map = {
+ "i386" : "x86",
+ "i486" : "x86",
+ "i586" : "x86",
+ "i686" : "x86",
+ "x86_64": "x86_64",
+ "ia64" : "ia64",
+ "ppc" : "powerpc",
+ "ppc64" : "powerpc",
+}
+
+# Lookup current platform.
+_arch = _uname_to_arch_map.get(os.uname()[4], "Unknown")
+if _arch == "x86" or _arch == "x86_64" or _arch == "ia64":
+ minSafeMem = ia_minSafeMem
+ getDefaultKernel = ia_getDefaultKernel
+ checkBuffer = ia_checkBuffer
+ if config.ENABLE_HVM_SUPPORT:
+ configDefaults = ia_HVMDefaults
+ else:
+ configDefaults = ia_ParavirtDefaults
+elif _arch == "powerpc":
+ minSafeMem = ppc_minSafeMem
+ getDefaultKernel = ppc_getDefaultKernel
+ checkBuffer = ppc_checkBuffer
+ configDefaults = ppc_ParavirtDefaults
+else:
+ raise ValueError, "Unknown architecture!"
diff --git a/tools/xm-test/lib/XmTestLib/block_utils.py b/tools/xm-test/lib/XmTestLib/block_utils.py
index 38c5d20d5f..c315c17bd1 100644
--- a/tools/xm-test/lib/XmTestLib/block_utils.py
+++ b/tools/xm-test/lib/XmTestLib/block_utils.py
@@ -6,6 +6,7 @@
import time
from XmTestLib import *
+from acm import *
import xen.util.blkif
@@ -26,6 +27,7 @@ def get_state(domain, devname):
def block_attach(domain, phy, virt):
+ ACMLabelResource(phy)
status, output = traceCommand("xm block-attach %s %s %s w" %
(domain.getName(), phy, virt))
if status != 0:
diff --git a/tools/xm-test/lib/XmTestReport/OSReport.py b/tools/xm-test/lib/XmTestReport/OSReport.py
index c73f9c7821..cb4759ea3b 100644
--- a/tools/xm-test/lib/XmTestReport/OSReport.py
+++ b/tools/xm-test/lib/XmTestReport/OSReport.py
@@ -29,6 +29,7 @@ import re
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 --git a/tools/xm-test/lib/XmTestReport/arch.py b/tools/xm-test/lib/XmTestReport/arch.py
new file mode 100644
index 0000000000..965e7fb9c6
--- /dev/null
+++ b/tools/xm-test/lib/XmTestReport/arch.py
@@ -0,0 +1,52 @@
+#!/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",
+ "x86_64": "x86_64",
+ "ia64" : "ia64",
+ "ppc" : "powerpc",
+ "ppc64" : "powerpc",
+}
+
+_arch = _uname_to_arch_map.get(os.uname()[4], "Unknown")
+if _arch == "x86":
+ cpuValues = {"model_name" : "Unknown",
+ "flags" : "Unknown"}
+elif _arch == "x86_64":
+ cpuValues = {"model_name" : "Unknown",
+ "flags" : "Unknown"}
+elif _arch == "ia64":
+ cpuValues = {"arch" : "Unknown",
+ "features" : "Unknown"}
+elif _arch == "powerpc":
+ cpuValues = {"cpu" : "Unknown",
+ "platform" : "Unknown",
+ "revision" : "Unknown"}
+else:
+ raise ValueError, "Unknown architecture!"