Skip to content

Commit

Permalink
Merge pull request #3 from cchoate54/ideleon/show_cmd_isis_topology
Browse files Browse the repository at this point in the history
[show/tests] Add support for "show isis topology"
  • Loading branch information
cchoate54 committed Apr 24, 2023
2 parents 503bd9c + 0fdf927 commit fc89b29
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 10 deletions.
20 changes: 19 additions & 1 deletion show/isis_frr.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ def interface(interface, verbose, display):

click.echo(output.rstrip('\n'))

# 'topology' subcommand ("show isis topology")
@isis.command()
@click.option('--level-1', is_flag=True, help="Show IS-IS level-1 information")
@click.option('--level-2', is_flag=True, help="Show IS-IS level-2 information")
def topology(level_1, level_2):
"""Show ISIS topology"""

command = 'show isis topology'

if level_1:
command += ' level-1'
elif level_2:
command += ' level-2'

output = ""
output += bgp_util.run_bgp_show_command(command)

click.echo(output.rstrip('\n'))

# 'summary' subcommand ("show isis summary")
@isis.command()
Expand All @@ -129,4 +147,4 @@ def summary():
output = ""
output += bgp_util.run_bgp_show_command(command)

click.echo(output.rstrip('\n'))
click.echo(output.rstrip('\n'))
9 changes: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
mock_show_isis_database,
mock_show_isis_hostname,
mock_show_isis_interface,
mock_show_isis_summary
mock_show_isis_topology,
mock_show_isis_summary,
mock_show_run_isis
)
from . import config_int_ip_common
Expand Down Expand Up @@ -401,7 +402,11 @@ def setup_single_isis_instance(request):
elif request.param.startswith('isis_interface') or \
request.param.startswith('isis_interface'):
bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_show_isis_interface(request))
return_value=mock_show_isis_interface(request))
elif request.param.startswith('isis_topology') or \
request.param.startswith('isis_topology'):
bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_show_isis_topology(request))
elif request.param.startswith('isis_summary'):
bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_show_isis_summary(request))
Expand Down
95 changes: 95 additions & 0 deletions tests/isis_frr_input/isis_frr_test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,16 @@ def mock_show_isis_hostname(request):
'Ethernet116, Ethernet120, Ethernet124, PortChannel0001, PortChannel0002, ' \
'PortChannel0003, PortChannel0004, PortChannel1001)\n'

isis_interface_display_output = \
"[INTERFACE] options: " \
"['Ethernet0', 'Ethernet4', 'Ethernet8', 'Ethernet12', 'Ethernet16', " \
"'Ethernet20', 'Ethernet24', 'Ethernet28', 'Ethernet32', 'Ethernet36', 'Ethernet40', " \
"'Ethernet44', 'Ethernet48', 'Ethernet52', 'Ethernet56', 'Ethernet60', 'Ethernet64', " \
"'Ethernet68', 'Ethernet72', 'Ethernet76', 'Ethernet80', 'Ethernet84', 'Ethernet88', " \
"'Ethernet92', 'Ethernet96', 'Ethernet100', 'Ethernet104', 'Ethernet108', 'Ethernet112', " \
"'Ethernet116', 'Ethernet120', 'Ethernet124', 'PortChannel0001', 'PortChannel0002', " \
"'PortChannel0003', 'PortChannel0004', 'PortChannel1001']\n"

def mock_show_isis_interface(request):
if request.param == 'isis_interface_output':
return isis_interface_output
Expand All @@ -449,9 +459,35 @@ def mock_show_isis_interface(request):
return isis_interface_ifname_output
elif request.param == 'isis_interface_unknown_ifname_output':
return isis_interface_unknown_ifname_output
elif request.param == 'isis_interface_display_output':
return ""
else:
return ""

isis_topology_output = \
"""Area 1:
IS-IS paths to level-2 routers that speak IP
Vertex Type Metric Next-Hop Interface Parent
vlab-01
10.0.0.56/31 IP internal 0 vlab-01(4)
10.1.0.32/32 IP internal 0 vlab-01(4)
ARISTA01T1 TE-IS 10 ARISTA01T1 PortChannel101 vlab-01(4)
10.0.0.56/31 IP TE 16777225 ARISTA01T1 PortChannel101 ARISTA01T1(4)
IS-IS paths to level-2 routers that speak IPv6
Vertex Type Metric Next-Hop Interface Parent
vlab-01
fc00::70/126 IP6 internal 0 vlab-01(4)
fc00:1::32/128 IP6 internal 0 vlab-01(4)
"""

isis_topology_invalid_help_output = \
"""Usage: topology [OPTIONS]
Try "topology --help" for help.
Error: Got unexpected extra argument (?)
"""

show_run_isis_output = \
"""Building configuration...
Expand Down Expand Up @@ -492,6 +528,39 @@ def mock_show_isis_interface(request):
Error: Got unexpected extra argument (?)
"""

isis_topology_level_1_output = \
"""Area 1:
"""

isis_topology_level_2_output = \
"""Area 1:
IS-IS paths to level-2 routers that speak IP
Vertex Type Metric Next-Hop Interface Parent
vlab-01
10.0.0.56/31 IP internal 0 vlab-01(4)
10.1.0.32/32 IP internal 0 vlab-01(4)
ARISTA01T1 TE-IS 10 ARISTA01T1 PortChannel101 vlab-01(4)
10.0.0.56/31 IP TE 16777225 ARISTA01T1 PortChannel101 ARISTA01T1(4)
IS-IS paths to level-2 routers that speak IPv6
Vertex Type Metric Next-Hop Interface Parent
vlab-01
fc00::70/126 IP6 internal 0 vlab-01(4)
fc00:1::32/128 IP6 internal 0 vlab-01(4)
"""

def mock_show_isis_topology(request):
if request.param == 'isis_topology_output':
return isis_topology_output
elif request.param == 'isis_topology_invalid_help_output':
return isis_topology_invalid_help_output
elif request.param == 'isis_topology_level_1_output':
return isis_topology_level_1_output
elif request.param == 'isis_topology_level_2_output':
return isis_topology_level_2_output
else:
return ""

def mock_show_run_isis(request):
if request.param == 'show_run_isis_output':
return show_run_isis_output
Expand Down Expand Up @@ -666,6 +735,31 @@ def mock_show_isis_summary(request):
'rc': 2,
'rc_output': isis_interface_unknown_ifname_output
},
'isis_interface_display': {
'args': ['--display'],
'rc': 0,
'rc_output': isis_interface_display_output
},
'isis_topology': {
'args': [],
'rc': 0,
'rc_output': isis_topology_output
},
'isis_topology_invalid_help': {
'args': ['?'],
'rc': 2,
'rc_output': isis_topology_invalid_help_output
},
'isis_topology_level_1': {
'args': ['--level-1'],
'rc': 0,
'rc_output': isis_topology_level_1_output
},
'isis_topology_level_2': {
'args': ['--level-2'],
'rc': 0,
'rc_output': isis_topology_level_2_output
},
'isis_summary': {
'args': [],
'rc': 0,
Expand All @@ -675,6 +769,7 @@ def mock_show_isis_summary(request):
'args': ['?'],
'rc': 2,
'rc_output': isis_summary_invalid_help_output
},
'show_run_isis': {
'args': [],
'rc': 0,
Expand Down
39 changes: 32 additions & 7 deletions tests/isis_frr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def setup_class(cls):
],
indirect=['setup_single_isis_instance'])
def test_isis_neighbors(self,
setup_isis_commands,
setup_single_isis_instance,
test_vector):
setup_isis_commands,
setup_single_isis_instance,
test_vector):
show = setup_isis_commands
exec_cmd = show.cli.commands["isis"].commands["neighbors"]
executor(test_vector, show, exec_cmd)
Expand Down Expand Up @@ -116,14 +116,39 @@ def setup_class(cls):
('isis_interface_verbose_output', 'isis_interface_verbose'),
('isis_interface_ifname_verbose_output', 'isis_interface_ifname_verbose'),
('isis_interface_unknown_ifname_output', 'isis_interface_unknown_ifname'),
('isis_interface_unknown_ifname_output', 'isis_interface_unknown_ifname'),
('isis_interface_display_output', 'isis_interface_display')
],
indirect=['setup_single_isis_instance'])
def test_isis_interface(self,
setup_isis_commands,
setup_single_isis_instance,
test_vector):
show = setup_isis_commands
exec_cmd = show.cli.commands["isis"].commands["interface"]
executor(test_vector, show, exec_cmd)


class TestIsisTopology(object):

@classmethod
def setup_class(cls):
print("SETUP")

@pytest.mark.parametrize('setup_single_isis_instance, test_vector',
[
('isis_topology_output', 'isis_topology'),
('isis_topology_invalid_help_output', 'isis_topology_invalid_help'),
('isis_topology_level_1_output', 'isis_topology_level_1'),
('isis_topology_level_2_output', 'isis_topology_level_2')
],
indirect=['setup_single_isis_instance'])
def test_isis_topology(self,
setup_isis_commands,
setup_single_isis_instance,
test_vector):
show = setup_isis_commands
exec_cmd = show.cli.commands["isis"].commands["interface"]
exec_cmd = show.cli.commands["isis"].commands["topology"]
executor(test_vector, show, exec_cmd)


Expand All @@ -146,7 +171,7 @@ def test_isis_summary(self,
show = setup_isis_commands
exec_cmd = show.cli.commands["isis"].commands["summary"]
executor(test_vector, show, exec_cmd)


class TestShowRunIsis(object):

Expand All @@ -156,8 +181,8 @@ def setup_class(cls):

@pytest.mark.parametrize('setup_single_isis_instance, test_vector',
[
('show_run_isis_output', 'show_run_isis'),
('show_run_isis_invalid_help_output', 'show_run_isis_invalid_help')
('show_run_isis_output', 'show_run_isis'),
('show_run_isis_invalid_help_output', 'show_run_isis_invalid_help')
],
indirect=['setup_single_isis_instance'])
def test_show_run_isis(self,
Expand Down

0 comments on commit fc89b29

Please sign in to comment.