ia64/xen-unstable

changeset 13350:56e2341f02c4

This simple patch allows domains created in the xm-test suite to be
created as managed domains using either a parameter to the
XenTestDomain() constructor or by setting the environment variable
XM_MANAGED_DOMAINS and running the tests with it.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Jan 09 17:25:28 2007 +0000 (2007-01-09)
parents fb38d0794f50
children 7fd4e256196b
files tools/xm-test/lib/XmTestLib/DomainTracking.py tools/xm-test/lib/XmTestLib/XenDomain.py
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/xm-test/lib/XmTestLib/DomainTracking.py	Tue Jan 09 17:25:28 2007 +0000
     1.3 @@ -0,0 +1,43 @@
     1.4 +#!/usr/bin/python
     1.5 +"""
     1.6 + Copyright (C) International Business Machines Corp., 2005
     1.7 + Author: Dan Smith <danms@us.ibm.com>
     1.8 +
     1.9 + This program is free software; you can redistribute it and/or modify
    1.10 + it under the terms of the GNU General Public License as published by
    1.11 + the Free Software Foundation; under version 2 of the License.
    1.12 +
    1.13 + This program is distributed in the hope that it will be useful,
    1.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 + GNU General Public License for more details.
    1.17 +
    1.18 + You should have received a copy of the GNU General Public License
    1.19 + along with this program; if not, write to the Free Software
    1.20 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +"""
    1.23 +
    1.24 +import atexit
    1.25 +import Test
    1.26 +
    1.27 +# Tracking of managed domains
    1.28 +_managedDomains = []
    1.29 +registered = 0
    1.30 +
    1.31 +def addManagedDomain(name):
    1.32 +    global registered
    1.33 +    _managedDomains.append(name)
    1.34 +    if not registered:
    1.35 +        atexit.register(destroyManagedDomains)
    1.36 +        registered = 1
    1.37 +
    1.38 +def delManagedDomain(name):
    1.39 +    if name in _managedDomains:
    1.40 +        del _managedDomains[_managedDomains.index(name)]
    1.41 +
    1.42 +def destroyManagedDomains():
    1.43 +    if len(_managedDomains) > 0:
    1.44 +        for m in _managedDomains:
    1.45 +            Test.traceCommand("xm destroy %s" % m)
    1.46 +            Test.traceCommand("xm delete %s" % m)
     2.1 --- a/tools/xm-test/lib/XmTestLib/XenDomain.py	Tue Jan 09 17:23:22 2007 +0000
     2.2 +++ b/tools/xm-test/lib/XmTestLib/XenDomain.py	Tue Jan 09 17:25:28 2007 +0000
     2.3 @@ -29,6 +29,7 @@ from Test import *
     2.4  from config import *
     2.5  from Console import *
     2.6  from XenDevice import *
     2.7 +from DomainTracking import *
     2.8  from acm import *
     2.9  
    2.10  
    2.11 @@ -147,7 +148,7 @@ class DomainError(Exception):
    2.12  
    2.13  class XenDomain:
    2.14  
    2.15 -    def __init__(self, name=None, config=None):
    2.16 +    def __init__(self, name=None, config=None, isManaged=False):
    2.17          """Create a domain object.
    2.18          @param config: String filename of config file
    2.19          """
    2.20 @@ -162,6 +163,10 @@ class XenDomain:
    2.21          self.devices = {}
    2.22          self.netEnv = "bridge"
    2.23  
    2.24 +        if os.getenv("XM_MANAGED_DOMAINS"):
    2.25 +            isManaged = True
    2.26 +        self.isManaged = isManaged
    2.27 +
    2.28          # Set domain type, either PV for ParaVirt domU or HVM for
    2.29          # FullVirt domain
    2.30          if ENABLE_HVM_SUPPORT:
    2.31 @@ -171,7 +176,17 @@ class XenDomain:
    2.32  
    2.33      def start(self, noConsole=False):
    2.34  
    2.35 -        ret, output = traceCommand("xm create %s" % self.config)
    2.36 +        if not self.isManaged:
    2.37 +            ret, output = traceCommand("xm create %s" % self.config)
    2.38 +        else:
    2.39 +            ret, output = traceCommand("xm new %s" % self.config)
    2.40 +            if ret != 0:
    2.41 +                _ret, output = traceCommand("xm delete " +
    2.42 +                                            self.config.getOpt("name"))
    2.43 +            else:
    2.44 +                ret, output = traceCommand("xm start " +
    2.45 +                                           self.config.getOpt("name"))
    2.46 +                addManagedDomain(self.config.getOpt("name"))
    2.47  
    2.48          if ret != 0:
    2.49              raise DomainError("Failed to create domain",
    2.50 @@ -218,6 +233,10 @@ class XenDomain:
    2.51              self.closeConsole()
    2.52  
    2.53          ret, output = traceCommand(prog + cmd + self.config.getOpt("name"))
    2.54 +        if self.isManaged:
    2.55 +            ret, output = traceCommand(prog + " delete " +
    2.56 +                                       self.config.getOpt("name"))
    2.57 +            delManagedDomain(self.config.getOpt("name"))
    2.58  
    2.59          return ret
    2.60  
    2.61 @@ -296,7 +315,7 @@ class XenDomain:
    2.62  class XmTestDomain(XenDomain):
    2.63  
    2.64      def __init__(self, name=None, extraConfig=None,
    2.65 -                 baseConfig=arch.configDefaults):
    2.66 +                 baseConfig=arch.configDefaults, isManaged=False):
    2.67          """Create a new xm-test domain
    2.68          @param name: The requested domain name
    2.69          @param extraConfig: Additional configuration options
    2.70 @@ -312,7 +331,8 @@ class XmTestDomain(XenDomain):
    2.71          elif not config.getOpt("name"):
    2.72              config.setOpt("name", getUniqueName())
    2.73  
    2.74 -        XenDomain.__init__(self, config.getOpt("name"), config=config)
    2.75 +        XenDomain.__init__(self, config.getOpt("name"), config=config,
    2.76 +                           isManaged=isManaged)
    2.77  
    2.78      def minSafeMem(self):
    2.79          return arch.minSafeMem