Example #1
0
    def test_custom_output(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)
        outputs[
            'show bgp all neighbors | i BGP neighbor'] = BgpOutput.nbr1_bgp_all_neighbors
        # Get outputs
        bgp.maker.outputs[ShowBgpAllSummary] = \
            {"{'address_family':'vpnv4 unicast','vrf':'VRF1'}":BgpOutput.ShowBgpAllSummary_custom}
        bgp.maker.outputs[ShowBgpAllClusterIds] = \
            {'':BgpOutput.ShowBgpAllClusterIds}
        bgp.maker.outputs[ShowIpBgpTemplatePeerPolicy] = \
            {'':BgpOutput.ShowIpBgpTemplatePeerPolicy}
        bgp.maker.outputs[ShowBgpAllNeighbors] = \
            {"{'address_family':'vpnv4 unicast','neighbor':'10.16.2.2'}":BgpOutput.ShowBgpAllNeighbors_nbr1}
        bgp.maker.outputs[ShowIpBgpAllDampeningParameters] = \
            {'':BgpOutput.ShowIpBgpAllDampeningParameters}
        bgp.maker.outputs[ShowIpBgpTemplatePeerSession] = \
            {'':BgpOutput.ShowIpBgpTemplatePeerSession}
        bgp.maker.outputs[ShowBgpAllDetail] = \
            {"{'address_family':'vpnv4 unicast','vrf':'VRF1'}":BgpOutput.ShowBgpAllDetail_custom}
        bgp.maker.outputs[ShowBgpAll] = \
            {"{'address_family':'vpnv4 unicast'}":BgpOutput.ShowBgpAll_custom}

        # Return outputs above as inputs to parser when called
        self.device.execute = Mock()
        self.device.execute.side_effect = mapper

        # Learn the feature
        bgp.learn(address_family='vpnv4 unicast RD 300:1',
                  vrf='VRF1',
                  neighbor='10.16.2.2')
        outputs[
            'show bgp all neighbors | i BGP neighbor'] = BgpOutput.bgp_all_neighbors
        # Verify Ops was created successfully
        self.assertDictEqual(bgp.info, BgpOutput.BgpOpsOutput_info_custom)
        self.assertDictEqual(bgp.table, BgpOutput.BgpOpsOutput_table_custom)
        self.assertDictEqual(bgp.routes_per_peer,
                             BgpOutput.BgpOpsOutput_routesperpeer_custom)
Example #2
0
    def test_empty_output(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)
        # Get outputs
        bgp.maker.outputs[ShowBgpAllSummary] = \
            {"{'address_family':'','vrf':''}":''}
        bgp.maker.outputs[ShowBgpAllClusterIds] = \
            {'':''}
        bgp.maker.outputs[ShowIpBgpTemplatePeerPolicy] = \
            {'':''}
        bgp.maker.outputs[ShowBgpAllNeighbors] = \
            {"{'address_family':'','neighbor':''}":''}
        bgp.maker.outputs[ShowIpBgpAllDampeningParameters] = \
            {'':''}
        bgp.maker.outputs[ShowIpBgpTemplatePeerSession] = \
            {'':''}
        bgp.maker.outputs[ShowBgpAllDetail] = \
            {"{'address_family':'','vrf':''}":''}
        bgp.maker.outputs[ShowBgpAll] = \
            {"{'address_family':''}":''}
        self.device.execute = Mock()
        self.device.execute.side_effect = mapper
        # Learn the feature
        bgp.learn()

        # Check no attribute not found
        # info - bgp_id
        with self.assertRaises(AttributeError):
            bgp_id = (bgp.info['instance']['default']['bgp_id'])
        # table - bgp_table_version
        with self.assertRaises(AttributeError):
            bgp_table_version = (bgp.table['instance']['default']['vrf']\
                ['default']['address_family']['ipv4 unicast']\
                ['bgp_table_version'])
        # routes_per_peer - remote_as
        with self.assertRaises(AttributeError):
            remote_as = (bgp.routes_per_peer['instance']['default']['vrf']\
                ['default']['neighbor']['10.16.2.2']['remote_as'])