diff --git a/resource_management/alembic.ini b/resource_management/alembic.ini index 0aad7a6e5e6cd079ffb64a6c68f290e6dcec4973..22d9b90d7b87f658aeb5b38a234376d320a13e4c 100644 --- a/resource_management/alembic.ini +++ b/resource_management/alembic.ini @@ -4,6 +4,5 @@ # a migration for script_location = migrations sqlalchemy.url = sqlite:////absolute/path/to/foo.db -sqlalchemy.url = sqlite:////Users/reid/workspace/nat/resource-management/resource_management/foo.db # or here is an example of a mysql dsn # sqlalchemy.url = mysql://dummy:dummy-pass@localhost/resources_db_name diff --git a/resource_management/juniper.py b/resource_management/juniper.py index 4c3eb4dc5f0e277b303d6b382b6d153cdb33a511..6eba0d71813b55c80d650e550e12ddcc31310184 100644 --- a/resource_management/juniper.py +++ b/resource_management/juniper.py @@ -77,6 +77,12 @@ LINE_CARDS_LIST_SCHEMA = { } +def _is_physical_ifc_name(name): + # TODO: is there a better way to filter out lags? other interfaces? + # cf. https://github.com/Juniper/py-junos-eznc/blob/master/lib/jnpr/junos/op/ethport.yml#L6 # noqa: E501 + return re.match('[fgxe][et]-', name) is not None + + def _slot_number(name): """ parses names like 'FPC 2', 'PIC 17' and returns @@ -371,6 +377,8 @@ def load_logical_interfaces(router: 'jnpr.junos.Device'): interfaces = {} for lu in LogicalInterfacesTable(router).get(): assert lu.logical.startswith(lu.physical) # sanity + if not _is_physical_ifc_name(lu.physical): + continue interfaces.setdefault(lu.physical, set()).add(lu.logical) return interfaces @@ -416,6 +424,8 @@ def load_installed_ethernet_ports(router: 'jnpr.junos.Device'): interfaces = {} for ifc in PhysicalInterfacesTable(router).get(): + if not _is_physical_ifc_name(ifc.interface): + continue interfaces[ifc.interface] = { 'admin': ifc.admin == 'up', 'oper': ifc.admin == 'up' diff --git a/test/test_parse_router.py b/test/test_parse_router.py index ffe6157f9a4a80bba0cfb5a22b133a62a0d61aa9..f4dfe4a49253e7c714580c56cc5e682d68839534 100644 --- a/test/test_parse_router.py +++ b/test/test_parse_router.py @@ -77,6 +77,26 @@ def test_no_db_load_interfaces(mocked_router): assert aggregates +def test_physical_no_lag(mocked_router): + """ + confirm no ae* interfaces are present in the list + of physical interfaces + """ + + ssh = { + 'username': 'bogus', + 'private-key': 'no file' + } + + with juniper.router( + hostname='blah-bogus', + port=12345, + ssh_config=ssh) as dev: + + physical = juniper.load_installed_ethernet_ports(dev) + assert all(p.startswith('ae') is False for p in physical.keys()) + + def test_load_interfaces( mocked_router, resources_db, config_file, router_name): """