Skip to content

Commit

Permalink
[req-change] Don't overwrite the organization of RadiusAccounting
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed May 10, 2024
1 parent c73ee88 commit 193ac59
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tests/openwisp2/saml/*

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
9 changes: 2 additions & 7 deletions openwisp_radius/integrations/monitoring/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def post_save_radiusaccounting(
output_octets,
calling_station_id,
called_station_id,
time=None,
):
try:
registration_method = (
Expand Down Expand Up @@ -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',
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions openwisp_radius/integrations/monitoring/tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
)

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 193ac59

Please sign in to comment.