Esempio n. 1
0
def test_no_duplicate_router_ids_no_session():
    """Confirm no-duplicate-router-ids assert passes and fails as expected when not specifying a session."""
    with patch.object(bfq, "bgpProcessConfiguration",
                      create=True) as bgpProcessConfiguration:
        # Test success
        mock_df_unique = DataFrame.from_records([
            {
                "Router_ID": "1.1.1.1",
                "VRF": "vrf1"
            },
            {
                "Router_ID": "1.1.1.2",
                "VRF": "vrf2"
            },
        ])
        bgpProcessConfiguration.return_value = MockQuestion(
            MockTableAnswer(mock_df_unique))
        assert_no_duplicate_router_ids(protocols=["bgp"])
        # Test failure
        mock_df_duplicate = DataFrame.from_records([
            {
                "Router_ID": "1.1.1.1",
                "VRF": "vrf1"
            },
            {
                "Router_ID": "1.1.1.1",
                "VRF": "vrf2"
            },
        ])
        bgpProcessConfiguration.return_value = MockQuestion(
            MockTableAnswer(mock_df_duplicate))
        with pytest.raises(BatfishAssertException) as excinfo:
            assert_no_duplicate_router_ids(protocols=["bgp"])
        # Ensure found answer is printed
        assert mock_df_duplicate.to_string() in str(excinfo.value)
Esempio n. 2
0
    def assert_no_duplicate_router_ids(
        self, snapshot=None, nodes=None, protocols=None, soft=False, df_format="table"
    ):
        # type: (Optional[str], Optional[str], Optional[List[str]], bool, str) -> bool
        """Assert that there are no duplicate router IDs present in the snapshot.

        :param snapshot: the snapshot on which to check the assertion
        :param nodes: the nodes on which to run the assertion
        :param protocols: the protocol on which to use the assertion, e.g. bgp, ospf, etc.
        :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_duplicate_router_ids(
            snapshot, nodes, protocols, soft, self.session, df_format
        )