[kvm-autotest]client.tests.kvm.tests.cgroup: Add TestDeviceAccess subtest

2011-10-24 Thread Lukas Doktor
Hi guys,

I have a new subtest which tests the 'devices' cgroup subsystem and improve the 
logging a bit.

Please find the pull request on github:
https://github.com/autotest/autotest/pull/48

Cheers,
Lukáš

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [kvm-autotest]client.tests.kvm.tests.cgroup: Add TestDeviceAccess subtest

2011-10-24 Thread Lukas Doktor
This subtest tries to attach scsi_debug disk with different cgroup
devices.list setting.

 * subtests the devices.{allow, deny, list} cgroup functionality
 * new function get_maj_min(dev) which returns (major, minor) numbers
   of dev
 * rm_drive: support for rm_device without drive (only remove the host
   file)
 * improved logging

Signed-off-by: Lukas Doktor ldok...@redhat.com
---
 client/tests/kvm/tests/cgroup.py |  234 +-
 1 files changed, 203 insertions(+), 31 deletions(-)

diff --git a/client/tests/kvm/tests/cgroup.py b/client/tests/kvm/tests/cgroup.py
index 6c64532..c83f91a 100644
--- a/client/tests/kvm/tests/cgroup.py
+++ b/client/tests/kvm/tests/cgroup.py
@@ -50,7 +50,7 @@ def run_cgroup(test, params, env):
 return abs(float(actual-reference) / reference)
 
 
-def get_dd_cmd(direction, dev='vd?', count=None, bs=None):
+def get_dd_cmd(direction, dev=None, count=None, bs=None):
 
 Generates dd_cmd string
 @param direction: {read,write,bi} dd direction
@@ -59,6 +59,11 @@ def run_cgroup(test, params, env):
 @param bs: bs parameter of dd
 @return: dd command string
 
+if dev is None:
+if get_device_driver() == virtio:
+dev = 'vd?'
+else:
+dev = '[sh]d?'
 if direction == read:
 params = if=$FILE of=/dev/null iflag=direct
 elif direction == write:
@@ -82,6 +87,21 @@ def run_cgroup(test, params, env):
 return params.get('drive_format', 'virtio')
 
 
+def get_maj_min(dev):
+
+Returns the major and minor numbers of the dev device
+@return: Tupple(major, minor) numbers of the dev device
+
+try:
+ret = utils.system_output(ls -l %s % dev)
+ret = re.match(r'[bc][rwx-]{9} \d+ \w+ \w+ (\d+), (\d+)',
+   ret).groups()
+except Exception, details:
+raise error.TestFail(Couldn't get %s maj and min numbers: %s %
+  (dev, details))
+return ret
+
+
 def add_file_drive(vm, driver=get_device_driver(), host_file=None):
 
 Hot-add a drive based on file to a vm
@@ -173,14 +193,17 @@ def run_cgroup(test, params, env):
 
 err = False
 # TODO: Implement also via QMP
-vm.monitor.cmd(pci_del %s % device)
-time.sleep(3)
-qtree = vm.monitor.info('qtree', debug=False)
-if qtree.count('addr %s.0' % device) != 0:
-err = True
-vm.destroy()
-
-if isinstance(host_file, str):# scsi device
+if device:
+vm.monitor.cmd(pci_del %s % device)
+time.sleep(3)
+qtree = vm.monitor.info('qtree', debug=False)
+if qtree.count('addr %s.0' % device) != 0:
+err = True
+vm.destroy()
+
+if host_file is None:   # Do not remove
+pass
+elif isinstance(host_file, str):# scsi device
 utils.system(echo -1 
/sys/bus/pseudo/drivers/scsi_debug/add_host)
 else: # file
 host_file.close()
@@ -334,7 +357,7 @@ def run_cgroup(test, params, env):
 _TestBlkioBandwidth.__init__(self, vms, modules)
 # Read from the last vd* in a loop until test removes the
 # /tmp/cgroup_lock file (and kills us)
-self.dd_cmd = get_dd_cmd(read, bs=100K)
+self.dd_cmd = get_dd_cmd(read, dev='vd?', bs=100K)
 
 
 class TestBlkioBandwidthWeigthWrite(_TestBlkioBandwidth):
@@ -350,7 +373,7 @@ def run_cgroup(test, params, env):
 # Write on the last vd* in a loop until test removes the
 # /tmp/cgroup_lock file (and kills us)
 _TestBlkioBandwidth.__init__(self, vms, modules)
-self.dd_cmd = get_dd_cmd(write, bs=100K)
+self.dd_cmd = get_dd_cmd(write, dev='vd?', bs=100K)
 
 
 class _TestBlkioThrottle:
@@ -376,10 +399,6 @@ def run_cgroup(test, params, env):
 self.devices = None # Temporary virt devices (PCI drive 1 per vm)
 self.dd_cmd = None  # DD command used to test the throughput
 self.speeds = None  # cgroup throughput
-if get_device_driver() == virtio:
-self.dev = vd?
-else:
-self.dev = [sh]d?
 
 def cleanup(self):
 
@@ -417,13 +436,8 @@ def run_cgroup(test, params, env):
 driver=virtio)
 else:
 (self.files, self.devices) = add_scsi_drive(self.vm)
-try:
-dev = utils.system_output(ls -l %s % self.files).split()[4:6]
-dev[0] = dev[0][:-1]# Remove tailing ','
-except:
-time.sleep(5)
-raise error.TestFail(Couldn't get %s maj and min numbers
- %