def assert_has_route(routes, expected_route, node, vrf='default', soft=False): """Assert that a particular route is present. :param routes: All routes returned by the Batfish routes question. :param expected_route: A dictionary describing route to match. :param node: node hostname on which to look for a route. :param vrf: VRF name where the route should be present. Default is `default`. :param soft: whether this assertion is soft (i.e., generates a warning but not a failure) :type soft: bool """ __tracebackhide__ = operator.methodcaller("errisinstance", BatfishAssertException) try: d = routes[node] except KeyError: raise BatfishAssertException("No node: {}".format(node)) try: d = d[vrf] except KeyError: raise BatfishAssertException("No VRF: {} on node {}".format(vrf, node)) if not any( _is_dict_match(actual_route, expected_route) for actual_route in d): err_text = "No route matches for {} on node {}, VRF {}".format( expected_route, node, vrf) return _raise_common(err_text, soft) return True
def _raise_common(err_text, soft=False): # type: (str, bool) -> bool """Utility function for soft/hard exception raising.""" if soft: warnings.warn(err_text, category=BatfishAssertWarning) return False else: raise BatfishAssertException(err_text)
def _raise_common(err_text, soft=False): # type: (str, bool) -> bool """Utility function for soft/hard exception raising.""" __tracebackhide__ = operator.methodcaller("errisinstance", BatfishAssertException) if soft: warnings.warn(err_text, category=BatfishAssertWarning) return False else: raise BatfishAssertException(err_text)