ia64/xen-unstable

view tools/xm-test/tests/security-acm/01_security-acm_basic.py @ 11902:d27d1f8ca25c

[ACM] An environment where ACM and its tools have not been installed before
will throw an error during 'make' of the test suite. This fixes the problem.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author kfraser@localhost.localdomain
date Thu Oct 19 15:15:36 2006 +0100 (2006-10-19)
parents 4ecfbf08b449
children 7ef821ff6d89
line source
1 #!/usr/bin/python
3 # Copyright (C) International Business Machines Corp., 2006
4 # Author: Stefan Berger <stefanb@us.ibm.com>
5 #
6 # A couple of simple tests that test ACM security extensions
7 # for the xm tool. The following xm subcommands are tested:
8 #
9 # - makepolicy
10 # - labels
11 # - rmlabel
12 # - addlabel
13 # - getlabel
14 # - resources
16 from XmTestLib import *
17 from xen.util import security
18 import commands
19 import os
20 import re
22 testpolicy = "xm-test"
23 testlabel = "blue"
24 vmconfigfile = "/tmp/xm-test.conf"
25 testresource = "phy:ram0"
27 if not isACMEnabled():
28 SKIP("Not running this test since ACM not enabled.")
30 status, output = traceCommand("xm makepolicy %s" % (testpolicy))
31 if status != 0 or output != "":
32 FAIL("'xm makepolicy' failed with status %d and output\n%s" %
33 (status,output));
35 status, output = traceCommand("xm labels %s" % (testpolicy))
36 if status != 0:
37 FAIL("'xm labels' failed with status %d.\n" % status)
39 #Need to get a vm config file - just have it written to a file
40 domain = XmTestDomain()
41 domain.config.write(vmconfigfile)
43 #Whatever label it might have - remove it
44 status, output = traceCommand("xm rmlabel dom %s" %
45 (vmconfigfile))
47 status, output = traceCommand("xm addlabel %s dom %s %s" %
48 (testlabel, vmconfigfile, testpolicy))
49 if status != 0:
50 FAIL("'xm addlabel' failed with status %d.\n" % status)
52 status, output = traceCommand("xm getlabel dom %s" %
53 (vmconfigfile))
55 if status != 0:
56 FAIL("'xm getlabel' failed with status %d, output:\n%s" %
57 (status, output))
58 if output != "policy=%s,label=%s" % (testpolicy,testlabel):
59 FAIL("Received unexpected output from 'xm getlabel': \n%s" %
60 (output))
63 status, output = traceCommand("xm rmlabel dom %s" %
64 (vmconfigfile))
66 if status != 0:
67 FAIL("'xm rmlabel' failed with status %d, output: \n%s" %
68 (status,output))
69 if output != "":
70 FAIL("Received unexpected output from 'xm rmlabel': \n%s" %
71 (output))
73 status, output = traceCommand("xm getlabel dom %s" %
74 (vmconfigfile))
76 if output != "Error: 'Domain not labeled'":
77 FAIL("Received unexpected output from 'xm getlabel': \n%s" %
78 (output))
80 #Whatever label the resource might have, remove it
81 status, output = traceCommand("xm rmlabel res %s" %
82 (testresource))
84 status, output = traceCommand("xm addlabel %s res %s %s" %
85 (testlabel, testresource, testpolicy))
86 if status != 0:
87 FAIL("'xm addlabel' on resource failed with status %d.\n" % status)
89 status, output = traceCommand("xm getlabel res %s" % (testresource))
91 if status != 0:
92 FAIL("'xm getlabel' on resource failed with status %d, output:\n%s" %
93 (status, output))
94 if output != "policy=%s,label=%s" % (testpolicy,testlabel):
95 FAIL("Received unexpected output from 'xm getlabel': \n%s" %
96 (output))
98 status, output = traceCommand("xm resources")
100 if status != 0:
101 FAIL("'xm resources' did not run properly")
102 if not re.search(security.unify_resname(testresource), output):
103 FAIL("'xm resources' did not show the tested resource '%s'." %
104 testresource)
106 status, output = traceCommand("xm rmlabel res %s" %
107 (testresource))
109 if status != 0:
110 FAIL("'xm rmlabel' on resource failed with status %d, output: \n%s" %
111 (status,output))
112 if output != "":
113 FAIL("Received unexpected output from 'xm rmlabel': \n%s" %
114 (output))
116 status, output = traceCommand("xm getlabel res %s" %
117 (testresource))
119 if output != "Error: 'Resource not labeled'":
120 FAIL("Received unexpected output from 'xm getlabel': \n%s" %
121 (output))