-
Notifications
You must be signed in to change notification settings - Fork 173
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
disk_utilities: new functions provider #4219
base: master
Are you sure you want to change the base?
disk_utilities: new functions provider #4219
Conversation
a9a7080
to
b126ffe
Compare
@qingwangrh please, could you help reviewing this PR? Thanks ! |
provider/disk_utilities.py
Outdated
guest_cmd = guest_cmd.format(output_path) | ||
|
||
session.cmd(guest_cmd) | ||
vm.reboot() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qingwangrh I've tried many things after the reboot but it always complains about: Shell process terminated while waiting for command to complete
I am not sure if either the file doesn't exist or the the command is not working, do you have any suggestion here? I tried with a single dir {output_path}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the file check as first, it doesn't belong to the intention of this provider and second, it is not really needed if the dd command succeeds
FYI @qingwangrh
ee6ef9a
to
997fc06
Compare
idx_info = get_disk_props_by_serial_number(session, serial, ["Index"]) | ||
if idx_info: | ||
return idx_info["Index"] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest adding a function like get_disk_by_id or get_disk_by_serial. The ID may be the serial/www/device ID. It may handle different OSs. for windows it return disk idx, for linux , it return disk name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qingwangrh done!
if idx_info: | ||
return idx_info["Index"] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after the first function is ready, We can provide more functional encapsulation. like as
fake code:
init_disk_by_id(mountpoint=“1“,fstype=none):
“”“
mountpoint:
0 :it does not need mount
- auto select the mountpoint
other: user specify the mountpoint
“”“
id=get_disk_by_id
if not fstype:
fstype= ntfs if windows else xfs
format_disk_with_fstype
mount disk->mountpoint
return mountpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qingwangrh done!
provider/disk_utilities.py
Outdated
return guest_cmd | ||
|
||
|
||
def guest_fs_mount_and_dd_cmd(os_type, tmp_dir): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thinking. we may consider more powerful encapsulation, like as
execute_cmd_on_disk_by_id():
drv= init_disk_by_id
cmd=xxxxx
session_cmd ()
the utils provide different granularity functions, most cases may use execute_cmd_on_disk_by_id directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qingwangrh
Just one comment here, we may want to directly execute the command? or just return it? Because execution could be done on the test side e.g. after rebooting the VM and renewing the session
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the session and cmd as parameters, it could have two functions, 1 hardcode execute dd 2. execute cmd come from parameter.
I prefer the function 2. based on the function 2 , you may wrap the function 1
.
997fc06
to
f126ecf
Compare
@qingwangrh pleasae could you review again this PR? Thanks ! |
This is a kindly reminder, @qingwangrh please could you review again this PR? Thanks ! |
@yanan-fu and @YongxueHong could you also help reviewing this PR? Thanks ! |
provider/disk_utilities.py
Outdated
session.cmd(cmd) | ||
|
||
|
||
def execute_cmd_on_disk_by_id(params, disk_id, session, tmp_dir): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function hardcodes dd cmd, so I suggest to change the name to execute_dd_on_disk_by_id.
this function may cover the most user cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And could you please add a new execute_cmd_on_disk_by_id(params, disk_id, session, cmd) to support user defined cmd ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qingwangrh renamed the existing function and added a new one
provider/disk_utilities.py
Outdated
tmp_dir=tmp_dir, | ||
) | ||
if os_type == "windows": | ||
cmd = "dd if=/dev/urandom of={}:\\test.dat bs=1M count=10" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
count=10 ->count=100 to keep consistency with linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qingwangrh updated !
provider/disk_utilities.py
Outdated
session.cmd(cmd) | ||
|
||
|
||
def execute_cmd_on_disk_by_id(params, disk_id, session, tmp_dir): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parameter change to (params, disk_id, session, tmp_dir=None): most user they do not need to care the tmp_dir
the implementation may help to do the following:
if not tmp_dir:
tmp_dir="/var/tmp/"+disk_id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qingwangrh updated !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Creates a new file containing a set of functions useful for managing disks and filesystems in guest environments Signed-off-by: mcasquer <[email protected]>
f126ecf
to
41c59b2
Compare
We're approaching to the end of the quarter... again a kindly reminder, @yanan-fu @YongxueHong could you help reviewing this PR? Thanks ! |
from virttest.utils_windows.drive import get_disk_props_by_serial_number | ||
|
||
|
||
def get_disk_by_id(os_type, disk_id, session): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_disk_by_id(os_type, disk_id, session): | |
def get_disk_by_id(vm, os_type, disk_id): |
From my understanding, we want to provde an interface of VM for the user, so I suggest that we could specify the scope with the vm
argument, and then get the session object by the interface wait_for_login
of the vm
object inside the function.
Pls let me know your thougths.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mcasquer
I am a bit confused about the definition of the disk
object by calling get_disk_by_id
.
How do you define it? I think we are better to clarify what kind of information the user will get with the naming of the function. The concept disk
of get_disk_by_id
compares with it returns is a bit of generalization
Here, we can get the disk index inside Windows guest, and the disk path inside Linux guest.
So I think we could figure out and abstract out a name to represent such return value, for example: get_disk_xxxx_by_id
to let the users know how and where they can call it instead of reading the code to get to know which information they will get.
Feel free to share your thoughts. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YongxueHong what about get_disk_reference_by_id()
?
return utils_disk.configure_empty_disk(session, disk, img_size, "windows")[0] | ||
|
||
|
||
def mount_disk(disk, session, tmp_dir): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it does not support the Windows guest session.
:param img_size: The size of the image to be configured in Windows. | ||
:param session: The guest session. | ||
""" | ||
if fstype == "xfs": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Linux, there are several fs type it support, such as ext3, ext4, Btrfs, and others.
Do we just cover the xfs fs type? I suggest raising an error to let the user know we do not support other types besides xfs.
return driver | ||
|
||
|
||
def format_disk_by_fstype(disk, fstype, img_size, session): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mcasquer
Could you explain more about the purpose?
From your code, I see the different behaviors between Linux guest and Window guest.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, disk formatting is needed if we want to access to the disk inside the guest, please @qingwangrh correct me if I am wrong
session.cmd(f"umount {tmp_dir}") | ||
|
||
|
||
def execute_cmd_on_disk_by_id(params, disk_id, session, cmd, tmp_dir=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mcasquer
Could you provide more information about it?
Which scenario do you want to apply?
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function won't be used right now, but the idea is for the users to execute a command that applies to the specific guest disk, cc @qingwangrh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function won't be used right now, but the idea is for the users to execute a command that applies to the specific guest disk, cc @qingwangrh
Thanks for your explanation.
I suggest not adding it at this moment as there is no such place to call it, we could add it when we really need it.
The reason is that we need to collect the requirement for the interface and then we could design it well in order to satisfy the user's scenarios.
Please let me know your opinion.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YongxueHong I agree with you :) removing it
session.cmd(cmd) | ||
|
||
|
||
def execute_dd_on_disk_by_id(params, disk_id, session, tmp_dir=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like not only executes the dd command but also other jobs, like mount and umount here, but the name of the function mainly focuses on executing the dd command by the user's requirement, I think.
From my perspective, we just execute the dd command, not provide to customize the dd option for the user.
And we should make sure this function is the common interface as the provider module if we really want to create it.
Hi @mcasquer
Would you help to explain the reason for this function?
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YongxueHong here are all the steps needed to execute a dd command on a specific guest disk. If the function only does the dd it shouldn't be necessary because it will be the same as session.cmd("dd ...") so that's the reason of the function. I will add more info in the docstring, please @qingwangrh correct me if I am wrong
Hi @mcasquer |
from virttest.utils_windows.drive import get_disk_props_by_serial_number | ||
|
||
|
||
def get_disk_by_id(os_type, disk_id, session): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest use the same way to get os_type, os_type = params["os_type"]
from virttest.utils_windows.drive import get_disk_props_by_serial_number | ||
|
||
|
||
def get_disk_by_id(os_type, disk_id, session): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest use the same way to get os_type, os_type = params["os_type"]
def init_disk_by_id( | ||
mount_point="1", | ||
fstype=None, | ||
os_type="linux", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest use the same way to get os_type, os_type = params["os_type"]
return driver | ||
|
||
|
||
def format_disk_by_fstype(disk, fstype, img_size, session): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest set default value None for img_size.
disk_utilities: new functions provider
Creates a new file containing a set of functions
useful for managing disks and filesystems in guest
environments
Signed-off-by: mcasquer [email protected]
ID: 3118