Assertion helpers

Utility assert functions for writing network tests (or policies).

All assert_* methods will raise an BatfishAssertException if the assertion fails.

pybatfish.client.asserts.assert_filter_has_no_unreachable_lines(filters, soft=False, snapshot=None, session=None, df_format='table')[source]

Check that a filter (e.g. an ACL) has no unreachable lines.

A filter line is considered unreachable if it will never match a packet, e.g., because its match condition is empty or covered completely by those of prior lines.”

Parameters:
  • filters – the specification for the filter (filterSpec) to check
  • soft – whether this assertion is soft (i.e., generates a warning but not a failure)
  • snapshot – the snapshot on which to check the assertion
  • session – Batfish session to use for the assertion
  • df_format – How to format the Dataframe content in the output message. Valid options are ‘table’ and ‘records’ (each row is a key-value pairs).
Returns:

True if the assertion passes

pybatfish.client.asserts.assert_filter_denies(filters, headers, startLocation=None, soft=False, snapshot=None, session=None, df_format='table')[source]

Check if a filter (e.g., ACL) denies a specified set of flows.

Parameters:
  • filters – the specification for the filter (filterSpec) to check
  • headersHeaderConstraints
  • startLocation – LocationSpec indicating where a flow starts
  • soft – whether this assertion is soft (i.e., generates a warning but not a failure)
  • snapshot – the snapshot on which to check the assertion
  • session – Batfish session to use for the assertion
  • df_format – How to format the Dataframe content in the output message. Valid options are ‘table’ and ‘records’ (each row is a key-value pairs).
Returns:

True if the assertion passes

pybatfish.client.asserts.assert_filter_permits(filters, headers, startLocation=None, soft=False, snapshot=None, session=None, df_format='table')[source]

Check if a filter (e.g., ACL) permits a specified set of flows.

Parameters:
  • filters – the specification for the filter (filterSpec) to check
  • headersHeaderConstraints
  • startLocation – LocationSpec indicating where a flow starts
  • soft – whether this assertion is soft (i.e., generates a warning but not a failure)
  • snapshot – the snapshot on which to check the assertion
  • session – Batfish session to use for the assertion
  • df_format – How to format the Dataframe content in the output message. Valid options are ‘table’ and ‘records’ (each row is a key-value pairs).
Returns:

True if the assertion passes

pybatfish.client.asserts.assert_flows_fail(startLocation, headers, soft=False, snapshot=None, session=None, df_format='table')[source]

Check if the specified set of flows, denoted by starting locations and headers, fail.

Parameters:
  • startLocation – LocationSpec indicating where the flow starts
  • headersHeaderConstraints
  • soft – whether this assertion is soft (i.e., generates a warning but not a failure)
  • snapshot – the snapshot on which to check the assertion
  • session – Batfish session to use for the assertion
  • df_format – How to format the Dataframe content in the output message. Valid options are ‘table’ and ‘records’ (each row is a key-value pairs).
Returns:

True if the assertion passes

pybatfish.client.asserts.assert_flows_succeed(startLocation, headers, soft=False, snapshot=None, session=None, df_format='table')[source]

Check if the specified set of flows, denoted by starting locations and headers, succeed.

Parameters:
  • startLocation – LocationSpec indicating where the flow starts
  • headersHeaderConstraints
  • soft – whether this assertion is soft (i.e., generates a warning but not a failure)
  • snapshot – the snapshot on which to check the assertion
  • session – Batfish session to use for the assertion
  • df_format – How to format the Dataframe content in the output message. Valid options are ‘table’ and ‘records’ (each row is a key-value pairs).
Returns:

True if the assertion passes

pybatfish.client.asserts.assert_has_no_route(routes, expected_route, node, vrf='default', soft=False)[source]

Assert that a particular route is NOT present.

Note

If a node or VRF is missing in the route answer the assertion will NOT fail, but a warning will be generated.

Parameters:
  • routes – All routes returned by the Batfish routes question.
  • expected_route – A dictionary describing route to match.
  • node – node hostname on which to look for expected route.
  • vrf – VRF name to check. Default is default.
  • soft (bool) – whether this assertion is soft (i.e., generates a warning but not a failure)
pybatfish.client.asserts.assert_has_route(routes, expected_route, node, vrf='default', soft=False)[source]

Assert that a particular route is present.

Parameters:
  • routes – All routes returned by the Batfish routes question.
  • expected_route – A dictionary describing route to match.
  • node – node hostname on which to look for a route.
  • vrf – VRF name where the route should be present. Default is default.
  • soft (bool) – whether this assertion is soft (i.e., generates a warning but not a failure)
pybatfish.client.asserts.assert_no_forwarding_loops(snapshot=None, soft=False, session=None, df_format='table')[source]

Assert that there are no forwarding loops in the snapshot.

Parameters:
  • snapshot – the snapshot on which to check the assertion
  • soft – whether this assertion is soft (i.e., generates a warning but not a failure)
  • session – Batfish session to use for the assertion
  • df_format – How to format the Dataframe content in the output message. Valid options are ‘table’ and ‘records’ (each row is a key-value pairs).
pybatfish.client.asserts.assert_no_incompatible_bgp_sessions(nodes=None, remote_nodes=None, status=None, snapshot=None, soft=False, session=None, df_format='table')[source]

Assert that there are no incompatible BGP sessions present in the snapshot.

Parameters:
  • nodes – search sessions with specified nodes on one side of the sessions.
  • remote_nodes – search sessions with specified remote_nodes on other side of the sessions.
  • status – select sessions matching the specified BGP session status specifier, if none is specified then all statuses other than UNIQUE_MATCH, DYNAMIC_MATCH, and UNKNOWN_REMOTE are selected.
  • snapshot – the snapshot on which to check the assertion
  • soft – whether this assertion is soft (i.e., generates a warning but not a failure)
  • session – Batfish session to use for the assertion
  • df_format – How to format the Dataframe content in the output message. Valid options are ‘table’ and ‘records’ (each row is a key-value pairs).
pybatfish.client.asserts.assert_no_unestablished_bgp_sessions(nodes=None, remote_nodes=None, snapshot=None, soft=False, session=None, df_format='table')[source]

Assert that there are no BGP sessions that are compatible but not established.

Parameters:
  • nodes – search sessions with specified nodes on one side of the sessions.
  • remote_nodes – search sessions with specified remote_nodes on other side of the sessions.
  • snapshot – the snapshot on which to check the assertion
  • soft – whether this assertion is soft (i.e., generates a warning but not a failure)
  • session – Batfish session to use for the assertion
  • df_format – How to format the Dataframe content in the output message. Valid options are ‘table’ and ‘records’ (each row is a key-value pairs).
pybatfish.client.asserts.assert_no_undefined_references(snapshot=None, soft=False, session=None, df_format='table')[source]

Assert that there are no undefined references present in the snapshot.

Parameters:
  • snapshot – the snapshot on which to check the assertion
  • soft – whether this assertion is soft (i.e., generates a warning but not a failure)
  • session – Batfish session to use for the assertion
  • df_format – How to format the Dataframe content in the output message. Valid options are ‘table’ and ‘records’ (each row is a key-value pairs).
pybatfish.client.asserts.assert_num_results(answer, num, soft=False)[source]

Assert an exact number of results were returned.

Parameters:
  • answer – Batfish answer or DataFrame
  • num (int) – expected number of results
  • soft (bool) – whether this assertion is soft (i.e., generates a warning but not a failure)
pybatfish.client.asserts.assert_zero_results(answer, soft=False)[source]

Assert no results were returned.

Parameters:
  • answer – Batfish answer or DataFrame
  • soft (bool) – whether this assertion is soft (i.e., generates a warning but not a failure)