From 193ac5961a81a9deec76d947a668753ee796aec3 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Wed, 8 May 2024 22:49:36 +0530 Subject: [PATCH] [req-change] Don't overwrite the organization of RadiusAccounting --- .gitignore | 2 ++ openwisp_radius/integrations/monitoring/tasks.py | 9 ++------- .../integrations/monitoring/tests/test_metrics.py | 4 ++-- setup.cfg | 2 ++ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index d2241941..0f91b06b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +tests/openwisp2/saml/* + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/openwisp_radius/integrations/monitoring/tasks.py b/openwisp_radius/integrations/monitoring/tasks.py index b6f271e0..f8aef603 100644 --- a/openwisp_radius/integrations/monitoring/tasks.py +++ b/openwisp_radius/integrations/monitoring/tasks.py @@ -180,6 +180,7 @@ def post_save_radiusaccounting( output_octets, calling_station_id, called_station_id, + time=None, ): try: registration_method = ( @@ -221,13 +222,6 @@ def post_save_radiusaccounting( location_id = str(device.devicelocation.location_id) else: location_id = None - # Give preference to the organization_id of the device - # over RadiusAccounting object. - # This would also handle the case when SHARED_ACCOUNTING is enabled, - # and write the metric with the same organization_id as the device. - # If SHARED_ACCOUNTING is disabled, the organization_id of - # Device and RadiusAccounting would be same. - organization_id = str(device.organization_id) metric, created = Metric._get_or_create( configuration='radius_acc', @@ -249,6 +243,7 @@ def post_save_radiusaccounting( 'output_octets': output_octets, 'username': sha1_hash(username), }, + time=time, ) if not object_id: # Adding a chart requires all parameters of extra_tags to be present. diff --git a/openwisp_radius/integrations/monitoring/tests/test_metrics.py b/openwisp_radius/integrations/monitoring/tests/test_metrics.py index c2317af6..336c5167 100644 --- a/openwisp_radius/integrations/monitoring/tests/test_metrics.py +++ b/openwisp_radius/integrations/monitoring/tests/test_metrics.py @@ -135,7 +135,7 @@ def test_post_save_radius_accounting_shared_accounting(self, mocked_logger): 'calling_station_id': sha1_hash('00:00:00:00:00:00'), 'location_id': str(device_loc.location.id), 'method': reg_user.method, - 'organization_id': str(device.organization_id), + 'organization_id': str(self.default_org.id), }, ) @@ -175,7 +175,7 @@ def test_post_save_radius_accounting_shared_accounting(self, mocked_logger): ) metric = device_metric_qs.first() self.assertEqual( - metric.extra_tags['organization_id'], str(device.organization_id) + metric.extra_tags['organization_id'], str(self.default_org.id) ) traffic_chart = metric.chart_set.get(configuration='radius_traffic') points = traffic_chart.read() diff --git a/setup.cfg b/setup.cfg index 574a6ac6..a98bfd8a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,6 +19,8 @@ force_grid_wrap=0 ignore = W605, W503, W504, E203 exclude = *.egg-info, .git, + ./tests/openwisp2/saml/* + ./test-* ./tests/*settings*.py, docs/* max-line-length = 88