提交 224afa22 编写于 作者: L lolyu

dd_test: add different block size

add different block size, which will execute multiple dd test
based on the block sizes provided.
1. use extra parameter to specify partition size.
2. add readonly=off.
3. add dd I/O flag: direct.
Signed-off-by: Nlolyu <lolyu@redhat.com>
上级 4f1b203b
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
only Linux only Linux
type = dd_test type = dd_test
images += " stg1" images += " stg1"
create_image_stg1 = yes force_create_image_stg1 = yes
image_name_stg1 = images/stg1 image_name_stg1 = images/stg1
image_size_stg1 = 1M image_size_stg1 = 20G
image_snapshot_stg1 = no image_snapshot_stg1 = no
image_readonly_stg1 = no
drive_index_stg1 = 3 drive_index_stg1 = 3
image_boot_stg1 = no image_boot_stg1 = no
blk_extra_params_stg1 = "serial=TARGET_DISK0" blk_extra_params_stg1 = "serial=TARGET_DISK0"
...@@ -39,3 +40,16 @@ ...@@ -39,3 +40,16 @@
dd_if = stg1 dd_if = stg1
dd_of = NULL dd_of = NULL
dd_stat = 0 dd_stat = 0
- multiple:
partition_size = 2G
variants:
- zero2disk:
dd_if = ZERO
dd_of = stg1
dd_bs = "4k 8k 16k 64k 128k 256k 4M 1G"
dd_oflag = direct
- disk2null:
dd_if = stg1
dd_of = NULL
dd_bs = "4k 8k 16k 64k 128k 256k 4M 1G"
dd_iflag = direct
...@@ -4,12 +4,20 @@ Configurable on-guest dd test. ...@@ -4,12 +4,20 @@ Configurable on-guest dd test.
:author: Lukas Doktor <ldoktor@redhat.com> :author: Lukas Doktor <ldoktor@redhat.com>
:copyright: 2012 Red Hat, Inc. :copyright: 2012 Red Hat, Inc.
""" """
import os
import re
import logging import logging
import aexpect import aexpect
from virttest import error_context
from virttest import utils_misc from virttest import utils_misc
from virttest import utils_disk
from virttest import utils_numeric
from virttest import error_context
try:
from itertools import zip_longest as zip_longest
except Exception:
from itertools import izip_longest as zip_longest
@error_context.context_aware @error_context.context_aware
...@@ -60,62 +68,105 @@ def run(test, params, env): ...@@ -60,62 +68,105 @@ def run(test, params, env):
error_context.context("Wait guest boot up", logging.info) error_context.context("Wait guest boot up", logging.info)
session = vm.wait_for_login(timeout=timeout) session = vm.wait_for_login(timeout=timeout)
dd_if = params.get("dd_if") dd_keys = ['dd_if', 'dd_of', 'dd_bs', 'dd_count', 'dd_iflag',
dd_if_select = int(params.get("dd_if_select", '-1')) 'dd_oflag', 'dd_skip', 'dd_seek']
dd_of = params.get("dd_of")
dd_of_select = int(params.get("dd_of_select", '-1'))
dd_bs = params.get("dd_bs")
dd_count = params.get("dd_count")
dd_iflag = params.get("dd_iflag")
dd_oflag = params.get("dd_oflag")
dd_skip = params.get("dd_skip")
dd_seek = params.get("dd_seek")
dd_timeout = int(params.get("dd_timeout", 60)) dd_params = {key: params.get(key, None) for key in dd_keys}
if dd_params['dd_bs'] is None:
dd_params['dd_bs'] = '512'
dd_params['dd_bs'] = dd_params['dd_bs'].split()
bs_count = len(dd_params['dd_bs'])
dd_timeout = int(params.get("dd_timeout", 180))
dd_output = params.get("dd_output", "") dd_output = params.get("dd_output", "")
dd_stat = int(params.get("dd_stat", 0)) dd_stat = int(params.get("dd_stat", 0))
dd_cmd = "dd" dev_partitioned = []
if dd_if: for arg in ['dd_if', 'dd_of']:
dd_if = _get_file(dd_if, dd_if_select) filename = dd_params[arg]
dd_cmd += " if=%s" % dd_if path = _get_file(filename,
if dd_of: int(params.get('%s_select' % arg, '-1')))
dd_of = _get_file(dd_of, dd_of_select) if (bs_count > 1
dd_cmd += " of=%s" % dd_of and filename in params.objects('images')):
if dd_bs: psize = float(
dd_cmd += " bs=%s" % dd_bs utils_numeric.normalize_data_size(
if dd_count: params.get("partition_size", '2G')
dd_cmd += " count=%s" % dd_count )
if dd_iflag: )
dd_cmd += " iflag=%s" % dd_iflag start = 0.0
if dd_oflag: dev_id = os.path.split(path)[-1]
dd_cmd += " oflag=%s" % dd_oflag dev_partitioned.append(dev_id)
if dd_skip:
dd_cmd += " skip=%s" % dd_skip utils_disk.create_partition_table_linux(session, dev_id, 'gpt')
if dd_seek: for i in range(bs_count):
dd_cmd += " seek=%s" % dd_seek utils_disk.create_partition_linux(session, dev_id,
logging.info("Using '%s' cmd", dd_cmd) '%fM' % psize,
'%fM' % start)
error_context.context("Execute dd in guest", logging.info) start += psize
disks = utils_disk.get_linux_disks(session, partition=True)
partitions = [key for key in disks if
re.match(r'%s\d+$' % dev_id, key)]
partitions.sort()
dd_params[arg] = [path.replace(dev_id, part)
for part in partitions]
else:
dd_params[arg] = [path]
if bs_count > 1 and not dev_partitioned:
test.error('with multiple bs, either dd_if or \
dd_of must be a block device')
dd_cmd = ['dd']
for key in dd_keys:
value = dd_params[key]
if value is None:
continue
arg = key.split('_')[-1]
if key in ['dd_if', 'dd_of', 'dd_bs']:
part = '%s=%s' % (arg, '{}')
else:
part = '%s=%s' % (arg, value)
dd_cmd.append(part)
dd_cmd = ' '.join(dd_cmd)
remaining = [dd_params[key] for key in ['dd_if', 'dd_of', 'dd_bs']]
if len(dd_params['dd_if']) != bs_count:
fillvalue = dd_params['dd_if'][-1]
else:
fillvalue = dd_params['dd_of'][-1]
cmd = [dd_cmd.format(*t) for t in
zip_longest(*remaining, fillvalue=fillvalue)]
cmd = ' & '.join(cmd)
logging.info("Using '%s' cmd", cmd)
try: try:
(stat, out) = session.cmd_status_output(dd_cmd, timeout=dd_timeout) error_context.context("Execute dd in guest", logging.info)
except aexpect.ShellTimeoutError: try:
err = ("dd command timed-out (cmd='%s', timeout=%d)" (stat, out) = session.cmd_status_output(cmd, timeout=dd_timeout)
% (dd_cmd, dd_timeout)) except aexpect.ShellTimeoutError:
test.fail(err) err = ("dd command timed-out (cmd='%s', timeout=%d)"
except aexpect.ShellCmdError as details: % (cmd, dd_timeout))
stat = details.status test.fail(err)
out = details.output except aexpect.ShellCmdError as details:
stat = details.status
error_context.context("Check command exit status and output", logging.info) out = details.output
logging.debug("Returned dd_status: %s\nReturned output:\n%s", stat, out)
if stat != dd_stat: error_context.context("Check command exit status and output",
err = ("Return code doesn't match (expected=%s, actual=%s)\n" logging.info)
"Output:\n%s" % (dd_stat, stat, out)) logging.debug("Returned dd_status: %s\nReturned output:\n%s",
test.fail(err) stat, out)
if dd_output not in out: if stat != dd_stat:
err = ("Output doesn't match:\nExpected:\n%s\nActual:\n%s" err = ("Return code doesn't match (expected=%s, actual=%s)\n"
% (dd_output, out)) "Output:\n%s" % (dd_stat, stat, out))
test.fail(err) test.fail(err)
logging.info("dd test succeeded.") if dd_output not in out:
err = ("Output doesn't match:\nExpected:\n%s\nActual:\n%s"
% (dd_output, out))
test.fail(err)
logging.info("dd test succeeded.")
finally:
for dev_id in dev_partitioned:
utils_disk.clean_partition_linux(session, dev_id)
session.close()
vm.destroy(gracefully=True)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册