ia64/xen-unstable

changeset 13392:568ba07641c6

This patch does the following:

- renames the XenManagedDomain.py file to XenAPIDomain.py, since this
name better reflects its functionality/purpose
- adds domain tracking to the XenAPIDomain class so that xend-managed
domains can be deleted in an 'atexit' handler upon test case termination
- adds one basic xapi-related test which is part of the grouptests
'xapi'
- refactors the vtpm-related test using xen-api and adds it to the
grouptest 'xapi'
- adds documentation to the README for how to configure xm and xend to
use XML-RPC or Xen-API for communication

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Jan 11 19:00:35 2007 +0000 (2007-01-11)
parents 09e3072f71e6
children ecf6a0a05350
files tools/xm-test/README tools/xm-test/configure.ac tools/xm-test/grouptest/xapi tools/xm-test/lib/XmTestLib/DomainTracking.py tools/xm-test/lib/XmTestLib/XenAPIDomain.py tools/xm-test/lib/XmTestLib/XenManagedDomain.py tools/xm-test/lib/XmTestLib/xapi.py tools/xm-test/tests/vtpm/09_vtpm-xapi.py tools/xm-test/tests/xapi/01_xapi-vm_basic.py tools/xm-test/tests/xapi/Makefile.am
line diff
     1.1 --- a/tools/xm-test/README	Thu Jan 11 18:56:59 2007 +0000
     1.2 +++ b/tools/xm-test/README	Thu Jan 11 19:00:35 2007 +0000
     1.3 @@ -207,6 +207,49 @@ dedicated machine.  As such, the library
     1.4  running DomUs on the system to provide each test with a "clean slate".
     1.5  
     1.6  
     1.7 +Testing the XML-RPC and Xen-API interfaces of xend
     1.8 +==================================================
     1.9 +
    1.10 +The xm-test suite can be used to test xm's interface with xend using
    1.11 +either XML-RPC or the Xen-API. In order to use either one of these modes,
    1.12 +xm needs to be configured using its configuration file
    1.13 +'/etc/xen/xm-config.xml'.
    1.14 +Note: The current default configuration after a fresh install of the xen
    1.15 +sources currently is to use the XML-RPC interface for communication with xend.
    1.16 +
    1.17 +Example content for the xm-config.xml for using the Xen-API looks as
    1.18 +follows:
    1.19 +
    1.20 +<xm>
    1.21 +  <server type='Xen-API'
    1.22 +          uri='http://localhost:9363/'
    1.23 +          username='me'
    1.24 +          password='mypassword' />
    1.25 +</xm>
    1.26 +
    1.27 +This configuration makes xm talk to xend using port 9363. For this to
    1.28 +work, also xend needs to be configured to listen to port 9363. Therefore
    1.29 +The following line must be in /etc/xen/xend-config.sxp.
    1.30 +
    1.31 +(xen-api-server (( 127.0.0.1:9363 none )))
    1.32 +
    1.33 +To communicate via the legacy XML-RPC interface, the file
    1.34 +'/etc/xen/xm-config.xml' may simply have the following content or
    1.35 +may be complete remove from the /etc/xen directory.
    1.36 +
    1.37 +<xm>
    1.38 +</xm>
    1.39 +
    1.40 +A few tests have been written for the xm-test suite that test the
    1.41 +Xen-API interface directly without relying on 'xm'. These tests can be
    1.42 +found in the grouptest 'xapi' and for them to work properly, xm must have
    1.43 +been configured to use the Xen-API following the instructions above. To
    1.44 +run these test, the following command line can be invoked:
    1.45 +
    1.46 +   # ./runtest.sh -g xapi <logfile>
    1.47 +
    1.48 +
    1.49 +
    1.50  Extending
    1.51  =========
    1.52  
     2.1 --- a/tools/xm-test/configure.ac	Thu Jan 11 18:56:59 2007 +0000
     2.2 +++ b/tools/xm-test/configure.ac	Thu Jan 11 19:00:35 2007 +0000
     2.3 @@ -150,6 +150,7 @@ AC_CONFIG_FILES([
     2.4      tests/vcpu-pin/Makefile
     2.5      tests/vcpu-disable/Makefile
     2.6      tests/vtpm/Makefile
     2.7 +    tests/xapi/Makefile
     2.8      tests/enforce_dom0_cpus/Makefile
     2.9      lib/XmTestReport/xmtest.py
    2.10      lib/XmTestLib/config.py
     3.1 --- a/tools/xm-test/grouptest/xapi	Thu Jan 11 18:56:59 2007 +0000
     3.2 +++ b/tools/xm-test/grouptest/xapi	Thu Jan 11 19:00:35 2007 +0000
     3.3 @@ -1,1 +1,2 @@
     3.4 +xapi
     3.5  vtpm 09_vtpm-xapi.test
     4.1 --- a/tools/xm-test/lib/XmTestLib/DomainTracking.py	Thu Jan 11 18:56:59 2007 +0000
     4.2 +++ b/tools/xm-test/lib/XmTestLib/DomainTracking.py	Thu Jan 11 19:00:35 2007 +0000
     4.3 @@ -20,9 +20,11 @@
     4.4  
     4.5  import atexit
     4.6  import Test
     4.7 +import xapi
     4.8  
     4.9  # Tracking of managed domains
    4.10  _managedDomains = []
    4.11 +_VMuuids = []
    4.12  registered = 0
    4.13  
    4.14  def addManagedDomain(name):
    4.15 @@ -36,8 +38,24 @@ def delManagedDomain(name):
    4.16      if name in _managedDomains:
    4.17          del _managedDomains[_managedDomains.index(name)]
    4.18  
    4.19 +def addXAPIDomain(uuid):
    4.20 +    global registered
    4.21 +    _VMuuids.append(uuid)
    4.22 +    if not registered:
    4.23 +        atexit.register(destroyManagedDomains)
    4.24 +        registered = 1
    4.25 +
    4.26 +def delXAPIDomain(uuid):
    4.27 +    _VMuuids.remove(uuid)
    4.28 +
    4.29  def destroyManagedDomains():
    4.30      if len(_managedDomains) > 0:
    4.31          for m in _managedDomains:
    4.32              Test.traceCommand("xm destroy %s" % m)
    4.33              Test.traceCommand("xm delete %s" % m)
    4.34 +    if len(_VMuuids) > 0:
    4.35 +        for uuid in _VMuuids:
    4.36 +            Test.traceCommand("xm destroy %s" % uuid)
    4.37 +            Test.traceCommand("xm delete %s" % uuid)
    4.38 +
    4.39 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/xm-test/lib/XmTestLib/XenAPIDomain.py	Thu Jan 11 19:00:35 2007 +0000
     5.3 @@ -0,0 +1,176 @@
     5.4 +#!/usr/bin/python
     5.5 +"""
     5.6 + Copyright (C) International Business Machines Corp., 2005
     5.7 + Author: Stefan Berger <stefanb@us.ibm.com>
     5.8 +
     5.9 + Based on XenDomain.py by Dan Smith <danms@us.ibm.com>
    5.10 +
    5.11 + This program is free software; you can redistribute it and/or modify
    5.12 + it under the terms of the GNU General Public License as published by
    5.13 + the Free Software Foundation; under version 2 of the License.
    5.14 +
    5.15 + This program is distributed in the hope that it will be useful,
    5.16 + but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.17 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.18 + GNU General Public License for more details.
    5.19 +
    5.20 + You should have received a copy of the GNU General Public License
    5.21 + along with this program; if not, write to the Free Software
    5.22 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.23 +
    5.24 +"""
    5.25 +import os
    5.26 +import sys
    5.27 +from XmTestLib import *
    5.28 +from xen.util.xmlrpclib2 import ServerProxy
    5.29 +from types import DictType
    5.30 +
    5.31 +
    5.32 +class XenAPIConfig:
    5.33 +    """An object to help create a VM configuration usable via Xen-API"""
    5.34 +    def __init__(self):
    5.35 +        self.opts = {}
    5.36 +        #Array to translate old option to new ones
    5.37 +        self.opttrlate = { 'name' : 'name_label' ,
    5.38 +                           'memory' : [ 'memory_static_max' ,
    5.39 +                                        'memory_static_min' ,
    5.40 +                                        'memory_dynamic_min',
    5.41 +                                        'memory_dynamic_max' ],
    5.42 +                           'kernel' : 'PV_kernel',
    5.43 +                           'ramdisk': 'PV_ramdisk',
    5.44 +                           'root'   : 'PV_args'}
    5.45 +
    5.46 +    def setOpt(self, name, value):
    5.47 +        """Set an option in the config"""
    5.48 +        if name in self.opttrlate.keys():
    5.49 +            _name = self.opttrlate[name]
    5.50 +        else:
    5.51 +            _name = name
    5.52 +
    5.53 +        if isinstance(_name, list):
    5.54 +            for _n in _name:
    5.55 +                self.opts[_n] = value
    5.56 +        else:
    5.57 +            self.opts[_name] = value
    5.58 +
    5.59 +    def getOpt(self, name):
    5.60 +        """Return the value of a config option"""
    5.61 +        if name in self.opts.keys():
    5.62 +            return self.opts[name]
    5.63 +        else:
    5.64 +            return None
    5.65 +
    5.66 +    def setOpts(self, opts):
    5.67 +        """Batch-set options from a dictionary"""
    5.68 +        for k, v in opts.items():
    5.69 +            self.setOpt(k, v)
    5.70 +
    5.71 +    def getOpts(self):
    5.72 +        return self.opts
    5.73 +
    5.74 +
    5.75 +class XenAPIDomain(XenDomain):
    5.76 +
    5.77 +    def __init__(self, name=None, config=None):
    5.78 +        if name:
    5.79 +            self.name = name
    5.80 +        else:
    5.81 +            self.name = getUniqueName()
    5.82 +
    5.83 +        self.config = config
    5.84 +        self.console = None
    5.85 +        self.netEnv = "bridge"
    5.86 +
    5.87 +        self.session = xapi.connect()
    5.88 +        session = self.session
    5.89 +        try:
    5.90 +            self.vm_uuid = session.xenapi.VM.create(self.config.getOpts())
    5.91 +            addXAPIDomain(self.vm_uuid)
    5.92 +        except:
    5.93 +            raise DomainError("Could not create VM config file for "
    5.94 +                              "managed domain.")
    5.95 +
    5.96 +        #Only support PV for now.
    5.97 +        self.type = "PV"
    5.98 +
    5.99 +    def start(self, noConsole=False, startpaused=False):
   5.100 +        #start the VM
   5.101 +        session = self.session
   5.102 +        if self.vm_uuid:
   5.103 +            try:
   5.104 +                session.xenapi.VM.start(self.vm_uuid, startpaused)
   5.105 +            except:
   5.106 +                raise DomainError("Could not start domain")
   5.107 +        else:
   5.108 +            raise DomainError("VM has no UUID - does VM config exist?")
   5.109 +
   5.110 +        if startpaused:
   5.111 +           return
   5.112 +
   5.113 +        if self.getDomainType() == "HVM":
   5.114 +           waitForBoot()
   5.115 +
   5.116 +        if self.console and noConsole == True:
   5.117 +            self.closeConsole()
   5.118 +
   5.119 +        elif self.console and noConsole == False:
   5.120 +            return self.console
   5.121 +
   5.122 +        elif not self.console and noConsole == False:
   5.123 +            return self.getConsole()
   5.124 +
   5.125 +    def stop(self):
   5.126 +        if self.vm_uuid:
   5.127 +            self.session.xenapi.VM.hard_shutdown(self.vm_uuid)
   5.128 +        else:
   5.129 +            raise DomainError("VM has no UUID - does VM config exist?")
   5.130 +
   5.131 +    def destroy(self):
   5.132 +        #Stop VM first.
   5.133 +        self.stop()
   5.134 +        if self.vm_uuid:
   5.135 +            self.session.xenapi.VM.destroy(self.vm_uuid)
   5.136 +            delXAPIDomain(self.vm_uuid)
   5.137 +        else:
   5.138 +            raise DomainError("VM has no UUID - does VM config exist?")
   5.139 +
   5.140 +    def get_uuid(self):
   5.141 +        return self.vm_uuid
   5.142 +
   5.143 +    def newDevice(self, Device, *args):
   5.144 +        raise DomainError("No support for newDevice().")
   5.145 +
   5.146 +    def removeDevice(self, id):
   5.147 +        raise DomainError("No support for removeDevice().")
   5.148 +
   5.149 +    def removeAllDevices(self, id):
   5.150 +        raise DomainError("No support for removeAllDevices().")
   5.151 +
   5.152 +    def isRunning(self):
   5.153 +        return isDomainRunning(self.name)
   5.154 +
   5.155 +    def getDevice(self, id):
   5.156 +        raise DomainError("No support for getDevice().")
   5.157 +
   5.158 +
   5.159 +class XmTestAPIDomain(XenAPIDomain):
   5.160 +
   5.161 +    """Create a new managed xm-test domain
   5.162 +    @param name: The requested domain name
   5.163 +    @param extraConfig: Additional configuration options
   5.164 +    @param baseConfig: The initial configuration defaults to use
   5.165 +    """
   5.166 +    def __init__(self, name=None, extraConfig=None,
   5.167 +                 baseConfig=arch.configDefaults):
   5.168 +        config = XenAPIConfig()
   5.169 +        config.setOpts(baseConfig)
   5.170 +        if extraConfig:
   5.171 +            config.setOpts(extraConfig)
   5.172 +
   5.173 +        if name:
   5.174 +            config.setOpt("name_label", name)
   5.175 +        elif not config.getOpt("name_label"):
   5.176 +            config.setOpt("name_label", getUniqueName())
   5.177 +
   5.178 +        XenAPIDomain.__init__(self, config.getOpt("name_label"),
   5.179 +                              config=config)
     6.1 --- a/tools/xm-test/lib/XmTestLib/XenManagedDomain.py	Thu Jan 11 18:56:59 2007 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,177 +0,0 @@
     6.4 -#!/usr/bin/python
     6.5 -"""
     6.6 - Copyright (C) International Business Machines Corp., 2005
     6.7 - Author: Stefan Berger <stefanb@us.ibm.com>
     6.8 -
     6.9 - Based on XenDomain.py by Dan Smith <danms@us.ibm.com>
    6.10 -
    6.11 - This program is free software; you can redistribute it and/or modify
    6.12 - it under the terms of the GNU General Public License as published by
    6.13 - the Free Software Foundation; under version 2 of the License.
    6.14 -
    6.15 - This program is distributed in the hope that it will be useful,
    6.16 - but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.17 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.18 - GNU General Public License for more details.
    6.19 -
    6.20 - You should have received a copy of the GNU General Public License
    6.21 - along with this program; if not, write to the Free Software
    6.22 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.23 -
    6.24 -"""
    6.25 -import os
    6.26 -import sys
    6.27 -from XmTestLib import *
    6.28 -from xen.util.xmlrpclib2 import ServerProxy
    6.29 -from types import DictType
    6.30 -
    6.31 -
    6.32 -class XenManagedConfig:
    6.33 -    """An object to help create a VM configuration usable via Xen-API"""
    6.34 -    def __init__(self):
    6.35 -        self.opts = {}
    6.36 -        #Array to translate old option to new ones
    6.37 -        self.opttrlate = { 'name' : 'name_label' ,
    6.38 -                           'memory' : [ 'memory_static_max' ,
    6.39 -                                        'memory_static_min' ,
    6.40 -                                        'memory_dynamic_min',
    6.41 -                                        'memory_dynamic_max' ],
    6.42 -                           'kernel' : 'kernel_kernel',
    6.43 -                           'ramdisk': 'kernel_initrd',
    6.44 -                           'root'   : 'kernel_args'}
    6.45 -
    6.46 -    def setOpt(self, name, value):
    6.47 -        """Set an option in the config"""
    6.48 -        if name in self.opttrlate.keys():
    6.49 -            _name = self.opttrlate[name]
    6.50 -        else:
    6.51 -            _name = name
    6.52 -
    6.53 -        if isinstance(_name, list):
    6.54 -            for _n in _name:
    6.55 -                self.opts[_n] = value
    6.56 -        else:
    6.57 -            self.opts[_name] = value
    6.58 -
    6.59 -    def getOpt(self, name):
    6.60 -        """Return the value of a config option"""
    6.61 -        if name in self.opts.keys():
    6.62 -            return self.opts[name]
    6.63 -        else:
    6.64 -            return None
    6.65 -
    6.66 -    def setOpts(self, opts):
    6.67 -        """Batch-set options from a dictionary"""
    6.68 -        for k, v in opts.items():
    6.69 -            self.setOpt(k, v)
    6.70 -
    6.71 -    def getOpts(self):
    6.72 -        return self.opts
    6.73 -
    6.74 -
    6.75 -class XenManagedDomain(XenDomain):
    6.76 -
    6.77 -    def __init__(self, name=None, config=None):
    6.78 -        if name:
    6.79 -            self.name = name
    6.80 -        else:
    6.81 -            self.name = getUniqueName()
    6.82 -
    6.83 -        self.config = config
    6.84 -        self.console = None
    6.85 -        self.netEnv = "bridge"
    6.86 -
    6.87 -        self.server, self.session = xapi._connect()
    6.88 -        server = self.server
    6.89 -        try:
    6.90 -            self.vm_uuid = xapi.execute(server.VM.create, self.session,
    6.91 -                                        self.config.getOpts())
    6.92 -            xapi._VMuuids.append(self.vm_uuid)
    6.93 -        except:
    6.94 -            raise DomainError("Could not create VM config file for "
    6.95 -                              "managed domain.")
    6.96 -
    6.97 -        #Only support PV for now.
    6.98 -        self.type = "PV"
    6.99 -
   6.100 -    def start(self, noConsole=False, startpaused=False):
   6.101 -        #start the VM
   6.102 -        server = self.server
   6.103 -        if self.vm_uuid:
   6.104 -            try:
   6.105 -                xapi.execute(server.VM.start, self.session, self.vm_uuid,
   6.106 -                             startpaused)
   6.107 -            except:
   6.108 -                raise DomainError("Could not start domain")
   6.109 -        else:
   6.110 -            raise DomainError("VM has not UUID - VM config does not exist?")
   6.111 -
   6.112 -        if self.getDomainType() == "HVM":
   6.113 -           waitForBoot()
   6.114 -
   6.115 -        if self.console and noConsole == True:
   6.116 -            self.closeConsole()
   6.117 -
   6.118 -        elif self.console and noConsole == False:
   6.119 -            return self.console
   6.120 -
   6.121 -        elif not self.console and noConsole == False:
   6.122 -            return self.getConsole()
   6.123 -
   6.124 -    def stop(self):
   6.125 -        if self.vm_uuid:
   6.126 -            server = self.server
   6.127 -            xapi.execute(server.VM.hard_shutdown, self.session, self.vm_uuid)
   6.128 -        else:
   6.129 -            raise DomainError("VM has not UUID - VM config does not exist?")
   6.130 -
   6.131 -    def destroy(self):
   6.132 -        #Stop VM first.
   6.133 -        self.stop()
   6.134 -        if self.vm_uuid:
   6.135 -            server = self.server
   6.136 -            xapi.execute(server.VM.destroy, self.session, self.vm_uuid)
   6.137 -            xapi._VMuuids.remove(self.vm_uuid)
   6.138 -        else:
   6.139 -            raise DomainError("VM has not UUID - VM config does not exist?")
   6.140 -
   6.141 -    def get_uuid(self):
   6.142 -        return self.vm_uuid
   6.143 -
   6.144 -    def newDevice(self, Device, *args):
   6.145 -        raise DomainError("No support for newDevice().")
   6.146 -
   6.147 -    def removeDevice(self, id):
   6.148 -        raise DomainError("No support for removeDevice().")
   6.149 -
   6.150 -    def removeAllDevices(self, id):
   6.151 -        raise DomainError("No support for removeAllDevices().")
   6.152 -
   6.153 -    def isRunning(self):
   6.154 -        return isDomainRunning(self.name)
   6.155 -
   6.156 -    def getDevice(self, id):
   6.157 -        raise DomainError("No support for getDevice().")
   6.158 -
   6.159 -
   6.160 -class XmTestManagedDomain(XenManagedDomain):
   6.161 -
   6.162 -    """Create a new managed xm-test domain
   6.163 -    @param name: The requested domain name
   6.164 -    @param extraConfig: Additional configuration options
   6.165 -    @param baseConfig: The initial configuration defaults to use
   6.166 -    """
   6.167 -    def __init__(self, name=None, extraConfig=None,
   6.168 -                 baseConfig=arch.configDefaults):
   6.169 -        config = XenManagedConfig()
   6.170 -        config.setOpts(baseConfig)
   6.171 -        if extraConfig:
   6.172 -            config.setOpts(extraConfig)
   6.173 -
   6.174 -        if name:
   6.175 -            config.setOpt("name_label", name)
   6.176 -        elif not config.getOpt("name_label"):
   6.177 -            config.setOpt("name_label", getUniqueName())
   6.178 -
   6.179 -        XenManagedDomain.__init__(self, config.getOpt("name_label"),
   6.180 -                                  config=config)
     7.1 --- a/tools/xm-test/lib/XmTestLib/xapi.py	Thu Jan 11 18:56:59 2007 +0000
     7.2 +++ b/tools/xm-test/lib/XmTestLib/xapi.py	Thu Jan 11 19:00:35 2007 +0000
     7.3 @@ -17,50 +17,49 @@
     7.4  # Copyright (C) 2006 IBM Corporation
     7.5  #============================================================================
     7.6  
     7.7 +import atexit
     7.8  import os
     7.9  import sys
    7.10  from XmTestLib import *
    7.11 -from xen.util.xmlrpclib2 import ServerProxy
    7.12 +from xen.xm import main as xmmain
    7.13 +from xen.xm import XenAPI
    7.14 +from xen.xm.opts import OptionError
    7.15  from types import DictType
    7.16 -
    7.17 -
    7.18 -XAPI_DEFAULT_LOGIN = " "
    7.19 -XAPI_DEFAULT_PASSWORD = " "
    7.20 -
    7.21 -class XenAPIError(Exception):
    7.22 -    pass
    7.23 -
    7.24 +import xml.dom.minidom
    7.25  
    7.26 -#A list of VMs' UUIDs that were created using vm_create
    7.27 -_VMuuids = []
    7.28 +def get_login_pwd():
    7.29 +    if xmmain.serverType == xmmain.SERVER_XEN_API:
    7.30 +        try:
    7.31 +            login, password = xmmain.parseAuthentication()
    7.32 +            return (login, password)
    7.33 +        except:
    7.34 +            raise OptionError("Configuration for login/pwd not found. "
    7.35 +                              "Need to run xapi-setup.py?")
    7.36 +    raise OptionError("Xm configuration file not using Xen-API for "
    7.37 +                      "communication with xend.")
    7.38  
    7.39 -#Terminate previously created managed(!) VMs and destroy their configs
    7.40 -def vm_destroy_all():
    7.41 -    server, session = _connect()
    7.42 -    for uuid in _VMuuids:
    7.43 -        execute(server.VM.hard_shutdown, session, uuid)
    7.44 -        execute(server.VM.destroy      , session, uuid)
    7.45 -
    7.46 +sessions=[]
    7.47  
    7.48 -def execute(fn, *args):
    7.49 -    result = fn(*args)
    7.50 -    if type(result) != DictType:
    7.51 -        raise TypeError("Function returned object of type: %s" %
    7.52 -                        str(type(result)))
    7.53 -    if 'Value' not in result:
    7.54 -        raise XenAPIError(*result['ErrorDescription'])
    7.55 -    return result['Value']
    7.56 -
    7.57 -_initialised = False
    7.58 -_server = None
    7.59 -_session = None
    7.60 -def _connect(*args):
    7.61 -    global _server, _session, _initialised
    7.62 -    if not _initialised:
    7.63 -        _server = ServerProxy('httpu:///var/run/xend/xen-api.sock')
    7.64 -        login = XAPI_DEFAULT_LOGIN
    7.65 -        password = XAPI_DEFAULT_PASSWORD
    7.66 -        creds = (login, password)
    7.67 -        _session = execute(_server.session.login_with_password, *creds)
    7.68 -        _initialised = True
    7.69 -    return (_server, _session)
    7.70 +def connect(*args):
    7.71 +    try:
    7.72 +        creds = get_login_pwd()
    7.73 +    except Exception, e:
    7.74 +        FAIL("%s" % str(e))
    7.75 +    try:
    7.76 +        session = XenAPI.Session(xmmain.serverURI)
    7.77 +    except:
    7.78 +        raise OptionError("Could not create XenAPI session with Xend." \
    7.79 +                          "URI=%s" % xmmain.serverURI)
    7.80 +    try:
    7.81 +        session.login_with_password(*creds)
    7.82 +    except:
    7.83 +        raise OptionError("Could not login to Xend. URI=%s" % xmmain.serverURI)
    7.84 +    def logout():
    7.85 +        try:
    7.86 +            for s in sessions:
    7.87 +                s.xenapi.session.logout()
    7.88 +        except:
    7.89 +            pass
    7.90 +    sessions.append(session)
    7.91 +    atexit.register(logout)
    7.92 +    return session
     8.1 --- a/tools/xm-test/tests/vtpm/09_vtpm-xapi.py	Thu Jan 11 18:56:59 2007 +0000
     8.2 +++ b/tools/xm-test/tests/vtpm/09_vtpm-xapi.py	Thu Jan 11 19:00:35 2007 +0000
     8.3 @@ -6,71 +6,66 @@
     8.4  # Test to test the vtpm class through the Xen-API
     8.5  
     8.6  from XmTestLib import xapi
     8.7 -from XmTestLib.XenManagedDomain import XmTestManagedDomain
     8.8 +from XmTestLib.XenAPIDomain import XmTestAPIDomain
     8.9  from XmTestLib import *
    8.10  from vtpm_utils import *
    8.11  import commands
    8.12  import os
    8.13  
    8.14 -def do_test():
    8.15 -    domain = XmTestManagedDomain()
    8.16 -    vm_uuid = domain.get_uuid()
    8.17 -
    8.18 -    vtpmcfg = {}
    8.19 -    vtpmcfg['type'] = "paravirtualised"
    8.20 -    vtpmcfg['backend'] = "Domain-0"
    8.21 -    vtpmcfg['instance'] = 1
    8.22 -    vtpmcfg['VM'] = vm_uuid
    8.23 -
    8.24 -    server, session = xapi._connect()
    8.25 +try:
    8.26 +    # XmTestAPIDomain tries to establish a connection to XenD
    8.27 +    domain = XmTestAPIDomain()
    8.28 +except Exception, e:
    8.29 +    SKIP("Skipping test. Error: %s" % str(e))
    8.30 +vm_uuid = domain.get_uuid()
    8.31  
    8.32 -    vtpm_uuid = xapi.execute(server.VTPM.create, session, vtpmcfg)
    8.33 +vtpmcfg = {}
    8.34 +vtpmcfg['type'] = "paravirtualised"
    8.35 +vtpmcfg['backend'] = "Domain-0"
    8.36 +vtpmcfg['instance'] = 1
    8.37 +vtpmcfg['VM'] = vm_uuid
    8.38  
    8.39 -    vtpm_id = xapi.execute(server.VTPM.get_instance, session, vtpm_uuid)
    8.40 -    vtpm_be = xapi.execute(server.VTPM.get_backend , session, vtpm_uuid)
    8.41 -    if vtpm_be != vtpmcfg['backend']:
    8.42 -        FAIL("vTPM's backend is in '%s', expected: '%s'" %
    8.43 -             (vtpm_be, vtpmcfg['backend']))
    8.44 +session = xapi.connect()
    8.45  
    8.46 -    driver = xapi.execute(server.VTPM.get_driver, session, vtpm_uuid)
    8.47 -    if driver != vtpmcfg['type']:
    8.48 -        FAIL("vTPM has driver type '%s', expected: '%s'" %
    8.49 -             (driver, vtpmcfg['type']))
    8.50 -
    8.51 -    vtpm_rec = xapi.execute(server.VTPM.get_record, session, vtpm_uuid)
    8.52 +vtpm_uuid = session.xenapi.VTPM.create(vtpmcfg)
    8.53  
    8.54 -    if vtpm_rec['driver']  != vtpmcfg['type']:
    8.55 -        FAIL("vTPM record shows driver type '%s', expected: '%s'" %
    8.56 -             (vtpm_rec['driver'], vtpmcfg['type']))
    8.57 -    if vtpm_rec['uuid']  != vtpm_uuid:
    8.58 -        FAIL("vTPM record shows vtpm uuid '%s', expected: '%s'" %
    8.59 -             (vtpm_rec['uuid'], vtpm_uuid))
    8.60 -    if vtpm_rec['VM']  != vm_uuid:
    8.61 -        FAIL("vTPM record shows VM uuid '%s', expected: '%s'" %
    8.62 -             (vtpm_rec['VM'], vm_uuid))
    8.63 +vtpm_id = session.xenapi.VTPM.get_instance(vtpm_uuid)
    8.64 +vtpm_be = session.xenapi.VTPM.get_backend(vtpm_uuid)
    8.65 +if vtpm_be != vtpmcfg['backend']:
    8.66 +    FAIL("vTPM's backend is in '%s', expected: '%s'" %
    8.67 +         (vtpm_be, vtpmcfg['backend']))
    8.68  
    8.69 -    success = domain.start()
    8.70 +driver = session.xenapi.VTPM.get_driver(vtpm_uuid)
    8.71 +if driver != vtpmcfg['type']:
    8.72 +    FAIL("vTPM has driver type '%s', expected: '%s'" %
    8.73 +         (driver, vtpmcfg['type']))
    8.74  
    8.75 -    console = domain.getConsole()
    8.76 +vtpm_rec = session.xenapi.VTPM.get_record(vtpm_uuid)
    8.77  
    8.78 -    try:
    8.79 -        run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
    8.80 -    except ConsoleError, e:
    8.81 -        saveLog(console.getHistory())
    8.82 -        vtpm_cleanup(domName)
    8.83 -        FAIL("No result from dumping the PCRs")
    8.84 +if vtpm_rec['driver']  != vtpmcfg['type']:
    8.85 +    FAIL("vTPM record shows driver type '%s', expected: '%s'" %
    8.86 +         (vtpm_rec['driver'], vtpmcfg['type']))
    8.87 +if vtpm_rec['uuid']  != vtpm_uuid:
    8.88 +    FAIL("vTPM record shows vtpm uuid '%s', expected: '%s'" %
    8.89 +         (vtpm_rec['uuid'], vtpm_uuid))
    8.90 +if vtpm_rec['VM']  != vm_uuid:
    8.91 +    FAIL("vTPM record shows VM uuid '%s', expected: '%s'" %
    8.92 +         (vtpm_rec['VM'], vm_uuid))
    8.93  
    8.94 -    if re.search("No such file",run["output"]):
    8.95 -        vtpm_cleanup(domName)
    8.96 -        FAIL("TPM frontend support not compiled into (domU?) kernel")
    8.97 +success = domain.start()
    8.98  
    8.99 -    domain.stop()
   8.100 -    domain.destroy()
   8.101 -
   8.102 -
   8.103 +console = domain.getConsole()
   8.104  
   8.105  try:
   8.106 -    do_test()
   8.107 -finally:
   8.108 -    #Make sure all domains are gone that were created in this test case
   8.109 -    xapi.vm_destroy_all()
   8.110 +    run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
   8.111 +except ConsoleError, e:
   8.112 +    saveLog(console.getHistory())
   8.113 +    vtpm_cleanup(domName)
   8.114 +    FAIL("No result from dumping the PCRs")
   8.115 +
   8.116 +if re.search("No such file",run["output"]):
   8.117 +    vtpm_cleanup(domName)
   8.118 +    FAIL("TPM frontend support not compiled into (domU?) kernel")
   8.119 +
   8.120 +domain.stop()
   8.121 +domain.destroy()
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/xm-test/tests/xapi/01_xapi-vm_basic.py	Thu Jan 11 19:00:35 2007 +0000
     9.3 @@ -0,0 +1,61 @@
     9.4 +#!/usr/bin/python
     9.5 +
     9.6 +# Copyright (C) International Business Machines Corp., 2006
     9.7 +# Author: Stefan Berger <stefanb@us.ibm.com>
     9.8 +
     9.9 +# Basic VM creation test
    9.10 +
    9.11 +from XmTestLib import xapi
    9.12 +from XmTestLib.XenAPIDomain import XmTestAPIDomain
    9.13 +from XmTestLib import *
    9.14 +from xen.xend import XendAPIConstants
    9.15 +import commands
    9.16 +import os
    9.17 +
    9.18 +try:
    9.19 +    # XmTestAPIDomain tries to establish a connection to XenD
    9.20 +    domain = XmTestAPIDomain()
    9.21 +except Exception, e:
    9.22 +    SKIP("Skipping test. Error: %s" % str(e))
    9.23 +vm_uuid = domain.get_uuid()
    9.24 +
    9.25 +session = xapi.connect()
    9.26 +
    9.27 +domain.start(startpaused=True)
    9.28 +
    9.29 +res = session.xenapi.VM.get_power_state(vm_uuid)
    9.30 +
    9.31 +if res != XendAPIConstants.XEN_API_VM_POWER_STATE[XendAPIConstants.XEN_API_VM_POWER_STATE_PAUSED]:
    9.32 +    FAIL("VM was not started in 'paused' state")
    9.33 +
    9.34 +res = session.xenapi.VM.unpause(vm_uuid)
    9.35 +
    9.36 +res = session.xenapi.VM.get_power_state(vm_uuid)
    9.37 +
    9.38 +if res != XendAPIConstants.XEN_API_VM_POWER_STATE[XendAPIConstants.XEN_API_VM_POWER_STATE_RUNNING]:
    9.39 +    FAIL("VM could not be put into 'running' state")
    9.40 +
    9.41 +console = domain.getConsole()
    9.42 +
    9.43 +try:
    9.44 +    run = console.runCmd("cat /proc/interrupts")
    9.45 +except ConsoleError, e:
    9.46 +    saveLog(console.getHistory())
    9.47 +    FAIL("Could not access proc-filesystem")
    9.48 +
    9.49 +res = session.xenapi.VM.pause(vm_uuid)
    9.50 +
    9.51 +res = session.xenapi.VM.get_power_state(vm_uuid)
    9.52 +
    9.53 +if res != XendAPIConstants.XEN_API_VM_POWER_STATE[XendAPIConstants.XEN_API_VM_POWER_STATE_PAUSED]:
    9.54 +    FAIL("VM could not be put into 'paused' state")
    9.55 +
    9.56 +res = session.xenapi.VM.unpause(vm_uuid)
    9.57 +
    9.58 +res = session.xenapi.VM.get_power_state(vm_uuid)
    9.59 +
    9.60 +if res != XendAPIConstants.XEN_API_VM_POWER_STATE[XendAPIConstants.XEN_API_VM_POWER_STATE_RUNNING]:
    9.61 +    FAIL("VM could not be 'unpaused'")
    9.62 +
    9.63 +domain.stop()
    9.64 +domain.destroy()
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/xm-test/tests/xapi/Makefile.am	Thu Jan 11 19:00:35 2007 +0000
    10.3 @@ -0,0 +1,19 @@
    10.4 +SUBDIRS =
    10.5 +
    10.6 +TESTS = 01_xapi-vm_basic.test
    10.7 +
    10.8 +XFAIL_TESTS =
    10.9 +
   10.10 +EXTRA_DIST = $(TESTS) $(XFAIL_TESTS) xapi_utils.py
   10.11 +TESTS_ENVIRONMENT=@TENV@
   10.12 +
   10.13 +%.test: %.py
   10.14 +	cp $< $@
   10.15 +	chmod +x $@
   10.16 +
   10.17 +clean-local: am_config_clean-local
   10.18 +
   10.19 +am_config_clean-local:
   10.20 +	rm -f *test
   10.21 +	rm -f *log
   10.22 +	rm -f *~