mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
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@xensource.com>
This commit is contained in:
1 parent
4697d093c7
commit
aed92ee453
15 files changed
+88
-127
No files matched your search
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Copyright (c) 2006 XenSource Inc.
|
||||
# Author: Ewan Mellor <ewan@xensource.com>
|
||||
|
||||
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")
|
||||
@@ -3,11 +3,10 @@
|
||||
# Copyright (C) International Business Machines Corp., 2005
|
||||
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
|
||||
|
||||
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")
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
# Copyright (C) International Business Machines Corp., 2005
|
||||
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
|
||||
|
||||
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")
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
# Copyright (C) International Business Machines Corp., 2005
|
||||
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
|
||||
|
||||
import sys
|
||||
import re
|
||||
import time
|
||||
|
||||
from XmTestLib import *
|
||||
|
||||
|
||||
+3
-10
@@ -3,11 +3,10 @@
|
||||
# Copyright (C) International Business Machines Corp., 2005
|
||||
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
|
||||
|
||||
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!")
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
# Copyright (C) International Business Machines Corp., 2005
|
||||
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
|
||||
|
||||
import sys
|
||||
import re
|
||||
import time
|
||||
|
||||
from XmTestLib import *
|
||||
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
# Copyright (C) International Business Machines Corp., 2005
|
||||
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
|
||||
|
||||
import sys
|
||||
import re
|
||||
import time
|
||||
|
||||
from XmTestLib import *
|
||||
|
||||
|
||||
+3
-10
@@ -3,11 +3,10 @@
|
||||
# Copyright (C) International Business Machines Corp., 2005
|
||||
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
|
||||
|
||||
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!")
|
||||
|
||||
@@ -3,15 +3,14 @@
|
||||
# Copyright (C) International Business Machines Corp., 2005
|
||||
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# Author: Dan Smith <danms@us.ibm.com>
|
||||
|
||||
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 @@ except ConsoleError, e:
|
||||
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")
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# Author: Dan Smith <danms@us.ibm.com>
|
||||
|
||||
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 @@ except ConsoleError, e:
|
||||
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:
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# Author: Dan Smith <danms@us.ibm.com>
|
||||
|
||||
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 @@ except ConsoleError, e:
|
||||
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")
|
||||
|
||||
@@ -4,19 +4,10 @@
|
||||
# Author: Dan Smith <danms@us.ibm.com>
|
||||
|
||||
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())
|
||||
if s != 0:
|
||||
@@ -26,12 +17,6 @@ def checkXmLongList(domain):
|
||||
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 @@ try:
|
||||
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")
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
|
||||
# Copyright (C) International Business Machines Corp., 2005
|
||||
# Author: Li Ge <lge@us.ibm.com)
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# Author: Dan Smith <danms@us.ibm.com>
|
||||
|
||||
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 s != 0:
|
||||
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 s != 0:
|
||||
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 s != 0:
|
||||
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("769") != -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")
|
||||
|
||||