Exemplo n.º 1
0
 def test_configure_logging_file(self, logging_conf_file_path: Path,
                                 mock_logger: logging.Logger) -> None:
     """Test `start.configure_logging` with correct logging config file path."""
     start.configure_logging(logger=mock_logger,
                             logging_conf=str(logging_conf_file_path))
     mock_logger.debug.assert_called_once_with(  # type: ignore[attr-defined]
         f"Logging dict config loaded from {logging_conf_file_path}.")
Exemplo n.º 2
0
 def test_configure_logging_module_incorrect(
         self, mock_logger: logging.Logger) -> None:
     with pytest.raises(ImportError):
         start.configure_logging(logger=mock_logger,
                                 logging_conf="no.module.here")
         import_error_msg = "Unable to import no.module.here."
         logger_error_msg = "Error when configuring logging:"
         mock_logger.debug.assert_called_once_with(  # type: ignore[attr-defined]
             f"{logger_error_msg} {import_error_msg}.")
Exemplo n.º 3
0
 def test_configure_logging_tmp_module(
     self,
     logging_conf_tmp_file_path: Path,
     mock_logger: logging.Logger,
     monkeypatch: MonkeyPatch,
 ) -> None:
     """Test `start.configure_logging` with temporary logging config path."""
     monkeypatch.syspath_prepend(logging_conf_tmp_file_path)
     monkeypatch.setenv("LOGGING_CONF", "tmp_log")
     assert os.getenv("LOGGING_CONF") == "tmp_log"
     start.configure_logging(logger=mock_logger, logging_conf="tmp_log")
     mock_logger.debug.assert_called_once_with(  # type: ignore[attr-defined]
         "Logging dict config loaded from tmp_log.")
Exemplo n.º 4
0
 def test_configure_logging_tmp_file_incorrect_extension(
     self,
     logging_conf_tmp_path_incorrect_extension: Path,
     mock_logger: logging.Logger,
 ) -> None:
     """Test `start.configure_logging` with incorrect temporary file type."""
     with pytest.raises(ImportError):
         start.configure_logging(
             logger=mock_logger,
             logging_conf=str(logging_conf_tmp_path_incorrect_extension),
         )
         import_error_msg = (
             f"Unable to import {logging_conf_tmp_path_incorrect_extension}."
         )
         logger_error_msg = "Error when configuring logging:"
         mock_logger.debug.assert_called_once_with(  # type: ignore[attr-defined]
             f"{logger_error_msg} {import_error_msg}.")
Exemplo n.º 5
0
 def test_configure_logging_tmp_module_no_dict(
     self,
     logging_conf_tmp_path_no_dict: Path,
     mock_logger: logging.Logger,
     monkeypatch: MonkeyPatch,
 ) -> None:
     """Test `start.configure_logging` with temporary logging config path.
     - Correct module name
     - No `LOGGING_CONFIG` object
     """
     monkeypatch.syspath_prepend(logging_conf_tmp_path_no_dict)
     monkeypatch.setenv("LOGGING_CONF", "no_dict")
     assert os.getenv("LOGGING_CONF") == "no_dict"
     with pytest.raises(AttributeError):
         start.configure_logging(logger=mock_logger, logging_conf="no_dict")
         logger_error_msg = "Error when configuring logging:"
         attribute_error_msg = "No LOGGING_CONFIG in no_dict."
         mock_logger.debug.assert_called_once_with(  # type: ignore[attr-defined]
             f"{logger_error_msg} {attribute_error_msg}.")
Exemplo n.º 6
0
 def test_configure_logging_tmp_module_incorrect_type(
     self,
     logging_conf_tmp_path_incorrect_type: Path,
     mock_logger: logging.Logger,
     monkeypatch: MonkeyPatch,
 ) -> None:
     """Test `start.configure_logging` with temporary logging config path.
     - Correct module name
     - `LOGGING_CONFIG` object with incorrect type
     """
     monkeypatch.syspath_prepend(logging_conf_tmp_path_incorrect_type)
     monkeypatch.setenv("LOGGING_CONF", "incorrect_type")
     assert os.getenv("LOGGING_CONF") == "incorrect_type"
     with pytest.raises(TypeError):
         start.configure_logging(logger=mock_logger,
                                 logging_conf="incorrect_type")
         logger_error_msg = "Error when configuring logging:"
         type_error_msg = "LOGGING_CONFIG is not a dictionary instance."
         mock_logger.debug.assert_called_once_with(  # type: ignore[attr-defined]
             f"{logger_error_msg} {type_error_msg}.")
Exemplo n.º 7
0
# Gunicorn setup
max_workers_str = os.getenv("MAX_WORKERS")
web_concurrency_str = os.getenv("WEB_CONCURRENCY")
workers_per_core_str = os.getenv("WORKERS_PER_CORE", "1")
workers = calculate_workers(max_workers_str, web_concurrency_str,
                            workers_per_core_str)
worker_tmp_dir = "/dev/shm"
host = os.getenv("HOST", "0.0.0.0")
port = os.getenv("PORT", "80")
bind_env = os.getenv("BIND")
use_bind = bind_env or f"{host}:{port}"
use_loglevel = os.getenv("LOG_LEVEL", "info")
accesslog_var = os.getenv("ACCESS_LOG", "-")
use_accesslog = accesslog_var or None
errorlog_var = os.getenv("ERROR_LOG", "-")
use_errorlog = errorlog_var or None
graceful_timeout_str = os.getenv("GRACEFUL_TIMEOUT", "120")
timeout_str = os.getenv("TIMEOUT", "120")
keepalive_str = os.getenv("KEEP_ALIVE", "5")

# Gunicorn config variables
logconfig_dict = configure_logging(
    logging_conf=os.getenv("LOGGING_CONF", "inboard.logging_conf"))
loglevel = use_loglevel
bind = use_bind
errorlog = use_errorlog
accesslog = use_accesslog
graceful_timeout = int(graceful_timeout_str)
timeout = int(timeout_str)
keepalive = int(keepalive_str)