def test_complete_output(self): self.maxDiff = None bgp = Bgp(device=self.device) bgp.maker.outputs[ShowVrf] = {"{'vrf':'all'}": BgpOutput.ShowVrf} bgp.maker.outputs[ShowRoutingVrfAll] = { "{'vrf':'all'}": BgpOutput.ShowRoutingVrfAll} bgp.maker.outputs[ShowBgpPeerSession] = {'': BgpOutput.ShowBgpPeerSession} bgp.maker.outputs[ShowBgpPeerPolicy] = {'': BgpOutput.ShowBgpPeerPolicy} bgp.maker.outputs[ShowBgpPeerTemplate] = {'': BgpOutput.ShowBgpPeerTemplate} bgp.maker.outputs[ShowBgpVrfAllAll] = { "{'address_family':'all','vrf':'all'}": BgpOutput.ShowBgpVrfAllAll} bgp.maker.outputs[ShowBgpVrfAllAllNextHopDatabase] = \ {"{'address_family':'all','vrf':'all'}": BgpOutput.ShowBgpVrfAllAllNextHopDatabase} bgp.maker.outputs[ShowBgpVrfAllAllSummary] = \ {"{'address_family':'all','vrf':'all'}": BgpOutput.ShowBgpVrfAllAllSummary} bgp.maker.outputs[ShowBgpVrfAllAllDampeningParameters] = \ { "{'address_family':'all','vrf':'all'}": BgpOutput.ShowBgpVrfAllAllDampeningParameters} # Return outputs above as inputs to parser when called self.device.execute = Mock() self.device.get = Mock() self.device.execute.side_effect = mapper self.device.get.side_effect = mapper # Learn the feature bgp.learn() # Verify Ops was created successfully self.assertDictEqual(bgp.info, BgpOutput.BgpOpsOutput_info) self.assertEqual(bgp.table, BgpOutput.BgpOpsOutput_table) self.assertDictEqual(bgp.routes_per_peer, BgpOutput.BgpOpsOutput_routesperpeer)
def test_incomplete_output(self): self.maxDiff = None bgp = Bgp(device=self.device) # Get outputs bgp.maker.outputs[ShowVrf] = {'': BgpOutput.ShowVrf} bgp.maker.outputs[ShowRoutingVrfAll] = { '': BgpOutput.ShowRoutingVrfAll } bgp.maker.outputs[ShowBgpVrfAllAll] = {'': BgpOutput.ShowBgpVrfAllAll} bgp.maker.outputs[ShowBgpVrfAllAllNextHopDatabase] =\ {'': BgpOutput.ShowBgpVrfAllAllNextHopDatabase} bgp.maker.outputs[ShowBgpVrfAllAllSummary]=\ {'':BgpOutput.ShowBgpVrfAllAllSummary} bgp.maker.outputs[ShowBgpVrfAllAllDampeningParameters] =\ {'':BgpOutput.ShowBgpVrfAllAllDampeningParameters} # Set empty outputs bgp.maker.outputs[ShowBgpPeerSession] = {'': ''} bgp.maker.outputs[ShowBgpPeerPolicy] = {'': ''} bgp.maker.outputs[ShowBgpPeerTemplate] = {'': ''} # Return outputs above as inputs to parser when called self.device.execute = Mock() self.device.get = Mock() self.device.execute.side_effect = mapper self.device.get.side_effect = mapper # Learn the feature bgp.learn() # Verify attributes are not learnt in ops self.assertTrue('peer_policy' not in bgp.info['instance']['default']) self.assertTrue('peer_session' not in bgp.info['instance']['default'])
def test_selective_attribute(self): self.maxDiff = None bgp = Bgp(device=self.device) bgp.maker.outputs[ShowVrf] = {"{'vrf':'all'}": BgpOutput.ShowVrf} bgp.maker.outputs[ShowRoutingVrfAll] = { "{'vrf':'all'}": BgpOutput.ShowRoutingVrfAll} bgp.maker.outputs[ShowBgpPeerSession] = {'': BgpOutput.ShowBgpPeerSession} bgp.maker.outputs[ShowBgpPeerPolicy] = {'': BgpOutput.ShowBgpPeerPolicy} bgp.maker.outputs[ShowBgpPeerTemplate] = {'': BgpOutput.ShowBgpPeerTemplate} bgp.maker.outputs[ShowBgpVrfAllAll] = { "{'address_family':'all','vrf':'all'}": BgpOutput.ShowBgpVrfAllAll} bgp.maker.outputs[ShowBgpVrfAllAllNextHopDatabase] = \ {"{'address_family':'all','vrf':'all'}": BgpOutput.ShowBgpVrfAllAllNextHopDatabase} bgp.maker.outputs[ShowBgpVrfAllAllSummary] = \ {"{'address_family':'all','vrf':'all'}": BgpOutput.ShowBgpVrfAllAllSummary} bgp.maker.outputs[ShowBgpVrfAllAllDampeningParameters] = \ { "{'address_family':'all','vrf':'all'}": BgpOutput.ShowBgpVrfAllAllDampeningParameters} # Return outputs above as inputs to parser when called self.device.execute = Mock() self.device.get = Mock() self.device.execute.side_effect = mapper self.device.get.side_effect = mapper # Learn the feature bgp.learn() # Check specific attribute values self.assertEqual(bgp.info['instance']['default']['bgp_id'], 100) self.assertEqual(bgp.table['instance']['default']['vrf']['VRF1']\ ['address_family']['ipv4 unicast']['bgp_table_version'], 35) self.assertEqual(bgp.routes_per_peer['instance']['default']['vrf']\ ['default']['neighbor']['10.16.2.2']['remote_as'], 100)
def test_empty_output(self): self.maxDiff = None bgp = Bgp(device=self.device) # Get outputs bgp.maker.outputs[ShowVrf] = {'': ''} bgp.maker.outputs[ShowRoutingVrfAll] = {'': ''} bgp.maker.outputs[ShowBgpProcessVrfAll] = {'': ''} bgp.maker.outputs[ShowBgpPeerSession] = {'': ''} bgp.maker.outputs[ShowBgpPeerPolicy] = {'': ''} bgp.maker.outputs[ShowBgpPeerTemplate] = {'': ''} bgp.maker.outputs[ShowBgpVrfAllAll] = {'': ''} bgp.maker.outputs[ShowBgpVrfAllAllNextHopDatabase] = {'': ''} bgp.maker.outputs[ShowBgpVrfAllAllSummary] = {'': ''} bgp.maker.outputs[ShowBgpVrfAllAllDampeningParameters] = {'': ''} # 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']\ ['VRF1']['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']\ ['VRF1']['neighbor']['2.2.2.10']['remote_as'])