예제 #1
0
    def test_output_with_attribute(self):
        self.maxDiff = None
        arp = Arp(device=self.device,
                  attributes=['info[statistics][(.*)]'])

        # Get outputs
        arp.maker.outputs[ShowArp] = \
            {"": ArpOutput.ShowArp}
        arp.maker.outputs[ShowVrf] = \
            {"": ArpOutput.ShowVrf}
        arp.maker.outputs[ShowIpArp] = \
            {"{'vrf':'VRF1'}": ArpOutput.ShowIpArp}
        arp.maker.outputs[ShowIpArpSummary] = \
            {"": ArpOutput.ShowIpArpSummary}

        arp.maker.outputs[ShowIpTraffic] = \
            {"": ArpOutput.ShowIpTraffic}

        arp.maker.outputs[ShowIpInterface] = \
            {"": ArpOutput.ShowIpInterface}

        # Learn the feature
        arp.learn()

        # Check no attribute not found
        with self.assertRaises(KeyError):
            arp.info['interfaces']

        # info - statistics
        self.assertEqual(arp.info['statistics'], ArpOutput.Arp_info['statistics'])
예제 #2
0
    def test_complete_output(self):
        self.maxDiff = None
        arp = Arp(device=self.device)

        # Get outputs
        arp.maker.outputs[ShowArp] = \
            {"": ArpOutput.ShowArp}
        arp.maker.outputs[ShowVrf] = \
            {"": ArpOutput.ShowVrf}
        arp.maker.outputs[ShowIpArp] = \
            {"{'vrf':'VRF1'}": ArpOutput.ShowIpArp}
        arp.maker.outputs[ShowIpArpSummary] = \
            {"": ArpOutput.ShowIpArpSummary}

        arp.maker.outputs[ShowIpTraffic] = \
            {"": ArpOutput.ShowIpTraffic}

        arp.maker.outputs[ShowIpInterface] = \
            {"": ArpOutput.ShowIpInterface}
        self.device.execute = Mock()
        self.device.execute.side_effect = mapper
        # Learn the feature
        arp.learn()

        # Verify Ops was created successfully
        self.assertDictEqual(arp.info, ArpOutput.Arp_info)

        # Check specific attribute values
        # info - interfaces
        self.assertEqual(arp.info['interfaces']['Vlan100']['ipv4']\
            ['neighbors']['192.168.234.1']['ip'], '192.168.234.1')
        # info - statistics
        self.assertEqual(arp.info['statistics']['entries_total'], 8)
예제 #3
0
    def test_incomplete_output(self):
        self.maxDiff = None
        
        arp = Arp(device=self.device)

        # Get outputs
        arp.maker.outputs[ShowArp] = \
            {"": ArpOutput.ShowArp}
        arp.maker.outputs[ShowVrf] = \
            {"": ArpOutput.ShowVrf}
        arp.maker.outputs[ShowIpArp] = \
            {"{'vrf':'VRF1'}": ArpOutput.ShowIpArp}
        arp.maker.outputs[ShowIpArpSummary] = \
            {"": {}}

        arp.maker.outputs[ShowIpTraffic] = \
            {"": {}}

        arp.maker.outputs[ShowIpInterface] = \
            {"": ArpOutput.ShowIpInterface}
        self.device.execute = Mock()
        self.device.execute.side_effect = mapper
        # Learn the feature
        arp.learn()
                
        # Check no attribute not found
        with self.assertRaises(KeyError):
            arp.info['statistics']
예제 #4
0
    def test_complete_output(self):
        self.maxDiff = None
        arp = Arp(device=self.device)

        # Get outputs
        arp.maker.outputs[ShowArp] = \
            {"": ArpOutput.ShowArp}

        arp.maker.outputs[ShowIpArpSummary] = \
            {"": ArpOutput.ShowIpArpSummary}

        arp.maker.outputs[ShowIpTraffic] = \
            {"": ArpOutput.ShowIpTraffic}

        arp.maker.outputs[ShowIpInterface] = \
            {"": ArpOutput.ShowIpInterface}

        # Learn the feature
        arp.learn()

        # Verify Ops was created successfully
        self.assertEqual(arp.info, ArpOutput.Arp_info)

        # Check specific attribute values
        # info - interfaces
        self.assertEqual(arp.info['interfaces']['Vlan100']['ipv4']\
            ['neighbors']['201.0.12.1']['ip'], '201.0.12.1')
        # info - statistics
        self.assertEqual(arp.info['statistics']['entries_total'], 8)
예제 #5
0
    def test_empty_output(self):
        self.maxDiff = None
        arp = Arp(device=self.device)

        # Get outputs
        arp.maker.outputs[ShowArp] = \
            {"": {}}

        arp.maker.outputs[ShowIpArpSummary] = \
            {"": {}}

        arp.maker.outputs[ShowIpTraffic] = \
            {"": {}}

        arp.maker.outputs[ShowIpInterface] = \
            {"": {}}

        # Learn the feature
        arp.learn()

        # Check no attribute not found
        with self.assertRaises(AttributeError):
            arp.info['statistics']