Additional tests for the xm-test suite
PATCH 1/1 Additional tests for the xm-test suite
This adds a couple of test cases exercising the new policy management functionality to the security tests.
--- xen-unstable.hg/tools/xm-test/lib/XmTestLib/XenAPIDomain.py | 4 xen-unstable.hg/tools/xm-test/lib/XmTestLib/acm.py | 52 + xen-unstable.hg/tools/xm-test/tests/security-acm/01_security-acm_basic.py | 24 xen-unstable.hg/tools/xm-test/tests/security-acm/07_security-acm_pol_update.py | 303 +++++++ xen-unstable.hg/tools/xm-test/tests/security-acm/08_security-acm_xapi.py | 354 ++++++++ xen-unstable.hg/tools/xm-test/tests/security-acm/09_security-acm_pol_update.py | 427 ++++++++++ xen-unstable.hg/tools/xm-test/tests/security-acm/Makefile.am | 5 xen-unstable.hg/tools/xm-test/tests/security-acm/xm-test-new-security_policy.xml | 97 ++ xen-unstable.hg/tools/xm-test/tests/vtpm/vtpm_utils.py | 4 9 files changed, 1250 insertions(+), 20 deletions(-)
xen-unstable.hg/tools/xm-test/lib/XmTestLib/acm.py +43 -9
@@ -19,6 +19,9 @@ """ from Test import * from xen.util import security +from xen.xm.main import server +from xen.util import xsconstants +import re try: from acm_config import *
@@ -32,16 +35,47 @@ def isACMEnabled(): return security.on() +def getSystemPolicyName(): + s,o = traceCommand("xm getpolicy") + m = re.compile("Policy name[\s]*: ([A-z\-]+)").search(o) + if m: + polname = m.group(1) + return polname + return "" + + +def ACMLoadPolicy_XenAPI(policy='xm-test'): + polname = getSystemPolicyName() + if polname != policy: + # Try it, maybe it's not activated + traceCommand("xm setpolicy %s %s" % + (xsconstants.XS_POLICY_ACM, policy)) + polname = getSystemPolicyName() + if polname != policy: + FAIL("Need to have a system with no or policy '%s' active, " + "not %s" % (policy,polname)) + else: + s, o = traceCommand("xm activatepolicy --load") + else: + s, o = traceCommand("xm activatepolicy --load") + if not re.search("Successfully", o): + FAIL("Could not set the policy '%s'." % policy) + + def ACMLoadPolicy(policy='xm-test'): - s, o = traceCommand("xm makepolicy %s" % (policy)) - if s != 0: - FAIL("Need to be able to do 'xm makepolicy %s' but could not" % - (policy)) - s, o = traceCommand("xm loadpolicy %s" % (policy)) - if s != 0: - FAIL("Could not load the required policy '%s'.\n" - "Start the system without any policy.\n%s" % - (policy, o)) + from xen.xm import main + if main.serverType == main.SERVER_XEN_API: + ACMLoadPolicy_XenAPI() + else: + s, o = traceCommand("xm makepolicy %s" % (policy)) + if s != 0: + FAIL("Need to be able to do 'xm makepolicy %s' but could not" % + (policy)) + s, o = traceCommand("xm loadpolicy %s" % (policy)) + if s != 0: + FAIL("Could not load the required policy '%s'.\n" + "Start the system without any policy.\n%s" % + (policy, o)) def ACMPrepareSystem(resources): if isACMEnabled():
xen-unstable.hg/tools/xm-test/tests/vtpm/vtpm_utils.py +3 -1
@@ -15,4 +15,6 @@ if output == "": "need /dev/tpm0") def vtpm_cleanup(domName): - traceCommand("/etc/xen/scripts/vtpm-delete %s" % domName) + from xen.xm import main + if main.serverType != main.SERVER_XEN_API: + traceCommand("/etc/xen/scripts/vtpm-delete %s" % domName)
xen-unstable.hg/tools/xm-test/tests/security-acm/08_security-acm_xapi.py new file +239 -0
239 lines not on this page · raw message
+#
+# Suspend the domain and relabel it
+#
+
+try:
+ status, output = traceCommand("xm suspend %s" % domName,
+ timeout=30)
+except TimeoutError, e:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("Failure from suspending VM: %s." % str(e))
+
+# Try to relabel while VM is suspended -- this should work +
+rc = session.xenapi.VM.set_security_label(vm_uuid, vm_label_green,
+ vm_label_red)
+if int(rc) != 0:
+ FAIL("VM security label could not be set to %s" % vm_label_green)
+
+res = session.xenapi.VM.get_security_label(vm_uuid)
+if res != vm_label_green:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("VM (suspended) has label '%s', expected '%s'." %
+ (res, vm_label_green))
+
+status, output = traceCommand("xm list")
+
+#Try to resume now -- should fail due to denied access to block device +try:
+ status, output = traceCommand("xm resume %s" % domName,
+ timeout=30)
+ if status == 0:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("Could resume re-labeled VM: %s" % output)
+except Exception, e:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("1. Error resuming the VM: %s." % str(e))
+
+# Relabel VM so it would resume
+res = session.xenapi.VM.set_security_label(vm_uuid, vm_label_red,
+ vm_label_green)
+if int(res) != 0:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("Could not relabel VM to have it resume.")
+
+res = session.xenapi.VM.get_security_label(vm_uuid)
+if res != vm_label_red:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("VM (suspended) has label '%s', expected '%s'." %
+ (res, vm_label_red))
+
+
+# Relabel the resource so VM should not resume
+try:
+ session.xenapi.XSPolicy.set_resource_label(vdi_path,
+ vdi_label_green,
+ "")
+except Exception, e:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("Could not label the VDI to '%s': %x" %
+ (vdi_label_green, int(rc)))
+
+#Try to resume now -- should fail due to denied access to block device +try:
+ status, output = traceCommand("xm resume %s" % domName,
+ timeout=30)
+ if status == 0:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("Could resume re-labeled VM: %s" % output)
+except Exception, e:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("2. Error resuming the VM: %s." % str(e))
+
+
+status, output = traceCommand("xm list")
+
+# Relabel the resource so VM can resume
+try:
+ session.xenapi.XSPolicy.set_resource_label(vdi_path,
+ vdi_label_red,
+ vdi_label_green)
+except Exception, e:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("Could not label the resource to '%s'" % vid_label_red)
+
+res = session.xenapi.XSPolicy.get_resource_label(vdi_path) +if res != vdi_label_red:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("'%s' has label '%s', expected '%s'." %
+ (vdi_path, res, vdi_label_red))
+
+#Try to resume now -- should work
+try:
+ status, output = traceCommand("xm resume %s" % domName,
+ timeout=30)
+ if status != 0:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("Could not resume re-labeled VM: %s" % output)
+except Exception, e:
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("3. Error resuming the VM: %s." % str(e))
+
+
+status, output = traceCommand("xm list")
+
+console = domain.getConsole()
+
+try:
+ run = console.runCmd("cat /proc/interrupts")
+except ConsoleError, e:
+ saveLog(console.getHistory())
+ session.xenapi.VDI.destroy(vdi_ref)
+ FAIL("Could not access proc-filesystem")+
+domain.stop()
+domain.destroy()
xen-unstable.hg/tools/xm-test/tests/security-acm/Makefile.am +4 -1
@@ -5,7 +5,10 @@ TESTS = 01_security-acm_basic.test \ 03_security-acm_dom_conflict.test \ 04_security-acm_dom_res.test \ 05_security-acm_dom_res_conf.test \ - 06_security-acm_dom_block_attach.test + 06_security-acm_dom_block_attach.test \ + 07_security-acm_pol_update.test \ + 08_security-acm_xapi.test \ + 09_security-acm_pol_update.test XFAIL_TESTS =
xen-unstable.hg/tools/xm-test/tests/security-acm/07_security-acm_pol_update.py new file +303 -0
303 lines not on this page · raw message
xen-unstable.hg/tools/xm-test/tests/security-acm/01_security-acm_basic.py +15 -9
@@ -15,6 +15,7 @@ from XmTestLib import * from xen.util import security +from xen.util import xsconstants import commands import os import re
@@ -28,7 +29,7 @@ if not isACMEnabled(): SKIP("Not running this test since ACM not enabled.") status, output = traceCommand("xm makepolicy %s" % (testpolicy)) -if status != 0 or output != "": +if status != 0: FAIL("'xm makepolicy' failed with status %d and output\n%s" % (status,output));
@@ -47,7 +48,7 @@ status, output = traceCommand("xm rmlabe status, output = traceCommand("xm addlabel %s dom %s %s" % (testlabel, vmconfigfile, testpolicy)) if status != 0: - FAIL("'xm addlabel' failed with status %d.\n" % status) + FAIL("(1) 'xm addlabel' failed with status %d.\n" % status) status, output = traceCommand("xm getlabel dom %s" % (vmconfigfile))
@@ -55,8 +56,9 @@ status, output = traceCommand("xm getlab if status != 0: FAIL("'xm getlabel' failed with status %d, output:\n%s" % (status, output)) -if output != "policy=%s,label=%s" % (testpolicy,testlabel): - FAIL("Received unexpected output from 'xm getlabel': \n%s" % +if output != "policytype=%s,policy=%s,label=%s" % \ + (xsconstants.ACM_POLICY_ID, testpolicy, testlabel): + FAIL("(1) Received unexpected output from 'xm getlabel dom': \n%s" % (output))
@@ -74,30 +76,34 @@ status, output = traceCommand("xm getlab (vmconfigfile)) if output != "Error: 'Domain not labeled'": - FAIL("Received unexpected output from 'xm getlabel': \n%s" % + FAIL("(2) Received unexpected output from 'xm getlabel dom': \n%s" % (output)) #Whatever label the resource might have, remove it status, output = traceCommand("xm rmlabel res %s" % (testresource)) +if status != 0: + FAIL("'xm rmlabel' on resource failed with status %d.\n" % status) status, output = traceCommand("xm addlabel %s res %s %s" % (testlabel, testresource, testpolicy)) if status != 0: - FAIL("'xm addlabel' on resource failed with status %d.\n" % status) + FAIL("(2) 'xm addlabel' on resource failed with status %d.\n" % status) status, output = traceCommand("xm getlabel res %s" % (testresource)) if status != 0: FAIL("'xm getlabel' on resource failed with status %d, output:\n%s" % (status, output)) -if output != "policy=%s,label=%s" % (testpolicy,testlabel): - FAIL("Received unexpected output from 'xm getlabel': \n%s" % +if output != "%s:%s:%s" % (xsconstants.ACM_POLICY_ID,\ + testpolicy,testlabel): + FAIL("Received unexpected output from 'xm getlabel res': \n%s" % (output)) status, output = traceCommand("xm resources") if status != 0: + print "status = %s" % str(status) FAIL("'xm resources' did not run properly") if not re.search(security.unify_resname(testresource), output): FAIL("'xm resources' did not show the tested resource '%s'." %
@@ -117,5 +123,5 @@ status, output = traceCommand("xm getlab (testresource)) if output != "Error: 'Resource not labeled'": - FAIL("Received unexpected output from 'xm getlabel': \n%s" % + FAIL("Received unexpected output from 'xm getlabel res': \n%s" % (output))
xen-unstable.hg/tools/xm-test/tests/security-acm/09_security-acm_pol_update.py new file +427 -0
427 lines not on this page · raw message
xen-unstable.hg/tools/xm-test/lib/XmTestLib/XenAPIDomain.py +4 -0
@@ -23,6 +23,7 @@ import os import sys from XmTestLib import * from types import DictType +from acm import * class XenAPIConfig:
@@ -38,6 +39,9 @@ class XenAPIConfig: 'kernel' : 'PV_kernel', 'ramdisk': 'PV_ramdisk', 'root' : 'PV_args'} + if isACMEnabled(): + #A default so every VM can start with ACM enabled + self.opts["security_label"] = "ACM:xm-test:red" def setOpt(self, name, value): """Set an option in the config"""
xen-unstable.hg/tools/xm-test/tests/security-acm/xm-test-new-security_policy.xml new file +97 -0
97 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel