Exemplo n.º 1
0
def dlrn_http_factory(host, config_file=None, logger=getLogger()):
    """
    Create a DlrnData instance based on a host.

    :param host: A host name string to build instances
    :param config_file: A dlrn config file(s) to use in addition to
                        the default.
    :param logger: An atkinson logger to use. Default is the base logger.
    :return: A DlrnData instance
    """
    manager = None
    files = ['dlrn.yml']
    if config_file is not None:
        if isinstance(config_file, list):
            files.extend(config_file)
        else:
            files.append(config_file)

    local_path = os.path.realpath(os.path.dirname(__file__))
    manager = ConfigManager(filenames=files, paths=local_path)

    if manager is None:
        return None

    config = manager.config
    if host not in config:
        return None

    return DlrnHttpData(config[host]['url'],
                        config[host]['release'],
                        logger=logger)
Exemplo n.º 2
0
def test_no_logger_specified():
    """
    GIVEN we request a logger without specifying any details
    THEN we get back a default python logger with log level = WARNING
    """
    mylogger = logger.getLogger()
    assert isinstance(mylogger, logging.Logger)
    assert mylogger.getEffectiveLevel() == logging.WARNING
Exemplo n.º 3
0
    def get(cls, report_id, config):
        """
        Retrieve an active report

        :param report_id: The unique id (the report title) for the report
        :param config: Configuration dictionary for the report
        :return: A LoggingReporter instance
        """
        return cls(report_id, getLogger())
Exemplo n.º 4
0
    def __init__(self, url, release, logger=getLogger()):
        """
        Class constructor

        :param url: The URL to the host to obtain data.
        :param releases: The release name to use for lookup.
        :param logger: An atkinson logger to use. Default is the base logger.
        """
        self.url = url
        self.release = release
        self._logger = logger
Exemplo n.º 5
0
    def new(cls, title, description, config):
        """
        Create a new report

        :param title: The title for the report
        :param description: A description for the report
        :param config: Configuration dictionary for the report
        :return: A LoggingReporter instance
        """
        log = getLogger()
        log.error(f"{title}: {description}")
        return cls(title, log)
Exemplo n.º 6
0
def test_driver_not_found():
    """
    GIVEN we request a logger with a driver that cannot be found
    THEN we get back a default python logger with log level = WARNING
    """
    logging.Logger.error = MagicMock()
    mylogger = logger.getLogger({'driver': 'foo.bar.baz'})

    mylogger.error.assert_called_with(
        "Loading the default driver, No module named 'foo'")
    assert isinstance(mylogger, logging.Logger)
    assert mylogger.getEffectiveLevel() == logging.WARNING
Exemplo n.º 7
0
def test_gets_default_logger():
    """
    GIVEN we request a logger with the default atkinson logger
    WHEN we specify the root log level
    THEN we get back a default python logger, with that level set.
    """
    mylogger = logger.getLogger({
        'driver': 'atkinson.logging.drivers.default',
        'root': {
            'level': 'DEBUG'
        }
    })
    assert isinstance(mylogger, logging.Logger)
    assert mylogger.getEffectiveLevel() == logging.DEBUG
Exemplo n.º 8
0
    def __init__(self, url, release, link_name='current', logger=getLogger()):
        """
        Class constructor

        :param url: The URL to the host to obtain data.
        :param releases: The release name to use for lookup.
        :param link_name: The name of the dlrn symlink to fetch data from.
        :param logger: An atkinson logger to use. Default is the base logger.
        """
        self.url = os.path.join(url, release)
        self.release = release
        self._logger = logger
        self._link_name = link_name
        self._commit_data = {}
        self._fetch_commit()