Пример #1
0
def test_no_unestablished_bgp_sessions_no_session():
    """Confirm no-unestablished-bgp-sessions assert passes and fails as expected when not specifying a session."""
    with patch.object(bfq, "bgpSessionStatus",
                      create=True) as bgpSessionStatus:
        # Test success
        bgpSessionStatus.return_value = MockQuestion()
        assert_no_unestablished_bgp_sessions(nodes="nodes",
                                             remote_nodes="remote_nodes")
        bgpSessionStatus.assert_called_with(nodes="nodes",
                                            remote_nodes="remote_nodes",
                                            status="NOT_ESTABLISHED")
        # Test failure
        mock_df = DataFrame.from_records([{
            "Session": "found",
            "More": "data"
        }])
        bgpSessionStatus.return_value = MockQuestion(MockTableAnswer(mock_df))
        with pytest.raises(BatfishAssertException) as excinfo:
            assert_no_unestablished_bgp_sessions(nodes="nodes",
                                                 remote_nodes="remote_nodes")
        # Ensure found answer is printed
        assert mock_df.to_string() in str(excinfo.value)
        bgpSessionStatus.assert_called_with(nodes="nodes",
                                            remote_nodes="remote_nodes",
                                            status="NOT_ESTABLISHED")
Пример #2
0
def test_no_unestablished_bgp_sessions():
    """Confirm no-uncompatible-bgp-sessions assert passes and fails as expected when specifying a session."""
    bf = Session(load_questions=False)
    with patch.object(bf.q, 'bgpSessionStatus',
                      create=True) as bgpSessionStatus:
        # Test success
        bgpSessionStatus.return_value = MockQuestion()
        assert_no_unestablished_bgp_sessions(nodes='nodes',
                                             remote_nodes='remote_nodes',
                                             session=bf)
        bgpSessionStatus.assert_called_with(nodes='nodes',
                                            remote_nodes='remote_nodes',
                                            status="NOT_ESTABLISHED")
        # Test failure
        mock_df = DataFrame.from_records([{'Session': 'found', 'More': 'data'}])
        bgpSessionStatus.return_value = MockQuestion(
            MockTableAnswer(mock_df))
        with pytest.raises(BatfishAssertException) as excinfo:
            assert_no_unestablished_bgp_sessions(nodes='nodes',
                                                 remote_nodes='remote_nodes',
                                                 session=bf)
        # Ensure found answer is printed
        assert mock_df.to_string() in str(excinfo.value)
        bgpSessionStatus.assert_called_with(nodes='nodes',
                                            remote_nodes='remote_nodes',
                                            status="NOT_ESTABLISHED")
Пример #3
0
    def assert_no_unestablished_bgp_sessions(self, nodes=None,
                                             remote_nodes=None,
                                             snapshot=None, soft=False,
                                             df_format="table"):
        # type: (Optional[str], Optional[str], Optional[str], bool, str) -> bool
        """Assert that there are no BGP sessions that are compatible but not established.

        :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 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_unestablished_bgp_sessions(nodes, remote_nodes,
                                                    snapshot, soft,
                                                    self.session, df_format)