From f0e70fe5983ac7af78fe900f8b30bb2da49c57d4 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Wed, 5 Aug 2009 13:36:24 +0100 Subject: xm-test: 10_block_attach_detach_multiple_devices fixed This patch fixes and (re-)enables test 10 of the block-create suite. The tests by random attach and detach devices to / from a domU and checks if everything is ok. Signed-off-by: Andreas Florath --- .../10_block_attach_dettach_multiple_devices.py | 71 ++++++++++++---------- tools/xm-test/tests/block-create/Makefile.am | 1 + 2 files changed, 40 insertions(+), 32 deletions(-) (limited to 'tools/xm-test') diff --git a/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py b/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py index 3ac6078388..58c70673f7 100644 --- a/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py +++ b/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py @@ -1,40 +1,42 @@ #!/usr/bin/python # Copyright (C) International Business Machines Corp., 2005 -# Author: Murillo F. Bernardes +# Copyright (C) flonatel GmbH & Co. KG, 2009 +# Authors: Murillo F. Bernardes +# Andreas Florath + +# Block devices are by random attached to and detached from the domU. import re import random from xen.util import blkif -from os import path.basename +from os.path import basename from XmTestLib import * from XmTestLib.block_utils import * def availableRamdisks(): - i = 0 - while os.access("/dev/ram%d" % i, os.F_OK ): - i += 1 - - return i + i=0 + while os.access("/dev/ram%d" % i, os.F_OK): + i+=1 + return i-1 def attach(phy, devname): 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!" - + return -2, "Failed to attach block device: " \ + + "/proc/partitions does not show that!" return 0, None def detach(devname): block_detach(domain, devname) - run = console.runCmd("cat /proc/partitions") if re.search(basename(devname), run["output"]): - return -2, "Failed to detach block device: /proc/partitions still showing that!" - + return -2, "Failed to detach block device: " \ + + "/proc/partitions still showing that!" return 0, None if ENABLE_HVM_SUPPORT: @@ -58,34 +60,39 @@ try: except ConsoleError, e: saveLog(console.getHistory()) FAIL(str(e)) - -ramdisks = availableRamdisks()-1 -print "ramdisks=%d" % ramdisks -i = 0 -devices = [] +ramdisk_cnt = availableRamdisks() -while i < ramdisks or devices: - op = random.randint(0,1) # 1 = attach, 0 = detach - if (not devices or op) and i < ramdisks: - i += 1 - devname = "/dev/xvda%d" % i - phy = "/dev/ram%d" % i - print "Attaching %s to %s" % (devname, phy) - status, msg = attach( phy, devname ) +detached = range(0, ramdisk_cnt) +attached = [] + +def attach_device(): + n = random.choice(detached) + status, msg = attach("ram%d" % n, "xvda%d" % n) if status: FAIL(msg) - else: - devices.append(devname) + detached.remove(n) + attached.append(n) - elif devices: - devname = random.choice(devices) - devices.remove(devname) - print "Detaching %s" % devname - status, msg = detach(devname) +def detach_device(): + n = random.choice(attached) + status, msg = detach("xvda%d" % n) if status: FAIL(msg) + detached.append(n) + attached.append(n) + +# First attach some +for i in xrange(0, ramdisk_cnt/2): + attach_device() +for i in xrange(0, ramdisk_cnt*5): + op = random.randint(0,1) # 1 = attach, 0 = detach + if op: + detach_device() + else: + attach_device() + # Close the console domain.closeConsole() diff --git a/tools/xm-test/tests/block-create/Makefile.am b/tools/xm-test/tests/block-create/Makefile.am index 7459cb9f49..c9b41f6f3d 100644 --- a/tools/xm-test/tests/block-create/Makefile.am +++ b/tools/xm-test/tests/block-create/Makefile.am @@ -9,6 +9,7 @@ TESTS = 01_block_attach_device_pos.test \ 07_block_attach_baddevice_neg.test \ 08_block_attach_bad_filedevice_neg.test \ 09_block_attach_and_dettach_device_check_data_pos.test \ + 10_block_attach_dettach_multiple_devices.test \ 11_block_attach_shared_dom0.test \ 12_block_attach_shared_domU.test -- cgit v1.2.3