Skip to content

Commit c93bf03

Browse files
committed
status: improve dual-stack mgmt display and integration coverage
Fixes #3358 What changed: - Render node management addresses in netlab status with IPv6 on a new line under IPv4 in the mgmt column. - Add platform integration test tests/platform-integration/cli/12-status-mgmt.yml to validate dual-stack mgmt output. - Harden tests/check-integration-tests.sh by initializing err_cnt and quoting topology path arguments. Why: - The status output did not clearly present dual-stack management addresses and could be ambiguous/truncated in narrow output. - Integration validation emitted a noisy shell warning when err_cnt was unset.
1 parent 1e6ddef commit c93bf03

7 files changed

Lines changed: 177 additions & 10 deletions

File tree

docs/netlab/status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Lab default in /home/user/net101/tools/X
4747
provider(s): clab
4848
4949
┏━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
50-
┃ node ┃ device ┃ image ┃ mgmt IPv4 ┃ connection ┃ provider ┃ VM/container ┃ status ┃
50+
┃ node ┃ device ┃ image ┃ mgmt IP ┃ connection ┃ provider ┃ VM/container ┃ status ┃
5151
┡━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
5252
│ host-1 │ linux │ python:3.9-alpine │ 192.168.121.107 │ docker │ clab │ clab-X-host-1 │ Up 4 minutes │
5353
├─────────┼────────┼─────────────────────────────┼─────────────────┼────────────┼──────────┼────────────────┼──────────────┤

netsim/cli/status.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ def fetch_node_status(ls: Box, topology: Box) -> None:
164164
p_module = providers.get_provider_module(topology,n_provider)
165165
load_provider_status(p_status,n_provider,topology)
166166

167-
ls.nodes[n_name] = {
168-
'device': n_data.device,
169-
'mgmt': n_data.mgmt.ipv4
170-
}
171-
node_stat = ls.nodes[n_name]
167+
node_stat = ls.nodes[n_name] = get_empty_box()
168+
for source_attr,status_attr in {
169+
'device': 'device',
170+
'mgmt.ipv4': 'mgmt',
171+
'mgmt.ipv6': 'mgmt6' }.items():
172+
attr_value = n_data.get(source_attr,None)
173+
if attr_value:
174+
node_stat[status_attr] = attr_value
175+
172176
node_stat.connection = n_ext.ansible_connection
173177
if n_data.get('unmanaged',False):
174178
node_stat.image = 'unmanaged'
@@ -190,6 +194,7 @@ def fetch_node_status(ls: Box, topology: Box) -> None:
190194
wk_state = p_status[n_provider].get(wk_name,get_empty_box())
191195
ls.nodes[t_name] = {
192196
'device': '(tool)',
197+
'mgmt': '',
193198
'image': wk_state.get('image',''),
194199
'connection': 'docker',
195200
'provider': n_provider,
@@ -199,10 +204,12 @@ def fetch_node_status(ls: Box, topology: Box) -> None:
199204

200205
def show_lab_nodes(ls: Box, topology: Box) -> None:
201206
rows = []
202-
heading = [ 'node', 'device', 'image', 'mgmt IPv4', 'connection', 'provider', 'VM/container', 'status']
207+
heading = [ 'node', 'device', 'image', 'mgmt IP', 'connection', 'provider', 'VM/container', 'status']
203208

204209
for n_name,n_data in ls.nodes.items():
205-
row = [ n_name, n_data.device, n_data.image, n_data.get('mgmt',''),
210+
mgmt = "\n".join([ addr for addr in (n_data.get('mgmt'),n_data.get('mgmt6')) if addr ])
211+
212+
row = [ n_name, n_data.device, n_data.image, mgmt,
206213
n_data.connection, n_data.get('provider',''),
207214
n_data.get('provider_name',''), n_data.status ]
208215
rows.append(row)

tests/check-integration-tests.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
# Run transformation code on integration tests for an additional
44
# verification before merging pull requests
55
#
6+
err_cnt=0
7+
68
for file in integration/**/[0-9]*.yml platform-integration/**/[0-9]*.yml; do
7-
../netlab create -o none -d none $file 2>/dev/null || (
9+
../netlab create -o none -d none "$file" 2>/dev/null || (
810
echo "Errors found in $file"
911
echo "========================================="
10-
../netlab create -o none -d none $file
12+
../netlab create -o none -d none "$file"
1113
echo ""
1214
exit 1
1315
) || err_cnt=$((err_cnt + 1))
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
message: |
3+
This test checks that netlab status displays both IPv4 and IPv6
4+
management addresses for dual-stack nodes.
5+
6+
plugin: [ files ]
7+
provider: clab
8+
defaults.device: linux
9+
10+
defaults.addressing.mgmt.ipv6: 2001:db8:121::/64
11+
12+
defaults.netlab.integration:
13+
skip: [ initial ]
14+
validate: bash validate.sh
15+
16+
nodes.x:
17+
mgmt.ipv4: 192.168.121.11
18+
mgmt.ipv6: 2001:db8:121::11
19+
20+
links: [ x ]
21+
22+
files:
23+
validate.sh: |
24+
#!/bin/bash
25+
set -e
26+
netlab status >status.out
27+
grep "mgmt" status.out >/dev/null
28+
grep "192.168.121.11" status.out >/dev/null
29+
grep "2001:db8:121::11" status.out >/dev/null
30+
echo "netlab status displays IPv4 and IPv6 management addresses"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
message: |
3+
This test checks that netlab status displays both IPv4 and IPv6
4+
management addresses in a mixed libvirt, clab, and tool topology.
5+
6+
plugin: [ files ]
7+
provider: libvirt
8+
defaults.device: linux
9+
10+
tools:
11+
graphite:
12+
13+
defaults.addressing.mgmt.ipv6: 2001:db8:121::/64
14+
15+
defaults.netlab.integration:
16+
skip: [ initial ]
17+
validate: bash validate.sh
18+
19+
nodes:
20+
vm:
21+
mgmt.ipv4: 192.168.121.31
22+
mgmt.ipv6: 2001:db8:121::31
23+
ctr:
24+
provider: clab
25+
mgmt.ipv4: 192.168.121.32
26+
27+
links: [ vm-ctr ]
28+
29+
files:
30+
validate.sh: |
31+
#!/bin/bash
32+
set -e
33+
netlab status >status.out
34+
grep "mgmt IP" status.out >/dev/null
35+
grep "192.168.121.31" status.out >/dev/null
36+
grep "2001:db8:121::31" status.out >/dev/null
37+
grep "192.168.121.32" status.out >/dev/null
38+
grep "graphite" status.out >/dev/null
39+
netlab status --format json >status.json
40+
python3 - <<'PY'
41+
import json
42+
43+
with open("status.json", encoding="utf-8") as status_file:
44+
nodes = json.load(status_file)["nodes"]
45+
46+
assert nodes["vm"]["mgmt"] == "192.168.121.31"
47+
assert nodes["vm"]["mgmt6"] == "2001:db8:121::31"
48+
assert nodes["ctr"]["mgmt"] == "192.168.121.32"
49+
assert nodes["graphite"]["device"] == "(tool)"
50+
assert "mgmt" not in nodes["graphite"]
51+
assert "mgmt6" not in nodes["graphite"]
52+
PY
53+
echo "netlab status displays dual-stack management addresses in a mixed topology"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
message: |
3+
This test checks that netlab status displays IPv4 management
4+
addresses for libvirt and clab nodes while keeping tool status
5+
JSON intact.
6+
7+
plugin: [ files ]
8+
provider: libvirt
9+
defaults.device: linux
10+
11+
tools:
12+
graphite:
13+
14+
defaults.netlab.integration:
15+
skip: [ initial ]
16+
validate: bash validate.sh
17+
18+
nodes:
19+
vm:
20+
mgmt.ipv4: 192.168.121.21
21+
ctr:
22+
provider: clab
23+
mgmt.ipv4: 192.168.121.22
24+
25+
links: [ vm-ctr ]
26+
27+
files:
28+
validate.sh: |
29+
#!/bin/bash
30+
set -e
31+
netlab status >status.out
32+
grep "mgmt IP" status.out >/dev/null
33+
grep "192.168.121.21" status.out >/dev/null
34+
grep "192.168.121.22" status.out >/dev/null
35+
grep "graphite" status.out >/dev/null
36+
netlab status --format json >status.json
37+
python3 - <<'PY'
38+
import json
39+
40+
with open("status.json", encoding="utf-8") as status_file:
41+
nodes = json.load(status_file)["nodes"]
42+
43+
assert nodes["vm"]["mgmt"] == "192.168.121.21"
44+
assert nodes["ctr"]["mgmt"] == "192.168.121.22"
45+
assert nodes["graphite"]["device"] == "(tool)"
46+
assert "mgmt" not in nodes["graphite"]
47+
assert "mgmt6" not in nodes["graphite"]
48+
PY
49+
echo "netlab status displays IPv4 management addresses for nodes and keeps tool JSON unchanged"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
message: |
3+
This test checks that netlab status displays an IPv4 management
4+
address for an IPv4-only node.
5+
6+
plugin: [ files ]
7+
provider: clab
8+
defaults.device: linux
9+
10+
defaults.netlab.integration:
11+
skip: [ initial ]
12+
validate: bash validate.sh
13+
14+
nodes.x:
15+
mgmt.ipv4: 192.168.121.21
16+
17+
links: [ x ]
18+
19+
files:
20+
validate.sh: |
21+
#!/bin/bash
22+
set -e
23+
netlab status >status.out
24+
grep "mgmt" status.out >/dev/null
25+
grep "192.168.121.21" status.out >/dev/null
26+
echo "netlab status displays IPv4-only management addresses"

0 commit comments

Comments
 (0)