Skip to content

Commit

Permalink
tests: Add topotest for MGMT OPER-DATA command.
Browse files Browse the repository at this point in the history
This commit ads a topotest test-case to check the GET-OPER-DATA
functionality.

Signed-off-by: Pushpasis Sarkar <pushpasis@gmail.com>
  • Loading branch information
pushpasis committed Sep 14, 2023
1 parent 5546fb1 commit 3a8aa68
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/topotests/mgmt_tests/show_mgmt_oper_data_route_1.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/distance": "1"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/metric": "0"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/selected": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/installed": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/internal-flags": "73"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/internal-status": "16"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/uptime": "2023-09-14T07:23:12.488159Z"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/nexthop-group/id": "20"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/active": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/fib": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/weight": "1"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/bh-type": "null"
]
26 changes: 26 additions & 0 deletions tests/topotests/mgmt_tests/show_mgmt_oper_data_route_1_2.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/distance": "1"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/metric": "0"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/selected": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/installed": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/internal-flags": "73"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/internal-status": "16"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/uptime": "2023-09-14T07:23:12.488159Z"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/nexthop-group/id": "20"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/active": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/fib": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/weight": "1"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.1']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/bh-type": "null"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/distance": "1"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/metric": "0"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/selected": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/installed": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/internal-flags": "73"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/internal-status": "16"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/uptime": "2023-09-14T07:23:12.488159Z"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/nexthop-group/id": "20"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/active": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/fib": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/weight": "1"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/bh-type": "null"
]
14 changes: 14 additions & 0 deletions tests/topotests/mgmt_tests/show_mgmt_oper_data_route_2 copy.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/distance": "1"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/metric": "0"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/selected": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/installed": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/internal-flags": "73"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/internal-status": "16"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/uptime": "2023-09-14T07:23:12.488159Z"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/nexthop-group/id": "20"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/active": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/fib": "(null)"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/weight": "1"
"/frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='frr-routing:ipv4-unicast'][table-id='254']/route[prefix='192.168.1.3']/route-entry[protocol='static']/nexthop-group/nexthop[nh-type='blackhole'][vrf='0'][gateway=''][interface=' ']/bh-type": "null"
]
2 changes: 2 additions & 0 deletions tests/topotests/mgmt_tests/show_mgmt_oper_data_route_none.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
117 changes: 117 additions & 0 deletions tests/topotests/mgmt_tests/test_yang_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@

# pylint: disable=C0413
# Import topogen and topotest helpers
from lib import topotest
from lib.topogen import Topogen, get_topogen
from lib.topotest import version_cmp
from functools import partial

# Import topoJson from lib, to create topology and initial configuration
from lib.common_config import (
Expand Down Expand Up @@ -156,6 +158,33 @@ def populate_nh():
return next_hop_ip


def router_compare_text_output(rname, command, reference, check_for_mismatch = False):
"Compare router text output"

logger.info('Comparing router "%s" "%s" output', rname, command)

tgen = get_topogen()
filename = "{}/{}/{}".format(CWD, rname, reference)
expected = open(filename).read()

# Run test function until we get an result. Wait at most 80 seconds.
test_func = partial(
topotest.router_output_cmp, tgen.gears[rname], command, expected
)
if check_for_mismatch :
result, diff = topotest.run_and_expect(test_func, "", count=3, wait=0.5)
logger.info('Expected result:\n========\n{}\n=========='.format(expected))
logger.info('Actual result:\n========\n{}\n========'.format(tgen.gears[rname].vtysh_cmd(command)))
assertmsg = '"{}" Text output does not mismatch the expected result. Diff:\n {}\n'.format(rname, diff)
assert result is not None, assertmsg
else :
result, diff = topotest.run_and_expect(test_func, "", count=3, wait=3.5)
logger.info('Expected result:\n========\n{}\n=========='.format(expected))
logger.info('Actual result:\n========\n{}\n========'.format(tgen.gears[rname].vtysh_cmd(command)))
assertmsg = '"{}" Text output mismatches the expected result. Diff:\n {}\n'.format(rname, diff)
assert result, assertmsg


#####################################################
#
# Testcases
Expand Down Expand Up @@ -401,6 +430,94 @@ def test_mgmt_delete_config(request):
write_test_footer(tc_name)


def test_mgmt_get_oper_data(request):
"""
Verify mgmt get oper-data.
"""
tc_name = request.node.name
write_test_header(tc_name)
tgen = get_topogen()
# Don't run this test if we have any failure.
if tgen.routers_have_failure():
pytest.skip(tgen.errors)

reset_config_on_routers(tgen)

step("Configure a static route using commit apply")

raw_config = {
"r1": {
"raw_config": [
"mgmt set-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.168.1.1/32'][afi-safi='frr-routing:ipv4-unicast']/path-list[table-id='0'][distance='1']/frr-nexthops/nexthop[nh-type='blackhole'][vrf='default'][gateway=''][interface='(null)']/vrf default",
"mgmt commit apply",
]
}
}

result = apply_raw_config(tgen, raw_config)
assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

step("Get and verify oper-data from Zebra for route #1")
router_compare_text_output(
rname, "show mgmt get-data operational /frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='*'][table-id='*']/route[prefix='192.168.1.1/32']/",
"show_mgmt_oper_data_route_1.ref"
)

step("Configure another static route using commit apply")

raw_config = {
"r1": {
"raw_config": [
"mgmt set-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.168.1.3/32'][afi-safi='frr-routing:ipv4-unicast']/path-list[table-id='0'][distance='1']/frr-nexthops/nexthop[nh-type='blackhole'][vrf='default'][gateway=''][interface='(null)']/vrf default",
"mgmt commit apply",
]
}
}

result = apply_raw_config(tgen, raw_config)
assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

step("Get and verify oper-data from Zebra for route #2")
router_compare_text_output(
"r1", "show mgmt get-data operational /frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='*'][table-id='*']/route[prefix='192.168.1.3/32']/",
"show_mgmt_oper_data_route_2.ref"
)

step("Get and verify oper-data from Zebra for all static route")
router_compare_text_output(
"r1", "show mgmt get-data operational /frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='*'][table-id='*']/route[prefix='*']/route-entry[protocol='static']/",
"show_mgmt_oper_data_route_2.ref"
)

step("Delete static route 1 and 2")
raw_config = {
"r1": {
"raw_config": [
"mgmt delete-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.168.1.1/32'][afi-safi='frr-routing:ipv4-unicast']",
"mgmt delete-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.168.1.3/32'][afi-safi='frr-routing:ipv4-unicast']",
"mgmt commit apply",
]
}
}

result = apply_raw_config(tgen, raw_config)
assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

step("Verify that the route is deleted from RIB")
router_compare_text_output(
"r1", "show mgmt get-data operational /frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='*'][table-id='*']/route[prefix='*']/route-entry[protocol='static']/",
"show_mgmt_oper_data_route_1_2.ref",
check_for_mismatch = True
)
router_compare_text_output(
"r1", "show mgmt get-data operational /frr-vrf:lib/vrf[name='default']/frr-zebra:zebra/ribs/rib[afi-safi-name='*'][table-id='*']/route[prefix='*']/route-entry[protocol='static']/",
"show_mgmt_oper_data_route_none.ref"
)

write_test_footer(tc_name)


def test_mgmt_chaos_stop_start_frr(request):
"""
Kill mgmtd - verify that watch frr restarts.
Expand Down

0 comments on commit 3a8aa68

Please sign in to comment.