3838)
3939from virttest .remote import RemoteRunner
4040from virttest .staging import service , utils_memory
41+ from virttest .utils_libvirt import libvirt_service
4142from virttest .utils_windows import system , virtio_win
4243from virttest .versionable_class import factory
4344
@@ -4608,8 +4609,9 @@ def create_ovs_bridge(
46084609 if session :
46094610 runner = session .cmd
46104611 iface_name = get_net_if (runner = runner , state = "UP" , ip_options = ip_options )[0 ]
4611- if not utils_package .package_install (["tmux" , "dhcp-client " ], session ):
4612+ if not utils_package .package_install (["tmux" , "dhcpcd " ], session ):
46124613 raise exceptions .TestError ("Failed to install the required packages." )
4614+ libvirt_service .ensure_service_status ("dhcpcd" )
46134615
46144616 res = utils_misc .cmd_status_output (
46154617 "which ovs-vsctl" , shell = True , ignore_status = False , session = session
@@ -4621,8 +4623,8 @@ def create_ovs_bridge(
46214623 "is installed."
46224624 )
46234625 cmd = (
4624- "ovs-vsctl add-br {0};ovs-vsctl add-port {0} {1};dhclient -r ;"
4625- "sleep 5 ;dhclient {0}" .format (ovs_bridge_name , iface_name )
4626+ "ovs-vsctl add-br {0};ovs-vsctl add-port {0} {1}; dhcpcd -k {1} ;"
4627+ "dhcpcd -n {0}" .format (ovs_bridge_name , iface_name )
46264628 )
46274629 tmux_cmd = 'tmux -c "{}"' .format (cmd )
46284630 return utils_misc .cmd_status_output (
@@ -4652,8 +4654,9 @@ def delete_ovs_bridge(
46524654 if session :
46534655 runner = session .cmd
46544656 iface_name = get_net_if (runner = runner , state = "UP" , ip_options = ip_options )[0 ]
4655- if not utils_package .package_install (["tmux" , "dhcp-client " ], session ):
4657+ if not utils_package .package_install (["tmux" , "dhcpcd " ], session ):
46564658 raise exceptions .TestError ("Failed to install the required packages." )
4659+ libvirt_service .ensure_service_status ("dhcpcd" )
46574660
46584661 res = utils_misc .cmd_status_output (
46594662 "which ovs-vsctl" , shell = True , ignore_status = False , session = session
@@ -4665,8 +4668,8 @@ def delete_ovs_bridge(
46654668 "is installed."
46664669 )
46674670 cmd = (
4668- "ovs-vsctl del-port {0} {1};ovs-vsctl del-br {0};dhclient -r; "
4669- "sleep 5 ;dhclient {1}" .format (ovs_bridge_name , iface_name )
4671+ "ovs-vsctl del-port {0} {1};ovs-vsctl del-br {0};"
4672+ "dhcpcd -n {1}; sleep 6; " .format (ovs_bridge_name , iface_name )
46704673 )
46714674 tmux_cmd = 'tmux -c "{}"' .format (cmd )
46724675 return utils_misc .cmd_status_output (
@@ -4752,7 +4755,7 @@ def create_linux_bridge_tmux(
47524755 """
47534756 # Create bridge
47544757 br_path = "/sys/class/net/%s" % linux_bridge_name
4755- if not utils_package .package_install (["tmux" , "dhcp-client " , "net-tools" ]):
4758+ if not utils_package .package_install (["tmux" , "dhcpcd " , "net-tools" ]):
47564759 raise exceptions .TestError ("Failed to install the required packages." )
47574760 if os .path .exists (br_path ):
47584761 s , o = delete_linux_bridge_tmux (linux_bridge_name , iface_name )
@@ -4761,15 +4764,14 @@ def create_linux_bridge_tmux(
47614764 "Create bridge fail as there is already interface named '%s' on the host "
47624765 "and can not delete with error: %s" % (linux_bridge_name , o )
47634766 )
4767+ libvirt_service .ensure_service_status ("dhcpcd" )
47644768 if iface_name :
4769+ rm_addr_cmd = f"dhcpcd -k { iface_name } " if remove_addr_on_dev else ""
47654770 shell_cmd = (
47664771 "ip link add name {0} type bridge; ip link set {1} up; "
4767- "ip link set {1} master {0}; ip link set {0} up; "
4768- "pkill dhclient; sleep 6; "
4769- "dhclient {0};" .format (linux_bridge_name , iface_name )
4772+ "ip link set {1} master {0}; ip link set {0} up; {2};"
4773+ "dhcpcd -n {0};" .format (linux_bridge_name , iface_name , rm_addr_cmd )
47704774 )
4771- if remove_addr_on_dev :
4772- shell_cmd = "%s ifconfig %s 0" % (shell_cmd , iface_name )
47734775 cmd = 'tmux -c "%s"' % shell_cmd
47744776 else :
47754777 cmd = "ip link add %s type bridge" % linux_bridge_name
@@ -4790,17 +4792,16 @@ def delete_linux_bridge_tmux(linux_bridge_name, iface_name=None, ignore_status=F
47904792 """
47914793 # Delete the linux bridge
47924794 br_path = "/sys/class/net/%s" % linux_bridge_name
4793- if not utils_package .package_install (
4794- ["tmux" , "dhcp-client" , "procps-ng" , "net-tools" ]
4795- ):
4795+ if not utils_package .package_install (["tmux" , "dhcpcd" , "procps-ng" , "net-tools" ]):
47964796 raise exceptions .TestError ("Failed to install the required packages." )
47974797 if not os .path .exists (br_path ):
47984798 LOG .info ("There is no bridge named '%s' on the host" % linux_bridge_name )
47994799 return
4800+ libvirt_service .ensure_service_status ("dhcpcd" )
48004801 if iface_name :
48014802 cmd = (
4802- 'tmux -c "ip link set {1} nomaster; ip link delete {0}; pkill dhclient; '
4803- 'sleep 5; dhclient {1}"' .format (linux_bridge_name , iface_name )
4803+ 'tmux -c "ip link set {1} nomaster; ip link delete {0};'
4804+ 'dhcpcd -n {1}; sleep 6; "' .format (linux_bridge_name , iface_name )
48044805 )
48054806 else :
48064807 cmd = "ip link delete %s" % linux_bridge_name
0 commit comments