Example #1
0
    def test_incomplete_output(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)

        # Set outputs
        bgp.maker.outputs[ShowBgpInstances] = {'': BgpOutput.ShowBgpInstances}
        bgp.maker.outputs[ShowPlacementProgramAll] = {
            '': BgpOutput.ShowPlacementProgramAll
        }
        bgp.maker.outputs[ShowBgpInstanceAfGroupConfiguration] = {
            '': BgpOutput.ShowBgpInstanceAfGroupConfiguration
        }
        bgp.maker.outputs[ShowBgpInstanceSessionGroupConfiguration] = {
            '': BgpOutput.ShowBgpInstanceSessionGroupConfiguration
        }

        # 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 - protocol_state
        self.assertEqual(bgp.info['instance']['default']['protocol_state'],
                         'RUNNING')
Example #2
0
    def test_empty_output(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)

        # Set outputs
        bgp.maker.outputs[ShowBgpInstances] = {'': ''}
        bgp.maker.outputs[ShowPlacementProgramAll] = {'': ''}
        bgp.maker.outputs[ShowBgpInstanceAfGroupConfiguration] = {'': ''}
        bgp.maker.outputs[ShowBgpInstanceSessionGroupConfiguration] = {'': ''}

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

        # Learn the feature
        bgp.learn()

        # Check no attribute not found

        # bgp.info - bgp_id
        with self.assertRaises(AttributeError):
            bgp_id = (bgp.info['instance']['default']['bgp_id'])

        # bgp.table - bgp_table_version
        with self.assertRaises(AttributeError):
            bgp_table_version = (bgp.table['instance']['default']['vrf']\
                ['VRF1']['address_family']['vpnv4 unicast']['bgp_table_version'])

        # bgp.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'])
Example #3
0
    def test_custom_output(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)
        # Set outputs
        bgp.maker.outputs[ShowBgpInstances] = {
            '': BgpOutput.ShowBgpInstances_custom
        }
        bgp.maker.outputs[ShowPlacementProgramAll] = {
            '': BgpOutput.ShowPlacementProgramAll
        }
        bgp.maker.outputs[ShowBgpInstanceAfGroupConfiguration] = {
            '': BgpOutput.ShowBgpInstanceAfGroupConfiguration
        }
        bgp.maker.outputs[ShowBgpInstanceSessionGroupConfiguration] = {
            '': BgpOutput.ShowBgpInstanceSessionGroupConfiguration
        }

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

        # Learn the feature
        bgp.learn(vrf='VRF1',
                  address_family='ipv4 unicast',
                  neighbor='10.1.5.5',
                  instance='default')

        # Verify Ops was created successfully
        self.assertDictEqual(bgp.info, BgpOutput.BgpInfo_custom)
        self.assertDictEqual(bgp.table, BgpOutput.BgpTable_custom)
        self.assertDictEqual(bgp.routes_per_peer,
                             BgpOutput.BgpRoutesPerPeer_custom)
Example #4
0
    def test_selective_attribute(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)
        # Set outputs
        bgp.maker.outputs[ShowBgpInstances] = {'': BgpOutput.ShowBgpInstances}
        bgp.maker.outputs[ShowPlacementProgramAll] = {
            '': BgpOutput.ShowPlacementProgramAll
        }
        bgp.maker.outputs[ShowBgpInstanceAfGroupConfiguration] = {
            '': BgpOutput.ShowBgpInstanceAfGroupConfiguration
        }
        bgp.maker.outputs[ShowBgpInstanceSessionGroupConfiguration] = {
            '': BgpOutput.ShowBgpInstanceSessionGroupConfiguration
        }

        # 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
        # bgp.info - bgp_id
        self.assertEqual(bgp.info['instance']['default']['bgp_id'], 100)

        # bgp.table - bgp_table_version
        self.assertEqual(bgp.table['instance']['default']['vrf']['VRF1']\
                ['address_family']['vpnv4 unicast']['bgp_table_version'], 47)

        # bgp.routes_per_peer - remote_as
        self.assertEqual(bgp.routes_per_peer['instance']['default']['vrf']\
                ['default']['neighbor']['10.16.2.2']['remote_as'], 100)
Example #5
0
    def test_complete_output(self):
        self.maxDiff = None
        bgp = Bgp(device=self.device)
        # Set outputs
        bgp.maker.outputs[ShowBgpInstances] = {'': BgpOutput.ShowBgpInstances}
        bgp.maker.outputs[ShowPlacementProgramAll] = {
            '': BgpOutput.ShowPlacementProgramAll
        }
        bgp.maker.outputs[ShowBgpInstanceAfGroupConfiguration] = {
            '': BgpOutput.ShowBgpInstanceAfGroupConfiguration
        }
        bgp.maker.outputs[ShowBgpInstanceSessionGroupConfiguration] = {
            '': BgpOutput.ShowBgpInstanceSessionGroupConfiguration
        }

        # 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.assertDictEqual(bgp.info, BgpOutput.BgpInfo)
        self.assertDictEqual(bgp.table, BgpOutput.BgpTable)
        self.assertDictEqual(bgp.routes_per_peer, BgpOutput.BgpRoutesPerPeer)