Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guest os booting: add hotplug case with boot order element #5222

Merged
merged 1 commit into from
Nov 27, 2023

Conversation

meinaLi
Copy link
Contributor

@meinaLi meinaLi commented Oct 12, 2023

This PR mainly implements the hotpluging of disk/usb/filesystem devices with boot order elements.

@meinaLi
Copy link
Contributor Author

meinaLi commented Oct 12, 2023

# avocado run --vt-type libvirt --test-runner=runner --vt-machine-type q35 guest_os_booting.boot_order.hotplug
JOB ID     : bc70ab994c4d27c90c0eb08ba786374e1b831ba0
JOB LOG    : /var/lib/avocado/job-results/job-2023-10-11T22.06-bc70ab9/job.log
 (1/3) type_specific.io-github-autotest-libvirt.guest_os_booting.boot_order.hotplug.disk_device: PASS (35.29 s)
 (2/3) type_specific.io-github-autotest-libvirt.guest_os_booting.boot_order.hotplug.usb_device: PASS (35.34 s)
 (3/3) type_specific.io-github-autotest-libvirt.guest_os_booting.boot_order.hotplug.filesystem_device: PASS (42.43 s)
RESULTS    : PASS 3 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB HTML   : /var/lib/avocado/job-results/job-2023-10-11T22.06-bc70ab9/results.html
JOB TIME   : 113.78 s

@meinaLi
Copy link
Contributor Author

meinaLi commented Oct 12, 2023

Depend on avocado-framework/avocado-vt#3778.

Copy link
Contributor

@cliping cliping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Others LGTM

def prepare_device_xml(vm_xml, device_type):
"""
Prepare the hot-plugged device xml.
:params device_type: the device type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miss vm_xml and return value docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

def check_dumpxml(vmxml, device_type, new_image_path):
"""
Check if the device is plugged and included the boot order element.
:params vmxml: the current guest xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

miss device_type and new_image_path docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Check if the device is plugged and included the boot order element.
:params vmxml: the current guest xml
:params device_type: the device type
:params new_image_path: the disk path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we directly use 'image_path'? I don't quite understand why we need a 'new_' param in this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can also directly use 'image_path'.

@Yingshun Yingshun added the depend on The PR has dependency on other PRs label Oct 31, 2023
Comment on lines 32 to 28
Prepare the hot-plugged device xml.
:params vm_xml: the instance of VMXML class
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz add a blank line between description and params, thx.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines 54 to 48
Check if the device is plugged and included the boot order element.
:params vmxml: the current guest xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz add a blank line between description and params, thx.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

check_dumpxml(vmxml, device_type, new_image_path)

test.log.info(f"STEP4: Hot-unplug the {device_type}.")
virsh.detach_device(vm_name, device_xml.xml, **virsh_dargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to wait for the events to make sure the devices are removed correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's better to wait to avoid the special situation. I've updated it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find the updates about waiting for the events, anything missed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I've added wait_for_event again.

Comment on lines 104 to 111
try:
libvirt_vmxml.check_guest_xml_by_xpaths(vmxml, order_xpath)
except exceptions.TestFail as detail:
test.log.debug(f"The device has been detached successfully because {detail}.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using 'try-except', it's better to set 'ignore_status' in libvirt_vmxml.check_guest_xml_by_xpaths().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I mainly check that the xpath is not in vmxml. So I used try-except. I think we can't use ignore_status. Could you help to check it again? Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you plz explain why you can't use 'ignore_status'? It was designed to avoid raising an exception when not matched. I'm not sure what your problem is, plz show us, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my understanding, we mainly use libvirt_vmxml.check_guest_xml_by_xpaths() to check it the xml is matched. If matched, it will pass. If unmatched, it will fail automatically. Is it right? Here I mainly check the detached xml, and hope it will pass when it unmatches. So I use exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with if statement.

Copy link
Contributor

@Yingshun Yingshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment above

@meinaLi meinaLi force-pushed the hotplug branch 2 times, most recently from 73668cf to b999ba0 Compare November 3, 2023 08:22
check_dumpxml(vmxml, device_type, new_image_path)

test.log.info(f"STEP4: Hot-unplug the {device_type}.")
virsh.detach_device(vm_name, device_xml.xml, **virsh_dargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find the updates about waiting for the events, anything missed?

Comment on lines 38 to 39
if not vm.is_alive():
virsh.start(vm_name, **virsh_dargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving L84~86 into L90 and deleting these 2 lines? I think we can merge these 2 vm startup steps into one. what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've merged the virsh.start in L84~86 before virsh.attach_device and removed the duplicated part in the function prepare_device_xml. I guess this is wat you are meaning. Please have a look again.

hpgs=False)
if not vm.is_alive():
virsh.start(vm_name, **virsh_dargs)
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not used, please remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.


test.log.info(f"STEP4: Hot-unplug the {device_type}.")
virsh.detach_device(vm_name, device_xml.xml, **virsh_dargs)
time.sleep(10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be removed if you update detach-device to wait for the events,right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Comment on lines 101 to 104
for xpath_text in order_xpath:
for boot_attrs in xpath_text['element_attrs']:
if vmxml.xmltreefile.findall(boot_attrs):
test.fail("The device hasn't been detached.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to only check order_xpath? Should it be checked like check_dumpxml() in this script? I wonder if you need to check the devices instead of 'boot attrs'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also updated the function check_dumpxml here to involve the hot-unplugging checking to replace these codes. In the functions, I directly used existed functions to check if the device existed, and also focused on the checking of boot order attributes.

@@ -0,0 +1,20 @@
- guest_os_booting.boot_order.hotplug:
type = hotplug
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meinaLi Can we have a proper name of these files? the current one is too common. what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to be much specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. And I've updated it to hotplug_device_with_boot_order.

device_xml, image_path = disk_obj.prepare_disk_obj("file", device_dict)
return device_xml, image_path

def check_dumpxml(device_type, image_path, hotplug=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter 'hotplug' is not quite easy to understand in this function, how about using expect,expected or status_error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't change it because here hotplug=True means we check the result after hotplugging. False means checking the result after hot-unplugging. So maybe no need to update it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @meinaLi , I think I can't agree with it. It is a common checking xml function, so I still think we should just focus on whether we expect the device to exist or not, rather than qualifying it at which test step it is executed. And also, hotplug=False does not directly mean to hotunplug, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing, I've updated it based on what we discussed.


def check_dumpxml(device_type, image_path, hotplug=True):
"""
Check if the device is plugged and included the boot order element.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugged -> existed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Copy link
Contributor

@Yingshun Yingshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above.

"""
Check if the device is existed and included the boot order element.

:params vmxml: the current guest xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no vmxml, plz remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

This PR mainly implements the hotpluging of disk/usb/filesystem devices with boot order elements.

Signed-off-by: Meina Li <[email protected]>
@Yingshun Yingshun merged commit 4fe9ba2 into autotest:master Nov 27, 2023
5 checks passed
@meinaLi meinaLi deleted the hotplug branch November 27, 2023 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
depend on The PR has dependency on other PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants