# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID bf56c745515fa0953cf28cea21ecb1a7107f7576
# Parent 491f3f48704e32e695b787541bd4e64ada3f8df9
Abstract block-attach and block-detach calls, and add to that the correct
polling waiting for the device to connect and disconnect.
Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
tools/xm-test/lib/XmTestLib/block_utils.py
| 53 ++++++++++
tools/xm-test/tests/block-create/01_block_attach_device_pos.py
| 7 -
tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py
| 7 -
tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py
| 2
tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py
| 13 --
tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py
| 2
tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py
| 2
tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py
| 13 --
tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py
| 21 +--
tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py
| 7 -
tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py
| 12 --
tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py
| 7 -
tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py
| 41 -------
tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py
| 9 -
tools/xm-test/tests/block-list/06_block-list_checkremove_pos.py
| 19 ---
15 files changed, 88 insertions(+), 127 deletions(-)
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-create/01_block_attach_device_pos.py
--- a/tools/xm-test/tests/block-create/01_block_attach_device_pos.py Sat May
06 15:42:12 2006 +0100
+++ b/tools/xm-test/tests/block-create/01_block_attach_device_pos.py Sun May
07 13:34:45 2006 +0100
@@ -3,11 +3,10 @@
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@xxxxxxxxxx>
-import sys
import re
-import time
from XmTestLib import *
+from XmTestLib.block_utils import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-attach not supported for HVM domains")
@@ -33,9 +32,7 @@ except ConsoleError, e:
FAIL(str(e))
-status, output = traceCommand("xm block-attach %s phy:ram1 sdb1 w" %
domain.getName())
-if status != 0:
- FAIL("xm block-attach returned invalid %i != 0" % status)
+block_attach(domain, "phy:ram1", "sdb1")
try:
run = console.runCmd("cat /proc/partitions")
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py
--- a/tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py
Sat May 06 15:42:12 2006 +0100
+++ b/tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py
Sun May 07 13:34:45 2006 +0100
@@ -3,11 +3,10 @@
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@xxxxxxxxxx>
-import sys
import re
-import time
from XmTestLib import *
+from XmTestLib.block_utils import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-attach not supported for HVM domains")
@@ -33,9 +32,7 @@ except ConsoleError, e:
FAIL(str(e))
-status, output = traceCommand("xm block-attach %s file:/dev/ram1 sdb2 w" %
domain.getName())
-if status != 0:
- FAIL("xm block-attach returned invalid %i != 0" % status)
+block_attach(domain, "file:/dev/ram1", "sdb2")
try:
run = console.runCmd("cat /proc/partitions")
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py
--- a/tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py
Sat May 06 15:42:12 2006 +0100
+++ b/tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py
Sun May 07 13:34:45 2006 +0100
@@ -3,9 +3,7 @@
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@xxxxxxxxxx>
-import sys
import re
-import time
from XmTestLib import *
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py
---
a/tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py
Sat May 06 15:42:12 2006 +0100
+++
b/tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py
Sun May 07 13:34:45 2006 +0100
@@ -3,11 +3,10 @@
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@xxxxxxxxxx>
-import sys
import re
-import time
from XmTestLib import *
+from XmTestLib.block_utils import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-attach not supported for HVM domains")
@@ -33,18 +32,12 @@ except ConsoleError, e:
for i in range(10):
- status, output = traceCommand("xm block-attach %s phy:ram1 sdb1 w" %
domain.getName())
- if status != 0:
- FAIL("xm block-attach returned invalid %i != 0" % status)
- # verify that it comes
+ block_attach(domain, "phy:ram1", "sdb1")
run = console.runCmd("cat /proc/partitions")
if not re.search("sdb1", run["output"]):
FAIL("Failed to attach block device: /proc/partitions does not
show that!")
- status, output = traceCommand("xm block-detach %s 2065" %
domain.getName())
- if status != 0:
- FAIL("xm block-detach returned invalid %i != 0" % status)
- # verify that it goes
+ block_detach(domain, "sdb1")
run = console.runCmd("cat /proc/partitions")
if re.search("sdb1", run["output"]):
FAIL("Failed to dettach block device: /proc/partitions still
showing that!")
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py
--- a/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py Sat May
06 15:42:12 2006 +0100
+++ b/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py Sun May
07 13:34:45 2006 +0100
@@ -3,9 +3,7 @@
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@xxxxxxxxxx>
-import sys
import re
-import time
from XmTestLib import *
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py
--- a/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py
Sat May 06 15:42:12 2006 +0100
+++ b/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py
Sun May 07 13:34:45 2006 +0100
@@ -3,9 +3,7 @@
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@xxxxxxxxxx>
-import sys
import re
-import time
from XmTestLib import *
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py
---
a/tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py
Sat May 06 15:42:12 2006 +0100
+++
b/tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py
Sun May 07 13:34:45 2006 +0100
@@ -3,11 +3,10 @@
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@xxxxxxxxxx>
-import sys
import re
-import time
from XmTestLib import *
+from XmTestLib.block_utils import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-attach not supported for HVM domains")
@@ -36,10 +35,7 @@ if s != 0:
FAIL("mke2fs returned %i != 0" % s)
for i in range(10):
- status, output = traceCommand("xm block-attach %s phy:ram1 hda1 w" %
domain.getName())
- if status != 0:
- FAIL("xm block-attach returned invalid %i != 0" % status)
- # verify that it comes
+ block_attach(domain, "phy:ram1", "hda1")
run = console.runCmd("cat /proc/partitions")
if not re.search("hda1", run["output"]):
FAIL("Failed to attach block device: /proc/partitions does not
show that!")
@@ -56,10 +52,7 @@ for i in range(10):
print run['output']
console.runCmd("umount /mnt/hda1")
- status, output = traceCommand("xm block-detach %s 769" %
domain.getName())
- if status != 0:
- FAIL("xm block-detach returned invalid %i != 0" % status)
- # verify that it goes
+ block_detach(domain, "hda1")
run = console.runCmd("cat /proc/partitions")
if re.search("hda1", run["output"]):
FAIL("Failed to dettach block device: /proc/partitions still
showing that!")
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py
---
a/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py
Sat May 06 15:42:12 2006 +0100
+++
b/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py
Sun May 07 13:34:45 2006 +0100
@@ -3,15 +3,14 @@
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@xxxxxxxxxx>
-import sys
import re
-import time
import random
from xen.util import blkif
from os import path.basename
from XmTestLib import *
+from XmTestLib.block_utils import *
def availableRamdisks():
i = 0
@@ -21,11 +20,7 @@ def availableRamdisks():
return i
def attach(phy, devname):
- # Attach
- status, output = traceCommand("xm block-attach %s phy:%s %s w" %
(domain.getName(), phy, devname))
- if status != 0:
- return -1, "xm block-attach returned invalid %i != 0" % status
-
+ block_attach(domain, "phy:%s" % phy, devname)
run = console.runCmd("cat /proc/partitions")
if not re.search(basename(devname), run["output"]):
return -2, "Failed to attach block device: /proc/partitions does not
show that!"
@@ -33,16 +28,12 @@ def attach(phy, devname):
return 0, None
-def dettach(devname):
- devnum = blkif.blkdev_name_to_number(devname)
-
- status, output = traceCommand("xm block-detach %s %d" % (domain.getName(),
devnum))
- if status != 0:
- return -1, "xm block-attach returned invalid %i != 0" % status
+def detach(devname):
+ block_detach(domain, devname)
run = console.runCmd("cat /proc/partitions")
if re.search(basename(devname), run["output"]):
- return -2, "Failed to dettach block device: /proc/partitions still
showing that!"
+ return -2, "Failed to detach block device: /proc/partitions still
showing that!"
return 0, None
@@ -91,7 +82,7 @@ while i < ramdisks or devices:
devname = random.choice(devices)
devices.remove(devname)
print "Detaching %s" % devname
- status, msg = dettach(devname)
+ status, msg = detach(devname)
if status:
FAIL(msg)
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py
--- a/tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py Sat May
06 15:42:12 2006 +0100
+++ b/tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py Sun May
07 13:34:45 2006 +0100
@@ -4,6 +4,7 @@
# Author: Dan Smith <danms@xxxxxxxxxx>
from XmTestLib import *
+from XmTestLib.block_utils import block_detach
if ENABLE_HVM_SUPPORT:
SKIP("Block-detach not supported for HVM domains")
@@ -28,11 +29,7 @@ if run["return"] != 0:
if run["return"] != 0:
FAIL("block device isn't attached; can't detach!")
-status, output = traceCommand("xm block-detach %s 769" % domain.getName(),
- logOutput=True)
-if status != 0:
- FAIL("block-detach returned invalid %i != 0" % status)
-
+block_detach(domain, "hda1")
try:
run = console.runCmd("cat /proc/partitions | grep hda1")
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py
--- a/tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py Sat May
06 15:42:12 2006 +0100
+++ b/tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py Sun May
07 13:34:45 2006 +0100
@@ -4,6 +4,7 @@
# Author: Dan Smith <danms@xxxxxxxxxx>
from XmTestLib import *
+from XmTestLib.block_utils import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-detach not supported for HVM domains")
@@ -17,11 +18,7 @@ except DomainError, e:
print e.extra
FAIL("Unable to create domain")
-status, output = traceCommand("xm block-attach %s phy:/dev/ram0 hda1 w" %
domain.getName())
-if status != 0:
- FAIL("Failed to attach block device")
- pass
-
+block_attach(domain, "phy:/dev/ram0", "hda1")
try:
run = console.runCmd("cat /proc/partitions | grep hda1")
except ConsoleError, e:
@@ -31,10 +28,7 @@ if run["return"] != 0:
if run["return"] != 0:
FAIL("Failed to verify that block dev is attached")
-status, output = traceCommand("xm block-detach %s 769" % domain.getName())
-if status != 0:
- FAIL("block-detach returned invalid %i != 0" % status)
-
+block_detach(domain, "hda1")
try:
run = console.runCmd("cat /proc/partitions | grep hda1")
except ConsoleError, e:
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py
--- a/tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py Sat May
06 15:42:12 2006 +0100
+++ b/tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py Sun May
07 13:34:45 2006 +0100
@@ -4,6 +4,7 @@
# Author: Dan Smith <danms@xxxxxxxxxx>
from XmTestLib import *
+from XmTestLib.block_utils import block_detach
if ENABLE_HVM_SUPPORT:
SKIP("Block-detach not supported for HVM domains")
@@ -27,11 +28,7 @@ if run["return"] != 0:
if run["return"] != 0:
FAIL("block device isn't attached; can't detach!")
-status, output = traceCommand("xm block-detach %s hda1" % domain.getName(),
- logOutput=True)
-if status != 0:
- FAIL("block-detach returned invalid %i != 0" % status)
-
+block_detach(domain, "hda1")
try:
run = console.runCmd("cat /proc/partitions | grep hda1")
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py
--- a/tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py
Sat May 06 15:42:12 2006 +0100
+++ b/tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py
Sun May 07 13:34:45 2006 +0100
@@ -4,18 +4,9 @@
# Author: Dan Smith <danms@xxxxxxxxxx>
from XmTestLib import *
+from XmTestLib.block_utils import *
-import time
import re
-
-def checkBlockList(domain):
- s, o = traceCommand("xm block-list %s" % domain.getName())
- if s != 0:
- FAIL("block-list failed")
- if re.search("769", o):
- return True
- else:
- return False
def checkXmLongList(domain):
s, o = traceCommand("xm list --long %s" % domain.getName())
@@ -25,12 +16,6 @@ def checkXmLongList(domain):
return True
else:
return False
-
-def checkBlockState(domain):
- s, o = traceCommand("xm block-list %s | awk '{print $4}' |tail -n 1" %
domain.getName())
- if s != 0:
- FAIL("block-list failed")
- return int(o)
if ENABLE_HVM_SUPPORT:
SKIP("Block-detach not supported for HVM domains")
@@ -42,32 +27,12 @@ except DomainError,e:
except DomainError,e:
FAIL(str(e))
-s, o = traceCommand("xm block-attach %s phy:/dev/ram0 hda1 w" %
domain.getName())
-if s != 0:
- FAIL("block-attach failed")
-
-if not checkBlockList(domain):
- FAIL("block-list does not show that hda1 was attached")
+block_attach(domain, "phy:/dev/ram0", "hda1")
if not checkXmLongList(domain):
FAIL("xm long list does not show that hda1 was attached")
-for i in range(1, 10):
- time.sleep(1)
- state = checkBlockState(domain)
- if state == 4:
- break
-
-s, o = traceCommand("xm block-detach %s hda1" % domain.getName())
-if s != 0:
- FAIL("block-detach failed")
-
-time.sleep(2)
-
-if checkBlockList(domain):
- FAIL("block-list does not show that hda1 was removed")
+block_detach(domain, "hda1")
if checkXmLongList(domain):
FAIL("xm long list does not show that hda1 was removed")
-
-
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py
--- a/tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py Sat May
06 15:42:12 2006 +0100
+++ b/tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py Sun May
07 13:34:45 2006 +0100
@@ -1,5 +1,5 @@
#!/usr/bin/python
-
+
# Copyright (C) International Business Machines Corp., 2005
# Author: Li Ge <lge@xxxxxxxxxx)
@@ -7,12 +7,13 @@
from XmTestLib import *
+from XmTestLib.block_utils import block_attach
if ENABLE_HVM_SUPPORT:
SKIP("Block-list not supported for HVM domains")
domain = XmTestDomain()
-
+
try:
console = domain.start()
except DomainError, e:
@@ -21,9 +22,7 @@ except DomainError, e:
FAIL("Unable to create domain")
#Attach one virtual block device to domainU
-status, output = traceCommand("xm block-attach %s phy:/dev/ram0 hda1 w" %
domain.getId())
-if status != 0:
- FAIL("Fail to attach block device")
+block_attach(domain, "phy:/dev/ram0", "hda1")
#Verify block-list on Domain0
status, output = traceCommand("xm block-list %s" % domain.getId())
diff -r 491f3f48704e -r bf56c745515f
tools/xm-test/tests/block-list/06_block-list_checkremove_pos.py
--- a/tools/xm-test/tests/block-list/06_block-list_checkremove_pos.py Sat May
06 15:42:12 2006 +0100
+++ b/tools/xm-test/tests/block-list/06_block-list_checkremove_pos.py Sun May
07 13:34:45 2006 +0100
@@ -4,6 +4,7 @@
# Author: Dan Smith <danms@xxxxxxxxxx>
from XmTestLib import *
+from XmTestLib.block_utils import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-list not supported for HVM domains")
@@ -21,9 +22,7 @@ if o:
if o:
FAIL("block-list without devices reported something!")
-s, o = traceCommand("xm block-attach %s phy:/dev/ram0 hda1 w" %
domain.getName())
-if s != 0:
- FAIL("Unable to attach /dev/ram0->hda1")
+block_attach(domain, "phy:/dev/ram0", "hda1")
s, o = traceCommand("xm block-list %s" % domain.getName())
if s != 0:
@@ -31,9 +30,7 @@ if o.find("769") == -1:
if o.find("769") == -1:
FAIL("block-list didn't show the block device I just attached!")
-s, o = traceCommand("xm block-attach %s phy:/dev/ram1 hda2 w" %
domain.getName())
-if s != 0:
- FAIL("Unable to attach /dev/ram1->hda2")
+block_attach(domain, "phy:/dev/ram1", "hda2")
s, o = traceCommand("xm block-list %s" % domain.getName())
if s != 0:
@@ -41,11 +38,8 @@ if o.find("770") == -1:
if o.find("770") == -1:
FAIL("block-list didn't show the other block device I just attached!")
-s, o = traceCommand("xm block-detach %s 769" % domain.getName())
-if s != 0:
- FAIL("block-detach of hda1 failed")
+block_detach(domain, "hda1")
-time.sleep(1)
s, o = traceCommand("xm block-list %s" % domain.getName())
if s != 0:
FAIL("block-list failed after detaching a device")
@@ -54,11 +48,8 @@ if o.find("770") == -1:
if o.find("770") == -1:
FAIL("hda2 not shown after detach of hda1!")
-s, o = traceCommand("xm block-detach %s 770" % domain.getName())
-if s != 0:
- FAIL("block-detach of hda2 failed")
+block_detach(domain, "hda2")
-time.sleep(1)
s, o = traceCommand("xm block-list %s" % domain.getName())
if s != 0:
FAIL("block-list failed after detaching another device")
diff -r 491f3f48704e -r bf56c745515f tools/xm-test/lib/XmTestLib/block_utils.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/xm-test/lib/XmTestLib/block_utils.py Sun May 07 13:34:45
2006 +0100
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+
+# Copyright (c) 2006 XenSource Inc.
+# Author: Ewan Mellor <ewan@xxxxxxxxxxxxx>
+
+import time
+
+from XmTestLib import *
+
+import xen.util.blkif
+
+
+__all__ = [ "block_attach", "block_detach" ]
+
+
+def get_state(domain, devname):
+ number = xen.util.blkif.blkdev_name_to_number(devname)
+ s, o = traceCommand("xm block-list %s | awk '/^%d/ {print $4}'" %
+ (domain.getName(), number))
+ if s != 0:
+ FAIL("block-list failed")
+ if o == "":
+ return 0
+ else:
+ return int(o)
+
+
+def block_attach(domain, phy, virt):
+ status, output = traceCommand("xm block-attach %s %s %s w" %
+ (domain.getName(), phy, virt))
+ if status != 0:
+ FAIL("xm block-attach returned invalid %i != 0" % status)
+
+ for i in range(10):
+ if get_state(domain, virt) == 4:
+ break
+ time.sleep(1)
+ else:
+ FAIL("block-attach failed: device did not switch to Connected state")
+
+
+def block_detach(domain, virt):
+ status, output = traceCommand("xm block-detach %s %s" %
+ (domain.getName(), virt))
+ if status != 0:
+ FAIL("xm block-detach returned invalid %i != 0" % status)
+
+ for i in range(10):
+ if get_state(domain, virt) == 0:
+ break
+ time.sleep(1)
+ else:
+ FAIL("block-detach failed: device did not disappear")
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|