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
@@ -4600,8 +4601,9 @@ def create_ovs_bridge(
46004601 if session :
46014602 runner = session .cmd
46024603 iface_name = get_net_if (runner = runner , state = "UP" , ip_options = ip_options )[0 ]
4603- if not utils_package .package_install (["tmux" , "dhcp-client " ], session ):
4604+ if not utils_package .package_install (["tmux" , "dhcpcd " ], session ):
46044605 raise exceptions .TestError ("Failed to install the required packages." )
4606+ libvirt_service .ensure_service_status ("dhcpcd" )
46054607
46064608 res = utils_misc .cmd_status_output (
46074609 "which ovs-vsctl" , shell = True , ignore_status = False , session = session
@@ -4613,8 +4615,8 @@ def create_ovs_bridge(
46134615 "is installed."
46144616 )
46154617 cmd = (
4616- "ovs-vsctl add-br {0};ovs-vsctl add-port {0} {1};dhclient -r ;"
4617- "sleep 5 ;dhclient {0}" .format (ovs_bridge_name , iface_name )
4618+ "ovs-vsctl add-br {0};ovs-vsctl add-port {0} {1}; dhcpcd -k {1} ;"
4619+ "dhcpcd -n {0}" .format (ovs_bridge_name , iface_name )
46184620 )
46194621 tmux_cmd = 'tmux -c "{}"' .format (cmd )
46204622 return utils_misc .cmd_status_output (
@@ -4644,8 +4646,9 @@ def delete_ovs_bridge(
46444646 if session :
46454647 runner = session .cmd
46464648 iface_name = get_net_if (runner = runner , state = "UP" , ip_options = ip_options )[0 ]
4647- if not utils_package .package_install (["tmux" , "dhcp-client " ], session ):
4649+ if not utils_package .package_install (["tmux" , "dhcpcd " ], session ):
46484650 raise exceptions .TestError ("Failed to install the required packages." )
4651+ libvirt_service .ensure_service_status ("dhcpcd" )
46494652
46504653 res = utils_misc .cmd_status_output (
46514654 "which ovs-vsctl" , shell = True , ignore_status = False , session = session
@@ -4656,9 +4659,8 @@ def delete_ovs_bridge(
46564659 "sure the openvswitch or openvswitch2 pkg "
46574660 "is installed."
46584661 )
4659- cmd = (
4660- "ovs-vsctl del-port {0} {1};ovs-vsctl del-br {0};dhclient -r;"
4661- "sleep 5 ;dhclient {1}" .format (ovs_bridge_name , iface_name )
4662+ cmd = "ovs-vsctl del-port {0} {1};ovs-vsctl del-br {0};" "dhcpcd -n {1}" .format (
4663+ ovs_bridge_name , iface_name
46624664 )
46634665 tmux_cmd = 'tmux -c "{}"' .format (cmd )
46644666 return utils_misc .cmd_status_output (
@@ -4744,7 +4746,7 @@ def create_linux_bridge_tmux(
47444746 """
47454747 # Create bridge
47464748 br_path = "/sys/class/net/%s" % linux_bridge_name
4747- if not utils_package .package_install (["tmux" , "dhcp-client " , "net-tools" ]):
4749+ if not utils_package .package_install (["tmux" , "dhcpcd " , "net-tools" ]):
47484750 raise exceptions .TestError ("Failed to install the required packages." )
47494751 if os .path .exists (br_path ):
47504752 s , o = delete_linux_bridge_tmux (linux_bridge_name , iface_name )
@@ -4753,12 +4755,12 @@ def create_linux_bridge_tmux(
47534755 "Create bridge fail as there is already interface named '%s' on the host "
47544756 "and can not delete with error: %s" % (linux_bridge_name , o )
47554757 )
4758+ libvirt_service .ensure_service_status ("dhcpcd" )
47564759 if iface_name :
47574760 shell_cmd = (
47584761 "ip link add name {0} type bridge; ip link set {1} up; "
4759- "ip link set {1} master {0}; ip link set {0} up; "
4760- "pkill dhclient; sleep 6; "
4761- "dhclient {0};" .format (linux_bridge_name , iface_name )
4762+ "ip link set {1} master {0}; ip link set {0} up; dhcpcd -k {1};"
4763+ "dhcpcd -n {0};" .format (linux_bridge_name , iface_name )
47624764 )
47634765 if remove_addr_on_dev :
47644766 shell_cmd = "%s ifconfig %s 0" % (shell_cmd , iface_name )
@@ -4782,17 +4784,16 @@ def delete_linux_bridge_tmux(linux_bridge_name, iface_name=None, ignore_status=F
47824784 """
47834785 # Delete the linux bridge
47844786 br_path = "/sys/class/net/%s" % linux_bridge_name
4785- if not utils_package .package_install (
4786- ["tmux" , "dhcp-client" , "procps-ng" , "net-tools" ]
4787- ):
4787+ if not utils_package .package_install (["tmux" , "dhcpcd" , "procps-ng" , "net-tools" ]):
47884788 raise exceptions .TestError ("Failed to install the required packages." )
47894789 if not os .path .exists (br_path ):
47904790 LOG .info ("There is no bridge named '%s' on the host" % linux_bridge_name )
47914791 return
4792+ libvirt_service .ensure_service_status ("dhcpcd" )
47924793 if iface_name :
47934794 cmd = (
4794- 'tmux -c "ip link set {1} nomaster; ip link delete {0}; pkill dhclient; '
4795- 'sleep 5; dhclient {1}"' .format (linux_bridge_name , iface_name )
4795+ 'tmux -c "ip link set {1} nomaster; ip link delete {0};'
4796+ 'dhcpcd -n {1}"' .format (linux_bridge_name , iface_name )
47964797 )
47974798 else :
47984799 cmd = "ip link delete %s" % linux_bridge_name
0 commit comments