Skip to content

Commit

Permalink
making the app status port configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mriehl committed Jul 7, 2014
1 parent e4e1ca1 commit 8297cbb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Expand Up @@ -45,6 +45,7 @@ def test(self):
script_to_execute = /spam/eggs/yadtshell
python_command = /spam/eggs/python
hostname = spameggs
app_status_port = 42
[broadcaster]
host = broadcaster.domain.tld
Expand All @@ -57,6 +58,8 @@ def test(self):
'/spam/eggs/yadtreceiver.log', actual_configuration['log_filename'])
self.assertEqual(
set(['spam', 'eggs']), actual_configuration['targets'])
self.assertEqual(
42, actual_configuration['app_status_port'])
self.assertEqual(
'/spam/eggs/targets', actual_configuration['targets_directory'])
self.assertEqual(
Expand Down
9 changes: 9 additions & 0 deletions src/main/python/yadtreceiver/configuration.py
Expand Up @@ -50,6 +50,7 @@
DEFAULT_SCRIPT_TO_EXECUTE = '/usr/bin/yadtshell'
DEFAULT_TARGETS = set()
DEFAULT_TARGETS_DIRECTORY = '/etc/yadtshell/targets/'
DEFAULT_APP_STATUS_PORT = "8080"

SECTION_BROADCASTER = 'broadcaster'
SECTION_RECEIVER = 'receiver'
Expand All @@ -68,6 +69,13 @@ def __init__(self):
"""
self._parser = YadtConfigParser()

def get_app_status_port(self):
"""
@return: the app status port from the configuration file as int,
otherwise DEFAULT_APP_STATUS_PORT.
"""
return self._parser.get_option_as_int(SECTION_RECEIVER, 'app_status_port', DEFAULT_APP_STATUS_PORT)

def get_broadcaster_host(self):
"""
@return: the broadcaster host from the configuration file,
Expand Down Expand Up @@ -171,6 +179,7 @@ def load(self):
'targets_directory': parser.get_targets_directory(),
'metrics_directory': parser.get_metrics_directory(),
'metrics_file': parser.get_metrics_file(),
'app_status_port': parser.get_app_status_port(),
}
self.compute_allowed_targets()

Expand Down
2 changes: 1 addition & 1 deletion src/main/python/yadtreceiver/yadtreceiver.tac
Expand Up @@ -48,4 +48,4 @@ fs.onChangeCallbacks = dict(
create=receiver.subscribeTarget, delete=receiver.unsubscribeTarget)

site = server.Site(AppStatusResource(receiver))
reactor.listenTCP(8080, site)
reactor.listenTCP(configuration.get("app_status_port"), site)
15 changes: 15 additions & 0 deletions src/unittest/python/configuration_tests.py
Expand Up @@ -30,6 +30,7 @@
DEFAULT_TARGETS_DIRECTORY,
SECTION_BROADCASTER,
SECTION_RECEIVER,
DEFAULT_APP_STATUS_PORT,
ReceiverConfigLoader,
ReceiverConfig,
load)
Expand Down Expand Up @@ -70,6 +71,20 @@ def test_should_return_broadcaster_port_option(self):
self.assertEqual(
call(SECTION_BROADCASTER, 'port', DEFAULT_BROADCASTER_PORT), mock_parser.get_option_as_int.call_args)

def test_should_return_broadcaster_port_option(self):
mock_loader = Mock(ReceiverConfigLoader)
mock_parser = Mock(YadtConfigParser)
mock_parser.get_option_as_int.return_value = 42
mock_loader._parser = mock_parser

actual_app_status_port = ReceiverConfigLoader.get_app_status_port(
mock_loader)

self.assertEqual(42, actual_app_status_port)
self.assertEqual(
call(SECTION_RECEIVER, 'app_status_port', DEFAULT_APP_STATUS_PORT), mock_parser.get_option_as_int.call_args)


@patch('yadtreceiver.configuration.socket')
def test_should_return_hostname_from_receiver_section(self, mock_socket):
mock_socket.gethostname.return_value = 'localhost'
Expand Down

0 comments on commit 8297cbb

Please sign in to comment.