Skip to content

Commit

Permalink
test: Avoid virsh iface-list
Browse files Browse the repository at this point in the history
This depends on the deprecated `virtinterfaced` which we are getting rid
of. This code was both unnecessarily complicated, and also too
arbitrary: It just took what interface appeared in `virsh iface-list`
first.

Change this to be more realistic: The test creates a new network which
NATs to a host device, so in most practical cases that should be the one
having the default route. Rename the function and add a comment to
clarify this.
  • Loading branch information
martinpitt committed Aug 26, 2024
1 parent 5760f3f commit 28e2e32
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions test/check-machines-networks
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,17 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.

import json
import xml.etree.ElementTree as ET

import machineslib
import testlib
from machinesxmls import TEST_NETWORK2_XML, TEST_NETWORK3_XML, TEST_NETWORK4_XML, TEST_NETWORK_IPV6_XML, TEST_NETWORK_XML


def getNetworkDevice(m):
net_devices_str = m.execute("virsh iface-list")
net_devices_str = net_devices_str.split("\n", 2)[2] # Remove first 2 lines of table header
if net_devices_str not in ["\n", "\r\n"]:
device = net_devices_str.split(' ', 2)[1] # Get the name of device, ignoring spacing before device string
else: # If $virsh-iface list did not return any device, check virsh nodedev-list net:noh
net_devices_str = m.execute("virsh nodedev-list net")
net_devices_str = net_devices_str.split("\n", 2)[0]
device = net_devices_str.split("_", 2)[1] # Ignore prefix (example: net_enp0s31f6_8c_16_45_5f_77_34)

return device
def getNetworkDefaultRouteDevice(m):
routes = json.loads(m.execute("ip --json route show default"))
return routes[0]["dev"]


@testlib.nondestructive
Expand Down Expand Up @@ -498,8 +491,8 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase):
xfail_error="IPv4 address cannot be same as the network's broadcast address",
).execute()

# Test network devices
device = getNetworkDevice(m)
# Test network devices: create a new network NATing to a host iface
device = getNetworkDefaultRouteDevice(m)
NetworkCreateDialog(
self,
name="test_network",
Expand Down

0 comments on commit 28e2e32

Please sign in to comment.