ia64/xen-unstable

changeset 12763:7dc0dd5cdb4d

Merge
author Alastair Tse <atse@xensource.com>
date Fri Dec 01 17:42:39 2006 +0000 (2006-12-01)
parents 98413fa7826c b37e66b08bf5
children 6544f92e4103
files tools/python/scripts/xapi.py
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/xm-test/grouptest/xapi	Fri Dec 01 17:42:39 2006 +0000
     1.3 @@ -0,0 +1,1 @@
     1.4 +vtpm 09_vtpm-xapi.test
     2.1 --- a/tools/xm-test/lib/XmTestLib/Test.py	Fri Dec 01 17:37:42 2006 +0000
     2.2 +++ b/tools/xm-test/lib/XmTestLib/Test.py	Fri Dec 01 17:42:39 2006 +0000
     2.3 @@ -33,6 +33,7 @@ import select
     2.4  import signal
     2.5  import re
     2.6  import glob
     2.7 +import xapi
     2.8  
     2.9  TEST_PASS = 0
    2.10  TEST_FAIL = 255
    2.11 @@ -133,10 +134,12 @@ def becomeNonRoot():
    2.12  
    2.13  def FAIL(format, *args):
    2.14      print "\nREASON:", (format % args)
    2.15 +    xapi.vm_destroy_all()
    2.16      sys.exit(TEST_FAIL)
    2.17  
    2.18  def SKIP(format, *args):
    2.19      print "\nREASON:", (format % args)
    2.20 +    xapi.vm_destroy_all()
    2.21      sys.exit(TEST_SKIP)
    2.22  
    2.23  def saveLog(logText, filename=None):
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/xm-test/lib/XmTestLib/XenManagedDomain.py	Fri Dec 01 17:42:39 2006 +0000
     3.3 @@ -0,0 +1,176 @@
     3.4 +#!/usr/bin/python
     3.5 +"""
     3.6 + Copyright (C) International Business Machines Corp., 2005
     3.7 + Author: Stefan Berger <stefanb@us.ibm.com>
     3.8 +
     3.9 + Based on XenDomain.py by Dan Smith <danms@us.ibm.com>
    3.10 +
    3.11 + This program is free software; you can redistribute it and/or modify
    3.12 + it under the terms of the GNU General Public License as published by
    3.13 + the Free Software Foundation; under version 2 of the License.
    3.14 +
    3.15 + This program is distributed in the hope that it will be useful,
    3.16 + but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.17 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.18 + GNU General Public License for more details.
    3.19 +
    3.20 + You should have received a copy of the GNU General Public License
    3.21 + along with this program; if not, write to the Free Software
    3.22 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.23 +
    3.24 +"""
    3.25 +import os
    3.26 +import sys
    3.27 +from XmTestLib import *
    3.28 +from xen.util.xmlrpclib2 import ServerProxy
    3.29 +from types import DictType
    3.30 +
    3.31 +
    3.32 +class XenManagedConfig:
    3.33 +    """An object to help create a VM configuration usable via Xen-API"""
    3.34 +    def __init__(self):
    3.35 +        self.opts = {}
    3.36 +        #Array to translate old option to new ones
    3.37 +        self.opttrlate = { 'name' : 'name_label' ,
    3.38 +                           'memory' : [ 'memory_static_max' ,
    3.39 +                                        'memory_static_min' ,
    3.40 +                                        'memory_dynamic_min',
    3.41 +                                        'memory_dynamic_max' ],
    3.42 +                           'kernel' : 'kernel_kernel',
    3.43 +                           'ramdisk': 'kernel_initrd',
    3.44 +                           'root'   : 'kernel_args'}
    3.45 +
    3.46 +    def setOpt(self, name, value):
    3.47 +        """Set an option in the config"""
    3.48 +        if name in self.opttrlate.keys():
    3.49 +            _name = self.opttrlate[name]
    3.50 +        else:
    3.51 +            _name = name
    3.52 +
    3.53 +        if isinstance(_name, list):
    3.54 +            for _n in _name:
    3.55 +                self.opts[_n] = value
    3.56 +        else:
    3.57 +            self.opts[_name] = value
    3.58 +
    3.59 +    def getOpt(self, name):
    3.60 +        """Return the value of a config option"""
    3.61 +        if name in self.opts.keys():
    3.62 +            return self.opts[name]
    3.63 +        else:
    3.64 +            return None
    3.65 +
    3.66 +    def setOpts(self, opts):
    3.67 +        """Batch-set options from a dictionary"""
    3.68 +        for k, v in opts.items():
    3.69 +            self.setOpt(k, v)
    3.70 +
    3.71 +    def getOpts(self):
    3.72 +        return self.opts
    3.73 +
    3.74 +
    3.75 +class XenManagedDomain(XenDomain):
    3.76 +
    3.77 +    def __init__(self, name=None, config=None):
    3.78 +        if name:
    3.79 +            self.name = name
    3.80 +        else:
    3.81 +            self.name = getUniqueName()
    3.82 +
    3.83 +        self.config = config
    3.84 +        self.console = None
    3.85 +        self.netEnv = "bridge"
    3.86 +
    3.87 +        self.server, self.session = xapi._connect()
    3.88 +        server = self.server
    3.89 +        try:
    3.90 +            self.vm_uuid = xapi.execute(server.VM.create, self.session,
    3.91 +                                        self.config.getOpts())
    3.92 +            xapi._VMuuids.append(self.vm_uuid)
    3.93 +        except:
    3.94 +            raise DomainError("Could not create VM config file for "
    3.95 +                              "managed domain.")
    3.96 +
    3.97 +        #Only support PV for now.
    3.98 +        self.type = "PV"
    3.99 +
   3.100 +    def start(self, noConsole=False):
   3.101 +        #start the VM
   3.102 +        server = self.server
   3.103 +        if self.vm_uuid:
   3.104 +            try:
   3.105 +                xapi.execute(server.VM.start, self.session, self.vm_uuid)
   3.106 +            except:
   3.107 +                raise DomainError("Could not start domain")
   3.108 +        else:
   3.109 +            raise DomainError("VM has not UUID - VM config does not exist?")
   3.110 +
   3.111 +        if self.getDomainType() == "HVM":
   3.112 +           waitForBoot()
   3.113 +
   3.114 +        if self.console and noConsole == True:
   3.115 +            self.closeConsole()
   3.116 +
   3.117 +        elif self.console and noConsole == False:
   3.118 +            return self.console
   3.119 +
   3.120 +        elif not self.console and noConsole == False:
   3.121 +            return self.getConsole()
   3.122 +
   3.123 +    def stop(self):
   3.124 +        if self.vm_uuid:
   3.125 +            server = self.server
   3.126 +            xapi.execute(server.VM.hard_shutdown, self.session, self.vm_uuid)
   3.127 +        else:
   3.128 +            raise DomainError("VM has not UUID - VM config does not exist?")
   3.129 +
   3.130 +    def destroy(self):
   3.131 +        #Stop VM first.
   3.132 +        self.stop()
   3.133 +        if self.vm_uuid:
   3.134 +            server = self.server
   3.135 +            xapi.execute(server.VM.destroy, self.session, self.vm_uuid)
   3.136 +            xapi._VMuuids.remove(self.vm_uuid)
   3.137 +        else:
   3.138 +            raise DomainError("VM has not UUID - VM config does not exist?")
   3.139 +
   3.140 +    def get_uuid(self):
   3.141 +        return self.vm_uuid
   3.142 +
   3.143 +    def newDevice(self, Device, *args):
   3.144 +        raise DomainError("No support for newDevice().")
   3.145 +
   3.146 +    def removeDevice(self, id):
   3.147 +        raise DomainError("No support for removeDevice().")
   3.148 +
   3.149 +    def removeAllDevices(self, id):
   3.150 +        raise DomainError("No support for removeAllDevices().")
   3.151 +
   3.152 +    def isRunning(self):
   3.153 +        return isDomainRunning(self.name)
   3.154 +
   3.155 +    def getDevice(self, id):
   3.156 +        raise DomainError("No support for getDevice().")
   3.157 +
   3.158 +
   3.159 +class XmTestManagedDomain(XenManagedDomain):
   3.160 +
   3.161 +    """Create a new managed xm-test domain
   3.162 +    @param name: The requested domain name
   3.163 +    @param extraConfig: Additional configuration options
   3.164 +    @param baseConfig: The initial configuration defaults to use
   3.165 +    """
   3.166 +    def __init__(self, name=None, extraConfig=None,
   3.167 +                 baseConfig=arch.configDefaults):
   3.168 +        config = XenManagedConfig()
   3.169 +        config.setOpts(baseConfig)
   3.170 +        if extraConfig:
   3.171 +            config.setOpts(extraConfig)
   3.172 +
   3.173 +        if name:
   3.174 +            config.setOpt("name_label", name)
   3.175 +        elif not config.getOpt("name_label"):
   3.176 +            config.setOpt("name_label", getUniqueName())
   3.177 +
   3.178 +        XenManagedDomain.__init__(self, config.getOpt("name_label"),
   3.179 +                                  config=config)
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/xm-test/lib/XmTestLib/xapi.py	Fri Dec 01 17:42:39 2006 +0000
     4.3 @@ -0,0 +1,66 @@
     4.4 +#!/usr/bin/python
     4.5 +#============================================================================
     4.6 +# This library is free software; you can redistribute it and/or
     4.7 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     4.8 +# License as published by the Free Software Foundation.
     4.9 +#
    4.10 +# This library is distributed in the hope that it will be useful,
    4.11 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.12 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.13 +# Lesser General Public License for more details.
    4.14 +#
    4.15 +# You should have received a copy of the GNU Lesser General Public
    4.16 +# License along with this library; if not, write to the Free Software
    4.17 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.18 +#============================================================================
    4.19 +# Copyright (C) 2006 XenSource Ltd.
    4.20 +# Copyright (C) 2006 IBM Corporation
    4.21 +#============================================================================
    4.22 +
    4.23 +import os
    4.24 +import sys
    4.25 +from XmTestLib import *
    4.26 +from xen.util.xmlrpclib2 import ServerProxy
    4.27 +from types import DictType
    4.28 +
    4.29 +
    4.30 +XAPI_DEFAULT_LOGIN = " "
    4.31 +XAPI_DEFAULT_PASSWORD = " "
    4.32 +
    4.33 +class XenAPIError(Exception):
    4.34 +    pass
    4.35 +
    4.36 +
    4.37 +#A list of VMs' UUIDs that were created using vm_create
    4.38 +_VMuuids = []
    4.39 +
    4.40 +#Terminate previously created managed(!) VMs and destroy their configs
    4.41 +def vm_destroy_all():
    4.42 +    server, session = _connect()
    4.43 +    for uuid in _VMuuids:
    4.44 +        execute(server.VM.hard_shutdown, session, uuid)
    4.45 +        execute(server.VM.destroy      , session, uuid)
    4.46 +
    4.47 +
    4.48 +def execute(fn, *args):
    4.49 +    result = fn(*args)
    4.50 +    if type(result) != DictType:
    4.51 +        raise TypeError("Function returned object of type: %s" %
    4.52 +                        str(type(result)))
    4.53 +    if 'Value' not in result:
    4.54 +        raise XenAPIError(*result['ErrorDescription'])
    4.55 +    return result['Value']
    4.56 +
    4.57 +_initialised = False
    4.58 +_server = None
    4.59 +_session = None
    4.60 +def _connect(*args):
    4.61 +    global _server, _session, _initialised
    4.62 +    if not _initialised:
    4.63 +        _server = ServerProxy('httpu:///var/run/xend/xmlrpc.sock')
    4.64 +        login = XAPI_DEFAULT_LOGIN
    4.65 +        password = XAPI_DEFAULT_PASSWORD
    4.66 +        creds = (login, password)
    4.67 +        _session = execute(_server.session.login_with_password, *creds)
    4.68 +        _initialised = True
    4.69 +    return (_server, _session)
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/xm-test/tests/vtpm/09_vtpm-xapi.py	Fri Dec 01 17:42:39 2006 +0000
     5.3 @@ -0,0 +1,76 @@
     5.4 +#!/usr/bin/python
     5.5 +
     5.6 +# Copyright (C) International Business Machines Corp., 2006
     5.7 +# Author: Stefan Berger <stefanb@us.ibm.com>
     5.8 +
     5.9 +# Test to test the vtpm class through the Xen-API
    5.10 +
    5.11 +from XmTestLib import xapi
    5.12 +from XmTestLib.XenManagedDomain import XmTestManagedDomain
    5.13 +from XmTestLib import *
    5.14 +from vtpm_utils import *
    5.15 +import commands
    5.16 +import os
    5.17 +
    5.18 +def do_test():
    5.19 +    domain = XmTestManagedDomain()
    5.20 +    vm_uuid = domain.get_uuid()
    5.21 +
    5.22 +    vtpmcfg = {}
    5.23 +    vtpmcfg['type'] = "paravirtualised"
    5.24 +    vtpmcfg['backend'] = "Domain-0"
    5.25 +    vtpmcfg['instance'] = 1
    5.26 +    vtpmcfg['VM'] = vm_uuid
    5.27 +
    5.28 +    server, session = xapi._connect()
    5.29 +
    5.30 +    vtpm_uuid = xapi.execute(server.VTPM.create, session, vtpmcfg)
    5.31 +
    5.32 +    vtpm_id = xapi.execute(server.VTPM.get_instance, session, vtpm_uuid)
    5.33 +    vtpm_be = xapi.execute(server.VTPM.get_backend , session, vtpm_uuid)
    5.34 +    if vtpm_be != vtpmcfg['backend']:
    5.35 +        FAIL("vTPM's backend is in '%s', expected: '%s'" %
    5.36 +             (vtpm_be, vtpmcfg['backend']))
    5.37 +
    5.38 +    driver = xapi.execute(server.VTPM.get_driver, session, vtpm_uuid)
    5.39 +    if driver != vtpmcfg['type']:
    5.40 +        FAIL("vTPM has driver type '%s', expected: '%s'" %
    5.41 +             (driver, vtpmcfg['type']))
    5.42 +
    5.43 +    vtpm_rec = xapi.execute(server.VTPM.get_record, session, vtpm_uuid)
    5.44 +
    5.45 +    if vtpm_rec['driver']  != vtpmcfg['type']:
    5.46 +        FAIL("vTPM record shows driver type '%s', expected: '%s'" %
    5.47 +             (vtpm_rec['driver'], vtpmcfg['type']))
    5.48 +    if vtpm_rec['uuid']  != vtpm_uuid:
    5.49 +        FAIL("vTPM record shows vtpm uuid '%s', expected: '%s'" %
    5.50 +             (vtpm_rec['uuid'], vtpm_uuid))
    5.51 +    if vtpm_rec['VM']  != vm_uuid:
    5.52 +        FAIL("vTPM record shows VM uuid '%s', expected: '%s'" %
    5.53 +             (vtpm_rec['VM'], vm_uuid))
    5.54 +
    5.55 +    success = domain.start()
    5.56 +
    5.57 +    console = domain.getConsole()
    5.58 +
    5.59 +    try:
    5.60 +        run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
    5.61 +    except ConsoleError, e:
    5.62 +        saveLog(console.getHistory())
    5.63 +        vtpm_cleanup(domName)
    5.64 +        FAIL("No result from dumping the PCRs")
    5.65 +
    5.66 +    if re.search("No such file",run["output"]):
    5.67 +        vtpm_cleanup(domName)
    5.68 +        FAIL("TPM frontend support not compiled into (domU?) kernel")
    5.69 +
    5.70 +    domain.stop()
    5.71 +    domain.destroy()
    5.72 +
    5.73 +
    5.74 +
    5.75 +try:
    5.76 +    do_test()
    5.77 +finally:
    5.78 +    #Make sure all domains are gone that were created in this test case
    5.79 +    xapi.vm_destroy_all()
     6.1 --- a/tools/xm-test/tests/vtpm/Makefile.am	Fri Dec 01 17:37:42 2006 +0000
     6.2 +++ b/tools/xm-test/tests/vtpm/Makefile.am	Fri Dec 01 17:42:39 2006 +0000
     6.3 @@ -7,7 +7,8 @@ TESTS = 01_vtpm-list_pos.test \
     6.4          05_vtpm-loc_migr.test \
     6.5          06_vtpm-susp_res_pcrs.test \
     6.6          07_vtpm-mig_pcrs.test \
     6.7 -        08_vtpm-mig_pcrs.test
     6.8 +        08_vtpm-mig_pcrs.test \
     6.9 +        09_vtpm-xapi.test
    6.10  
    6.11  XFAIL_TESTS =
    6.12