1 | #!/usr/bin/python |
---|
2 | |
---|
3 | # Copyright (C) International Business Machines Corp., 2005 |
---|
4 | # Author: Stefan Berger <stefanb@us.ibm.com> |
---|
5 | # Based on block-create/01_block_attach_device_pos.py |
---|
6 | # |
---|
7 | # Create a domain and attach 2 resources to it. The first resource |
---|
8 | # should be attacheable, the 2nd one should not be due to the label it has. |
---|
9 | |
---|
10 | import re |
---|
11 | from XmTestLib import * |
---|
12 | from XmTestLib import block_utils |
---|
13 | from acm_utils import * |
---|
14 | |
---|
15 | testlabel1 = "blue" |
---|
16 | resource1 = "phy:ram1" |
---|
17 | resourcelabel1 = "blue" |
---|
18 | resource2 = "phy:/dev/ram0" |
---|
19 | resourcelabel2 = "red" |
---|
20 | |
---|
21 | if ENABLE_HVM_SUPPORT: |
---|
22 | SKIP("Block-attach not supported for HVM domains") |
---|
23 | |
---|
24 | # Create a domain (default XmTestDomain, with our ramdisk) |
---|
25 | config = {"access_control":"policy=%s,label=%s" % (testpolicy,testlabel1)} |
---|
26 | |
---|
27 | domain = XmTestDomain(extraConfig=config) |
---|
28 | |
---|
29 | try: |
---|
30 | console = domain.start() |
---|
31 | except DomainError, e: |
---|
32 | FAIL(str(e)) |
---|
33 | |
---|
34 | # Attach a console to it |
---|
35 | try: |
---|
36 | console.setHistorySaveCmds(value=True) |
---|
37 | # Run 'ls' |
---|
38 | run = console.runCmd("ls") |
---|
39 | except ConsoleError, e: |
---|
40 | saveLog(console.getHistory()) |
---|
41 | FAIL(str(e)) |
---|
42 | |
---|
43 | |
---|
44 | # Explicitly label the 1st resource |
---|
45 | ACMLabelResource(resource1, resourcelabel1) |
---|
46 | block_utils.block_attach(domain, resource1, "xvda1") |
---|
47 | |
---|
48 | try: |
---|
49 | run1 = console.runCmd("cat /proc/partitions") |
---|
50 | except ConsoleError, e: |
---|
51 | FAIL(str(e)) |
---|
52 | |
---|
53 | #Explicitly label the 2nd resource |
---|
54 | ACMLabelResource(resource2, resourcelabel2) |
---|
55 | #Cannot call block_attach here since we legally may fail the command |
---|
56 | status, output = traceCommand("xm block-attach %s %s %s w" % |
---|
57 | (domain.getName(), resource2, "xvda2" )) |
---|
58 | |
---|
59 | for i in range(10): |
---|
60 | if block_utils.get_state(domain, "xvda2") == 4: |
---|
61 | break |
---|
62 | time.sleep(1) |
---|
63 | |
---|
64 | try: |
---|
65 | run2 = console.runCmd("cat /proc/partitions") |
---|
66 | except ConsoleError, e: |
---|
67 | FAIL(str(e)) |
---|
68 | |
---|
69 | # Close the console |
---|
70 | domain.closeConsole() |
---|
71 | |
---|
72 | # Stop the domain (nice shutdown) |
---|
73 | domain.stop() |
---|
74 | |
---|
75 | if not re.search("xvda1",run1["output"]): |
---|
76 | FAIL("Labeled device 'xvda1' is not actually connected to the domU") |
---|
77 | |
---|
78 | if not re.search("xvda1",run2["output"]): |
---|
79 | FAIL("Labeled device 'xbvda1' has disappeared?!") |
---|
80 | |
---|
81 | if re.search("xvda2",run2["output"]): |
---|
82 | FAIL("Labeled device 'xvda2' is connected to the domU but should not be") |
---|