Skip to content

Commit 7c12b3b

Browse files
Aniket SahuAniket Sahu
authored andcommitted
chore(tp-libvirt): fix libvirt connection handling
The current implementation is looking for interfaces in the UP state, while ignoring interfaces in the UNKNOWN state, which was causing tests to fail on hosts where no interfaces are in the UP state. Added logic to iterate through interfaces in UNKNOWN state, and check which one can be used to ping to the outside world, then using the same interface for the purpose of the tests where it is required.
1 parent 38d36f0 commit 7c12b3b

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

libvirt/tests/src/virtual_network/iface_network.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ def modify_iface_xml(sync=True):
125125
if not source:
126126
source = {"network": "default"}
127127
net_ifs = utils_net.get_net_if(state="UP")
128+
# if no interfaces are available in UP state,
129+
# iterate through all interfaces with UNKNOWN
130+
# state and check if they can be pinged to the
131+
# internet through.
132+
if len(net_ifs) == 0:
133+
unknown_net_ifs = utils_net.get_net_if(state="UNKNOWN")
134+
for interface in unknown_net_ifs:
135+
if utils_net.ping(dest="google.com", interface=interface, count=5, timeout=120)[0] == 0:
136+
net_ifs.append(interface)
137+
break
128138
# Check source device is valid or not,
129139
# if it's not in host interface list, try to set
130140
# source device to first active interface of host

libvirt/tests/src/virtual_network/iface_options.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ def modify_iface_xml(update, status_error=False):
104104
source = iface_source
105105
if source:
106106
net_ifs = utils_net.get_net_if(state="UP")
107+
# if no interfaces are available in UP state,
108+
# iterate through all interfaces with UNKNOWN
109+
# state and check if they can be pinged to the
110+
# internet through.
111+
if len(net_ifs) == 0:
112+
unknown_net_ifs = utils_net.get_net_if(state="UNKNOWN")
113+
for interface in unknown_net_ifs:
114+
if utils_net.ping(dest="google.com", interface=interface, count=5, timeout=120)[0] == 0:
115+
net_ifs.append(interface)
116+
break
107117
# Check source device is valid or not,
108118
# if it's not in host interface list, try to set
109119
# source device to first active interface of host

0 commit comments

Comments
 (0)