コード例 #1
0
    def test_empty_output(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)
        # Get outputs
        outputs['show bgp all summary'] = ''
        outputs['show bgp all'] = ''
        outputs['show bgp all detail'] = ''
        outputs['show bgp all neighbors'] = ''

        self.device.execute = Mock()
        self.device.execute.side_effect = mapper
        # Learn the feature
        bgp.learn()

        # put back output
        outputs['show bgp all summary'] = BgpOutput.show_bgp_all_summary
        outputs['show bgp all'] = BgpOutput.show_bgp_all
        outputs['show bgp all detail'] = BgpOutput.show_bgp_all_detail
        outputs['show bgp all neighbors'] = BgpOutput.show_bgp_all_neighbors

        # Check no attribute not found
        # info - bgp_id
        with self.assertRaises(KeyError):
            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'])
コード例 #2
0
ファイル: test_bgp.py プロジェクト: vkoprivica/genielibs
    def test_complete_output(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)

        # Get outputs
        bgp.maker.outputs[ShowBgpAllSummary] = \
            {"{'address_family':'','vrf':''}":BgpOutput.ShowBgpAllSummary}
        bgp.maker.outputs[ShowBgpAllClusterIds] = \
            {'':BgpOutput.ShowBgpAllClusterIds}
        bgp.maker.outputs[ShowIpBgpTemplatePeerPolicy] = \
            {'':BgpOutput.ShowIpBgpTemplatePeerPolicy}
        bgp.maker.outputs[ShowBgpAllNeighbors] = \
            {"{'address_family':'','neighbor':''}":BgpOutput.ShowBgpAllNeighbors}
        bgp.maker.outputs[ShowIpBgpAllDampeningParameters] = \
            {'':BgpOutput.ShowIpBgpAllDampeningParameters}
        bgp.maker.outputs[ShowIpBgpTemplatePeerSession] = \
            {'':BgpOutput.ShowIpBgpTemplatePeerSession}
        bgp.maker.outputs[ShowBgpAllDetail] = \
            {"{'address_family':'','vrf':''}":BgpOutput.ShowBgpAllDetail}
        bgp.maker.outputs[ShowBgpAll] = \
            {"{'address_family':''}":BgpOutput.ShowBgpAll}

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

        # Learn the feature
        bgp.learn()

        # Verify Ops was created successfully
        self.assertEqual(bgp.info, BgpOutput.BgpOpsOutput_info)
        self.assertDictEqual(bgp.table, BgpOutput.BgpOpsOutput_table)
        self.assertDictEqual(bgp.routes_per_peer,
                             BgpOutput.BgpOpsOutput_routesperpeer)
コード例 #3
0
    def test_complete_output(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)

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

        # Learn the feature
        bgp.learn()

        # Verify Ops was created successfully
        self.assertEqual(bgp.info, BgpOutput.bgp_info)
        self.assertDictEqual(bgp.table, BgpOutput.bgp_table)
        self.assertDictEqual(bgp.routes_per_peer,
                             BgpOutput.bgp_routes_per_peer)
コード例 #4
0
ファイル: test_bgp.py プロジェクト: vkoprivica/genielibs
    def test_incomplete_output(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)

        # Get outputs
        bgp.maker.outputs[ShowBgpAllSummary] = \
            {"{'address_family':'','vrf':''}":BgpOutput.ShowBgpAllSummary}
        bgp.maker.outputs[ShowBgpAllClusterIds] = \
            {'':BgpOutput.ShowBgpAllClusterIds}
        bgp.maker.outputs[ShowIpBgpTemplatePeerPolicy] = \
            {'':BgpOutput.ShowIpBgpTemplatePeerPolicy}
        bgp.maker.outputs[ShowBgpAllNeighbors] = \
            {"{'address_family':'','neighbor':''}":BgpOutput.ShowBgpAllNeighbors}
        bgp.maker.outputs[ShowIpBgpAllDampeningParameters] = \
            {'':BgpOutput.ShowIpBgpAllDampeningParameters}
        bgp.maker.outputs[ShowIpBgpTemplatePeerSession] = \
            {'':BgpOutput.ShowIpBgpTemplatePeerSession}
        bgp.maker.outputs[ShowBgpAllDetail] = \
            {"{'address_family':'','vrf':''}":BgpOutput.ShowBgpAllDetail}
        bgp.maker.outputs[ShowBgpAll] = \
            {"{'address_family':''}":BgpOutput.ShowBgpAll}

        # Outputs from side_effect set to empty
        bgp.maker.outputs[ShowBgpAllNeighborsPolicy] = {'': ''}
        bgp.maker.outputs[ShowBgpAllNeighborsAdvertisedRoutes] = {'': ''}
        bgp.maker.outputs[ShowBgpAllNeighborsRoutes] = {'': ''}
        bgp.maker.outputs[ShowBgpAllNeighborsReceivedRoutes] = {'': ''}

        # Return outputs above as inputs to parser when called
        self.device.execute = Mock()
        self.device.execute.side_effect = ['', '', '', '', '', '', '', '', '',\
                                           '', '', '', '', '', '', '', '', '',\
                                           '', '', '', '', '', '', '', '', '',\
                                           '', '', '', '', '', '', '', '', '',\
                                           '', '', '', '']

        # Learn the feature
        bgp.learn()

        # Check attribute values of output provided is found

        # bgp.info - bgp_id
        self.assertEqual(bgp.info['instance']['default']['bgp_id'], 100)
コード例 #5
0
    def test_custom_output(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)

        # 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',
                  vrf='default',
                  neighbor='2.2.2.2')

        # Verify Ops was created successfully
        self.assertDictEqual(bgp.info, BgpOutput.bgp_info_custom)
        self.assertDictEqual(bgp.routes_per_peer,
                             BgpOutput.bgp_routes_per_peer_custom)
        with self.assertRaises(AttributeError):
            bgp.table
コード例 #6
0
ファイル: test_bgp.py プロジェクト: vkoprivica/genielibs
    def test_selective_attribute(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)

        # Get outputs
        bgp.maker.outputs[ShowBgpAllSummary] = \
            {"{'address_family':'','vrf':''}":BgpOutput.ShowBgpAllSummary}
        bgp.maker.outputs[ShowBgpAllClusterIds] = \
            {'':BgpOutput.ShowBgpAllClusterIds}
        bgp.maker.outputs[ShowIpBgpTemplatePeerPolicy] = \
            {'':BgpOutput.ShowIpBgpTemplatePeerPolicy}
        bgp.maker.outputs[ShowBgpAllNeighbors] = \
            {"{'address_family':'','neighbor':''}":BgpOutput.ShowBgpAllNeighbors}
        bgp.maker.outputs[ShowIpBgpAllDampeningParameters] = \
            {'':BgpOutput.ShowIpBgpAllDampeningParameters}
        bgp.maker.outputs[ShowIpBgpTemplatePeerSession] = \
            {'':BgpOutput.ShowIpBgpTemplatePeerSession}
        bgp.maker.outputs[ShowBgpAllDetail] = \
            {"{'address_family':'','vrf':''}":BgpOutput.ShowBgpAllDetail}
        bgp.maker.outputs[ShowBgpAll] = \
            {"{'address_family':''}":BgpOutput.ShowBgpAll}

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

        # Learn the feature
        bgp.learn()

        # Check specific attribute values
        # info - bgp_id
        self.assertEqual(bgp.info['instance']['default']['bgp_id'], 100)
        # table - bgp_table_version
        self.assertEqual(bgp.table['instance']['default']['vrf']['evpn1']\
                ['address_family']['vpnv4 unicast RD 65535:1']\
                ['bgp_table_version'], 5)
        # routes_per_peer - localprf
        self.assertEqual(bgp.routes_per_peer['instance']['default']['vrf']\
                ['default']['neighbor']['10.16.2.2']['address_family']\
                ['ipv4 unicast']['advertised']['10.1.1.0/24']['index'][1]\
                ['localprf'], 100)
コード例 #7
0
    def test_selective_attribute(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)

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

        # Learn the feature
        bgp.learn()

        # Check specific attribute values
        # info - bgp_id
        self.assertEqual(bgp.info['instance']['default']['bgp_id'], 65000)
        # table - bgp_table_version
        self.assertEqual(bgp.table['instance']['default']['vrf']['VRF1']\
                ['address_family']['vpnv4 unicast RD 65000:1']\
                ['bgp_table_version'], 4)
        # routes_per_peer - remote_as
        self.assertEqual(bgp.routes_per_peer['instance']['default']['vrf']\
                ['VRF1']['neighbor']['2.2.2.2']['remote_as'], 65000)
コード例 #8
0
ファイル: test_bgp.py プロジェクト: vkoprivica/genielibs
    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'])
コード例 #9
0
ファイル: test_bgp.py プロジェクト: vkoprivica/genielibs
    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)