Skip to content
Snippets Groups Projects
Commit d87c0ec5 authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

Use enum to describe possible values

parent cea4da4b
No related branches found
No related tags found
1 merge request!5Add port_type parsing from description for BRIAN
...@@ -120,10 +120,16 @@ class BRIAN_DASHBOARDS(Enum): ...@@ -120,10 +120,16 @@ class BRIAN_DASHBOARDS(Enum):
# NREN customer # NREN customer
NREN = auto() NREN = auto()
class PORT_TYPES(Enum):
ACCESS = auto()
SERVICE = auto()
UNKNOWN = auto()
# only used in INTERFACE_LIST_SCHEMA and sphinx docs # only used in INTERFACE_LIST_SCHEMA and sphinx docs
_DASHBOARD_IDS = [d.name for d in list(BRIAN_DASHBOARDS)] _DASHBOARD_IDS = [d.name for d in list(BRIAN_DASHBOARDS)]
_PORT_TYPES = [t.name for t in list(PORT_TYPES)]
_INTERFACE_TYPES = [i.name for i in list(INTERFACE_TYPES)] _INTERFACE_TYPES = [i.name for i in list(INTERFACE_TYPES)]
INTERFACE_LIST_SCHEMA = { INTERFACE_LIST_SCHEMA = {
...@@ -183,7 +189,7 @@ INTERFACE_LIST_SCHEMA = { ...@@ -183,7 +189,7 @@ INTERFACE_LIST_SCHEMA = {
'type': 'array', 'type': 'array',
'items': {'$ref': '#/definitions/db_info'} 'items': {'$ref': '#/definitions/db_info'}
}, },
'port_type': {'type': 'string'} 'port_type': {'enum': _PORT_TYPES}
  • Owner

    enum.Enum is of course ok, too ... but I think it's mainly nice (in Python) if we're doing real mypy checking

  • Please register or sign in to reply
  • Owner

    not happy with 'enum': ['service', 'access', 'unknown'] ...?

  • Bjarke Madsen @bjarke.madsen ·
    Author Contributor

    I thought it was more consistent to go the same route as with the dashboard names

  • Please register or sign in to reply
}, },
'required': [ 'required': [
'router', 'name', 'description', 'router', 'name', 'description',
...@@ -719,10 +725,10 @@ def _get_port_type(description): ...@@ -719,10 +725,10 @@ def _get_port_type(description):
if rex: if rex:
sid = rex.group(1) sid = rex.group(1)
if 'GA' in sid: if 'GA' in sid:
return 'access' return PORT_TYPES.ACCESS.name
elif 'GS' in sid: elif 'GS' in sid:
return 'service' return PORT_TYPES.SERVICE.name
return 'unknown' return PORT_TYPES.UNKNOWN.name
def load_interfaces_to_poll( def load_interfaces_to_poll(
......
...@@ -413,9 +413,9 @@ def test_description_dashboard_parsing( ...@@ -413,9 +413,9 @@ def test_description_dashboard_parsing(
@pytest.mark.parametrize('description,expected_port_type', [ @pytest.mark.parametrize('description,expected_port_type', [
('SRV_IAS CUSTOMER JISC #JISC-AP1-IAS IASPS | ASN786', 'unknown'), ('SRV_IAS CUSTOMER JISC #JISC-AP1-IAS IASPS | ASN786', 'UNKNOWN'),
('SRV_GLOBAL CUSTOMER RENATER #RENATER-AP1 $GS-00505 | ASN2200 |', 'service'), # noqa: E501 ('SRV_GLOBAL CUSTOMER RENATER #RENATER-AP1 $GS-00505 | ASN2200 |', 'SERVICE'), # noqa: E501
('PHY CUSTOMER AZSCIENCENET SRF19095 $GA-01599 | GEANT-10G-Baku-CO-Interxion|', 'access') # noqa: E501 ('PHY CUSTOMER AZSCIENCENET SRF19095 $GA-01599 | GEANT-10G-Baku-CO-Interxion|', 'ACCESS') # noqa: E501
]) ])
def test_description_port_type_parsing( def test_description_port_type_parsing(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment