|
4 | 4 |
|
5 | 5 | from click.testing import CliRunner
|
6 | 6 |
|
| 7 | +from utilities_common import multi_asic |
| 8 | +from utilities_common import constants |
| 9 | + |
| 10 | +from unittest.mock import patch |
| 11 | + |
| 12 | +from sonic_py_common import device_info |
7 | 13 | show_bgp_summary_v4 = """\
|
8 | 14 |
|
9 | 15 | IPv4 Unicast Summary:
|
|
91 | 97 | Error: bgp summary from bgp container not in json format
|
92 | 98 | """
|
93 | 99 |
|
| 100 | +show_bgp_summary_v4_chassis = """\ |
| 101 | +
|
| 102 | +IPv4 Unicast Summary: |
| 103 | +BGP router identifier 10.3.147.15, local AS number 65100 vrf-id 0 |
| 104 | +BGP table version 21464 |
| 105 | +RIB entries 25783, using 4950336 bytes of memory |
| 106 | +Peers 23, using 501768 KiB of memory |
| 107 | +Peer groups 3, using 192 bytes of memory |
| 108 | +
|
| 109 | +
|
| 110 | +Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName |
| 111 | +----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- -------------- |
| 112 | +10.0.0.1 4 65200 4632 11028 0 0 0 00:18:31 8514 ARISTA01T2 |
| 113 | +10.0.0.9 4 65202 4632 11029 0 0 0 00:18:33 8514 ARISTA05T2 |
| 114 | +10.0.0.13 4 65203 4632 11028 0 0 0 00:18:33 8514 ARISTA07T2 |
| 115 | +10.0.0.17 4 65204 4631 11028 0 0 0 00:18:31 8514 ARISTA09T2 |
| 116 | +10.0.0.21 4 65205 4632 11031 0 0 0 00:18:33 8514 ARISTA11T2 |
| 117 | +10.0.0.25 4 65206 4632 11031 0 0 0 00:18:33 8514 ARISTA13T2 |
| 118 | +10.0.0.29 4 65207 4632 11028 0 0 0 00:18:31 8514 ARISTA15T2 |
| 119 | +10.0.0.33 4 65208 4633 11029 0 0 0 00:18:33 8514 ARISTA01T0 |
| 120 | +10.0.0.37 4 65210 4632 11028 0 0 0 00:18:32 8514 ARISTA03T0 |
| 121 | +10.0.0.39 4 65211 4629 6767 0 0 0 00:18:22 8514 ARISTA04T0 |
| 122 | +10.0.0.41 4 65212 4632 11028 0 0 0 00:18:32 8514 ARISTA05T0 |
| 123 | +10.0.0.43 4 65213 4629 6767 0 0 0 00:18:23 8514 ARISTA06T0 |
| 124 | +10.0.0.45 4 65214 4633 11029 0 0 0 00:18:33 8514 ARISTA07T0 |
| 125 | +10.0.0.47 4 65215 4629 6767 0 0 0 00:18:23 8514 ARISTA08T0 |
| 126 | +10.0.0.49 4 65216 4633 11029 0 0 0 00:18:35 8514 ARISTA09T0 |
| 127 | +10.0.0.51 4 65217 4633 11029 0 0 0 00:18:33 8514 ARISTA10T0 |
| 128 | +10.0.0.53 4 65218 4632 11029 0 0 0 00:18:35 8514 ARISTA11T0 |
| 129 | +10.0.0.55 4 65219 4632 11029 0 0 0 00:18:33 8514 ARISTA12T0 |
| 130 | +10.0.0.57 4 65220 4632 11029 0 0 0 00:18:35 8514 ARISTA13T0 |
| 131 | +10.0.0.59 4 65221 4632 11029 0 0 0 00:18:33 8514 ARISTA14T0 |
| 132 | +
|
| 133 | +Total number of neighbors 20 |
| 134 | +""" |
| 135 | + |
| 136 | +show_bgp_summary_v6_chassis = """\ |
| 137 | +
|
| 138 | +IPv6 Unicast Summary: |
| 139 | +BGP router identifier 10.3.147.15, local AS number 65100 vrf-id 0 |
| 140 | +BGP table version 12971 |
| 141 | +RIB entries 25783, using 4950336 bytes of memory |
| 142 | +Peers 23, using 501768 KiB of memory |
| 143 | +Peer groups 3, using 192 bytes of memory |
| 144 | +
|
| 145 | +
|
| 146 | +Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName |
| 147 | +----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- -------------- |
| 148 | +fc00::1a 4 65203 4438 6578 0 0 0 00:08:57 8514 ARISTA07T2 |
| 149 | +fc00::2 4 65200 4439 6578 0 0 0 00:08:56 8513 ARISTA01T2 |
| 150 | +fc00::2a 4 65205 4439 6578 0 0 0 00:08:57 8514 ARISTA11T2 |
| 151 | +fc00::3a 4 65207 4439 6578 0 0 0 00:08:57 8514 ARISTA15T2 |
| 152 | +fc00::4a 4 65210 4439 6579 0 0 0 00:08:59 8514 ARISTA03T0 |
| 153 | +fc00::4e 4 65211 4440 6579 0 0 0 00:09:00 8514 ARISTA04T0 |
| 154 | +fc00::5a 4 65214 4440 6579 0 0 0 00:09:00 8514 ARISTA07T0 |
| 155 | +fc00::5e 4 65215 4438 6576 0 0 0 00:08:50 8514 ARISTA08T0 |
| 156 | +fc00::6a 4 65218 4441 6580 0 0 0 00:09:01 8514 ARISTA11T0 |
| 157 | +fc00::6e 4 65219 4442 6580 0 0 0 00:09:01 8514 ARISTA12T0 |
| 158 | +fc00::7a 4 65222 4441 6580 0 0 0 00:09:01 8514 ARISTA15T0 |
| 159 | +fc00::12 4 65202 4438 6578 0 0 0 00:08:57 8514 ARISTA05T2 |
| 160 | +fc00::22 4 65204 4438 6578 0 0 0 00:08:57 8514 ARISTA09T2 |
| 161 | +fc00::32 4 65206 4438 6578 0 0 0 00:08:57 8514 ARISTA13T2 |
| 162 | +fc00::42 4 65208 4442 6580 0 0 0 00:09:01 8514 ARISTA01T0 |
| 163 | +fc00::52 4 65212 4439 6579 0 0 0 00:08:59 8514 ARISTA05T0 |
| 164 | +fc00::56 4 65213 4439 6579 0 0 0 00:08:59 8514 ARISTA06T0 |
| 165 | +fc00::62 4 65216 4438 6576 0 0 0 00:08:50 8514 ARISTA09T0 |
| 166 | +fc00::66 4 65217 4442 6580 0 0 0 00:09:01 8514 ARISTA10T0 |
| 167 | +fc00::72 4 65220 4441 6580 0 0 0 00:09:01 8514 ARISTA13T0 |
| 168 | +
|
| 169 | +Total number of neighbors 20 |
| 170 | +""" |
| 171 | + |
| 172 | +show_bgp_summary_v4_all_chassis = """\ |
| 173 | +
|
| 174 | +IPv4 Unicast Summary: |
| 175 | +BGP router identifier 10.3.147.15, local AS number 65100 vrf-id 0 |
| 176 | +BGP table version 21464 |
| 177 | +RIB entries 25783, using 4950336 bytes of memory |
| 178 | +Peers 23, using 501768 KiB of memory |
| 179 | +Peer groups 3, using 192 bytes of memory |
| 180 | +
|
| 181 | +
|
| 182 | +Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName |
| 183 | +----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- ------------------ |
| 184 | +3.3.3.6 4 65100 0 0 0 0 0 never Connect str2-chassis-lc6-1 |
| 185 | +3.3.3.7 4 65100 808 178891 0 0 0 00:17:47 1458 str2-chassis-lc7-1 |
| 186 | +10.0.0.1 4 65200 4632 11028 0 0 0 00:18:31 8514 ARISTA01T2 |
| 187 | +10.0.0.9 4 65202 4632 11029 0 0 0 00:18:33 8514 ARISTA05T2 |
| 188 | +10.0.0.13 4 65203 4632 11028 0 0 0 00:18:33 8514 ARISTA07T2 |
| 189 | +10.0.0.17 4 65204 4631 11028 0 0 0 00:18:31 8514 ARISTA09T2 |
| 190 | +10.0.0.21 4 65205 4632 11031 0 0 0 00:18:33 8514 ARISTA11T2 |
| 191 | +10.0.0.25 4 65206 4632 11031 0 0 0 00:18:33 8514 ARISTA13T2 |
| 192 | +10.0.0.29 4 65207 4632 11028 0 0 0 00:18:31 8514 ARISTA15T2 |
| 193 | +10.0.0.33 4 65208 4633 11029 0 0 0 00:18:33 8514 ARISTA01T0 |
| 194 | +10.0.0.37 4 65210 4632 11028 0 0 0 00:18:32 8514 ARISTA03T0 |
| 195 | +10.0.0.39 4 65211 4629 6767 0 0 0 00:18:22 8514 ARISTA04T0 |
| 196 | +10.0.0.41 4 65212 4632 11028 0 0 0 00:18:32 8514 ARISTA05T0 |
| 197 | +10.0.0.43 4 65213 4629 6767 0 0 0 00:18:23 8514 ARISTA06T0 |
| 198 | +10.0.0.45 4 65214 4633 11029 0 0 0 00:18:33 8514 ARISTA07T0 |
| 199 | +10.0.0.47 4 65215 4629 6767 0 0 0 00:18:23 8514 ARISTA08T0 |
| 200 | +10.0.0.49 4 65216 4633 11029 0 0 0 00:18:35 8514 ARISTA09T0 |
| 201 | +10.0.0.51 4 65217 4633 11029 0 0 0 00:18:33 8514 ARISTA10T0 |
| 202 | +10.0.0.53 4 65218 4632 11029 0 0 0 00:18:35 8514 ARISTA11T0 |
| 203 | +10.0.0.55 4 65219 4632 11029 0 0 0 00:18:33 8514 ARISTA12T0 |
| 204 | +10.0.0.57 4 65220 4632 11029 0 0 0 00:18:35 8514 ARISTA13T0 |
| 205 | +10.0.0.59 4 65221 4632 11029 0 0 0 00:18:33 8514 ARISTA14T0 |
| 206 | +10.0.0.61 4 65222 4633 11029 0 0 0 00:18:33 8514 INT_NEIGH0 |
| 207 | +
|
| 208 | +Total number of neighbors 23 |
| 209 | +""" |
| 210 | + |
94 | 211 |
|
95 | 212 | class TestBgpCommands(object):
|
96 | 213 | @classmethod
|
@@ -139,3 +256,66 @@ def test_bgp_summary_error(
|
139 | 256 | print("{}".format(result.output))
|
140 | 257 | assert result.exit_code == 2
|
141 | 258 | assert result.output == show_error_invalid_json
|
| 259 | + |
| 260 | + def display_external(self): |
| 261 | + return constants.DISPLAY_EXTERNAL |
| 262 | + |
| 263 | + def display_all(self): |
| 264 | + return constants.DISPLAY_ALL |
| 265 | + |
| 266 | + @pytest.mark.parametrize( |
| 267 | + 'setup_single_bgp_instance_chassis', ['v4'], |
| 268 | + indirect=['setup_single_bgp_instance_chassis'] |
| 269 | + ) |
| 270 | + @patch.object(multi_asic.MultiAsic, 'get_display_option', display_external) |
| 271 | + @patch('sonic_py_common.device_info.get_platform_info') |
| 272 | + def test_bgp_summary_v4_chassis( |
| 273 | + self, mock_is_chassis, setup_bgp_commands, |
| 274 | + setup_single_bgp_instance_chassis |
| 275 | + ): |
| 276 | + mock_is_chassis.return_value = {'switch_type': 'voq'} |
| 277 | + show = setup_bgp_commands |
| 278 | + runner = CliRunner() |
| 279 | + result = runner.invoke( |
| 280 | + show.cli.commands["ip"].commands["bgp"].commands["summary"], []) |
| 281 | + print("{}".format(result.output)) |
| 282 | + assert result.exit_code == 0 |
| 283 | + assert result.output == show_bgp_summary_v4_chassis |
| 284 | + |
| 285 | + @pytest.mark.parametrize( |
| 286 | + 'setup_single_bgp_instance_chassis', ['v6'], |
| 287 | + indirect=['setup_single_bgp_instance_chassis'] |
| 288 | + ) |
| 289 | + @patch.object(multi_asic.MultiAsic, 'get_display_option', display_external) |
| 290 | + @patch('sonic_py_common.device_info.get_platform_info') |
| 291 | + def test_bgp_summary_v6_chassis( |
| 292 | + self, mock_is_chassis, setup_bgp_commands, |
| 293 | + setup_single_bgp_instance_chassis |
| 294 | + ): |
| 295 | + mock_is_chassis.return_value = {'switch_type': 'voq'} |
| 296 | + show = setup_bgp_commands |
| 297 | + runner = CliRunner() |
| 298 | + result = runner.invoke( |
| 299 | + show.cli.commands["ipv6"].commands["bgp"].commands["summary"], []) |
| 300 | + print("{}".format(result.output)) |
| 301 | + assert result.exit_code == 0 |
| 302 | + assert result.output == show_bgp_summary_v6_chassis |
| 303 | + |
| 304 | + @pytest.mark.parametrize( |
| 305 | + 'setup_single_bgp_instance_chassis', ['v4'], |
| 306 | + indirect=['setup_single_bgp_instance_chassis'] |
| 307 | + ) |
| 308 | + @patch.object(multi_asic.MultiAsic, 'get_display_option', display_all) |
| 309 | + @patch('sonic_py_common.device_info.get_platform_info') |
| 310 | + def test_bgp_summary_v4_all_chassis( |
| 311 | + self, mock_is_chassis, setup_bgp_commands, |
| 312 | + setup_single_bgp_instance_chassis |
| 313 | + ): |
| 314 | + mock_is_chassis.return_value = {'switch_type': 'voq'} |
| 315 | + show = setup_bgp_commands |
| 316 | + runner = CliRunner() |
| 317 | + result = runner.invoke( |
| 318 | + show.cli.commands["ip"].commands["bgp"].commands["summary"], []) |
| 319 | + print("{}".format(result.output)) |
| 320 | + assert result.exit_code == 0 |
| 321 | + assert result.output == show_bgp_summary_v4_all_chassis |
0 commit comments