Skip to content

Commit 251d5bd

Browse files
authored
Merge pull request #6603 from meinaLi/sata_disk
Virtual disk: add sata product attribute test
2 parents d0fba1d + d7701f4 commit 251d5bd

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
- virtual_disks.product_info:
2+
type = virtual_disks_product
3+
start_vm = no
4+
target_disk = "sda"
5+
disk_bus = "sata"
6+
disk_type = "file"
7+
status_error = "no"
8+
variants:
9+
- sata_bus:
10+
func_supported_since_libvirt_ver = (11, 1, 0)
11+
disk_bus = "sata"
12+
variants:
13+
- positive_test:
14+
variants:
15+
- length_less_max:
16+
disk_product = "20BE0061MC20BE0061MC"
17+
- length_equal_max:
18+
disk_product = "20BE0061MC20BE0061MC20BE0061MC20BE0061MC"
19+
- negative_test:
20+
variants:
21+
- length_more_max:
22+
status_error = "yes"
23+
disk_product = "20BE0061MC20BE0061MC20BE0061MC20BE0061MC1"
24+
expected_error = "disk product is more than 40 characters"
25+
disk_dict = {"type_name":"${disk_type}", "target":{"dev": "${target_disk}", "bus": "${disk_bus}"}, "driver": {"name": "qemu", "type": "qcow2"}, "product": "${disk_product}"}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from ast import literal_eval
2+
3+
from virttest import libvirt_version
4+
from virttest import virsh
5+
from virttest.libvirt_xml import vm_xml, xcepts
6+
from virttest.utils_libvirt import libvirt_disk
7+
8+
from provider.virtual_disk import disk_base
9+
10+
11+
def run(test, params, env):
12+
"""
13+
Test disk with product info.
14+
15+
1. Define a guest with a disk include product info.
16+
2. Start guest.
17+
3. Login guest, check the disk info.
18+
4. Confirm that the product info is same as xml setting.
19+
"""
20+
def prepare_disk():
21+
"""
22+
Prepare the disk with product info.
23+
"""
24+
disk_dict = literal_eval(params.get("disk_dict", "{}"))
25+
expected_error = params.get("expected_error")
26+
status_error = "yes" == params.get("status_error", "no")
27+
try:
28+
disk_obj.add_vm_disk(disk_type, disk_dict)
29+
except xcepts.LibvirtXMLError as xml_error:
30+
if not status_error:
31+
test.fail(f"Failed to define VM:\n {str(xml_error)}")
32+
else:
33+
if expected_error and expected_error not in str(xml_error):
34+
test.fail(f"Expected error '{expected_error}' not found in"
35+
" actual error: {xml_error}")
36+
test.log.debug(f"Get expected error message:\n {expected_error}")
37+
return False
38+
return True
39+
40+
def check_guest():
41+
"""
42+
Check the disk info in guest.
43+
"""
44+
vm_session = vm.wait_for_login()
45+
new_disk, _ = libvirt_disk.get_non_root_disk_name(vm_session)
46+
sg_command = "sg_inq -p di -v /dev/%s" % new_disk
47+
sg_output = vm_session.cmd_output(sg_command)
48+
if disk_product not in sg_output:
49+
test.fail(f"Product info '{disk_product}' not found in command output: {sg_output}")
50+
else:
51+
test.log.debug("Product info found in guest as expected.")
52+
53+
libvirt_version.is_libvirt_feature_supported(params)
54+
vm_name = params.get("main_vm")
55+
disk_type = params.get("disk_type", "file")
56+
disk_product = params.get("disk_product")
57+
vm = env.get_vm(vm_name)
58+
59+
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
60+
backup_xml = vmxml.copy()
61+
disk_obj = disk_base.DiskBase(test, vm, params)
62+
63+
try:
64+
test.log.info("Start a guest with product info.")
65+
if not prepare_disk():
66+
return
67+
if not vm.is_alive():
68+
vm.start()
69+
test.log.debug(f"The current guest xml is: {virsh.dumpxml(vm_name).stdout_text}")
70+
test.log.info("Check the product info in guest.")
71+
check_guest()
72+
73+
finally:
74+
if vm.is_alive():
75+
vm.destroy()
76+
backup_xml.sync()
77+
disk_obj.cleanup_disk_preparation(disk_type)

0 commit comments

Comments
 (0)