source: trunk/packages/xen-3.1/xen-3.1/tools/xm-test/lib/XmTestLib/block_utils.py @ 34

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

Add xen and xen-common

  • Property svn:mime-type set to text/script
File size: 1.4 KB
Line 
1#!/usr/bin/python
2
3# Copyright (c) 2006 XenSource Inc.
4# Author: Ewan Mellor <ewan@xensource.com>
5
6import time
7
8from XmTestLib import *
9from acm import *
10
11import xen.util.blkif
12
13
14__all__ = [ "block_attach", "block_detach" ]
15
16
17def get_state(domain, devname):
18    number = xen.util.blkif.blkdev_name_to_number(devname)
19    s, o = traceCommand("xm block-list %s | awk '/^%d/ {print $4}'" %
20                        (domain.getName(), number))
21    if s != 0:
22        FAIL("block-list failed")
23    if o == "":
24        return 0
25    else:
26        return int(o)
27
28
29def block_attach(domain, phy, virt):
30    ACMLabelResource(phy)
31    status, output = traceCommand("xm block-attach %s %s %s w" %
32                                  (domain.getName(), phy, virt))
33    if status != 0:
34        FAIL("xm block-attach returned invalid %i != 0" % status)
35
36    for i in range(10):
37        if get_state(domain, virt) == 4:
38            break
39        time.sleep(1)
40    else:
41        FAIL("block-attach failed: device did not switch to Connected state")
42
43
44def block_detach(domain, virt):
45    status, output = traceCommand("xm block-detach %s %s" %
46                                  (domain.getName(), virt))
47    if status != 0:
48        FAIL("xm block-detach returned invalid %i != 0" % status)
49
50    for i in range(10):
51        if get_state(domain, virt) == 0:
52            break
53        time.sleep(1)
54    else:
55        FAIL("block-detach failed: device did not disappear")
Note: See TracBrowser for help on using the repository browser.