-
Notifications
You must be signed in to change notification settings - Fork 259
utils_net: add get_dhcp_client for dhcp commands #4278
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThis change adds a new public function Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Pre-merge checks✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)virttest/utils_net.py (2)
🪛 Ruff (0.14.7)virttest/utils_net.py1704-1704: Function call with (S604) 1710-1710: Avoid specifying long messages outside the exception class (TRY003) ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
1. Introduce "get_dhcp_client" function. 2. utils_net: update network functions to use "get_dhcp_client". Signed-off-by: Wenli Quan <wquan@redhat.com>
| """ | ||
| dhcp_clients = [("dhclient", "-r"), ("dhcpcd", "-k")] | ||
|
|
||
| for cmd, release_cmd in dhcp_clients: |
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.
Please change the naming from 'release_cmd' to 'release_flag'; IMO, release_cmd = f"{cmd} {release_flag}". If you agree, please change it here and also where it's used further below.
| :param timeout: timeout value for command. | ||
| """ | ||
| if os_type == "linux": | ||
| dhcp_clients = [("dhclient", "-r"), ("dhcpcd", "-k")] |
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.
Are these commands equivalent? If so, please mention it in the commit message and bring some proof that you tested that.
| cmd = ( | ||
| "ovs-vsctl add-br {0};ovs-vsctl add-port {0} {1};dhclient -r;" | ||
| "sleep 5 ;dhclient {0}".format(ovs_bridge_name, iface_name) | ||
| "ovs-vsctl add-br {0};ovs-vsctl add-port {0} {1};{2} {3};" |
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.
Using these placeholders is confusing IMO, because as a human I have to always go back to the list in format at the end and for this long string with 4 elements it's really hard. How about you changed the way this command is constructed to make it more readable? You can do for example f"...; sleep 5;{dhcp_cmd} {release_flag}" and also
cmd = f"ovs-vsctl add-br {ovs_bridge_name}"
cmd += f"...
...
cmd += f"{dhcp_cmd} {dhcp_flag}"
| "ip link set {1} master {0}; ip link set {0} up; " | ||
| "pkill dhclient; sleep 6; " | ||
| "dhclient {0};".format(linux_bridge_name, iface_name) | ||
| "pkill {2}; sleep 6; " |
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 use f-strings instead of .format() for better readabilty.
E.g.
f"pkill {dhcp_cmd}; sleep 6; "The same for line 4851-4853
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.
@qiankehan @smitterl I understand that f-strings improve readability, and I also considered using them during the design. However, using .format() or % formatting is safer because the framework may run tests on older product versions with lower python versions. What do you think—should we be concerned about version compatibility?
[LIBVIRTAT-22186]
Signed-off-by: Wenli Quan wquan@redhat.com
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.