Beispiel #1
0
 def test_absent_route_is_ignored_for_matching_and_equality(self):
     route = _create_route_dict("198.51.100.0/24", "192.0.2.1", "eth1", 50,
                                103)
     route[Route.STATE] = Route.STATE_ABSENT
     obj1 = state.RouteEntry(route)
     obj2 = state.RouteEntry(route)
     assert obj1.match(obj2)
     assert obj1 == obj2
Beispiel #2
0
 def test_absent_route_with_missing_props_as_dict(self, route_property):
     absent_route = _create_route_dict("198.51.100.0/24", "192.0.2.1",
                                       "eth1", 50, 103)
     absent_route[Route.STATE] = Route.STATE_ABSENT
     del absent_route[route_property]
     route_obj = state.RouteEntry(absent_route)
     assert route_obj.to_dict() == absent_route
Beispiel #3
0
 def test_absent_route_object_as_dict(self):
     route = _create_route_dict("198.51.100.0/24", "192.0.2.1", "eth1", 50,
                                103)
     route[Route.STATE] = Route.STATE_ABSENT
     route_obj = state.RouteEntry(route)
     assert route_obj.absent
     assert route_obj.to_dict() == route
Beispiel #4
0
def _create_route(dest, via_addr, via_iface, table, metric):
    return state.RouteEntry({
        Route.DESTINATION: dest,
        Route.METRIC: metric,
        Route.NEXT_HOP_ADDRESS: via_addr,
        Route.NEXT_HOP_INTERFACE: via_iface,
        Route.TABLE_ID: table,
    })
Beispiel #5
0
def test_state_iface_routes_with_same_iface():
    routes = _get_mixed_test_routes()
    for route in routes:
        route[Route.NEXT_HOP_INTERFACE] = "eth1"
    route_state = state.State({Route.KEY: {Route.CONFIG: routes}})
    expected_indexed_route_state = {
        "eth1": sorted([state.RouteEntry(r) for r in routes])
    }

    assert expected_indexed_route_state == route_state.config_iface_routes
Beispiel #6
0
def test_state_iface_routes_with_distinct_ifaces():
    routes = _get_mixed_test_routes()
    route_state = state.State({Route.KEY: {Route.CONFIG: routes}})
    expected_indexed_route_state = defaultdict(list)
    for route in routes:
        iface_name = route[Route.NEXT_HOP_INTERFACE]
        expected_indexed_route_state[iface_name].append(
            state.RouteEntry(route))
        # No need to sort the routes as there is only 1 route per interface.

    assert expected_indexed_route_state == route_state.config_iface_routes
Beispiel #7
0
    def test_absent_route_wildcard_match(self, route_property):
        original_route0 = _create_route("198.51.100.0/24", "192.0.2.1", "eth1",
                                        50, 103)
        original_route1 = _create_route("2001:db8:a::/64", "2001:db8:1::a",
                                        "eth2", 51, 104)

        absent_route0_state = _create_route_dict("198.51.100.0/24",
                                                 "192.0.2.1", "eth1", 50, 103)
        absent_route0_state[Route.STATE] = Route.STATE_ABSENT
        del absent_route0_state[route_property]
        new_route0 = state.RouteEntry(absent_route0_state)

        assert new_route0.match(original_route0)
        assert not new_route0.match(original_route1)
Beispiel #8
0
    def test_absent_route_with_exact_match(self):
        route0 = _create_route("198.51.100.0/24", "192.0.2.1", "eth1", 50, 103)

        absent_r0 = _create_route_dict("198.51.100.0/24", "192.0.2.1", "eth1",
                                       50, 103)
        absent_r0[Route.STATE] = Route.STATE_ABSENT
        absent_route0 = state.RouteEntry(absent_r0)

        route1 = _create_route("2001:db8:a::/64", "2001:db8:1::a", "eth2", 51,
                               104)

        assert absent_route0.match(route0)
        assert absent_route0 == route0
        assert not absent_route0.match(route1)
        assert absent_route0 != route1
Beispiel #9
0
 def test_sort_routes_with_absent_route(self, route_property):
     absent_route = _create_route("198.51.100.0/24", "192.0.1.1", "eth0", 9,
                                  103).to_dict()
     absent_route[Route.STATE] = Route.STATE_ABSENT
     del absent_route[route_property]
     absent_route = state.RouteEntry(absent_route)
     routes = [
         absent_route,
         _create_route("198.51.100.1/24", "192.0.2.1", "eth0", 50, 103),
         _create_route("198.51.100.0/24", "192.0.2.1", "eth0", 50, 103),
         _create_route("198.51.100.0/24", "192.0.2.1", "eth1", 10, 103),
     ]
     expected_routes = [
         absent_route,
         _create_route("198.51.100.0/24", "192.0.2.1", "eth1", 10, 103),
         _create_route("198.51.100.0/24", "192.0.2.1", "eth0", 50, 103),
         _create_route("198.51.100.1/24", "192.0.2.1", "eth0", 50, 103),
     ]
     assert expected_routes == sorted(routes)
Beispiel #10
0
def _create_route(dest, via_addr, via_iface, table, metric):
    return state.RouteEntry(
        _create_route_dict(dest, via_addr, via_iface, table, metric))
Beispiel #11
0
 def test_normal_route_object_as_dict(self):
     route = _create_route_dict("198.51.100.0/24", "192.0.2.1", "eth1", 50,
                                103)
     route_obj = state.RouteEntry(route)
     assert route_obj.to_dict() == route