forked from kernelkit/infix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add offline unit test for yanger and cli-pretty
In this patch we add some arbitrary system output files which contains interface data. Such as the output from "ip link" and "ethtool". These files are used by yanger instead of running the actual commands. Yanger then generates a lot of YANG json data, which are merged using jq into something that looks like the sysrepo operational data on a running system. This data is then passed though cli-pretty and its ouput is compared to the static expected output in the .txt files in cli-output. Here's a basic flow overview. * system-output/foo.json -> yanger ->> data * system-output/bar.json -> yanger ->> data * data -> merge -> sysrepo-operational-data * sysrepo-operational-data -> cli-pretty -> output.txt * compare output.txt too cli-output/show-foobar.txt The result of this is that if something changes in yanger OR in cli-pretty. The corresponding system-output file needs to be updated for the test to pass. This is indented to catch regression where the output is unintentionally changed. Signed-off-by: Richard Alpe <[email protected]>
- Loading branch information
Showing
36 changed files
with
1,771 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
--- | ||
# Tests in this suite can be run on localhost without a target environment | ||
|
||
- name: cli-output | ||
suite: cli/all.yaml | ||
|
||
- name: cli-pretty | ||
suite: cli_pretty/all.yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
- case: run.sh | ||
name: "cli-check-output" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name : br0 | ||
index : 7 | ||
mtu : 1500 | ||
operational status : up | ||
auto-negotiation : on | ||
duplex : full | ||
speed : 10000 | ||
physical address : 02:00:00:00:00:00 | ||
ipv4 addresses : | ||
ipv6 addresses : | ||
in-octets : 0 | ||
out-octets : 3158 | ||
|
||
eth-out-frames : 713 | ||
eth-out-multicast-frames : 605 | ||
eth-out-broadcast-frames : 69 | ||
eth-in-frames : 418 | ||
eth-in-multicast-frames : 336 | ||
eth-in-broadcast-frames : 46 | ||
eth-in-error-fcs-frames : 0 | ||
eth-in-total-frames : 418 | ||
eth-in-error-oversize-frames : 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name : e0 | ||
index : 2 | ||
mtu : 1500 | ||
operational status : up | ||
auto-negotiation : on | ||
duplex : full | ||
speed : 10000 | ||
physical address : 02:00:00:00:00:00 | ||
ipv4 addresses : | ||
ipv6 addresses : | ||
in-octets : 20891 | ||
out-octets : 6537 | ||
|
||
eth-out-frames : 713 | ||
eth-out-multicast-frames : 605 | ||
eth-out-broadcast-frames : 69 | ||
eth-in-frames : 418 | ||
eth-in-multicast-frames : 336 | ||
eth-in-broadcast-frames : 46 | ||
eth-in-error-fcs-frames : 0 | ||
eth-in-total-frames : 418 | ||
eth-in-error-oversize-frames : 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name : e1 | ||
index : 3 | ||
mtu : 1500 | ||
operational status : up | ||
auto-negotiation : on | ||
duplex : full | ||
speed : 10000 | ||
physical address : 02:00:00:00:00:01 | ||
ipv4 addresses : | ||
ipv6 addresses : | ||
in-octets : 24849 | ||
out-octets : 1397 | ||
|
||
eth-out-frames : 713 | ||
eth-out-multicast-frames : 605 | ||
eth-out-broadcast-frames : 69 | ||
eth-in-frames : 418 | ||
eth-in-multicast-frames : 336 | ||
eth-in-broadcast-frames : 46 | ||
eth-in-error-fcs-frames : 0 | ||
eth-in-total-frames : 418 | ||
eth-in-error-oversize-frames : 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name : e2 | ||
index : 4 | ||
mtu : 1500 | ||
operational status : up | ||
auto-negotiation : on | ||
duplex : full | ||
speed : 10000 | ||
physical address : 02:00:00:00:00:02 | ||
ipv4 addresses : | ||
ipv6 addresses : | ||
in-octets : 17582 | ||
out-octets : 1327 | ||
|
||
eth-out-frames : 713 | ||
eth-out-multicast-frames : 605 | ||
eth-out-broadcast-frames : 69 | ||
eth-in-frames : 418 | ||
eth-in-multicast-frames : 336 | ||
eth-in-broadcast-frames : 46 | ||
eth-in-error-fcs-frames : 0 | ||
eth-in-total-frames : 418 | ||
eth-in-error-oversize-frames : 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name : e3 | ||
index : 5 | ||
mtu : 1500 | ||
operational status : up | ||
auto-negotiation : on | ||
duplex : full | ||
speed : 10000 | ||
physical address : 02:00:00:00:00:03 | ||
ipv4 addresses : | ||
ipv6 addresses : | ||
in-octets : 15057 | ||
out-octets : 1327 | ||
|
||
eth-out-frames : 713 | ||
eth-out-multicast-frames : 605 | ||
eth-out-broadcast-frames : 69 | ||
eth-in-frames : 418 | ||
eth-in-multicast-frames : 336 | ||
eth-in-broadcast-frames : 46 | ||
eth-in-error-fcs-frames : 0 | ||
eth-in-total-frames : 418 | ||
eth-in-error-oversize-frames : 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name : e4 | ||
index : 6 | ||
mtu : 1500 | ||
operational status : up | ||
auto-negotiation : on | ||
duplex : full | ||
speed : 10000 | ||
physical address : 02:00:00:00:00:04 | ||
ipv4 addresses : | ||
ipv6 addresses : | ||
in-octets : 19022 | ||
out-octets : 1327 | ||
|
||
eth-out-frames : 713 | ||
eth-out-multicast-frames : 605 | ||
eth-out-broadcast-frames : 69 | ||
eth-in-frames : 418 | ||
eth-in-multicast-frames : 336 | ||
eth-in-broadcast-frames : 46 | ||
eth-in-error-fcs-frames : 0 | ||
eth-in-total-frames : 418 | ||
eth-in-error-oversize-frames : 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[7mINTERFACE PROTOCOL STATE DATA [0m | ||
br0 ethernet [32mUP [39m02:00:00:00:00:00 | ||
├ e0 ethernet [32mUP [39m02:00:00:00:00:00 | ||
└ e1 ethernet [32mUP [39m02:00:00:00:00:01 | ||
e2 ethernet [32mUP [39m02:00:00:00:00:02 | ||
e3 ethernet [32mUP [39m02:00:00:00:00:03 | ||
e4 ethernet [32mUP [39m02:00:00:00:00:04 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT_PATH="$(dirname "$(readlink -f "$0")")" | ||
ROOT_PATH="$SCRIPT_PATH/../../../" | ||
CLI_OUTPUT_PATH="$SCRIPT_PATH/cli-output/" | ||
|
||
CLI_PRETTY_TOOL="$ROOT_PATH/board/netconf/rootfs/lib/infix/cli-pretty" | ||
SR_EMULATOR_TOOL="$SCRIPT_PATH/sysrepo-emulator.sh" | ||
|
||
CLI_OUTPUT_FILE="$(mktemp)" | ||
|
||
TEST=1 | ||
|
||
cleanup() { | ||
rm -f "$CLI_OUTPUT_FILE" | ||
} | ||
trap cleanup EXIT | ||
|
||
ok() { | ||
echo "ok $TEST - $1" | ||
TEST=$((TEST + 1)) | ||
} | ||
|
||
fail() { | ||
echo "not ok $TEST - $1" | ||
exit 1 | ||
} | ||
|
||
print_update_txt() { | ||
echo | ||
echo "# CLI output has changed. This might not be an error if you intentionally" | ||
echo "# changed something in yanger or cli-pretty. If you did, you need to update" | ||
echo "# the template file." | ||
echo | ||
echo "# Here's how you update the CLI output templates:" | ||
echo "# $SCRIPT_PATH/run.sh update" | ||
echo | ||
echo "# Check the result" | ||
echo "# git diff" | ||
echo | ||
echo "# Then finish up by committing the new template" | ||
echo | ||
} | ||
|
||
if [ ! -e "$CLI_PRETTY_TOOL" ]; then | ||
echo "Error, cli-pretty tool not found" | ||
exit 1 | ||
fi | ||
|
||
if [ $# -eq 1 ] && [ $1 = "update" ]; then | ||
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-interfaces" > "$CLI_OUTPUT_PATH/show-interfaces.txt" | ||
for iface in "br0" "e0" "e1" "e2" "e3" "e4"; do | ||
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-interfaces" -n "$iface" \ | ||
> "$CLI_OUTPUT_PATH/show-interface-${iface}.txt" | ||
done | ||
echo "All files updated. Check git diff and commit if they look OK" | ||
exit 0 | ||
fi | ||
|
||
echo "1..7" | ||
|
||
# Show interfaces | ||
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-interfaces" > "$CLI_OUTPUT_FILE" | ||
if ! diff -u "$CLI_OUTPUT_PATH/show-interfaces.txt" "$CLI_OUTPUT_FILE"; then | ||
print_update_txt | ||
fail "\"show interfaces\" output has changed" | ||
fi | ||
ok "\"show interfaces\" output looks intact" | ||
|
||
# Show detailed interfaces | ||
for iface in "br0" "e0" "e1" "e2" "e3" "e4"; do | ||
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-interfaces" -n "$iface" > "$CLI_OUTPUT_FILE" | ||
if ! diff -u "$CLI_OUTPUT_PATH/show-interface-${iface}.txt" "$CLI_OUTPUT_FILE"; then | ||
print_update_txt | ||
fail "\"show interface name $iface\" output has changed" | ||
fi | ||
ok "\"show interface name $iface\" output looks intact" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT_PATH="$(dirname "$(readlink -f "$0")")" | ||
ROOT_PATH="$SCRIPT_PATH/../../../" | ||
|
||
YANGER_TOOL="$ROOT_PATH/board/netconf/rootfs/lib/infix/yanger" | ||
|
||
INTERFACES="br0 e0 e1 e2 e3 e4" | ||
|
||
YANGER_OUTPUT_FILE="$(mktemp)" | ||
|
||
cleanup() { | ||
rm -f "$YANGER_OUTPUT_FILE" | ||
} | ||
trap cleanup EXIT | ||
|
||
if [ ! -e "$YANGER_TOOL" ]; then | ||
echo "Error, yanger tool not found" | ||
exit 1 | ||
fi | ||
|
||
for iface in $INTERFACES; do | ||
if ! "$YANGER_TOOL" "ietf-interfaces" \ | ||
-t "$SCRIPT_PATH/system-output/" \ | ||
-p "$iface" >> "$YANGER_OUTPUT_FILE"; then | ||
echo "Error, running yanger for interface $iface" >&2 | ||
exit 1 | ||
fi | ||
done | ||
|
||
if ! jq -s 'reduce .[] as $item | ||
({}; .["ietf-interfaces:interfaces"].interface += | ||
$item["ietf-interfaces:interfaces"].interface)' \ | ||
"$YANGER_OUTPUT_FILE"; then | ||
echo "Error, merging yanger output data" >&2 | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Settings for e0: | ||
Supported ports: [ ] | ||
Supported link modes: 10baseT/Half 10baseT/Full | ||
100baseT/Half 100baseT/Full | ||
1000baseT/Full | ||
10000baseT/Full | ||
2500baseT/Full | ||
5000baseT/Full | ||
Supported pause frame use: Symmetric | ||
Supports auto-negotiation: Yes | ||
Supported FEC modes: Not reported | ||
Advertised link modes: 10baseT/Half 10baseT/Full | ||
100baseT/Half 100baseT/Full | ||
1000baseT/Full | ||
10000baseT/Full | ||
2500baseT/Full | ||
5000baseT/Full | ||
Advertised pause frame use: Symmetric | ||
Advertised auto-negotiation: Yes | ||
Advertised FEC modes: Not reported | ||
Link partner advertised link modes: 10baseT/Half 10baseT/Full | ||
100baseT/Half 100baseT/Full | ||
1000baseT/Full | ||
10000baseT/Full | ||
2500baseT/Full | ||
5000baseT/Full | ||
Link partner advertised pause frame use: Symmetric | ||
Link partner advertised auto-negotiation: Yes | ||
Link partner advertised FEC modes: Not reported | ||
Speed: 10000Mb/s | ||
Duplex: Full | ||
Auto-negotiation: on | ||
Port: Twisted Pair | ||
PHYAD: 4 | ||
Transceiver: external | ||
MDI-X: on (auto) | ||
Supports Wake-on: g | ||
Wake-on: d | ||
Link detected: yes |
Oops, something went wrong.