Ejemplo n.º 1
0
def test_json_intersect_true():
    "Test simple correct JSON intersections"

    dcomplete = {
        'i1': 'item1',
        'i2': 'item2',
        'i3': 'item3',
        'i100': 'item4',
    }

    dsub1 = {
        'i1': 'item1',
        'i3': 'item3',
    }
    dsub2 = {
        'i1': 'item1',
        'i2': 'item2',
    }
    dsub3 = {
        'i100': 'item4',
        'i2': 'item2',
    }
    dsub4 = {
        'i50': None,
        'i100': 'item4',
    }

    assert json_cmp(dcomplete, dsub1) is None
    assert json_cmp(dcomplete, dsub2) is None
    assert json_cmp(dcomplete, dsub3) is None
    assert json_cmp(dcomplete, dsub4) is None
Ejemplo n.º 2
0
def test_json_intersect_false():
    "Test simple incorrect JSON intersections"

    dcomplete = {
        'i1': 'item1',
        'i2': 'item2',
        'i3': 'item3',
        'i100': 'item4',
    }

    # Incorrect value for 'i1'
    dsub1 = {
        'i1': 'item3',
        'i3': 'item3',
    }
    # Non-existing key 'i5'
    dsub2 = {
        'i1': 'item1',
        'i5': 'item2',
    }
    # Key should not exist
    dsub3 = {
        'i100': None,
    }

    assert json_cmp(dcomplete, dsub1) is not None
    assert json_cmp(dcomplete, dsub2) is not None
    assert json_cmp(dcomplete, dsub3) is not None
Ejemplo n.º 3
0
def test_json_intersect_true():
    "Test simple correct JSON intersections"

    dcomplete = {
        'i1': 'item1',
        'i2': 'item2',
        'i3': 'item3',
        'i100': 'item4',
    }

    dsub1 = {
        'i1': 'item1',
        'i3': 'item3',
    }
    dsub2 = {
        'i1': 'item1',
        'i2': 'item2',
    }
    dsub3 = {
        'i100': 'item4',
        'i2': 'item2',
    }
    dsub4 = {
        'i50': None,
        'i100': 'item4',
    }

    assert json_cmp(dcomplete, dsub1) is None
    assert json_cmp(dcomplete, dsub2) is None
    assert json_cmp(dcomplete, dsub3) is None
    assert json_cmp(dcomplete, dsub4) is None
Ejemplo n.º 4
0
def test_json_intersect_true():
    "Test simple correct JSON intersections"

    dcomplete = {
        "i1": "item1",
        "i2": "item2",
        "i3": "item3",
        "i100": "item4",
    }

    dsub1 = {
        "i1": "item1",
        "i3": "item3",
    }
    dsub2 = {
        "i1": "item1",
        "i2": "item2",
    }
    dsub3 = {
        "i100": "item4",
        "i2": "item2",
    }
    dsub4 = {
        "i50": None,
        "i100": "item4",
    }

    assert json_cmp(dcomplete, dsub1) is None
    assert json_cmp(dcomplete, dsub2) is None
    assert json_cmp(dcomplete, dsub3) is None
    assert json_cmp(dcomplete, dsub4) is None
Ejemplo n.º 5
0
def test_json_intersect_false():
    "Test simple incorrect JSON intersections"

    dcomplete = {
        "i1": "item1",
        "i2": "item2",
        "i3": "item3",
        "i100": "item4",
    }

    # Incorrect value for 'i1'
    dsub1 = {
        "i1": "item3",
        "i3": "item3",
    }
    # Non-existing key 'i5'
    dsub2 = {
        "i1": "item1",
        "i5": "item2",
    }
    # Key should not exist
    dsub3 = {
        "i100": None,
    }

    assert json_cmp(dcomplete, dsub1) is not None
    assert json_cmp(dcomplete, dsub2) is not None
    assert json_cmp(dcomplete, dsub3) is not None
Ejemplo n.º 6
0
def test_json_object_exact_matching():
    "Test JSON object on exact matching using the 'exact' parameter."

    dcomplete = {
        'a': {"id": 1, "value": "abc"},
        'b': "some string",
        'c': 123,
        'd': [1,2,3],
    }

    dsub1 = {
        'a': {"id": 1, "value": "abc"},
        'c': 123,
        'd': [1,2,3],
    }

    dsub2 = {
        'a': {"id": 1},
        'b': "some string",
        'c': 123,
        'd': [1,2,3],
    }

    dsub3 = {
        'a': {"id": 1, "value": "abc"},
        'b': "some string",
        'c': 123,
        'd': [1,3],
    }

    assert json_cmp(dcomplete, dsub1, exact=True) is not None
    assert json_cmp(dcomplete, dsub2, exact=True) is not None
    assert json_cmp(dcomplete, dsub3, exact=True) is not None
Ejemplo n.º 7
0
        def run_command_and_expect():
            """
            Function that runs command and expect the following outcomes:
             * Full/DR
             * Full/DROther
             * Full/Backup
            """
            result = tgen.gears[router].vtysh_cmd(
                "show ip ospf neighbor json", isjson=True
            )
            if (
                topotest.json_cmp(
                    result, {"neighbors": {neighbor: [{"state": "Full/DR"}]}}
                )
                is None
            ):
                return None

            if (
                topotest.json_cmp(
                    result, {"neighbors": {neighbor: [{"state": "Full/DROther"}]}}
                )
                is None
            ):
                return None

            return topotest.json_cmp(
                result, {"neighbors": {neighbor: [{"state": "Full/Backup"}]}}
            )
Ejemplo n.º 8
0
def test_json_intersect_multilevel_true():
    "Test multi level correct JSON intersections"

    dcomplete = {
        "i1": "item1",
        "i2": "item2",
        "i3": {"i100": "item100",},
        "i4": {
            "i41": {"i411": "item411",},
            "i42": {"i421": "item421", "i422": "item422",},
        },
    }

    dsub1 = {
        "i1": "item1",
        "i3": {"i100": "item100",},
        "i10": None,
    }
    dsub2 = {
        "i1": "item1",
        "i2": "item2",
        "i3": {},
    }
    dsub3 = {
        "i2": "item2",
        "i4": {"i41": {"i411": "item411",}, "i42": {"i422": "item422", "i450": None,}},
    }
    dsub4 = {"i2": "item2", "i4": {"i41": {}, "i42": {"i450": None,}}}
    dsub5 = {"i2": "item2", "i3": {"i100": "item100",}, "i4": {"i42": {"i450": None,}}}

    assert json_cmp(dcomplete, dsub1) is None
    assert json_cmp(dcomplete, dsub2) is None
    assert json_cmp(dcomplete, dsub3) is None
    assert json_cmp(dcomplete, dsub4) is None
    assert json_cmp(dcomplete, dsub5) is None
Ejemplo n.º 9
0
def test_json_list_exact_matching():
    "Test JSON array on exact matching using the 'exact' parameter."

    dcomplete = [
        {"id": 1, "value": "abc"},
        "some string",
        123,
        [1,2,3],
    ]

    dsub1 = [
        "some string",
        {"id": 1, "value": "abc"},
        123,
        [1,2,3],
    ]

    dsub2 = [
        {"id": 1},
        "some string",
        123,
        [1,2,3],
    ]

    dsub3 = [
        {"id": 1, "value": "abc"},
        "some string",
        123,
        [1,3,2],
    ]

    assert json_cmp(dcomplete, dsub1, exact=True) is not None
    assert json_cmp(dcomplete, dsub2, exact=True) is not None
Ejemplo n.º 10
0
def test_json_with_list_failure():
    "Test failed json comparisons that have lists."

    dcomplete = {
        "list": [{"i1": "item 1", "i2": "item 2",}, {"i10": "item 10",},],
        "i100": "item 100",
    }

    # Test list type
    dsub1 = {
        "list": {},
    }
    # Test list incorrect list items
    dsub2 = {
        "list": [{"i1": "item 2",},],
        "i100": "item 100",
    }
    # Test list correct list size
    dsub3 = {
        "list": [{}, {}, {},],
    }

    assert json_cmp(dcomplete, dsub1) is not None
    assert json_cmp(dcomplete, dsub2) is not None
    assert json_cmp(dcomplete, dsub3) is not None
Ejemplo n.º 11
0
def test_json_with_list_sucess():
    "Test successful json comparisons that have lists."

    dcomplete = {
        "list": [{"i1": "item 1", "i2": "item 2",}, {"i10": "item 10",},],
        "i100": "item 100",
    }

    # Test list type
    dsub1 = {
        "list": [],
    }
    # Test list correct list items
    dsub2 = {
        "list": [{"i1": "item 1",},],
        "i100": "item 100",
    }
    # Test list correct list size
    dsub3 = {
        "list": [{}, {},],
    }

    assert json_cmp(dcomplete, dsub1) is None
    assert json_cmp(dcomplete, dsub2) is None
    assert json_cmp(dcomplete, dsub3) is None
Ejemplo n.º 12
0
def test_json_intersect_false():
    "Test simple incorrect JSON intersections"

    dcomplete = {
        'i1': 'item1',
        'i2': 'item2',
        'i3': 'item3',
        'i100': 'item4',
    }

    # Incorrect value for 'i1'
    dsub1 = {
        'i1': 'item3',
        'i3': 'item3',
    }
    # Non-existing key 'i5'
    dsub2 = {
        'i1': 'item1',
        'i5': 'item2',
    }
    # Key should not exist
    dsub3 = {
        'i100': None,
    }

    assert json_cmp(dcomplete, dsub1) is not None
    assert json_cmp(dcomplete, dsub2) is not None
    assert json_cmp(dcomplete, dsub3) is not None
Ejemplo n.º 13
0
def test_isis_convergence():
    "Wait for the protocol to converge before starting to test"
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    logger.info("waiting for ISIS protocol to converge")
    # Code to generate the json files.
    # for rname, router in tgen.routers().iteritems():
    #     open('/tmp/{}_topology.json'.format(rname), 'w').write(
    #         json.dumps(show_isis_topology(router), indent=2, sort_keys=True)
    #     )
    wait = 90
    startt = time.time()
    loop = True
    done = False
    while loop and not done:
        delta = time.time() - startt
        loop = delta < wait
        done = True
        for rname, router in tgen.routers().iteritems():
            filename = '{0}/{1}/{1}_topology.json'.format(CWD, rname)
            expected = json.loads(open(filename, 'r').read())
            actual = show_isis_topology(router)
            if topotest.json_cmp(actual, expected) != None:
                done = False
                if loop == False:
                    assertmsg = "Router '%s' topology mismatch after +%4.2f secs" % (
                        rname, delta)
                    assert topotest.json_cmp(actual,
                                             expected) is None, assertmsg
        if loop and not done:
            time.sleep(0.5)
    logger.info("ISIS protocol converged after +%4.2f secs" % (delta))
Ejemplo n.º 14
0
def test_json_list_start_failure():
    "Test JSON encoded data that starts with a list that should fail."

    dcomplete = [
        {
            "id": 100,
            "value": "abc"
        },
        {
            "id": 200,
            "value": "abcd"
        },
        {
            "id": 300,
            "value": "abcde"
        },
    ]

    dsub1 = [{
        "id": 100,
        "value": "abcd",
    }]

    dsub2 = [
        {
            "id": 100,
            "value": "abc",
        },
        {
            "id": 200,
            "value": "abc",
        },
    ]

    dsub3 = [
        {
            "id": 100,
            "value": "abc",
        },
        {
            "id": 350,
            "value": "abcde",
        },
    ]

    dsub4 = [
        {
            "value": "abcx",
        },
        {
            "id": 300,
            "value": "abcde",
        },
    ]

    assert json_cmp(dcomplete, dsub1) is not None
    assert json_cmp(dcomplete, dsub2) is not None
    assert json_cmp(dcomplete, dsub3) is not None
    assert json_cmp(dcomplete, dsub4) is not None
Ejemplo n.º 15
0
def test_json_list_start_success():
    "Test JSON encoded data that starts with a list that should succeed."

    dcomplete = [
        {
            "id": 100,
            "value": "abc",
        },
        {
            "id": 200,
            "value": "abcd",
        },
        {
            "id": 300,
            "value": "abcde",
        },
    ]

    dsub1 = [
        {
            "id": 100,
            "value": "abc",
        }
    ]

    dsub2 = [
        {
            "id": 100,
            "value": "abc",
        },
        {
            "id": 200,
            "value": "abcd",
        }
    ]

    dsub3 = [
        {
            "id": 300,
            "value": "abcde",
        }
    ]

    dsub4 = [
    ]

    dsub5 = [
        {
            "id": 100,
        }
    ]

    assert json_cmp(dcomplete, dsub1) is None
    assert json_cmp(dcomplete, dsub2) is None
    assert json_cmp(dcomplete, dsub3) is None
    assert json_cmp(dcomplete, dsub4) is None
    assert json_cmp(dcomplete, dsub5) is None
Ejemplo n.º 16
0
    def test_r2_r3_mroute():
        "Test r2/r3 multicast routing table function"
        r2_out = tgen.gears['r2'].vtysh_cmd('show ip mroute json', isjson=True)
        r3_out = tgen.gears['r3'].vtysh_cmd('show ip mroute json', isjson=True)

        if topotest.json_cmp(r2_out, expect_r2) is not None:
            return topotest.json_cmp(r3_out, expect_r3)

        return topotest.json_cmp(r2_out, expect_r2)
Ejemplo n.º 17
0
def compare_json_test(router, command, reference, exact):
    output = router.vtysh_cmd(command, isjson=True)
    result = topotest.json_cmp(output, reference)

    # Note: topotest.json_cmp() just checks on inclusion of keys.
    # For exact matching also compare the other way around.
    if not result and exact:
       return topotest.json_cmp(reference, output)
    else:
       return result
Ejemplo n.º 18
0
def test_json_object_asterisk_matching():
    "Test JSON object value elements on matching '*' as a placeholder for arbitrary data."

    dcomplete = {
        "a": {
            "id": 1,
            "value": "abc"
        },
        "b": "some string",
        "c": 123,
        "d": [1, 2, 3],
    }

    dsub1 = {
        "a": "*",
        "b": "some string",
        "c": 123,
        "d": [1, 2, 3],
    }

    dsub2 = {
        "a": {
            "id": 1,
            "value": "abc"
        },
        "b": "some string",
        "c": 123,
        "d": [1, "*", 3],
    }

    dsub3 = {
        "a": {
            "id": "*",
            "value": "abc"
        },
        "b": "some string",
        "c": 123,
        "d": [1, 2, 3],
    }

    dsub4 = {
        "a": "*",
        "b": "some string",
        "c": "*",
        "d": [1, 2, 3],
    }

    assert json_cmp(dcomplete, dsub1) is None
    assert json_cmp(dcomplete, dsub2) is None
    assert json_cmp(dcomplete, dsub3) is None
    assert json_cmp(dcomplete, dsub4) is None
Ejemplo n.º 19
0
def test_json_list_asterisk_matching():
    "Test JSON array elements on matching '*' as a placeholder for arbitrary data."

    dcomplete = [
        {
            "id": 1,
            "value": "abc"
        },
        "some string",
        123,
        [1, 2, 3],
    ]

    dsub1 = [
        "*",
        "some string",
        123,
        [1, 2, 3],
    ]

    dsub2 = [
        {
            "id": "*",
            "value": "abc"
        },
        "some string",
        123,
        [1, 2, 3],
    ]

    dsub3 = [
        {
            "id": 1,
            "value": "abc"
        },
        "some string",
        123,
        [1, "*", 3],
    ]

    dsub4 = [
        "*",
        "some string",
        "*",
        [1, 2, 3],
    ]

    assert json_cmp(dcomplete, dsub1) is None
    assert json_cmp(dcomplete, dsub2) is None
    assert json_cmp(dcomplete, dsub3) is None
    assert json_cmp(dcomplete, dsub4) is None
Ejemplo n.º 20
0
def test_json_list_start_success():
    "Test JSON encoded data that starts with a list that should succeed."

    dcomplete = [
        {
            "id": 100,
            "value": "abc",
        },
        {
            "id": 200,
            "value": "abcd",
        },
        {
            "id": 300,
            "value": "abcde",
        },
    ]

    dsub1 = [{
        "id": 100,
        "value": "abc",
    }]

    dsub2 = [
        {
            "id": 100,
            "value": "abc",
        },
        {
            "id": 200,
            "value": "abcd",
        },
    ]

    dsub3 = [{
        "id": 300,
        "value": "abcde",
    }]

    dsub4 = []

    dsub5 = [{
        "id": 100,
    }]

    assert json_cmp(dcomplete, dsub1) is None
    assert json_cmp(dcomplete, dsub2) is None
    assert json_cmp(dcomplete, dsub3) is None
    assert json_cmp(dcomplete, dsub4) is None
    assert json_cmp(dcomplete, dsub5) is None
Ejemplo n.º 21
0
def test_pbr_data():
    "Test PBR 'show ip eigrp'"

    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    # Verify PBR Status
    logger.info("Verifying PBR routes")

    router_list = tgen.routers().values()
    for router in router_list:
        intf_file = "{}/{}/pbr-interface.json".format(CWD, router.name)
        logger.info(intf_file)

        # Read expected result from file
        expected = json.loads(open(intf_file).read())

        # Actual output from router
        actual = router.vtysh_cmd("show pbr interface json", isjson=True)
        assertmsg = '"show pbr interface" mismatches on {}'.format(router.name)
        assert topotest.json_cmp(actual, expected) is None, assertmsg

        map_file = "{}/{}/pbr-map.json".format(CWD, router.name)
        logger.info(map_file)

        # Read expected result from file
        expected = json.loads(open(map_file).read())

        # Actual output from router
        actual = router.vtysh_cmd("show pbr map json", isjson=True)

        assertmsg = '"show pbr map" mismatches on {}'.format(router.name)
        assert topotest.json_cmp(actual, expected) is None, assertmsg

        nexthop_file = "{}/{}/pbr-nexthop-groups.json".format(CWD, router.name)
        logger.info(nexthop_file)

        # Read expected result from file
        expected = json.loads(open(nexthop_file).read())

        # Actual output from router
        actual = router.vtysh_cmd("show pbr nexthop-groups json", isjson=True)

        assertmsg = '"show pbr nexthop-groups" mismatches on {}'.format(
            router.name)
        assert topotest.json_cmp(actual, expected) is None, assertmsg
Ejemplo n.º 22
0
def test_isis_route6_installation():
    "Check whether all expected routes are present"
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    logger.info('Checking routers for installed ISIS IPv6 routes')

    # Check for routes in 'show ip route json'
    for rname, router in tgen.routers().iteritems():
        filename = '{0}/{1}/{1}_route6.json'.format(CWD, rname)
        expected = json.loads(open(filename, 'r').read())
        actual = router.vtysh_cmd('show ipv6 route json', isjson=True)

        # Older FRR versions don't list interfaces in some ISIS routes
        if router.has_version('<', '3.1'):
            for network, routes in expected.iteritems():
                for route in routes:
                    # Older versions display different metrics for IPv6 routes
                    route.pop('metric', None)

                    if route['protocol'] != 'isis':
                        continue

                    for nexthop in route['nexthops']:
                        nexthop.pop('interfaceIndex', None)
                        nexthop.pop('interfaceName', None)

        assertmsg = "Router '{}' routes mismatch".format(rname)
        assert topotest.json_cmp(actual, expected) is None, assertmsg
Ejemplo n.º 23
0
def test_pim_igmp_report():
    "Send a igmp report from r2->r1 and ensure that the *,G state is created on r1"
    logger.info("Send a igmp report from r2-r1 and ensure *,G created")

    tgen = get_topogen()

    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    r2 = tgen.gears['r2']
    r1 = tgen.gears['r1']

    # Let's send a igmp report from r2->r1
    CWD = os.path.dirname(os.path.realpath(__file__))
    r2.run("{}/mcast-rx.py 229.1.1.2 r2-eth0 &".format(CWD))

    out = r1.vtysh_cmd("show ip pim upstream json", isjson=True)
    expected = {
        '229.1.1.2': {
            '*': {
                'sourceIgmp': 1,
                'joinState': 'Joined',
                'regState': 'RegNoInfo',
                'sptBit': 0,
            }
        }
    }

    assert topotest.json_cmp(out, expected) is None, 'failed to converge pim'
Ejemplo n.º 24
0
def test_pim_send_mcast_stream():
    "Establish a Multicast stream from r2 -> r1 and then ensure S,G is created as appropriate"
    logger.info("Establish a Mcast stream from r2->r1 and then ensure S,G created")

    tgen = get_topogen()

    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    r2 = tgen.gears['r2']
    r1 = tgen.gears['r1']

    # Let's establish a S,G stream from r2 -> r1
    CWD = os.path.dirname(os.path.realpath(__file__))
    r2.run("{}/mcast-tx.py --ttl 5 --count 5 --interval 10 229.1.1.1 r2-eth0 > /tmp/bar".format(CWD))

    # Let's see that it shows up and we have established some basic state
    out = r1.vtysh_cmd("show ip pim upstream json", isjson=True)
    expected = {
        '229.1.1.1': {
            '10.0.20.2': {
                'firstHopRouter': 1,
                'joinState': 'NotJoined',
                'regState': 'RegPrune',
                'inboundInterface': 'r1-eth0',
            }
        }
    }

    assert topotest.json_cmp(out, expected) is None, 'failed to converge pim'
Ejemplo n.º 25
0
 def _bgp_converge(router):
     output = json.loads(router.vtysh_cmd("show ip route json"))
     expected = {
         "172.16.16.1/32": [
             {
                 "tag": 10,
                 "communities": "community-r2-1 65001:2",
                 "largeCommunities": "large-community-r2-1 65001:1:2",
             }
         ],
         "172.16.16.2/32": [
             {
                 "tag": 20,
                 "communities": "65002:1 community-r2-2",
                 "largeCommunities": "",
             }
         ],
         "172.16.16.3/32": [
             {
                 "tag": 100,
                 "communities": "",
                 "largeCommunities": "",
             }
         ],
     }
     return topotest.json_cmp(output, expected)
Ejemplo n.º 26
0
 def _bgp_check_local_preference(router):
     output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast json"))
     expected = {
         "routes": {
             "10.10.10.2/32": [{
                 "locPrf": 160
             }],
             "10.10.10.3/32": [{
                 "locPrf": 40
             }],
             "172.16.255.254/32": [
                 {
                     "locPrf": 50,
                     "nexthops": [{
                         "ip": "192.168.255.3"
                     }]
                 },
                 {
                     "locPrf": 150,
                     "nexthops": [{
                         "ip": "192.168.255.2"
                     }]
                 },
             ],
         }
     }
     return topotest.json_cmp(output, expected)
Ejemplo n.º 27
0
def router_compare_json_output_cb(rname, command, reference):
    tgen = get_topogen()
    router = tgen.gears[rname]
    output = router.vtysh_cmd(command, isjson=True)
    refTableFile = '{}/{}/{}'.format(CWD, router.name, reference)
    expected = json.loads(open(refTableFile).read())
    return topotest.json_cmp(output, expected)
Ejemplo n.º 28
0
 def check(router, dest, expected):
     output = json.loads(
         router.vtysh_cmd("show ipv6 route {} json".format(dest)))
     output = output.get("{}/128".format(dest))
     if output is None:
         return False
     return topotest.json_cmp(output, expected)
Ejemplo n.º 29
0
def test_isis_linux_route6_installation():

    dist = platform.dist()

    if dist[1] == "16.04":
        pytest.skip("Kernel not supported for vrf")

    "Check whether all expected routes are present and installed in the OS"
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    logger.info("Checking routers for installed ISIS vrf IPv6 routes in OS")
    # Check for routes in `ip -6 route show vrf {}-cust1`
    for rname, router in tgen.routers().items():
        filename = "{0}/{1}/{1}_route6_linux.json".format(CWD, rname)
        expected = json.loads(open(filename, "r").read())
        actual = topotest.ip6_vrf_route(router)

        # Older FRR versions install routes using different proto
        if router.has_version("<", "3.1"):
            for network, netoptions in expected.items():
                if "proto" in netoptions and netoptions["proto"] == "187":
                    netoptions["proto"] = "zebra"

        assertmsg = "Router '{}' OS routes mismatch".format(rname)
        assert topotest.json_cmp(actual, expected) is None, assertmsg
Ejemplo n.º 30
0
 def _check(name, cmd, expected_file):
     logger.info("polling")
     tgen = get_topogen()
     router = tgen.gears[name]
     output = json.loads(router.vtysh_cmd(cmd))
     expected = open_json_file("{}/{}".format(CWD, expected_file))
     return topotest.json_cmp(output, expected)
def show_vni_json_elide_ifindex(pe, vni, expected):
    output_json = pe.vtysh_cmd("show evpn vni {} json".format(vni), isjson=True)

    if "ifindex" in output_json:
        output_json.pop("ifindex")

    return topotest.json_cmp(output_json, expected)
Ejemplo n.º 32
0
def test_pim_send_mcast_stream():
    "Establish a Multicast stream from r2 -> r1 and then ensure S,G is created as appropriate"
    logger.info(
        "Establish a Mcast stream from r2->r1 and then ensure S,G created")

    tgen = get_topogen()

    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    rp = tgen.gears['rp']
    r2 = tgen.gears['r2']
    r1 = tgen.gears['r1']

    # Let's establish a S,G stream from r2 -> r1
    CWD = os.path.dirname(os.path.realpath(__file__))
    r2.run(
        "{}/mcast-tx.py --ttl 5 --count 5 --interval 10 229.1.1.1 r2-eth0 > /tmp/bar"
        .format(CWD))

    # Let's see that it shows up and we have established some basic state
    out = r1.vtysh_cmd("show ip pim upstream json", isjson=True)
    expected = {
        '229.1.1.1': {
            '10.0.20.2': {
                'firstHopRouter': 1,
                'joinState': 'NotJoined',
                'regState': 'RegPrune',
                'inboundInterface': 'r1-eth0',
            }
        }
    }

    assert topotest.json_cmp(out, expected) is None, 'failed to converge pim'
Ejemplo n.º 33
0
def test_isis_route6_installation():
    "Check whether all expected routes are present"
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    logger.info("Checking routers for installed ISIS vrf IPv6 routes")
    # Check for routes in 'show ipv6 route vrf {}-cust1 json'
    for rname, router in tgen.routers().items():
        filename = "{0}/{1}/{1}_route6.json".format(CWD, rname)
        expected = json.loads(open(filename, "r").read())
        actual = router.vtysh_cmd(
            "show ipv6 route vrf {}-cust1 json".format(rname), isjson=True)

        # Older FRR versions don't list interfaces in some ISIS routes
        if router.has_version("<", "3.1"):
            for network, routes in expected.items():
                for route in routes:
                    if route["protocol"] != "isis":
                        continue

                    for nexthop in route["nexthops"]:
                        nexthop.pop("interfaceIndex", None)
                        nexthop.pop("interfaceName", None)

        assertmsg = "Router '{}' routes mismatch".format(rname)
        assert topotest.json_cmp(actual, expected) is None, assertmsg
Ejemplo n.º 34
0
    def show_mpls_table_json_cmp(rt, expected):
        """
        Reformat MPLS table output to use a list of labels instead of dict.

        Original:
        {
         "X": {
            inLabel: "X",
            # ...
          }
        }

        List format:
        [
          {
            inLabel: "X",
          }
        ]
        """
        out = rt.vtysh_cmd('show mpls table json', isjson=True)

        outlist = []
        for key in out.keys():
            outlist.append(out[key])

        return topotest.json_cmp(outlist, expected)
Ejemplo n.º 35
0
        def compare_routing_table(router, expected):
            "Helper function to ensure zebra rib convergence"

            actual = router.vtysh_cmd(
                "show ip route vrf {0}-cust1 json".format(rname), isjson=True
            )
            return topotest.json_cmp(actual, expected)
Ejemplo n.º 36
0
def test_pim_igmp_report():
    "Send a igmp report from r2->r1 and ensure that the *,G state is created on r1"
    logger.info("Send a igmp report from r2-r1 and ensure *,G created")

    tgen = get_topogen()

    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    r2 = tgen.gears["r2"]
    r1 = tgen.gears["r1"]

    # Let's send a igmp report from r2->r1
    CWD = os.path.dirname(os.path.realpath(__file__))
    r2.run("{}/mcast-rx.py 229.1.1.2 r2-eth0 &".format(CWD))

    out = r1.vtysh_cmd("show ip pim upstream json", isjson=True)
    expected = {
        "229.1.1.2": {
            "*": {
                "sourceIgmp": 1,
                "joinState": "Joined",
                "regState": "RegNoInfo",
                "sptBit": 0,
            }
        }
    }

    assert topotest.json_cmp(out, expected) is None, "failed to converge pim"
Ejemplo n.º 37
0
 def _output_summary_cmp(router, cmd, data):
     """
     Runs `cmd` that returns JSON data (normally the command ends
     with 'json') and compare with `data` contents.
     """
     output = router.vtysh_cmd(cmd, isjson=True)
     if 'ipv4Unicast' in output:
         output['ipv4Unicast']['vrfName'] = \
                 output['ipv4Unicast']['vrfName'].replace(
                     'default', 'Default')
     elif 'vrfName' in output:
         output['vrfName'] = output['vrfName'].replace('default', 'Default')
     return topotest.json_cmp(output, data)
Ejemplo n.º 38
0
def test_json_with_list_sucess():
    "Test successful json comparisons that have lists."

    dcomplete = {
        'list': [
            {
                'i1': 'item 1',
                'i2': 'item 2',
            },
            {
                'i10': 'item 10',
            },
        ],
        'i100': 'item 100',
    }

    # Test list type
    dsub1 = {
        'list': [],
    }
    # Test list correct list items
    dsub2 = {
        'list': [
            {
                'i1': 'item 1',
            },
        ],
        'i100': 'item 100',
    }
    # Test list correct list size
    dsub3 = {
        'list': [
            {}, {},
        ],
    }

    assert json_cmp(dcomplete, dsub1) is None
    assert json_cmp(dcomplete, dsub2) is None
    assert json_cmp(dcomplete, dsub3) is None
Ejemplo n.º 39
0
def test_json_with_list_failure():
    "Test failed json comparisons that have lists."

    dcomplete = {
        'list': [
            {
                'i1': 'item 1',
                'i2': 'item 2',
            },
            {
                'i10': 'item 10',
            },
        ],
        'i100': 'item 100',
    }

    # Test list type
    dsub1 = {
        'list': {},
    }
    # Test list incorrect list items
    dsub2 = {
        'list': [
            {
                'i1': 'item 2',
            },
        ],
        'i100': 'item 100',
    }
    # Test list correct list size
    dsub3 = {
        'list': [
            {}, {}, {},
        ],
    }

    assert json_cmp(dcomplete, dsub1) is not None
    assert json_cmp(dcomplete, dsub2) is not None
    assert json_cmp(dcomplete, dsub3) is not None
Ejemplo n.º 40
0
def test_isis_linux_route6_installation():
    "Check whether all expected routes are present and installed in the OS"
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    logger.info('Checking routers for installed ISIS IPv6 routes in OS')

    # Check for routes in `ip route`
    for rname, router in tgen.routers().iteritems():
        filename = '{0}/{1}/{1}_route6_linux.json'.format(CWD, rname)
        expected = json.loads(open(filename, 'r').read())
        actual = topotest.ip6_route(router)

        # Older FRR versions install routes using different proto
        if router.has_version('<', '3.1'):
            for network, netoptions in expected.iteritems():
                if 'proto' in netoptions and netoptions['proto'] == '187':
                    netoptions['proto'] = 'zebra'

        assertmsg = "Router '{}' OS routes mismatch".format(rname)
        assert topotest.json_cmp(actual, expected) is None, assertmsg
Ejemplo n.º 41
0
 def compare_isis_topology(router, expected):
     "Helper function to test ISIS topology convergence."
     actual = show_isis_topology(router)
     return topotest.json_cmp(actual, expected)
Ejemplo n.º 42
0
def test_json_intersect_multilevel_false():
    "Test multi level incorrect JSON intersections"

    dcomplete = {
        'i1': 'item1',
        'i2': 'item2',
        'i3': {
            'i100': 'item100',
        },
        'i4': {
            'i41': {
                'i411': 'item411',
            },
            'i42': {
                'i421': 'item421',
                'i422': 'item422',
            }
        }
    }

    # Incorrect sub-level value
    dsub1 = {
        'i1': 'item1',
        'i3': {
            'i100': 'item00',
        },
        'i10': None,
    }
    # Inexistent sub-level
    dsub2 = {
        'i1': 'item1',
        'i2': 'item2',
        'i3': None,
    }
    # Inexistent sub-level value
    dsub3 = {
        'i1': 'item1',
        'i3': {
            'i100': None,
        },
    }
    # Inexistent sub-sub-level value
    dsub4 = {
        'i4': {
            'i41': {
                'i412': 'item412',
            },
            'i42': {
                'i421': 'item421',
            }
        }
    }
    # Invalid sub-sub-level value
    dsub5 = {
        'i4': {
            'i41': {
                'i411': 'item411',
            },
            'i42': {
                'i421': 'item420000',
            }
        }
    }
    # sub-sub-level should be value
    dsub6 = {
        'i4': {
            'i41': {
                'i411': 'item411',
            },
            'i42': 'foobar',
        }
    }

    assert json_cmp(dcomplete, dsub1) is not None
    assert json_cmp(dcomplete, dsub2) is not None
    assert json_cmp(dcomplete, dsub3) is not None
    assert json_cmp(dcomplete, dsub4) is not None
    assert json_cmp(dcomplete, dsub5) is not None
    assert json_cmp(dcomplete, dsub6) is not None
Ejemplo n.º 43
0
def test_json_list_start_failure():
    "Test JSON encoded data that starts with a list that should fail."

    dcomplete = [
        {
            "id": 100,
            "value": "abc"
        },
        {
            "id": 200,
            "value": "abcd"
        },
        {
            "id": 300,
            "value": "abcde"
        },
    ]

    dsub1 = [
        {
            "id": 100,
            "value": "abcd",
        }
    ]

    dsub2 = [
        {
            "id": 100,
            "value": "abc",
        },
        {
            "id": 200,
            "value": "abc",
        }
    ]

    dsub3 = [
        {
            "id": 100,
            "value": "abc",
        },
        {
            "id": 350,
            "value": "abcde",
        }
    ]

    dsub4 = [
        {
            "value": "abcx",
        },
        {
            "id": 300,
            "value": "abcde",
        }
    ]

    assert json_cmp(dcomplete, dsub1) is not None
    assert json_cmp(dcomplete, dsub2) is not None
    assert json_cmp(dcomplete, dsub3) is not None
    assert json_cmp(dcomplete, dsub4) is not None
Ejemplo n.º 44
0
def test_json_intersect_multilevel_true():
    "Test multi level correct JSON intersections"

    dcomplete = {
        'i1': 'item1',
        'i2': 'item2',
        'i3': {
            'i100': 'item100',
        },
        'i4': {
            'i41': {
                'i411': 'item411',
            },
            'i42': {
                'i421': 'item421',
                'i422': 'item422',
            }
        }
    }

    dsub1 = {
        'i1': 'item1',
        'i3': {
            'i100': 'item100',
        },
        'i10': None,
    }
    dsub2 = {
        'i1': 'item1',
        'i2': 'item2',
        'i3': {},
    }
    dsub3 = {
        'i2': 'item2',
        'i4': {
            'i41': {
                'i411': 'item411',
            },
            'i42': {
                'i422': 'item422',
                'i450': None,
            }
        }
    }
    dsub4 = {
        'i2': 'item2',
        'i4': {
            'i41': {},
            'i42': {
                'i450': None,
            }
        }
    }
    dsub5 = {
        'i2': 'item2',
        'i3': {
            'i100': 'item100',
        },
        'i4': {
            'i42': {
                'i450': None,
            }
        }
    }

    assert json_cmp(dcomplete, dsub1) is None
    assert json_cmp(dcomplete, dsub2) is None
    assert json_cmp(dcomplete, dsub3) is None
    assert json_cmp(dcomplete, dsub4) is None
    assert json_cmp(dcomplete, dsub5) is None