3
Copyright (C) International Business Machines Corp., 2006
4
Author: Stefan Berger <stefanb@us.ibm.com>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; under version 2 of the License.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
import xen.util.xsm.xsm as security
22
from xen.xm.main import server
23
from xen.util import xsconstants
27
from acm_config import *
29
ACM_LABEL_RESOURCES = False
31
labeled_resources = {}
39
def setCurrentPolicy(plcy):
44
cmd='xm dumppolicy | grep -E "^POLICY REFERENCE = ' + policy + '.$"'
45
s, o = traceCommand(cmd)
48
s, o = traceCommand("xm setpolicy ACM %s" % (policy))
50
FAIL("Could not load the required policy '%s'.\n"
51
"Start the system without any policy.\n%s" % \
54
def ACMPrepareSystem(resources):
57
ACMLabelResources(resources)
59
def ACMLabelResources(resources):
60
for k, v in resources.items():
63
res = vv.split(',')[0]
66
# Applications may label resources explicitly by calling this function
67
def ACMLabelResource(resource, label='red'):
68
if not isACMEnabled():
71
print "labeling resource %s with label %s" % (resource, label)
72
if not ACM_LABEL_RESOURCES:
73
SKIP("Skipping test since not allowed to label resources in "
75
if not isACMResourceLabeled(resource):
76
ACMUnlabelResource(resource)
77
s, o = traceCommand("xm addlabel %s res %s" % (label, resource))
79
FAIL("Could not add label to resource")
81
labeled_resources["%s" % resource] = 1
84
# Application may remove a label from a resource. It has to call this
85
# function and must do so once a resource for re-labeling a resource
86
def ACMUnlabelResource(resource):
87
s, o = traceCommand("xm rmlabel res %s" % (resource))
88
labeled_resources["%s" % resource] = 0
91
def isACMResourceLabeled(resource):
92
""" Check whether a resource has been labeled using this API
93
and while running the application """
95
if labeled_resources["%s" % resource] == 1:
97
print "resource %s already labeled!" % resource