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/lib | |
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/lib')
-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 |
3 files changed, 81 insertions, 65 deletions
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 |