1 | #!/usr/bin/python |
---|
2 | |
---|
3 | # Copyright (C) International Business Machines Corp., 2006 |
---|
4 | # Author: Stefan Berger <stefanb@us.ibm.com> |
---|
5 | |
---|
6 | # Positive Test: create domain with virtual TPM attached at build time, |
---|
7 | # extend a pcr |
---|
8 | # check list of pcrs; locally migrate the domain and |
---|
9 | # check list of pcrs again and validate extended pcr |
---|
10 | # This test does local live migration. |
---|
11 | |
---|
12 | from XmTestLib import * |
---|
13 | from vtpm_utils import * |
---|
14 | import commands |
---|
15 | import os |
---|
16 | import os.path |
---|
17 | |
---|
18 | config = {"vtpm":"instance=1,backend=0"} |
---|
19 | domain = XmTestDomain(extraConfig=config) |
---|
20 | domName = domain.getName() |
---|
21 | consoleHistory = "" |
---|
22 | |
---|
23 | try: |
---|
24 | console = domain.start() |
---|
25 | except DomainError, e: |
---|
26 | if verbose: |
---|
27 | print e.extra |
---|
28 | vtpm_cleanup(domName) |
---|
29 | FAIL("Unable to create domain (%s)" % domName) |
---|
30 | |
---|
31 | try: |
---|
32 | console.sendInput("input") |
---|
33 | except ConsoleError, e: |
---|
34 | saveLog(console.getHistory()) |
---|
35 | vtpm_cleanup(domName) |
---|
36 | FAIL(str(e)) |
---|
37 | |
---|
38 | try: |
---|
39 | run = console.runCmd("mknod /dev/tpm0 c 10 224") |
---|
40 | except ConsoleError, e: |
---|
41 | saveLog(console.getHistory()) |
---|
42 | vtpm_cleanup(domName) |
---|
43 | FAIL("Error while creating /dev/tpm0") |
---|
44 | |
---|
45 | try: |
---|
46 | run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > seq; cat seq > /dev/tpm0") |
---|
47 | except ConsoleError, e: |
---|
48 | saveLog(console.getHistory()) |
---|
49 | vtpm_cleanup(domName) |
---|
50 | FAIL("Error while extending PCR 0") |
---|
51 | |
---|
52 | try: |
---|
53 | run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs") |
---|
54 | except ConsoleError, e: |
---|
55 | saveLog(console.getHistory()) |
---|
56 | vtpm_cleanup(domName) |
---|
57 | FAIL("No result from dumping the PCRs") |
---|
58 | |
---|
59 | |
---|
60 | if re.search("No such file",run["output"]): |
---|
61 | vtpm_cleanup(domName) |
---|
62 | FAIL("TPM frontend support not compiled into (domU?) kernel") |
---|
63 | |
---|
64 | if not re.search("PCR-00:",run["output"]): |
---|
65 | saveLog(console.getHistory()) |
---|
66 | vtpm_cleanup(domName) |
---|
67 | FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"]) |
---|
68 | |
---|
69 | if not re.search("PCR-00: 1E A7 BD",run["output"]): |
---|
70 | saveLog(console.getHistory()) |
---|
71 | FAIL("Extend did not lead to expected result (1E A7 BD ...): \n%s" % run["output"]) |
---|
72 | |
---|
73 | consoleHistory = console.getHistory() |
---|
74 | domain.closeConsole() |
---|
75 | |
---|
76 | old_domid = domid(domName) |
---|
77 | |
---|
78 | loop = 0 |
---|
79 | while loop < 3: |
---|
80 | try: |
---|
81 | status, ouptut = traceCommand("xm migrate -l %s localhost" % |
---|
82 | domName, |
---|
83 | timeout=90) |
---|
84 | except TimeoutError, e: |
---|
85 | saveLog(consoleHistory) |
---|
86 | vtpm_cleanup(domName) |
---|
87 | FAIL(str(e)) |
---|
88 | |
---|
89 | if status != 0: |
---|
90 | saveLog(consoleHistory) |
---|
91 | vtpm_cleanup(domName) |
---|
92 | FAIL("xm migrate did not succeed. External device migration activated?") |
---|
93 | |
---|
94 | |
---|
95 | domName = domain.getName() |
---|
96 | new_domid = domid(domName) |
---|
97 | |
---|
98 | if (old_domid == new_domid): |
---|
99 | vtpm_cleanup(domName) |
---|
100 | FAIL("xm migrate failed, domain id is still %s (loop=%d)" % |
---|
101 | (old_domid,loop)) |
---|
102 | |
---|
103 | try: |
---|
104 | console = domain.getConsole() |
---|
105 | except ConsoleError, e: |
---|
106 | vtpm_cleanup(domName) |
---|
107 | FAIL(str(e)) |
---|
108 | |
---|
109 | try: |
---|
110 | run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs") |
---|
111 | except ConsoleError, e: |
---|
112 | saveLog(console.getHistory()) |
---|
113 | vtpm_cleanup(domName) |
---|
114 | FAIL("No result from dumping the PCRs") |
---|
115 | |
---|
116 | if not re.search("PCR-00:",run["output"]): |
---|
117 | saveLog(console.getHistory()) |
---|
118 | vtpm_cleanup(domName) |
---|
119 | FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side") |
---|
120 | |
---|
121 | if not re.search("PCR-00: 1E A7 BD",run["output"]): |
---|
122 | saveLog(console.getHistory()) |
---|
123 | vtpm_cleanup(domName) |
---|
124 | FAIL("Virtual TPM lost PCR 0 value: \n%s" % run["output"]) |
---|
125 | |
---|
126 | loop += 1 |
---|
127 | |
---|
128 | domain.closeConsole() |
---|
129 | |
---|
130 | domain.stop() |
---|
131 | |
---|
132 | vtpm_cleanup(domName) |
---|