Fixes on classes for testing of raw Xen-API
PATCH 1/1 Fixes on classes for testing of raw Xen-API
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
xen-unstable.hg/tools/xm-test/lib/XmTestLib/xapi.py +41 -42
@@ -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 - -XAPI_DEFAULT_LOGIN = " " -XAPI_DEFAULT_PASSWORD = " " - -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 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.") + +sessions=[] + +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
xen-unstable.hg/tools/xm-test/tests/vtpm/09_vtpm-xapi.py +54 -59
125 lines not on this page · raw message
xen-unstable.hg/tools/xm-test/lib/XmTestLib/XenManagedDomain.py deleted +0 -177
177 lines not on this page · raw message
xen-unstable.hg/tools/xm-test/configure.ac +1 -0
@@ -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
xen-unstable.hg/tools/xm-test/grouptest/xapi +1 -0
@@ -1 +1,2 @@ +xapi vtpm 09_vtpm-xapi.test
xen-unstable.hg/tools/xm-test/tests/xapi/01_xapi-vm_basic.py new file +61 -0
61 lines not on this page · raw message
xen-unstable.hg/tools/xm-test/tests/xapi/Makefile.am new file +19 -0
@@ -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 *~
xen-unstable.hg/tools/xm-test/lib/XmTestLib/XenAPIDomain.py new file +176 -0
176 lines not on this page · raw message
xen-unstable.hg/tools/xm-test/lib/XmTestLib/DomainTracking.py +18 -0
@@ -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) + +
xen-unstable.hg/tools/xm-test/README +43 -0
49 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Ewan Mellor
AppliedQuoted 13 lines · Stefan Berger
This patch does the following:
- renames the
XenManagedDomain.pyfile toXenAPIDomain.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
Quoted 1 line
Signed-off-by Stefan Berger <[email protected]>
Applied, thanks.
Ewan.