Skip to content
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

Experimenting with dhcpcd #4033

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions virttest/utils_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,15 +1426,16 @@ def local_runner_status(cmd, timeout=None, shell=False):
return process.run(cmd, verbose=False, timeout=timeout, shell=shell).exit_status


def get_net_if(runner=local_runner, state=".*", qdisc=".*", optional=".*"):
def get_net_if(runner=local_runner, state=".*", qdisc=".*", optional=".*", ip_options=""):
"""
:param runner: command runner.
:param state: interface state get from ip link
:param qdisc: interface qdisc get from ip link
:param optional: optional match for interface find
:param ip_options: optional params for ip link
:return: List of network interfaces.
"""
cmd = "ip link"
cmd = f"ip {ip_options} link"
# As the runner converts stdout to unicode on Python2,
# it has to be converted to string for struct.pack().
result = str(runner(cmd))
Expand Down Expand Up @@ -4594,8 +4595,20 @@ def create_ovs_bridge(ovs_bridge_name, session=None, ignore_status=False):
runner = local_runner
if session:
runner = session.cmd
iface_name = get_net_if(runner=runner, state="UP")[0]
if not utils_package.package_install(["tmux", "dhcp-client"], session):
iface_name = get_net_if(runner=runner, state="UP", ip_options="-c=never")[0]


dhcp_client = "dhcp-client"
dhcp_cmd = "dhclient"
dhcp_release_cmd = "-r"
res = utils_misc.cmd_status_output("which dhclient", shell=True, ignore_status=False, session=session)[0]
if res == 1:
dhcp_client = "dhcpcd"
dhcp_cmd = "dhcpcd"
dhcp_release_cmd = "-k"


if not utils_package.package_install(["tmux", dhcp_client], session):
raise exceptions.TestError("Failed to install the required packages.")

res = utils_misc.cmd_status_output(
Expand All @@ -4608,8 +4621,8 @@ def create_ovs_bridge(ovs_bridge_name, session=None, ignore_status=False):
"is installed."
)
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};"
"sleep 5 ;{2} {0}".format(ovs_bridge_name, iface_name, dhcp_cmd, dhcp_release_cmd)
)
tmux_cmd = 'tmux -c "{}"'.format(cmd)
return utils_misc.cmd_status_output(
Expand All @@ -4635,7 +4648,7 @@ def delete_ovs_bridge(ovs_bridge_name, session=None, ignore_status=False):
runner = local_runner
if session:
runner = session.cmd
iface_name = get_net_if(runner=runner, state="UP")[0]
iface_name = get_net_if(runner=runner, state="UP", ip_options="-c=never")[0]
if not utils_package.package_install(["tmux", "dhcp-client"], session):
raise exceptions.TestError("Failed to install the required packages.")

Expand Down
Loading