Skip to content

Commit

Permalink
tests:base: introduce iface_json() helper
Browse files Browse the repository at this point in the history
iproute2 v6.4 changed its CLI output, the JSON output is expected to
stay stable, so we should migrate to using iface_json() over time.

https://bugs.debian.org/1040004
  • Loading branch information
slyon committed Jul 11, 2023
1 parent 501f7cf commit 19bb7fa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/integration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import shutil
import gi
import glob
import json

# make sure we point to libnetplan properly.
os.environ.update({'LD_LIBRARY_PATH': '.:{}'.format(os.environ.get('LD_LIBRARY_PATH'))})
Expand Down Expand Up @@ -278,6 +279,15 @@ def start_dnsmasq(self, ipv6_mode, iface):
else:
self.poll_text(dnsmasq_log, 'DHCP, IP range')

def iface_json(self, iface: str) -> dict:
'''Return iproute2's (detailed) JSON representation'''
out = subprocess.check_output(['ip', '-j', '-d', 'a', 'show', 'dev', iface],
text=True)
json_dict = json.loads(out)
if json_dict:
return json_dict[0]
return {}

def assert_iface(self, iface, expected_ip_a=None, unexpected_ip_a=None):
'''Assert that client interface has been created'''

Expand Down

0 comments on commit 19bb7fa

Please sign in to comment.