Skip to content

Commit 087bd2b

Browse files
committed
[chores] Minor improvements to close_stale_sessions
- Loop over sessions using iterator() - Use "Session-Timeout" as terminate cause
1 parent 3c0c7cf commit 087bd2b

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

openwisp_radius/base/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,12 @@ def close_stale_sessions(cls, days=None, hours=None):
549549
| (Q(update_time=None) & Q(start_time__lt=older_than))
550550
)
551551
)
552-
for session in sessions:
552+
for session in sessions.iterator():
553553
# calculate seconds in between two dates
554554
session.session_time = (now() - session.start_time).total_seconds()
555555
session.stop_time = now()
556556
session.update_time = session.stop_time
557-
session.terminate_cause = "Session Timeout"
557+
session.terminate_cause = "Session-Timeout"
558558
session.save()
559559

560560
@classmethod

openwisp_radius/tests/test_commands.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_cleanup_stale_radacct_command(self):
4040
self.assertNotEqual(session.stop_time, None)
4141
self.assertNotEqual(session.session_time, None)
4242
self.assertEqual(session.update_time, session.stop_time)
43-
self.assertEqual(session.terminate_cause, "Session Timeout")
43+
self.assertEqual(session.terminate_cause, "Session-Timeout")
4444

4545
with self.subTest(
4646
"Test start_time older than specified time but update_time is recent"
@@ -67,7 +67,7 @@ def test_cleanup_stale_radacct_command(self):
6767
self.assertNotEqual(session.stop_time, None)
6868
self.assertNotEqual(session.session_time, None)
6969
self.assertEqual(session.update_time, session.stop_time)
70-
self.assertEqual(session.terminate_cause, "Session Timeout")
70+
self.assertEqual(session.terminate_cause, "Session-Timeout")
7171

7272
with self.subTest("Test start_time and update_time older than specified hours"):
7373
options["unique_id"] = "120"
@@ -79,7 +79,7 @@ def test_cleanup_stale_radacct_command(self):
7979
self.assertNotEqual(session.stop_time, None)
8080
self.assertNotEqual(session.session_time, None)
8181
self.assertEqual(session.update_time, session.stop_time)
82-
self.assertEqual(session.terminate_cause, "Session Timeout")
82+
self.assertEqual(session.terminate_cause, "Session-Timeout")
8383

8484
with self.subTest("Test does not affect closed session"):
8585
options["unique_id"] = "121"
@@ -96,7 +96,7 @@ def test_cleanup_stale_radacct_command(self):
9696
"2017-06-10 10:55:00",
9797
)
9898
self.assertEqual(session.update_time, session.stop_time)
99-
self.assertNotEqual(session.terminate_cause, "Session Timeout")
99+
self.assertNotEqual(session.terminate_cause, "Session-Timeout")
100100

101101
@capture_any_output()
102102
def test_delete_old_postauth_command(self):

0 commit comments

Comments
 (0)