debuggers.hg

view tools/xm-test/lib/XmTestLib/block_utils.py @ 17952:c5875621d79a

Fix up python breakage for blkdev_name_to_number

Signed-off-by: Chris Lalancette <clalance@redhat.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jun 30 10:01:44 2008 +0100 (2008-06-30)
parents 05bf8693c735
children
line source
1 #!/usr/bin/python
3 # Copyright (c) 2006 XenSource Inc.
4 # Author: Ewan Mellor <ewan@xensource.com>
6 import time
8 from XmTestLib import *
9 from acm import *
11 import xen.util.blkif
14 __all__ = [ "block_attach", "block_detach" ]
17 def get_state(domain, devname):
18 (path, 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)
29 def 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)
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")
44 def 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)
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")