ia64/xen-unstable

view tools/xm-test/tests/vtpm/09_vtpm-xapi.py @ 13801:2e80cd715047

Copy the definition of DOM0_UUID into XenDomain so that we don't need to import
large swathes of the server to run the Xen-API tests.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Feb 01 11:42:50 2007 +0000 (2007-02-01)
parents 7fdfa020d4ed
children 5dd14bfbe956
line source
1 #!/usr/bin/python
3 # Copyright (C) International Business Machines Corp., 2006
4 # Author: Stefan Berger <stefanb@us.ibm.com>
6 # Test to test the vtpm class through the Xen-API
7 #
8 # Tested methods:
9 # VTPM: get_uuid, get_backend, get_by_uuid, get_record
10 # create, destroy, get_VM
11 # VM: get_VTPMS
13 from XmTestLib import xapi
14 from XmTestLib.XenAPIDomain import XmTestAPIDomain
15 from XmTestLib import *
16 from vtpm_utils import *
17 import commands
18 import os
20 VTPM_RECORD_KEYS = [ 'backend', 'VM', 'uuid' ]
22 try:
23 # XmTestAPIDomain tries to establish a connection to XenD
24 domain = XmTestAPIDomain()
25 except Exception, e:
26 SKIP("Skipping test. Error: %s" % str(e))
27 vm_uuid = domain.get_uuid()
29 vtpmcfg = {}
30 vtpmcfg['backend'] = DOM0_UUID
31 vtpmcfg['VM'] = vm_uuid
33 session = xapi.connect()
35 vtpm_uuid = session.xenapi.VTPM.create(vtpmcfg)
37 vtpm_be = session.xenapi.VTPM.get_backend(vtpm_uuid)
38 if vtpm_be != vtpmcfg['backend']:
39 FAIL("vTPM's backend is in '%s', expected: '%s'" %
40 (vtpm_be, vtpmcfg['backend']))
42 vtpm_rec = session.xenapi.VTPM.get_record(vtpm_uuid)
44 miss_keys = []
45 for k in VTPM_RECORD_KEYS:
46 if k not in vtpm_rec.keys():
47 miss_keys.append(k)
48 if len(miss_keys) > 0:
49 FAIL("vTPM record is missing key(s): %s" % miss_keys)
51 if vtpm_rec['uuid'] != vtpm_uuid:
52 FAIL("vTPM record shows vtpm uuid '%s', expected: '%s'" %
53 (vtpm_rec['uuid'], vtpm_uuid))
54 if vtpm_rec['VM'] != vm_uuid:
55 FAIL("vTPM record shows VM uuid '%s', expected: '%s'" %
56 (vtpm_rec['VM'], vm_uuid))
57 if vtpm_rec['backend'] != vtpmcfg['backend']:
58 FAIL("vTPM record shows VM bakcned '%s', expected: '%s'" %
59 (vtpm_rev['backend'], vtpmcfg['backend']))
61 badkeys = []
62 keys = vtpm_rec.keys()
63 for k in keys:
64 if k not in VTPM_RECORD_KEYS:
65 badkeys.append(k)
66 if len(badkeys) > 0:
67 FAIL("Unexpected attributes in result: %s" % badkeys)
69 if vm_uuid != session.xenapi.VTPM.get_VM(vtpm_uuid):
70 FAIL("VM uuid from VTPM.get_VM different (%s) than expected (%s)." %
71 (vm_ref, vm_uuid))
73 uuid = session.xenapi.VTPM.get_uuid(vtpm_uuid)
74 if uuid != vtpm_uuid:
75 FAIL("vTPM from VTPM.get_uuid different (%s) than expected (%s)." %
76 (uuid, vtpm_uuid))
78 vtpm_ref = session.xenapi.VTPM.get_by_uuid(vtpm_uuid)
79 if vtpm_ref != vtpm_uuid:
80 FAIL("vTPM from VTPM.get_by_uuid different (%s) than expected (%s)." %
81 (vtpm_ref, vtpm_uuid))
83 vm_vtpms = session.xenapi.VM.get_VTPMs(vm_uuid)
84 if len(vm_vtpms) != 1:
85 FAIL("Number of vTPMs from get_VTPMs is (%d) not what was expected (%d)" %
86 (len(vm_vtpms), 1))
87 if vtpm_uuid not in vm_vtpms:
88 FAIL("Other vTPM uuid (%s) returned from VM.get_VTPMs than expected (%s)" %
89 (vm_vtpms[0], vtpm_uuid))
91 try:
92 console = domain.start()
93 except DomainError, e:
94 FAIL("Unable to create domain (%s)" % domName)
96 try:
97 console.sendInput("input")
98 except ConsoleError, e:
99 saveLog(console.getHistory())
100 FAIL(str(e))
102 try:
103 run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
104 except ConsoleError, e:
105 saveLog(console.getHistory())
106 FAIL("1. No result from dumping the PCRs")
108 if re.search("No such file",run["output"]):
109 FAIL("TPM frontend support not compiled into (domU?) kernel")
111 if not re.search("PCR-00:",run["output"]):
112 saveLog(console.getHistory())
113 FAIL("1. Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"])
115 try:
116 rc = session.xenapi.VTPM.destroy(vtpm_uuid)
117 #Should never get here
118 FAIL("Could destroy vTPM while VM is running")
119 except:
120 pass
122 rc = session.xenapi.VM.suspend(vm_uuid)
123 if rc:
124 FAIL("Could not suspend VM")
126 try:
127 rc = session.xenapi.VTPM.destroy(vtpm_uuid)
128 #May not throw an exception in 'suspend' state
129 except:
130 pass
132 rc = session.xenapi.VM.resume(vm_uuid, False)
133 if rc:
134 FAIL("Could not resume VM")
136 try:
137 console = domain.getConsole()
138 except ConsoleError, e:
139 FAIL(str(e))
141 try:
142 run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
143 except ConsoleError, e:
144 saveLog(console.getHistory())
145 FAIL("2. No result from dumping the PCRs. vTPM has been removed?")
147 if not re.search("PCR-00:",run["output"]):
148 saveLog(console.getHistory())
149 FAIL("2. Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"])
151 domain.stop()
153 rc = session.xenapi.VTPM.destroy(vtpm_uuid)
154 if not rc:
155 FAIL("Could NOT destroy vTPM while domain is halted.")
157 domain.destroy()