|
| 1 | +import os |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from click.testing import CliRunner |
| 6 | + |
| 7 | +show_bgp_summary_v4 = """\ |
| 8 | +
|
| 9 | +IPv4 Unicast Summary: |
| 10 | +BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0 |
| 11 | +BGP table version 12811 |
| 12 | +RIB entries 12817, using 2358328 bytes of memory |
| 13 | +Peers 24, using 502080 KiB of memory |
| 14 | +Peer groups 4, using 256 bytes of memory |
| 15 | +
|
| 16 | +
|
| 17 | +Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName |
| 18 | +----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- -------------- |
| 19 | +10.0.0.1 4 65200 5919 2717 0 0 0 1d21h11m 6402 ARISTA01T2 |
| 20 | +10.0.0.5 4 65200 5916 2714 0 0 0 1d21h10m 6402 ARISTA03T2 |
| 21 | +10.0.0.9 4 65200 5915 2713 0 0 0 1d21h09m 6402 ARISTA05T2 |
| 22 | +10.0.0.13 4 65200 5917 2716 0 0 0 1d21h11m 6402 ARISTA07T2 |
| 23 | +10.0.0.17 4 65200 5916 2713 0 0 0 1d21h09m 6402 ARISTA09T2 |
| 24 | +10.0.0.21 4 65200 5917 2716 0 0 0 1d21h11m 6402 ARISTA11T2 |
| 25 | +10.0.0.25 4 65200 5917 2716 0 0 0 1d21h11m 6402 ARISTA13T2 |
| 26 | +10.0.0.29 4 65200 5916 2714 0 0 0 1d21h10m 6402 ARISTA15T2 |
| 27 | +10.0.0.33 4 64001 0 0 0 0 0 never Active ARISTA01T0 |
| 28 | +10.0.0.35 4 64002 0 0 0 0 0 never Active ARISTA02T0 |
| 29 | +10.0.0.37 4 64003 0 0 0 0 0 never Active ARISTA03T0 |
| 30 | +10.0.0.39 4 64004 0 0 0 0 0 never Active ARISTA04T0 |
| 31 | +10.0.0.41 4 64005 0 0 0 0 0 never Active ARISTA05T0 |
| 32 | +10.0.0.43 4 64006 0 0 0 0 0 never Active ARISTA06T0 |
| 33 | +10.0.0.45 4 64007 0 0 0 0 0 never Active ARISTA07T0 |
| 34 | +10.0.0.47 4 64008 0 0 0 0 0 never Active ARISTA08T0 |
| 35 | +10.0.0.49 4 64009 0 0 0 0 0 never Active ARISTA09T0 |
| 36 | +10.0.0.51 4 64010 0 0 0 0 0 never Active ARISTA10T0 |
| 37 | +10.0.0.53 4 64011 0 0 0 0 0 never Active ARISTA11T0 |
| 38 | +10.0.0.55 4 64012 0 0 0 0 0 never Active ARISTA12T0 |
| 39 | +10.0.0.57 4 64013 0 0 0 0 0 never Active ARISTA13T0 |
| 40 | +10.0.0.59 4 64014 0 0 0 0 0 never Active ARISTA14T0 |
| 41 | +10.0.0.61 4 64015 0 0 0 0 0 never Active ARISTA15T0 |
| 42 | +10.0.0.63 4 64016 0 0 0 0 0 never Active ARISTA16T0 |
| 43 | +""" |
| 44 | + |
| 45 | +show_bgp_summary_v6 = """\ |
| 46 | +
|
| 47 | +IPv6 Unicast Summary: |
| 48 | +BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0 |
| 49 | +BGP table version 8972 |
| 50 | +RIB entries 12817, using 2358328 bytes of memory |
| 51 | +Peers 24, using 502080 KiB of memory |
| 52 | +Peer groups 4, using 256 bytes of memory |
| 53 | +
|
| 54 | +
|
| 55 | +Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName |
| 56 | +----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- -------------- |
| 57 | +fc00::1a 4 65200 6665 6672 0 0 0 2d09h39m 6402 ARISTA07T2 |
| 58 | +fc00::2 4 65200 6666 7913 0 0 0 2d09h39m 6402 ARISTA01T2 |
| 59 | +fc00::2a 4 65200 6666 7913 0 0 0 2d09h39m 6402 ARISTA11T2 |
| 60 | +fc00::3a 4 65200 6666 7912 0 0 0 2d09h39m 6402 ARISTA15T2 |
| 61 | +fc00::4a 4 64003 0 0 0 0 0 never Active ARISTA03T0 |
| 62 | +fc00::4e 4 64004 0 0 0 0 0 never Active ARISTA04T0 |
| 63 | +fc00::5a 4 64007 0 0 0 0 0 never Active ARISTA07T0 |
| 64 | +fc00::5e 4 64008 0 0 0 0 0 never Active ARISTA08T0 |
| 65 | +fc00::6a 4 64011 0 0 0 0 0 never Connect ARISTA11T0 |
| 66 | +fc00::6e 4 64012 0 0 0 0 0 never Active ARISTA12T0 |
| 67 | +fc00::7a 4 64015 0 0 0 0 0 never Active ARISTA15T0 |
| 68 | +fc00::7e 4 64016 0 0 0 0 0 never Active ARISTA16T0 |
| 69 | +fc00::12 4 65200 6666 7915 0 0 0 2d09h39m 6402 ARISTA05T2 |
| 70 | +fc00::22 4 65200 6667 7915 0 0 0 2d09h39m 6402 ARISTA09T2 |
| 71 | +fc00::32 4 65200 6663 6669 0 0 0 2d09h36m 6402 ARISTA13T2 |
| 72 | +fc00::42 4 64001 0 0 0 0 0 never Active ARISTA01T0 |
| 73 | +fc00::46 4 64002 0 0 0 0 0 never Active ARISTA02T0 |
| 74 | +fc00::52 4 64005 0 0 0 0 0 never Active ARISTA05T0 |
| 75 | +fc00::56 4 64006 0 0 0 0 0 never Active ARISTA06T0 |
| 76 | +fc00::62 4 64009 0 0 0 0 0 never Active ARISTA09T0 |
| 77 | +fc00::66 4 64010 0 0 0 0 0 never Active ARISTA10T0 |
| 78 | +fc00::72 4 64013 0 0 0 0 0 never Active ARISTA13T0 |
| 79 | +fc00::76 4 64014 0 0 0 0 0 never Active ARISTA14T0 |
| 80 | +fc00::a 4 65200 6665 6671 0 0 0 2d09h38m 6402 ARISTA03T2 |
| 81 | +""" |
| 82 | + |
| 83 | +show_error_invalid_json = """\ |
| 84 | +Usage: summary [OPTIONS] |
| 85 | +Try 'summary --help' for help. |
| 86 | +
|
| 87 | +Error: bgp summary from bgp container not in json format |
| 88 | +""" |
| 89 | + |
| 90 | + |
| 91 | +class TestBgpCommands(object): |
| 92 | + @classmethod |
| 93 | + def setup_class(cls): |
| 94 | + print("SETUP") |
| 95 | + import mock_tables.dbconnector |
| 96 | + |
| 97 | + @pytest.mark.parametrize('setup_single_bgp_instance', |
| 98 | + ['v4'], indirect=['setup_single_bgp_instance']) |
| 99 | + def test_bgp_summary_v4( |
| 100 | + self, |
| 101 | + setup_bgp_commands, |
| 102 | + setup_single_bgp_instance): |
| 103 | + show = setup_bgp_commands |
| 104 | + runner = CliRunner() |
| 105 | + result = runner.invoke( |
| 106 | + show.cli.commands["ip"].commands["bgp"].commands["summary"], []) |
| 107 | + print("{}".format(result.output)) |
| 108 | + assert result.exit_code == 0 |
| 109 | + assert result.output == show_bgp_summary_v4 |
| 110 | + |
| 111 | + @pytest.mark.parametrize('setup_single_bgp_instance', |
| 112 | + ['v6'], indirect=['setup_single_bgp_instance']) |
| 113 | + def test_bgp_summary_v6( |
| 114 | + self, |
| 115 | + setup_bgp_commands, |
| 116 | + setup_single_bgp_instance): |
| 117 | + show = setup_bgp_commands |
| 118 | + runner = CliRunner() |
| 119 | + result = runner.invoke( |
| 120 | + show.cli.commands["ipv6"].commands["bgp"].commands["summary"], []) |
| 121 | + print("{}".format(result.output)) |
| 122 | + assert result.exit_code == 0 |
| 123 | + assert result.output == show_bgp_summary_v6 |
| 124 | + |
| 125 | + @pytest.mark.parametrize('setup_single_bgp_instance', |
| 126 | + [' '], indirect=['setup_single_bgp_instance']) |
| 127 | + def test_bgp_summary_error( |
| 128 | + self, |
| 129 | + setup_bgp_commands, |
| 130 | + setup_single_bgp_instance): |
| 131 | + show = setup_bgp_commands |
| 132 | + runner = CliRunner() |
| 133 | + result = runner.invoke( |
| 134 | + show.cli.commands["ipv6"].commands["bgp"].commands["summary"], []) |
| 135 | + print("{}".format(result.output)) |
| 136 | + assert result.exit_code == 2 |
| 137 | + assert result.output == show_error_invalid_json |
0 commit comments