Skip to content

Commit b393304

Browse files
committed
Improve package installation for network utilities
utils_package: add package_install_any to try multiple candidates utils_net: update package install to support multiple dhcp clients Signed-off-by: Wenli Quan <wquan@redhat.com>
1 parent 21a1b78 commit b393304

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

virttest/utils_net.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4628,7 +4628,9 @@ def create_ovs_bridge(
46284628
if session:
46294629
runner = session.cmd
46304630
iface_name = get_net_if(runner=runner, state="UP", ip_options=ip_options)[0]
4631-
if not utils_package.package_install(["tmux", "dhcp-client"], session):
4631+
if not utils_package.package_install(
4632+
["tmux"], session
4633+
) or not utils_package.package_install_any(["dhcp-client", "dhcpcd"], session):
46324634
raise exceptions.TestError("Failed to install the required packages.")
46334635

46344636
res = utils_misc.cmd_status_output(
@@ -4672,8 +4674,9 @@ def delete_ovs_bridge(
46724674
if session:
46734675
runner = session.cmd
46744676
iface_name = get_net_if(runner=runner, state="UP", ip_options=ip_options)[0]
4675-
if not utils_package.package_install(["tmux", "dhcp-client"], session):
4676-
raise exceptions.TestError("Failed to install the required packages.")
4677+
if not utils_package.package_install(
4678+
["tmux"], session
4679+
) or not utils_package.package_install_any(["dhcp-client", "dhcpcd"], session):
46774680

46784681
res = utils_misc.cmd_status_output(
46794682
"which ovs-vsctl", shell=True, ignore_status=False, session=session
@@ -4777,7 +4780,9 @@ def create_linux_bridge_tmux(
47774780
"""
47784781
# Create bridge
47794782
br_path = "/sys/class/net/%s" % linux_bridge_name
4780-
if not utils_package.package_install(["tmux", "dhcp-client", "net-tools"], session):
4783+
if not utils_package.package_install(
4784+
["tmux", "net-tools"], session
4785+
) or not utils_package.package_install_any(["dhcp-client", "dhcpcd"], session):
47814786
raise exceptions.TestError("Failed to install the required packages.")
47824787
if session:
47834788
bridge_exists = session.cmd_status("ip link show %s" % linux_bridge_name) == 0

virttest/utils_package.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,20 @@ def package_install(pkg, session=None, timeout=PKG_MGR_TIMEOUT):
237237
return utils_misc.wait_for(mgr.install, timeout)
238238

239239

240-
def package_remove(pkg, session=None, timeout=PKG_MGR_TIMEOUT):
240+
def package_install_any(candidates, session=None, timeout=PKG_MGR_TIMEOUT):
241241
"""
242-
Try to remove packages on system with package manager.
242+
Try to install packages from candidates in order until one succeeds.
243243
244-
:param pkg: package name or list of packages
244+
:param candidates: iterable of package names to try in order
245245
:param session: session Object
246-
:param timeout: timeout for remove with session
247-
:return: True if all packages removed, False if any error
246+
:param timeout: timeout for each install session
247+
:return: True if any candidate installed successfully, else False
248248
"""
249-
mgr = package_manager(session, pkg)
250-
return utils_misc.wait_for(mgr.remove, timeout)
249+
for pkg in candidates:
250+
mgr = package_manager(session, pkg)
251+
if utils_misc.wait_for(mgr.install, timeout):
252+
return True
253+
return False
251254

252255

253256
def package_upgrade(pkg, session=None, timeout=PKG_MGR_TIMEOUT):

0 commit comments

Comments
 (0)