virt: Support for indirect image_name definition
Hi,
this patch adds support for indirect image_name specification. The purpose is to set wildcard + offset instead of the exact name.
I'm using it for testing devices I add in the test. Eg. I use pre_script = "modprobe scsi_debug" which adds new /dev/sg? device. I know it's the last device so I can set the wildcard "/dev/sg?" and offset '-1'.
To prevent data loss I added blacklist with support for re which protects /dev/sda.* /dev/hda.* ...
For details please see the patch.
Pull request page:
https://github.com/autotest/autotest/pull/308
Regards,
Lukáš Doktor
PATCH 1/1 virt: Support for indirect image_name definition
This patch adds a support to specify the disk image by re + select instead of the image_name.
Params:
indirect_image_select: Index of the disk from list matching disks
image_name: regular expression (ls $image_name)
Usage:
images += " stg"
image_name_stg = "/dev/sd*"
image_raw_device_stg = yes
image_format_stg = raw
drive_index_stg = 3
drive_format_stg = scsi-block
indirect_image_select_stg = -1
--- client/virt/base.cfg.sample | 2 ++ client/virt/virt_vm.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 0 deletions(-)
client/virt/base.cfg.sample +2 -0
@@ -248,3 +248,5 @@ netdev_peer_re = "\s{2,}(.*?): .*?\\\s(.*?):" image_clone_commnad = 'cp --reflink=auto %s %s' image_remove_commnad = 'rm -rf %s' + +indirect_image_blacklist = "/dev/hda.* /dev/sda.* /dev/sg0 /dev/md0"
client/virt/virt_vm.py +22 -0
@@ -310,8 +310,30 @@ def get_image_filename(params, root_dir): @note: params should contain: image_name -- the name of the image file, without extension image_format -- the format of the image (qcow2, raw etc) + @raise VMDeviceError: When no matching disk found (in indirect method). """ image_name = params.get("image_name", "image") + indirect_image_select = params.get("indirect_image_select") + if indirect_image_select: + re_name = image_name + indirect_image_select = int(indirect_image_select) + matching_images = utils.system_output("ls -1d %s" % re_name) + matching_images = sorted(matching_images.split('\n')) + if matching_images[-1] == '': + matching_images = matching_images[:-1] + try: + image_name = matching_images[indirect_image_select] + except IndexError: + raise VMDeviceError("No matching disk found for name = '%s', " + "matching = '%s' and selector = '%s'" % + (re_name, matching_images, + indirect_image_select)) + for protected in params.get('indirect_image_blacklist', '').split(' '): + if re.match(protected, image_name): + raise VMDeviceError("Matching disk is in blacklist. name = '%s" + "', matching = '%s' and selector = '%s'" % + (re_name, matching_images, + indirect_image_select)) image_format = params.get("image_format", "qcow2") if params.get("image_raw_device") == "yes": return image_name
Signature · 1 line
1.7.7.6