Exemplo n.º 1
0
def test_no_incompatible_bgp_sessions_no_session():
    """Confirm no-incompatible-bgp-sessions assert passes and fails as expected when not specifying a session."""
    with patch.object(bfq, 'bgpSessionCompatibility',
                      create=True) as bgpSessionCompatibility:
        # Test success
        bgpSessionCompatibility.return_value = MockQuestion()
        assert_no_incompatible_bgp_sessions(nodes='nodes',
                                            remote_nodes='remote_nodes',
                                            status='.*')
        bgpSessionCompatibility.assert_called_with(nodes='nodes',
                                                   remote_nodes='remote_nodes',
                                                   status='.*')
        # Test failure
        mock_df = DataFrame.from_records([{'Session': 'found', 'More': 'data'}])
        bgpSessionCompatibility.return_value = MockQuestion(
            MockTableAnswer(mock_df))
        with pytest.raises(BatfishAssertException) as excinfo:
            assert_no_incompatible_bgp_sessions(nodes='nodes',
                                                remote_nodes='remote_nodes',
                                                status='.*')
        # Ensure found answer is printed
        assert mock_df.to_string() in str(excinfo.value)
        bgpSessionCompatibility.assert_called_with(nodes='nodes',
                                                   remote_nodes='remote_nodes',
                                                   status='.*')
Exemplo n.º 2
0
def test_no_incompatible_bgp_sessions():
    """Confirm no-incompatible-bgp-sessions assert passes and fails as expected when specifying a session."""
    bf = Session(load_questions=False)
    with patch.object(bf.q, "bgpSessionCompatibility",
                      create=True) as bgpSessionCompatibility:
        # Test success
        bgpSessionCompatibility.return_value = MockQuestion()
        assert_no_incompatible_bgp_sessions(nodes="nodes",
                                            remote_nodes="remote_nodes",
                                            status=".*",
                                            session=bf)
        bgpSessionCompatibility.assert_called_with(nodes="nodes",
                                                   remote_nodes="remote_nodes",
                                                   status=".*")
        # Test failure
        mock_df = DataFrame.from_records([{
            "Session": "found",
            "More": "data"
        }])
        bgpSessionCompatibility.return_value = MockQuestion(
            MockTableAnswer(mock_df))
        with pytest.raises(BatfishAssertException) as excinfo:
            assert_no_incompatible_bgp_sessions(nodes="nodes",
                                                remote_nodes="remote_nodes",
                                                status=".*",
                                                session=bf)
        # Ensure found answer is printed
        assert mock_df.to_string() in str(excinfo.value)
        bgpSessionCompatibility.assert_called_with(nodes="nodes",
                                                   remote_nodes="remote_nodes",
                                                   status=".*")
Exemplo n.º 3
0
    def assert_no_incompatible_bgp_sessions(self, nodes=None, remote_nodes=None,
                                            status=None,
                                            snapshot=None, soft=False,
                                            df_format="table"):
        # type: (Optional[str], Optional[str], Optional[str], Optional[str], bool, str) -> bool
        """Assert that there are no incompatible BGP sessions present in the snapshot.

        :param nodes: search sessions with specified nodes on one side of the sessions.
        :param remote_nodes: search sessions with specified remote_nodes on other side of the sessions.
        :param status: select sessions matching the specified `BGP session status specifier <https://github.com/batfish/batfish/blob/master/questions/Parameters.md#bgp-session-compat-status-specifier>`_, if none is specified then all statuses other than `UNIQUE_MATCH`, `DYNAMIC_MATCH`, and `UNKNOWN_REMOTE` are selected.
        :param snapshot: the snapshot on which to check the assertion
        :param soft: whether this assertion is soft (i.e., generates a warning but
            not a failure)
        :param 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).
        """
        return assert_no_incompatible_bgp_sessions(nodes, remote_nodes, status,
                                                   snapshot, soft, self.session,
                                                   df_format)
Exemplo n.º 4
0
    def assert_no_incompatible_bgp_sessions(
            self,
            nodes=None,
            remote_nodes=None,
            status=_INCOMPATIBLE_BGP_SESSION_STATUS_REGEX,
            snapshot=None,
            soft=False,
            df_format="table"):
        # type: (Optional[str], Optional[str], str, Optional[str], bool, str) -> bool
        """Assert that there are no incompatible BGP sessions present in the snapshot.

        :param nodes: search sessions with specified nodes on one side of the sessions.
        :param remote_nodes: search sessions with specified remote_nodes on other side of the sessions.
        :param status: select sessions matching the specified session status.
        :param snapshot: the snapshot on which to check the assertion
        :param soft: whether this assertion is soft (i.e., generates a warning but
            not a failure)
        :param 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).
        """
        return assert_no_incompatible_bgp_sessions(nodes, remote_nodes, status,
                                                   snapshot, soft,
                                                   self.session, df_format)