|
12 | 12 | """
|
13 | 13 | test_isis_topo1.py: Test ISIS topology.
|
14 | 14 | """
|
| 15 | +import time |
15 | 16 | import datetime
|
16 | 17 | import functools
|
17 | 18 | import json
|
@@ -314,6 +315,107 @@ def test_isis_neighbor_json():
|
314 | 315 | ), assertmsg
|
315 | 316 |
|
316 | 317 |
|
| 318 | +def test_isis_neighbor_state(): |
| 319 | + "Check that the neighbor states remain normal when the ISIS type is switched." |
| 320 | + |
| 321 | + tgen = get_topogen() |
| 322 | + # Don't run this test if we have any failure. |
| 323 | + if tgen.routers_have_failure(): |
| 324 | + pytest.skip(tgen.errors) |
| 325 | + |
| 326 | + logger.info("Checking 'show isis neighbor state on a p2p link'") |
| 327 | + |
| 328 | + # Establish a P2P link |
| 329 | + # When the IS-IS type of r3 is set to level-1-2 and the IS-IS type of r5 is set to level-1, |
| 330 | + # it is expected that all neighbors exist and are in the Up state |
| 331 | + r3 = tgen.gears["r3"] |
| 332 | + r3.vtysh_cmd( |
| 333 | + """ |
| 334 | + configure |
| 335 | + router isis 1 |
| 336 | + no redistribute ipv4 connected level-1 |
| 337 | + no redistribute ipv4 connected level-2 |
| 338 | + no redistribute ipv6 connected level-1 |
| 339 | + no redistribute ipv6 connected level-2 |
| 340 | + interface r3-eth1 |
| 341 | + no isis circuit-type |
| 342 | + isis network point-to-point |
| 343 | + end |
| 344 | + """ |
| 345 | + ) |
| 346 | + r5 = tgen.gears["r5"] |
| 347 | + r5.vtysh_cmd( |
| 348 | + """ |
| 349 | + configure |
| 350 | + router isis 1 |
| 351 | + no redistribute ipv4 connected level-1 |
| 352 | + no redistribute ipv6 connected level-1 |
| 353 | + no redistribute ipv4 table 20 level-1 |
| 354 | + interface r5-eth0 |
| 355 | + no isis circuit-type |
| 356 | + isis network point-to-point |
| 357 | + end |
| 358 | + """ |
| 359 | + ) |
| 360 | + result = _check_isis_neighbor_json("r3", "r5", True, "Up") |
| 361 | + assert result is True, result |
| 362 | + result = _check_isis_neighbor_json("r5", "r3", True, "Up") |
| 363 | + assert result is True, result |
| 364 | + |
| 365 | + # Remove the configuration that affects the switch of IS-IS type. |
| 366 | + # Configure the IS-IS type of r3 to transition from level-1-2 to level-2-only, |
| 367 | + # while maintaining the IS-IS type of r5 as level-1. |
| 368 | + # In this scenario, |
| 369 | + # the expectation is that some neighbors do not exist or are in the Initializing state |
| 370 | + r3.vtysh_cmd( |
| 371 | + """ |
| 372 | + configure |
| 373 | + router isis 1 |
| 374 | + is-type level-2-only |
| 375 | + end |
| 376 | + """ |
| 377 | + ) |
| 378 | + result = _check_isis_neighbor_json("r3", "r5", False, "Initializing") |
| 379 | + assert result is True, result |
| 380 | + result = _check_isis_neighbor_json("r5", "r3", False, "Initializing") |
| 381 | + assert result is True, result |
| 382 | + |
| 383 | + # Restore to initial configuration |
| 384 | + logger.info("Checking 'restore to initial configuration'") |
| 385 | + r3.vtysh_cmd( |
| 386 | + """ |
| 387 | + configure |
| 388 | + interface r3-eth1 |
| 389 | + isis circuit-type level-1 |
| 390 | + no isis network point-to-point |
| 391 | + router isis 1 |
| 392 | + no is-type |
| 393 | + redistribute ipv4 connected level-1 |
| 394 | + redistribute ipv4 connected level-2 |
| 395 | + redistribute ipv6 connected level-1 |
| 396 | + redistribute ipv6 connected level-2 |
| 397 | + end |
| 398 | + """ |
| 399 | + ) |
| 400 | + r5.vtysh_cmd( |
| 401 | + """ |
| 402 | + configure |
| 403 | + interface r5-eth0 |
| 404 | + isis circuit-type level-1 |
| 405 | + no isis network point-to-point |
| 406 | + router isis 1 |
| 407 | + redistribute ipv4 connected level-1 |
| 408 | + redistribute ipv6 connected level-1 |
| 409 | + redistribute ipv4 table 20 level-1 |
| 410 | + end |
| 411 | + """ |
| 412 | + ) |
| 413 | + result = _check_isis_neighbor_json("r3", "r5", True, "Up") |
| 414 | + assert result is True, result |
| 415 | + result = _check_isis_neighbor_json("r5", "r3", True, "Up") |
| 416 | + assert result is True, result |
| 417 | + |
| 418 | + |
317 | 419 | def test_isis_database_json():
|
318 | 420 | "Check json struct in show isis database json"
|
319 | 421 |
|
@@ -623,6 +725,65 @@ def test_isis_hello_padding_during_adjacency_formation():
|
623 | 725 | assert result is True, result
|
624 | 726 |
|
625 | 727 |
|
| 728 | +def _check_isis_neighbor_json( |
| 729 | + self, neighbor, neighbor_expected, neighbor_state_expected |
| 730 | +): |
| 731 | + tgen = get_topogen() |
| 732 | + router = tgen.gears[self] |
| 733 | + logger.info( |
| 734 | + f"check_isis_neighbor_json {router} {neighbor} {neighbor_expected} {neighbor_state_expected}" |
| 735 | + ) |
| 736 | + |
| 737 | + result = _check_isis_neighbor_exist(self, neighbor) |
| 738 | + if result == True: |
| 739 | + return _check_isis_neighbor_state(self, neighbor, neighbor_state_expected) |
| 740 | + elif neighbor_expected == True: |
| 741 | + return "{} with expected neighbor {} got none ".format(router.name, neighbor) |
| 742 | + else: |
| 743 | + return True |
| 744 | + |
| 745 | + |
| 746 | +@retry(retry_timeout=60) |
| 747 | +def _check_isis_neighbor_exist(self, neighbor): |
| 748 | + tgen = get_topogen() |
| 749 | + router = tgen.gears[self] |
| 750 | + logger.info(f"check_isis_neighbor_exist {router} {neighbor}") |
| 751 | + neighbor_json = router.vtysh_cmd("show isis neighbor json", isjson=True) |
| 752 | + |
| 753 | + circuits = neighbor_json.get("areas", [])[0].get("circuits", []) |
| 754 | + for circuit in circuits: |
| 755 | + if "adj" in circuit and circuit["adj"] == neighbor: |
| 756 | + return True |
| 757 | + |
| 758 | + return "The neighbor {} of router {} has not been learned yet ".format( |
| 759 | + neighbor, router.name |
| 760 | + ) |
| 761 | + |
| 762 | + |
| 763 | +@retry(retry_timeout=5) |
| 764 | +def _check_isis_neighbor_state(self, neighbor, neighbor_state_expected): |
| 765 | + tgen = get_topogen() |
| 766 | + router = tgen.gears[self] |
| 767 | + logger.info( |
| 768 | + f"check_isis_neighbor_state {router} {neighbor} {neighbor_state_expected}" |
| 769 | + ) |
| 770 | + neighbor_json = router.vtysh_cmd( |
| 771 | + "show isis neighbor {} json".format(neighbor), isjson=True |
| 772 | + ) |
| 773 | + |
| 774 | + circuits = neighbor_json.get("areas", [])[0].get("circuits", []) |
| 775 | + for circuit in circuits: |
| 776 | + interface = circuit.get("interface", {}) |
| 777 | + if "state" in interface: |
| 778 | + neighbor_state = interface["state"] |
| 779 | + if neighbor_state == neighbor_state_expected: |
| 780 | + return True |
| 781 | + |
| 782 | + return "{} peer with expected neighbor_state {} got {} ".format( |
| 783 | + router.name, neighbor_state_expected, neighbor_state |
| 784 | + ) |
| 785 | + |
| 786 | + |
626 | 787 | @retry(retry_timeout=10)
|
627 | 788 | def check_last_iih_packet_for_padding(router, expect_padding):
|
628 | 789 | logfilename = "{}/{}".format(router.gearlogdir, "isisd.log")
|
|
0 commit comments