Skip to content
Snippets Groups Projects
Commit ae001c94 authored by Erik Reid's avatar Erik Reid
Browse files

Finished feature fix-physical-filter.

parents 8aeb094f 1d9db9bd
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,5 @@ ...@@ -4,6 +4,5 @@
# a migration for # a migration for
script_location = migrations script_location = migrations
sqlalchemy.url = sqlite:////absolute/path/to/foo.db 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 # or here is an example of a mysql dsn
# sqlalchemy.url = mysql://dummy:dummy-pass@localhost/resources_db_name # sqlalchemy.url = mysql://dummy:dummy-pass@localhost/resources_db_name
...@@ -77,6 +77,12 @@ LINE_CARDS_LIST_SCHEMA = { ...@@ -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): def _slot_number(name):
""" """
parses names like 'FPC 2', 'PIC 17' and returns parses names like 'FPC 2', 'PIC 17' and returns
...@@ -371,6 +377,8 @@ def load_logical_interfaces(router: 'jnpr.junos.Device'): ...@@ -371,6 +377,8 @@ def load_logical_interfaces(router: 'jnpr.junos.Device'):
interfaces = {} interfaces = {}
for lu in LogicalInterfacesTable(router).get(): for lu in LogicalInterfacesTable(router).get():
assert lu.logical.startswith(lu.physical) # sanity assert lu.logical.startswith(lu.physical) # sanity
if not _is_physical_ifc_name(lu.physical):
continue
interfaces.setdefault(lu.physical, set()).add(lu.logical) interfaces.setdefault(lu.physical, set()).add(lu.logical)
return interfaces return interfaces
...@@ -416,6 +424,8 @@ def load_installed_ethernet_ports(router: 'jnpr.junos.Device'): ...@@ -416,6 +424,8 @@ def load_installed_ethernet_ports(router: 'jnpr.junos.Device'):
interfaces = {} interfaces = {}
for ifc in PhysicalInterfacesTable(router).get(): for ifc in PhysicalInterfacesTable(router).get():
if not _is_physical_ifc_name(ifc.interface):
continue
interfaces[ifc.interface] = { interfaces[ifc.interface] = {
'admin': ifc.admin == 'up', 'admin': ifc.admin == 'up',
'oper': ifc.admin == 'up' 'oper': ifc.admin == 'up'
......
...@@ -77,6 +77,26 @@ def test_no_db_load_interfaces(mocked_router): ...@@ -77,6 +77,26 @@ def test_no_db_load_interfaces(mocked_router):
assert aggregates 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( def test_load_interfaces(
mocked_router, resources_db, config_file, router_name): mocked_router, resources_db, config_file, router_name):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment