All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Breeds <tony@bakeyournoodle.com>
To: Xen-Devel <xen-devel@lists.xensource.com>
Cc: XenPPC-devel <xen-ppc-devel@lists.xensource.com>
Subject: [PATCH 5/10][TOOLS][XM-TEST] Refactor code to encapsulate architecture decisions in one place
Date: Fri, 20 Oct 2006 13:21:16 +1000	[thread overview]
Message-ID: <20061020032116.GL27551@bakeyournoodle.com> (raw)
In-Reply-To: <patchbomb.1161308910@localhost.localdomain>

Refactor code to encapsulate architecture decisions in one place.

Also includes some whitespace fixes.

Signed-off-by: Tony Breeds <tony@bakeyournoodle.com>
---

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!"

  parent reply	other threads:[~2006-10-20  3:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <patchbomb.1161308910@localhost.localdomain>
2006-10-20  3:20 ` [PATCH 1/10][TOOLS][XM-TEST] Update to use uClibc buildroot-snapshot Tony Breeds
2006-10-20  3:20 ` [PATCH 2/10][TOOLS][XM-TEST] Remove hard coded reference to i386 Tony Breeds
2006-10-20  3:20 ` [PATCH 3/10][TOOLS][XM-TEST] Rename buildroot -> buildroot-i386 Tony Breeds
2006-10-20  3:21 ` [PATCH 4/10][TOOLS][XM-TEST] Update .hgignore to remove artifacts of ramdisk build Tony Breeds
2006-10-20  3:21 ` Tony Breeds [this message]
2006-10-20  3:21 ` [PATCH 6/10][TOOLS][XM-TEST] Add configuration data for powerpc Tony Breeds
2006-10-20  3:21 ` [PATCH 7/10][TOOLS][XM-TEST] Add ability to inspect messages from domain for arbitrary strings Tony Breeds
2006-10-20  3:21 ` [PATCH 8/10][TOOLS][XM-TEST] Ignore generated .test files Tony Breeds
2006-10-20  3:22 ` [PATCH 9/10][TOOLS][XM-TEST] Default to appending to "extra" in XenConfig Tony Breeds
2006-10-20  3:22 ` [PATCH 10/10][TOOLS][XM-TEST] Fix Memory assumptions in the create tests Tony Breeds
2006-10-23 10:55   ` Ewan Mellor
2006-10-23 23:45     ` Tony Breeds
2006-10-24 13:54       ` [Xen-devel] " Ewan Mellor
2006-10-24 23:50         ` Tony Breeds
2006-10-25  1:16           ` Tony Breeds
2006-10-31  2:16         ` Tony Breeds
2006-11-01 15:54           ` Ewan Mellor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061020032116.GL27551@bakeyournoodle.com \
    --to=tony@bakeyournoodle.com \
    --cc=xen-devel@lists.xensource.com \
    --cc=xen-ppc-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.