Exemple #1
0
 def test_view_json(self, mock_execute):
     mock_execute.side_effect = self._mock_manager
     rst = RouteSummaryTable(self.dev)
     rst.get()
     resp = rst["ISP-1.inet.0"].to_json()
     j = {
         "ISP-1.inet.0": {
             "proto": {
                 "Local": {
                     "count": 1,
                     "active": 1
                 },
                 "Direct": {
                     "count": 3,
                     "active": 3
                 },
             },
             "dests": 4,
             "holddown": 0,
             "active": 4,
             "hidden": 0,
             "total": 4,
         }
     }
     self.assertEqual(eval(resp), j)
 def test_table_json(self, mock_execute):
     mock_execute.side_effect = self._mock_manager
     rst = RouteSummaryTable(self.dev)
     rst.get()
     resp = rst.to_json()
     j = '{"ISP-1.inet.0": {"proto": {"Local": {"count": 1, "active": 1}, ' \
         '"Direct": {"count": 3, "active": 3}}, "dests": 4, "holddown": 0, "active": 4, "hidden": 0, "total": 4}, ' \
         '"ISP-2.inet.0": {"proto": {"Local": {"count": 1, "active": 1}, "Direct": {"count": 3, "active": 3}}, ' \
         '"dests": 4, "holddown": 0, "active": 4, "hidden": 0, "total": 4}, "inet.0": {"proto": {"Static": {"count": 1, "active": 1}, ' \
         '"Local": {"count": 4, "active": 4}, "Direct": {"count": 4, "active": 3}}, "dests": 8, "holddown": 0, "active": 8, "hidden": 0, "total": 9}}'
     self.assertEqual(resp, j)
Exemple #3
0
 def test_table_json(self, mock_execute):
     mock_execute.side_effect = self._mock_manager
     rst = RouteSummaryTable(self.dev)
     rst.get()
     resp = rst.to_json()
     j = {'ISP-1.inet.0': {'proto': {'Local': {'count': 1, 'active': 1}, 'Direct': {'count': 3, 'active': 3}},
                           'dests': 4, 'holddown': 0, 'active': 4, 'hidden': 0, 'total': 4},
          'ISP-2.inet.0': {'proto': {'Local': {'count': 1, 'active': 1}, 'Direct': {'count': 3, 'active': 3}},
                           'dests': 4, 'holddown': 0, 'active': 4, 'hidden': 0, 'total': 4},
          'inet.0': {'proto': {'Local': {'count': 4, 'active': 4}, 'Static': {'count': 1, 'active': 1},
                               'Direct': {'count': 4, 'active': 3}}, 'dests': 8, 'holddown': 0, 'active': 8,
                     'hidden': 0, 'total': 9}}
     self.assertEqual(eval(resp), j)
Exemple #4
0
def ospf(dev, instance=None):
    print(
        f"{Fore.YELLOW}{_create_header('begin troubleshoot ospf')}{Style.RESET_ALL}\n"
    )
    if instance:
        neighbors = OspfNeighborTable(dev).get(instance=instance)
        interfaces = OspfInterfaceTable(dev).get(instance=instance)
    else:
        neighbors = OspfNeighborTable(dev).get()
        interfaces = OspfInterfaceTable(dev).get()
    for interface in interfaces:
        if interface.passive:
            passive = 'yes'
        else:
            passive = 'no'
        print(
            f"Interface: {interface.interface_name:21} Neighbor Count: {interface.neighbor_count}\n"
            f"  Passive: {passive}")
        print("  Neighbors:")
        for neighbor in neighbors:
            if interface.interface_name == neighbor.interface_name:
                if neighbor.ospf_neighbor_state != "Full":
                    print(
                        f"    {Fore.RED}{neighbor.neighbor_address:15} Uptime: {str(neighbor.neighbor_up_time):15}"
                        f"Neighbor state: {neighbor.ospf_neighbor_state}{Style.RESET_ALL}"
                    )
                else:
                    print(
                        f"    {neighbor.neighbor_address:15} Uptime: {neighbor.neighbor_up_time}"
                    )
    routes = RouteSummaryTable(dev).get()
    total_routes = 0
    for route in routes:
        if route.proto['OSPF']:
            print(
                f"Table: {route.name} routes:{route.proto['OSPF'].count} active:{route.proto['OSPF'].active}"
            )
            total_routes = total_routes + route.proto['OSPF'].count
    print(f"Total OSPF Routes: {total_routes}")
    print(
        f"{Fore.YELLOW}{_create_header('end of troubleshoot ospf')}{Style.RESET_ALL}\n"
    )