diff --git a/libvirt/tests/src/virtual_network/iface_network.py b/libvirt/tests/src/virtual_network/iface_network.py index 4a42a118f3..028e7174e5 100644 --- a/libvirt/tests/src/virtual_network/iface_network.py +++ b/libvirt/tests/src/virtual_network/iface_network.py @@ -125,6 +125,16 @@ def modify_iface_xml(sync=True): if not source: source = {"network": "default"} net_ifs = utils_net.get_net_if(state="UP") + # if no interfaces are available in UP state, + # iterate through all interfaces with UNKNOWN + # state and check if they can be pinged to the + # internet through. + if len(net_ifs) == 0: + unknown_net_ifs = utils_net.get_net_if(state="UNKNOWN") + for interface in unknown_net_ifs: + if utils_net.ping(dest="google.com", interface=interface, count=5, timeout=120)[0] == 0: + net_ifs.append(interface) + break # Check source device is valid or not, # if it's not in host interface list, try to set # source device to first active interface of host diff --git a/libvirt/tests/src/virtual_network/iface_options.py b/libvirt/tests/src/virtual_network/iface_options.py index f2c28632f2..4ff4b51bc1 100644 --- a/libvirt/tests/src/virtual_network/iface_options.py +++ b/libvirt/tests/src/virtual_network/iface_options.py @@ -104,6 +104,16 @@ def modify_iface_xml(update, status_error=False): source = iface_source if source: net_ifs = utils_net.get_net_if(state="UP") + # if no interfaces are available in UP state, + # iterate through all interfaces with UNKNOWN + # state and check if they can be pinged to the + # internet through. + if len(net_ifs) == 0: + unknown_net_ifs = utils_net.get_net_if(state="UNKNOWN") + for interface in unknown_net_ifs: + if utils_net.ping(dest="google.com", interface=interface, count=5, timeout=120)[0] == 0: + net_ifs.append(interface) + break # Check source device is valid or not, # if it's not in host interface list, try to set # source device to first active interface of host