def test_should_read_configuration_file (self, mock_exists):
        mock_parser = Mock(YadtConfigParser)
        mock_wrapped_parser = Mock()
        mock_parser._parser = mock_wrapped_parser
        mock_exists.return_value = True

        YadtConfigParser.read_configuration_file(mock_parser, 'some.cfg')

        self.assertEqual(call(['some.cfg']), mock_wrapped_parser.read.call_args)
    def test_should_read_configuration_file(self, mock_exists):
        mock_parser = Mock(YadtConfigParser)
        mock_wrapped_parser = Mock()
        mock_parser._parser = mock_wrapped_parser
        mock_exists.return_value = True

        YadtConfigParser.read_configuration_file(mock_parser, 'some.cfg')

        self.assertEqual(call(['some.cfg']),
                         mock_wrapped_parser.read.call_args)
Пример #3
0
class ControllerConfigLoader (object):
    """
        uses a YadtConfigParser which offers convenience methods.
    """
    DEFAULT_BROADCASTER_HOST = 'localhost'
    DEFAULT_BROADCASTER_PORT = '8081'

    def __init__(self, defaults=None):
        """
            Creates instance of YadtConfigParser which will be used to parse the configuration file.
        """
        if defaults:
            self.DEFAULT_BROADCASTER_HOST = defaults.get('--broadcaster-host')
            self.DEFAULT_BROADCASTER_PORT = defaults.get('--broadcaster-port')
        self._parser = YadtConfigParser()

    def get_broadcaster_host(self):
        """
            @return: the broadcaster host from the configuration file,
                     otherwise DEFAULT_BROADCASTER_HOST.
        """
        return self._parser.get_option(SECTION_BROADCASTER, 'host', self.DEFAULT_BROADCASTER_HOST)

    def get_broadcaster_port(self):
        """
            @return: the broadcaster port from the configuration file as int,
                     otherwise DEFAULT_BROADCASTER_PORT.
        """
        return self._parser.get_option_as_int(SECTION_BROADCASTER, 'port', self.DEFAULT_BROADCASTER_PORT)

    def read_configuration_file(self, filename):
        """
            Reads the given configuration file. Uses the YadtConfigParser.

            @return: configuration dictionary
        """
        return self._parser.read_configuration_file(filename)
Пример #4
0
class ReceiverConfigLoader (object):

    """
        uses a YadtConfigParser which offers convenience methods.
    """

    def __init__(self):
        """
            Creates instance of YadtConfigParser which will be used to parse
            the configuration file.
        """
        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,
                     otherwise DEFAULT_BROADCASTER_HOST.
        """
        return self._parser.get_option(SECTION_BROADCASTER, 'host', DEFAULT_BROADCASTER_HOST)

    def get_broadcaster_port(self):
        """
            @return: the broadcaster port from the configuration file as int,
                     otherwise DEFAULT_BROADCASTER_PORT.
        """
        return self._parser.get_option_as_int(SECTION_BROADCASTER, 'port', DEFAULT_BROADCASTER_PORT)

    def get_hostname(self):
        """
            @return: if a hostname is given in the configuration file it will
                     return it, otherwise it will return the host name as
                     given by socket.gethostname
        """
        return self._parser.get_option(SECTION_RECEIVER, 'hostname', socket.gethostname())

    def get_log_filename(self):
        """
            @return: the log filename from the configuration file if given,
                     otherwise DEFAULT_LOG_FILENAME
        """
        return self._parser.get_option(SECTION_RECEIVER, 'log_filename', DEFAULT_LOG_FILENAME)

    def get_python_command(self):
        """
            @return: the python command from the configuration file if given,
                     otherwise DEFAULT_PYTHON_COMMAND
        """
        return self._parser.get_option(SECTION_RECEIVER, 'python_command', DEFAULT_PYTHON_COMMAND)

    def get_script_to_execute(self):
        """
            @return: if the configuration file provides a script to execute,
                     otherwise DEFAULT_SCRIPT_TO_EXECUTE.
        """
        return self._parser.get_option(SECTION_RECEIVER, 'script_to_execute', DEFAULT_SCRIPT_TO_EXECUTE)

    def get_targets(self):
        """
            @return: the set of targets given in the configuration file,
                     otherwise DEFAULT_TARGETS.
        """
        return self._parser.get_option_as_set(SECTION_RECEIVER, 'targets', DEFAULT_TARGETS)

    def get_targets_directory(self):
        """
            @return: the targets directory from the configuration file,
                     otherwise DEFAULT_TARGETS_DIRECTORY.
        """
        return self._parser.get_option(SECTION_RECEIVER, 'targets_directory', DEFAULT_TARGETS_DIRECTORY)

    def read_configuration_file(self, filename):
        """
            Reads the given configuration file. Uses the YadtConfigParser.

            @return: configuration dictionary
        """
        return self._parser.read_configuration_file(filename)

    def get_metrics_directory(self):
        """
            @return: the metrics_directory from the receiver configuration and
            None otherwise
        """
        return self._parser.get_option(SECTION_RECEIVER, 'metrics_directory',
                                       None)

    def get_metrics_file(self):
        """
            @return: the derived metrics_file or None
        """
        metrics_directory = self.get_metrics_directory()
        if metrics_directory is not None:
            return os.path.join(metrics_directory, 'yrc.metrics')
Пример #5
0
class ReceiverConfigLoader(object):
    """
        uses a YadtConfigParser which offers convenience methods.
    """
    def __init__(self):
        """
            Creates instance of YadtConfigParser which will be used to parse
            the configuration file.
        """
        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,
                     otherwise DEFAULT_BROADCASTER_HOST.
        """
        return self._parser.get_option(SECTION_BROADCASTER, 'host',
                                       DEFAULT_BROADCASTER_HOST)

    def get_broadcaster_port(self):
        """
            @return: the broadcaster port from the configuration file as int,
                     otherwise DEFAULT_BROADCASTER_PORT.
        """
        return self._parser.get_option_as_int(SECTION_BROADCASTER, 'port',
                                              DEFAULT_BROADCASTER_PORT)

    def get_hostname(self):
        """
            @return: if a hostname is given in the configuration file it will
                     return it, otherwise it will return the host name as
                     given by socket.gethostname
        """
        return self._parser.get_option(SECTION_RECEIVER, 'hostname',
                                       socket.gethostname())

    def get_log_filename(self):
        """
            @return: the log filename from the configuration file if given,
                     otherwise DEFAULT_LOG_FILENAME
        """
        return self._parser.get_option(SECTION_RECEIVER, 'log_filename',
                                       DEFAULT_LOG_FILENAME)

    def get_python_command(self):
        """
            @return: the python command from the configuration file if given,
                     otherwise DEFAULT_PYTHON_COMMAND
        """
        return self._parser.get_option(SECTION_RECEIVER, 'python_command',
                                       DEFAULT_PYTHON_COMMAND)

    def get_script_to_execute(self):
        """
            @return: if the configuration file provides a script to execute,
                     otherwise DEFAULT_SCRIPT_TO_EXECUTE.
        """
        return self._parser.get_option(SECTION_RECEIVER, 'script_to_execute',
                                       DEFAULT_SCRIPT_TO_EXECUTE)

    def get_targets(self):
        """
            @return: the set of targets given in the configuration file,
                     otherwise DEFAULT_TARGETS.
        """
        return self._parser.get_option_as_set(SECTION_RECEIVER, 'targets',
                                              DEFAULT_TARGETS)

    def get_targets_directory(self):
        """
            @return: the targets directory from the configuration file,
                     otherwise DEFAULT_TARGETS_DIRECTORY.
        """
        return self._parser.get_option(SECTION_RECEIVER, 'targets_directory',
                                       DEFAULT_TARGETS_DIRECTORY)

    def read_configuration_file(self, filename):
        """
            Reads the given configuration file. Uses the YadtConfigParser.

            @return: configuration dictionary
        """
        return self._parser.read_configuration_file(filename)

    def get_metrics_directory(self):
        """
            @return: the metrics_directory from the receiver configuration and
            None otherwise
        """
        return self._parser.get_option(SECTION_RECEIVER, 'metrics_directory',
                                       None)

    def get_metrics_file(self):
        """
            @return: the derived metrics_file or None
        """
        metrics_directory = self.get_metrics_directory()
        if metrics_directory is not None:
            return os.path.join(metrics_directory, 'yrc.metrics')