diff options
author | Ewan Mellor <ewan@xensource.com> | 2007-01-11 19:00:35 +0000 |
---|---|---|
committer | Ewan Mellor <ewan@xensource.com> | 2007-01-11 19:00:35 +0000 |
commit | baacea8058282908ae5078f8f0373de10d58e150 (patch) | |
tree | 95350cd16431fe3b6643c1eef39d846783cb2c4f /tools/xm-test | |
parent | aeb7c09a6613aae8e39c271283f8db9f7a99d32f (diff) | |
download | xen-baacea8058282908ae5078f8f0373de10d58e150.tar.gz xen-baacea8058282908ae5078f8f0373de10d58e150.tar.bz2 xen-baacea8058282908ae5078f8f0373de10d58e150.zip |
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>
Diffstat (limited to 'tools/xm-test')
-rw-r--r-- | tools/xm-test/README | 43 | ||||
-rw-r--r-- | tools/xm-test/configure.ac | 1 | ||||
-rw-r--r-- | tools/xm-test/grouptest/xapi | 1 | ||||
-rw-r--r-- | tools/xm-test/lib/XmTestLib/DomainTracking.py | 18 | ||||
-rw-r--r-- | tools/xm-test/lib/XmTestLib/XenAPIDomain.py (renamed from tools/xm-test/lib/XmTestLib/XenManagedDomain.py) | 49 | ||||
-rw-r--r-- | tools/xm-test/lib/XmTestLib/xapi.py | 79 | ||||
-rw-r--r-- | tools/xm-test/tests/vtpm/09_vtpm-xapi.py | 99 | ||||
-rw-r--r-- | tools/xm-test/tests/xapi/01_xapi-vm_basic.py | 61 | ||||
-rw-r--r-- | tools/xm-test/tests/xapi/Makefile.am | 19 |
9 files changed, 253 insertions, 117 deletions
diff --git a/tools/xm-test/README b/tools/xm-test/README index 9157f7681d..b63a34be32 100644 --- a/tools/xm-test/README +++ b/tools/xm-test/README @@ -207,6 +207,49 @@ dedicated machine. As such, the library automatically destroys any running DomUs on the system to provide each test with a "clean slate". +Testing the XML-RPC and Xen-API interfaces of xend +================================================== + +The xm-test suite can be used to test xm's interface with xend using +either XML-RPC or the Xen-API. In order to use either one of these modes, +xm needs to be configured using its configuration file +'/etc/xen/xm-config.xml'. +Note: The current default configuration after a fresh install of the xen +sources currently is to use the XML-RPC interface for communication with xend. + +Example content for the xm-config.xml for using the Xen-API looks as +follows: + +<xm> + <server type='Xen-API' + uri='http://localhost:9363/' + username='me' + password='mypassword' /> +</xm> + +This configuration makes xm talk to xend using port 9363. For this to +work, also xend needs to be configured to listen to port 9363. Therefore +The following line must be in /etc/xen/xend-config.sxp. + +(xen-api-server (( 127.0.0.1:9363 none ))) + +To communicate via the legacy XML-RPC interface, the file +'/etc/xen/xm-config.xml' may simply have the following content or +may be complete remove from the /etc/xen directory. + +<xm> +</xm> + +A few tests have been written for the xm-test suite that test the +Xen-API interface directly without relying on 'xm'. These tests can be +found in the grouptest 'xapi' and for them to work properly, xm must have +been configured to use the Xen-API following the instructions above. To +run these test, the following command line can be invoked: + + # ./runtest.sh -g xapi <logfile> + + + Extending ========= diff --git a/tools/xm-test/configure.ac b/tools/xm-test/configure.ac index 87df5cd6bd..ffbf146f34 100644 --- a/tools/xm-test/configure.ac +++ b/tools/xm-test/configure.ac @@ -150,6 +150,7 @@ AC_CONFIG_FILES([ tests/vcpu-pin/Makefile tests/vcpu-disable/Makefile tests/vtpm/Makefile + tests/xapi/Makefile tests/enforce_dom0_cpus/Makefile lib/XmTestReport/xmtest.py lib/XmTestLib/config.py diff --git a/tools/xm-test/grouptest/xapi b/tools/xm-test/grouptest/xapi index 407368e6b4..3b049219dd 100644 --- a/tools/xm-test/grouptest/xapi +++ b/tools/xm-test/grouptest/xapi @@ -1 +1,2 @@ +xapi vtpm 09_vtpm-xapi.test diff --git a/tools/xm-test/lib/XmTestLib/DomainTracking.py b/tools/xm-test/lib/XmTestLib/DomainTracking.py index cbd25146f5..7e0bb3013a 100644 --- a/tools/xm-test/lib/XmTestLib/DomainTracking.py +++ b/tools/xm-test/lib/XmTestLib/DomainTracking.py @@ -20,9 +20,11 @@ import atexit import Test +import xapi # Tracking of managed domains _managedDomains = [] +_VMuuids = [] registered = 0 def addManagedDomain(name): @@ -36,8 +38,24 @@ def delManagedDomain(name): if name in _managedDomains: del _managedDomains[_managedDomains.index(name)] +def addXAPIDomain(uuid): + global registered + _VMuuids.append(uuid) + if not registered: + atexit.register(destroyManagedDomains) + registered = 1 + +def delXAPIDomain(uuid): + _VMuuids.remove(uuid) + def destroyManagedDomains(): if len(_managedDomains) > 0: for m in _managedDomains: Test.traceCommand("xm destroy %s" % m) Test.traceCommand("xm delete %s" % m) + if len(_VMuuids) > 0: + for uuid in _VMuuids: + Test.traceCommand("xm destroy %s" % uuid) + Test.traceCommand("xm delete %s" % uuid) + + diff --git a/tools/xm-test/lib/XmTestLib/XenManagedDomain.py b/tools/xm-test/lib/XmTestLib/XenAPIDomain.py index 1b211fe016..cfec7911ee 100644 --- a/tools/xm-test/lib/XmTestLib/XenManagedDomain.py +++ b/tools/xm-test/lib/XmTestLib/XenAPIDomain.py @@ -26,7 +26,7 @@ from xen.util.xmlrpclib2 import ServerProxy from types import DictType -class XenManagedConfig: +class XenAPIConfig: """An object to help create a VM configuration usable via Xen-API""" def __init__(self): self.opts = {} @@ -36,9 +36,9 @@ class XenManagedConfig: 'memory_static_min' , 'memory_dynamic_min', 'memory_dynamic_max' ], - 'kernel' : 'kernel_kernel', - 'ramdisk': 'kernel_initrd', - 'root' : 'kernel_args'} + 'kernel' : 'PV_kernel', + 'ramdisk': 'PV_ramdisk', + 'root' : 'PV_args'} def setOpt(self, name, value): """Set an option in the config""" @@ -69,7 +69,7 @@ class XenManagedConfig: return self.opts -class XenManagedDomain(XenDomain): +class XenAPIDomain(XenDomain): def __init__(self, name=None, config=None): if name: @@ -81,12 +81,11 @@ class XenManagedDomain(XenDomain): self.console = None self.netEnv = "bridge" - self.server, self.session = xapi._connect() - server = self.server + self.session = xapi.connect() + session = self.session try: - self.vm_uuid = xapi.execute(server.VM.create, self.session, - self.config.getOpts()) - xapi._VMuuids.append(self.vm_uuid) + self.vm_uuid = session.xenapi.VM.create(self.config.getOpts()) + addXAPIDomain(self.vm_uuid) except: raise DomainError("Could not create VM config file for " "managed domain.") @@ -96,15 +95,17 @@ class XenManagedDomain(XenDomain): def start(self, noConsole=False, startpaused=False): #start the VM - server = self.server + session = self.session if self.vm_uuid: try: - xapi.execute(server.VM.start, self.session, self.vm_uuid, - startpaused) + session.xenapi.VM.start(self.vm_uuid, startpaused) except: raise DomainError("Could not start domain") else: - raise DomainError("VM has not UUID - VM config does not exist?") + raise DomainError("VM has no UUID - does VM config exist?") + + if startpaused: + return if self.getDomainType() == "HVM": waitForBoot() @@ -120,20 +121,18 @@ class XenManagedDomain(XenDomain): def stop(self): if self.vm_uuid: - server = self.server - xapi.execute(server.VM.hard_shutdown, self.session, self.vm_uuid) + self.session.xenapi.VM.hard_shutdown(self.vm_uuid) else: - raise DomainError("VM has not UUID - VM config does not exist?") + raise DomainError("VM has no UUID - does VM config exist?") def destroy(self): #Stop VM first. self.stop() if self.vm_uuid: - server = self.server - xapi.execute(server.VM.destroy, self.session, self.vm_uuid) - xapi._VMuuids.remove(self.vm_uuid) + self.session.xenapi.VM.destroy(self.vm_uuid) + delXAPIDomain(self.vm_uuid) else: - raise DomainError("VM has not UUID - VM config does not exist?") + raise DomainError("VM has no UUID - does VM config exist?") def get_uuid(self): return self.vm_uuid @@ -154,7 +153,7 @@ class XenManagedDomain(XenDomain): raise DomainError("No support for getDevice().") -class XmTestManagedDomain(XenManagedDomain): +class XmTestAPIDomain(XenAPIDomain): """Create a new managed xm-test domain @param name: The requested domain name @@ -163,7 +162,7 @@ class XmTestManagedDomain(XenManagedDomain): """ def __init__(self, name=None, extraConfig=None, baseConfig=arch.configDefaults): - config = XenManagedConfig() + config = XenAPIConfig() config.setOpts(baseConfig) if extraConfig: config.setOpts(extraConfig) @@ -173,5 +172,5 @@ class XmTestManagedDomain(XenManagedDomain): elif not config.getOpt("name_label"): config.setOpt("name_label", getUniqueName()) - XenManagedDomain.__init__(self, config.getOpt("name_label"), - config=config) + XenAPIDomain.__init__(self, config.getOpt("name_label"), + config=config) diff --git a/tools/xm-test/lib/XmTestLib/xapi.py b/tools/xm-test/lib/XmTestLib/xapi.py index bab0e103d9..773b3c1739 100644 --- a/tools/xm-test/lib/XmTestLib/xapi.py +++ b/tools/xm-test/lib/XmTestLib/xapi.py @@ -17,50 +17,49 @@ # Copyright (C) 2006 IBM Corporation #============================================================================ +import atexit import os import sys from XmTestLib import * -from xen.util.xmlrpclib2 import ServerProxy +from xen.xm import main as xmmain +from xen.xm import XenAPI +from xen.xm.opts import OptionError from types import DictType +import xml.dom.minidom +def get_login_pwd(): + if xmmain.serverType == xmmain.SERVER_XEN_API: + try: + login, password = xmmain.parseAuthentication() + return (login, password) + except: + raise OptionError("Configuration for login/pwd not found. " + "Need to run xapi-setup.py?") + raise OptionError("Xm configuration file not using Xen-API for " + "communication with xend.") -XAPI_DEFAULT_LOGIN = " " -XAPI_DEFAULT_PASSWORD = " " +sessions=[] -class XenAPIError(Exception): - pass - - -#A list of VMs' UUIDs that were created using vm_create -_VMuuids = [] - -#Terminate previously created managed(!) VMs and destroy their configs -def vm_destroy_all(): - server, session = _connect() - for uuid in _VMuuids: - execute(server.VM.hard_shutdown, session, uuid) - execute(server.VM.destroy , session, uuid) - - -def execute(fn, *args): - result = fn(*args) - if type(result) != DictType: - raise TypeError("Function returned object of type: %s" % - str(type(result))) - if 'Value' not in result: - raise XenAPIError(*result['ErrorDescription']) - return result['Value'] - -_initialised = False -_server = None -_session = None -def _connect(*args): - global _server, _session, _initialised - if not _initialised: - _server = ServerProxy('httpu:///var/run/xend/xen-api.sock') - login = XAPI_DEFAULT_LOGIN - password = XAPI_DEFAULT_PASSWORD - creds = (login, password) - _session = execute(_server.session.login_with_password, *creds) - _initialised = True - return (_server, _session) +def connect(*args): + try: + creds = get_login_pwd() + except Exception, e: + FAIL("%s" % str(e)) + try: + session = XenAPI.Session(xmmain.serverURI) + except: + raise OptionError("Could not create XenAPI session with Xend." \ + "URI=%s" % xmmain.serverURI) + try: + session.login_with_password(*creds) + except: + raise OptionError("Could not login to Xend. URI=%s" % xmmain.serverURI) + def logout(): + try: + for s in sessions: + s.xenapi.session.logout() + except: + pass + sessions.append(session) + atexit.register(logout) + return session diff --git a/tools/xm-test/tests/vtpm/09_vtpm-xapi.py b/tools/xm-test/tests/vtpm/09_vtpm-xapi.py index 8547a08b03..89975d077f 100644 --- a/tools/xm-test/tests/vtpm/09_vtpm-xapi.py +++ b/tools/xm-test/tests/vtpm/09_vtpm-xapi.py @@ -6,71 +6,66 @@ # Test to test the vtpm class through the Xen-API from XmTestLib import xapi -from XmTestLib.XenManagedDomain import XmTestManagedDomain +from XmTestLib.XenAPIDomain import XmTestAPIDomain from XmTestLib import * from vtpm_utils import * import commands import os -def do_test(): - domain = XmTestManagedDomain() - vm_uuid = domain.get_uuid() - - vtpmcfg = {} - vtpmcfg['type'] = "paravirtualised" - vtpmcfg['backend'] = "Domain-0" - vtpmcfg['instance'] = 1 - vtpmcfg['VM'] = vm_uuid - - server, session = xapi._connect() - - vtpm_uuid = xapi.execute(server.VTPM.create, session, vtpmcfg) - - vtpm_id = xapi.execute(server.VTPM.get_instance, session, vtpm_uuid) - vtpm_be = xapi.execute(server.VTPM.get_backend , session, vtpm_uuid) - if vtpm_be != vtpmcfg['backend']: - FAIL("vTPM's backend is in '%s', expected: '%s'" % - (vtpm_be, vtpmcfg['backend'])) - - driver = xapi.execute(server.VTPM.get_driver, session, vtpm_uuid) - if driver != vtpmcfg['type']: - FAIL("vTPM has driver type '%s', expected: '%s'" % - (driver, vtpmcfg['type'])) +try: + # XmTestAPIDomain tries to establish a connection to XenD + domain = XmTestAPIDomain() +except Exception, e: + SKIP("Skipping test. Error: %s" % str(e)) +vm_uuid = domain.get_uuid() - vtpm_rec = xapi.execute(server.VTPM.get_record, session, vtpm_uuid) +vtpmcfg = {} +vtpmcfg['type'] = "paravirtualised" +vtpmcfg['backend'] = "Domain-0" +vtpmcfg['instance'] = 1 +vtpmcfg['VM'] = vm_uuid - if vtpm_rec['driver'] != vtpmcfg['type']: - FAIL("vTPM record shows driver type '%s', expected: '%s'" % - (vtpm_rec['driver'], vtpmcfg['type'])) - if vtpm_rec['uuid'] != vtpm_uuid: - FAIL("vTPM record shows vtpm uuid '%s', expected: '%s'" % - (vtpm_rec['uuid'], vtpm_uuid)) - if vtpm_rec['VM'] != vm_uuid: - FAIL("vTPM record shows VM uuid '%s', expected: '%s'" % - (vtpm_rec['VM'], vm_uuid)) +session = xapi.connect() - success = domain.start() +vtpm_uuid = session.xenapi.VTPM.create(vtpmcfg) - console = domain.getConsole() +vtpm_id = session.xenapi.VTPM.get_instance(vtpm_uuid) +vtpm_be = session.xenapi.VTPM.get_backend(vtpm_uuid) +if vtpm_be != vtpmcfg['backend']: + FAIL("vTPM's backend is in '%s', expected: '%s'" % + (vtpm_be, vtpmcfg['backend'])) - try: - run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs") - except ConsoleError, e: - saveLog(console.getHistory()) - vtpm_cleanup(domName) - FAIL("No result from dumping the PCRs") +driver = session.xenapi.VTPM.get_driver(vtpm_uuid) +if driver != vtpmcfg['type']: + FAIL("vTPM has driver type '%s', expected: '%s'" % + (driver, vtpmcfg['type'])) - if re.search("No such file",run["output"]): - vtpm_cleanup(domName) - FAIL("TPM frontend support not compiled into (domU?) kernel") +vtpm_rec = session.xenapi.VTPM.get_record(vtpm_uuid) - domain.stop() - domain.destroy() +if vtpm_rec['driver'] != vtpmcfg['type']: + FAIL("vTPM record shows driver type '%s', expected: '%s'" % + (vtpm_rec['driver'], vtpmcfg['type'])) +if vtpm_rec['uuid'] != vtpm_uuid: + FAIL("vTPM record shows vtpm uuid '%s', expected: '%s'" % + (vtpm_rec['uuid'], vtpm_uuid)) +if vtpm_rec['VM'] != vm_uuid: + FAIL("vTPM record shows VM uuid '%s', expected: '%s'" % + (vtpm_rec['VM'], vm_uuid)) +success = domain.start() +console = domain.getConsole() try: - do_test() -finally: - #Make sure all domains are gone that were created in this test case - xapi.vm_destroy_all() + run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs") +except ConsoleError, e: + saveLog(console.getHistory()) + vtpm_cleanup(domName) + FAIL("No result from dumping the PCRs") + +if re.search("No such file",run["output"]): + vtpm_cleanup(domName) + FAIL("TPM frontend support not compiled into (domU?) kernel") + +domain.stop() +domain.destroy() diff --git a/tools/xm-test/tests/xapi/01_xapi-vm_basic.py b/tools/xm-test/tests/xapi/01_xapi-vm_basic.py new file mode 100644 index 0000000000..6f149a0dd9 --- /dev/null +++ b/tools/xm-test/tests/xapi/01_xapi-vm_basic.py @@ -0,0 +1,61 @@ +#!/usr/bin/python + +# Copyright (C) International Business Machines Corp., 2006 +# Author: Stefan Berger <stefanb@us.ibm.com> + +# Basic VM creation test + +from XmTestLib import xapi +from XmTestLib.XenAPIDomain import XmTestAPIDomain +from XmTestLib import * +from xen.xend import XendAPIConstants +import commands +import os + +try: + # XmTestAPIDomain tries to establish a connection to XenD + domain = XmTestAPIDomain() +except Exception, e: + SKIP("Skipping test. Error: %s" % str(e)) +vm_uuid = domain.get_uuid() + +session = xapi.connect() + +domain.start(startpaused=True) + +res = session.xenapi.VM.get_power_state(vm_uuid) + +if res != XendAPIConstants.XEN_API_VM_POWER_STATE[XendAPIConstants.XEN_API_VM_POWER_STATE_PAUSED]: + FAIL("VM was not started in 'paused' state") + +res = session.xenapi.VM.unpause(vm_uuid) + +res = session.xenapi.VM.get_power_state(vm_uuid) + +if res != XendAPIConstants.XEN_API_VM_POWER_STATE[XendAPIConstants.XEN_API_VM_POWER_STATE_RUNNING]: + FAIL("VM could not be put into 'running' state") + +console = domain.getConsole() + +try: + run = console.runCmd("cat /proc/interrupts") +except ConsoleError, e: + saveLog(console.getHistory()) + FAIL("Could not access proc-filesystem") + +res = session.xenapi.VM.pause(vm_uuid) + +res = session.xenapi.VM.get_power_state(vm_uuid) + +if res != XendAPIConstants.XEN_API_VM_POWER_STATE[XendAPIConstants.XEN_API_VM_POWER_STATE_PAUSED]: + FAIL("VM could not be put into 'paused' state") + +res = session.xenapi.VM.unpause(vm_uuid) + +res = session.xenapi.VM.get_power_state(vm_uuid) + +if res != XendAPIConstants.XEN_API_VM_POWER_STATE[XendAPIConstants.XEN_API_VM_POWER_STATE_RUNNING]: + FAIL("VM could not be 'unpaused'") + +domain.stop() +domain.destroy() diff --git a/tools/xm-test/tests/xapi/Makefile.am b/tools/xm-test/tests/xapi/Makefile.am new file mode 100644 index 0000000000..2a0c44f578 --- /dev/null +++ b/tools/xm-test/tests/xapi/Makefile.am @@ -0,0 +1,19 @@ +SUBDIRS = + +TESTS = 01_xapi-vm_basic.test + +XFAIL_TESTS = + +EXTRA_DIST = $(TESTS) $(XFAIL_TESTS) xapi_utils.py +TESTS_ENVIRONMENT=@TENV@ + +%.test: %.py + cp $< $@ + chmod +x $@ + +clean-local: am_config_clean-local + +am_config_clean-local: + rm -f *test + rm -f *log + rm -f *~ |