Skip to content

Commit

Permalink
Added support for setting the timeouts in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
scibi committed May 12, 2015
1 parent d4fae33 commit 8f9a5d0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pyradacctsrv/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ def __init__(self, yaml_config):
if 'hosts' not in self.config:
raise ConfigError("Unable to finde hosts definitions")

self.session_timeout = 900
self.removed_timeout = 900

try:
self.session_timeout = self.config['timeouts']['session']
except KeyError:
pass

try:
self.removed_timeout = self.config['timeouts']['removed']
except KeyError:
pass

def hosts(self):
hosts = {}
default_secret = None
Expand Down
4 changes: 3 additions & 1 deletion pyradacctsrv/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def __init__(self, config_file):

def startService(self):
print("startService()")
self.sdb = SessionDB(redis=txredisapi.lazyConnectionPool())
self.sdb = SessionDB(redis=txredisapi.lazyConnectionPool(),
session_timeout=self.config.session_timeout,
removed_timeout=self.config.removed_timeout)
self.cleaner = SessionCleaner(session_db=self.sdb)
self._port = reactor.listenUDP(1813, RADIUSAccountingProtocol(
session_db=self.sdb,
Expand Down
20 changes: 20 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

@python_2_unicode_compatible
class ConfigTest(unittest.TestCase):
def setUp(self):
self.minimal_config = Config("""
---
hosts:
""")

def test_empty_config(self):
self.assertRaises(ConfigError, Config, "---")
Expand Down Expand Up @@ -63,3 +68,18 @@ def test_default_secret(self):
self.assertEqual(hosts['10.0.0.1']['secret'], 'sec_nas1')
self.assertEqual(hosts['10.0.0.2']['secret'], 'sec_def')
self.assertEqual(hosts['10.0.0.3']['secret'], 'sec_def')

def test_timeout_defaults(self):
self.assertEqual(self.minimal_config.session_timeout, 900)
self.assertEqual(self.minimal_config.removed_timeout, 900)

def test_timeout_custom(self):
c = Config("""
---
timeouts:
session: 60
removed: 61
hosts:
""")
self.assertEqual(c.session_timeout, 60)
self.assertEqual(c.removed_timeout, 61)

0 comments on commit 8f9a5d0

Please sign in to comment.