source: trunk/packages/xen-3.1/xen-3.1/tools/xm-test/tests/security-acm/06_security-acm_dom_block_attach.py @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

  • Property svn:mime-type set to text/script
File size: 2.1 KB
Line 
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
10import re
11from XmTestLib import *
12from XmTestLib import block_utils
13from acm_utils import *
14
15testlabel1 = "blue"
16resource1 = "phy:ram1"
17resourcelabel1 = "blue"
18resource2 = "phy:/dev/ram0"
19resourcelabel2 = "red"
20
21if ENABLE_HVM_SUPPORT:
22    SKIP("Block-attach not supported for HVM domains")
23
24# Create a domain (default XmTestDomain, with our ramdisk)
25config = {"access_control":"policy=%s,label=%s" % (testpolicy,testlabel1)}
26
27domain = XmTestDomain(extraConfig=config)
28
29try:
30    console = domain.start()
31except DomainError, e:
32    FAIL(str(e))
33
34# Attach a console to it
35try:
36    console.setHistorySaveCmds(value=True)
37    # Run 'ls'
38    run = console.runCmd("ls")
39except ConsoleError, e:
40    saveLog(console.getHistory())
41    FAIL(str(e))
42
43
44# Explicitly label the 1st resource
45ACMLabelResource(resource1, resourcelabel1)
46block_utils.block_attach(domain, resource1, "xvda1")
47
48try:
49    run1 = console.runCmd("cat /proc/partitions")
50except ConsoleError, e:
51    FAIL(str(e))
52
53#Explicitly label the 2nd resource
54ACMLabelResource(resource2, resourcelabel2)
55#Cannot call block_attach here since we legally may fail the command
56status, output = traceCommand("xm block-attach %s %s %s w" %
57                               (domain.getName(), resource2, "xvda2" ))
58
59for i in range(10):
60    if block_utils.get_state(domain, "xvda2") == 4:
61        break
62    time.sleep(1)
63
64try:
65    run2 = console.runCmd("cat /proc/partitions")
66except ConsoleError, e:
67    FAIL(str(e))
68
69# Close the console
70domain.closeConsole()
71
72# Stop the domain (nice shutdown)
73domain.stop()
74
75if not re.search("xvda1",run1["output"]):
76    FAIL("Labeled device 'xvda1' is not actually connected to the domU")
77
78if not re.search("xvda1",run2["output"]):
79    FAIL("Labeled device 'xbvda1' has disappeared?!")
80
81if re.search("xvda2",run2["output"]):
82    FAIL("Labeled device 'xvda2' is connected to the domU but should not be")
Note: See TracBrowser for help on using the repository browser.