From 435b524f590e99c34054da3a89708281e654e24f Mon Sep 17 00:00:00 2001 From: Pelle Koster <pelle.koster@geant.org> Date: Mon, 8 Apr 2024 07:52:37 +0200 Subject: [PATCH] [POL1-801] get-interface-stats does not filter on admin/oper status --- brian_polling_manager/interface_stats/cli.py | 8 +++----- .../interface_stats/vendors/juniper.py | 8 ++++---- test/interface_stats/test_interface_stats.py | 12 +++++------- tox.ini | 1 + 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/brian_polling_manager/interface_stats/cli.py b/brian_polling_manager/interface_stats/cli.py index 7c8035d..ac18cfd 100644 --- a/brian_polling_manager/interface_stats/cli.py +++ b/brian_polling_manager/interface_stats/cli.py @@ -176,7 +176,7 @@ def process_juniper_router( ) ) - _log_interface_points_sorted(points, point_kind='error') + _log_interface_points_sorted(points, point_kind="error") write_points(points, influx_params=influx_params) @@ -184,10 +184,8 @@ def _log_interface_points_sorted(points: Sequence[dict], point_kind=""): N_COLUMNS = 5 num_points = len(points) point_kind = point_kind + " " if point_kind else "" - semicolon = ':' if num_points else '' - logger.info( - f"Found {point_kind}points for {num_points} interfaces{semicolon}" - ) + semicolon = ":" if num_points else "" + logger.info(f"Found {point_kind}points for {num_points} interfaces{semicolon}") if not points: return diff --git a/brian_polling_manager/interface_stats/vendors/juniper.py b/brian_polling_manager/interface_stats/vendors/juniper.py index 7102b3a..bd1b149 100644 --- a/brian_polling_manager/interface_stats/vendors/juniper.py +++ b/brian_polling_manager/interface_stats/vendors/juniper.py @@ -138,8 +138,8 @@ def _physical_interface_counters(ifc_doc): ' or name[(starts-with(normalize-space(), "ae"))]' ' or name[(starts-with(normalize-space(), "irb"))]' ' or name[(starts-with(normalize-space(), "gr"))])' - ' and normalize-space(admin-status)="up"' - ' and normalize-space(oper-status)="up"' + # ' and normalize-space(admin-status)="up"' + # ' and normalize-space(oper-status)="up"' "]" ): result = parse_interface_xml(phy, PHYSICAL_INTERFACE_COUNTERS) @@ -156,8 +156,8 @@ def _logical_interface_counters(ifc_doc): ' or name[(starts-with(normalize-space(), "ae"))]' ' or name[(starts-with(normalize-space(), "irb"))]' ' or name[(starts-with(normalize-space(), "gr"))])' - ' and normalize-space(admin-status)="up"' - ' and normalize-space(oper-status)="up"' + # ' and normalize-space(admin-status)="up"' + # ' and normalize-space(oper-status)="up"' "]/logical-interface" ): result = parse_interface_xml(logical, LOGICAL_INTERFACE_COUNTERS) diff --git a/test/interface_stats/test_interface_stats.py b/test/interface_stats/test_interface_stats.py index 421417f..40ff6ae 100644 --- a/test/interface_stats/test_interface_stats.py +++ b/test/interface_stats/test_interface_stats.py @@ -43,6 +43,7 @@ def test_verify_all_interfaces_present(single_router_fqdn, polled_interfaces): over all test data sets ... the point of the test is a sanity check of our test data """ + def _is_enabled(ifc_name, ifc_doc): m = re.match(r"^([^\.]+)\.?.*", ifc_name) assert m # sanity: should never fail @@ -386,8 +387,8 @@ def test_main_for_all_juniper_routers(write_points, all_juniper_routers): @pelle: this is not a maintainable pattern (e.g. POL1-799 or similar things) ... please do something nicer (actually > a few calls/points is enough) """ - assert calls == 104 - assert total_points == 6819 + assert calls > 0 + assert total_points > 0 class TestGetJuniperNetConnf: @@ -400,9 +401,7 @@ class TestGetJuniperNetConnf: @pytest.fixture(autouse=True) def mocked_rpc(self, data_dir): raw_response = data_dir.joinpath(self.RAW_RESPONSE_FILE).read_text() - with patch.object( - juniper, "_rpc", return_value=RPCReply(raw_response) - ) as mock: + with patch.object(juniper, "_rpc", return_value=RPCReply(raw_response)) as mock: yield mock def test_calls_rpc_with_params(self, mocked_rpc): @@ -522,8 +521,7 @@ def test_prepare_influx_params(input_params, expected): @pytest.mark.parametrize( - "hostname", - ['rt0.lon.uk.lab.office.geant.net', 'rt0.ams.nl.lab.office.geant.net'] + "hostname", ["rt0.lon.uk.lab.office.geant.net", "rt0.ams.nl.lab.office.geant.net"] ) def test_nokia_counters(hostname): """ diff --git a/tox.ini b/tox.ini index d71b8bb..a0c8412 100644 --- a/tox.ini +++ b/tox.ini @@ -3,6 +3,7 @@ envlist = py36 [flake8] max-line-length = 120 +extend-ignore = E203,E701,W605 [testenv] passenv = USE_COMPOSE -- GitLab