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 = RouteEntry(absent_route) assert route_obj.to_dict() == absent_route
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 = RouteEntry(route) assert route_obj.absent assert route_obj.to_dict() == route
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 = RouteEntry(route) obj2 = RouteEntry(route) assert obj1.match(obj2) assert obj1 == obj2
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 = RouteEntry(absent_route0_state) assert new_route0.match(original_route0) assert not new_route0.match(original_route1)
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 = 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
def test_remove_route_with_wildcard_match_without_next_hop_iface(self): ipv4_route = gen_ipv4_route() route_absent = RouteEntry({ Route.DESTINATION: IPV4_ROUTE_DESITNATION, Route.STATE: Route.STATE_ABSENT, }) state = self._gen_route_state([route_absent], [ipv4_route]) assert not list(state.config_iface_routes.keys())
def test_remove_route_with_wildcard_match_with_next_hop_iface(self): ipv4_route = gen_ipv4_route() route_absent = RouteEntry({ Route.NEXT_HOP_INTERFACE: IPV4_ROUTE_IFACE_NAME, Route.STATE: Route.STATE_ABSENT, }) state = self._gen_route_state([route_absent], [ipv4_route]) assert not list(state.config_iface_routes.keys())
def _create_route(dest, metric, via_addr, via_iface, table_id): return RouteEntry({ Route.DESTINATION: dest, Route.METRIC: metric, Route.NEXT_HOP_ADDRESS: via_addr, Route.NEXT_HOP_INTERFACE: via_iface, Route.TABLE_ID: table_id, })
def test_remove_route_with_exact_match(self): ipv4_route = gen_ipv4_route() ipv4_route_absent_dict = gen_ipv4_route().to_dict() ipv4_route_absent_dict[Route.STATE] = Route.STATE_ABSENT ipv4_route_absent = RouteEntry(ipv4_route_absent_dict) state = self._gen_route_state([ipv4_route_absent], [ipv4_route]) assert not list(state.config_iface_routes.keys())
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 = 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)
def _create_route(dest, via_addr, via_iface, table, metric): return RouteEntry( _create_route_dict(dest, via_addr, via_iface, table, metric))
def test_validate_route_next_hop_to_unknown_iface(self): ipv4_route_dict = gen_ipv4_route().to_dict() ipv4_route_dict[Route.NEXT_HOP_INTERFACE] = "not_exit_iface" with pytest.raises(NmstateValueError): self._gen_route_state([RouteEntry(ipv4_route_dict)], [])
def test_validate_route_without_destination(self): ipv4_route_dict = gen_ipv4_route().to_dict() ipv4_route_dict.pop(Route.DESTINATION) with pytest.raises(NmstateValueError): self._gen_route_state([RouteEntry(ipv4_route_dict)], [])
def test_validate_route_without_next_hop_iface(self): ipv4_route_dict = gen_ipv4_route().to_dict() ipv4_route_dict.pop(Route.NEXT_HOP_INTERFACE) with pytest.raises(NmstateValueError): self._gen_route_state([RouteEntry(ipv4_route_dict)], [])
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 = RouteEntry(route) assert route_obj.to_dict() == route