Beispiel #1
0
    def test_rename_failure(self, capsys, tmpdir, spec, old_config):
        old_filename = os.path.join(str(tmpdir), "config.json")
        cli_args = {"configuration": {"file": old_filename, "type": "json"}}

        with open(old_filename, "w") as f:
            f.write(json.dumps(old_config, ensure_ascii=False))

        with patch("os.rename", Mock(side_effect=ValueError)):
            generated_config = bg_utils.load_application_config(spec, cli_args)

        # Make sure we printed something
        assert capsys.readouterr().err

        assert generated_config.log.level == "INFO"

        # Both the tmp file and the old JSON should still be there.
        assert len(os.listdir(str(tmpdir))) == 2
        with open(old_filename + ".tmp") as f:
            yaml.safe_load(f)

        # The loaded config should be the JSON file.
        with open(old_filename) as f:
            new_config_value = json.load(f)

        assert new_config_value == old_config
Beispiel #2
0
    def test_catastrophe(self, capsys, tmpdir, spec, old_config):
        old_filename = os.path.join(str(tmpdir), "config.json")
        cli_args = {"configuration": {"file": old_filename, "type": "json"}}

        with open(old_filename, "w") as f:
            f.write(json.dumps(old_config, ensure_ascii=False))

        with patch("os.rename", Mock(side_effect=[Mock(), ValueError])):
            with pytest.raises(ValueError):
                bg_utils.load_application_config(spec, cli_args)

        # Make sure we printed something
        assert capsys.readouterr().err

        # Both the tmp file and the old JSON should still be there.
        assert len(os.listdir(str(tmpdir))) == 2
Beispiel #3
0
    def test_setup_with_config_file(self, tmpdir, spec, config):

        config_file = os.path.join(str(tmpdir), "config." + config[0])
        cli_args = {"configuration": {"file": config_file, "type": config[1]}}

        with open(config_file, "w") as f:
            f.write(config[2])

        generated_config = bg_utils.load_application_config(spec, cli_args)
        assert generated_config.log.level == "DEBUG"
        assert len(spec.sources) == 3
Beispiel #4
0
def setup(spec, cli_args):
    global config, logger, app_logging_config

    config = bg_utils.load_application_config(spec, cli_args)

    app_logging_config = bg_utils.setup_application_logging(
        config, get_default_logging_config(config.log.level, config.log.file))
    logger = logging.getLogger(__name__)
    logger.debug("Logging configured. First post!")

    load_plugin_logging_config(config)
    _setup_application()
Beispiel #5
0
def setup_bartender(spec, cli_args):
    global application, config, logger, bv_client

    config = bg_utils.load_application_config(spec, cli_args)
    config.web.url_prefix = brewtils.rest.normalize_url_prefix(config.web.url_prefix)

    log_default = get_default_logging_config(config.log.level, config.log.file)
    bg_utils.setup_application_logging(config, log_default)
    logger = logging.getLogger(__name__)

    bv_client = EasyClient(**config.web)

    application = BartenderApp()

    logger.debug("Successfully loaded the bartender application")
Beispiel #6
0
    def test_success(self, tmpdir, spec, old_config, new_config):
        old_filename = os.path.join(str(tmpdir), "config.json")
        old_config["configuration"]["file"] = old_filename
        cli_args = {"configuration": {"file": old_filename, "type": "json"}}

        with open(old_filename, "w") as f:
            f.write(json.dumps(old_config, ensure_ascii=False))

        generated_config = bg_utils.load_application_config(spec, cli_args)
        assert generated_config.log.level == "INFO"

        with open(old_filename) as f:
            new_config_value = json.load(f)

        assert new_config_value == new_config
        assert len(os.listdir(str(tmpdir))) == 2
Beispiel #7
0
    def test_no_change(self, tmpdir, spec, new_config):
        config_file = os.path.join(str(tmpdir), "config.yaml")
        cli_args = {"configuration": {"file": config_file}}

        with open(config_file, "w") as f:
            yaml.safe_dump(new_config,
                           f,
                           default_flow_style=False,
                           encoding="utf-8")

        generated_config = bg_utils.load_application_config(spec, cli_args)
        assert generated_config.log.level == "INFO"

        with open(config_file) as f:
            new_config_value = yaml.safe_load(f)

        assert new_config_value == new_config
        assert len(os.listdir(str(tmpdir))) == 1
Beispiel #8
0
    def test_migration_failure(self, capsys, tmpdir, spec, old_config):
        old_filename = os.path.join(str(tmpdir), "config.json")
        cli_args = {"configuration": {"file": old_filename, "type": "json"}}

        spec.migrate_config_file = Mock(side_effect=ValueError)

        with open(old_filename, "w") as f:
            f.write(json.dumps(old_config, ensure_ascii=False))

        generated_config = bg_utils.load_application_config(spec, cli_args)

        # Make sure we printed something
        assert capsys.readouterr().err

        # If the migration fails, we should still have a single unchanged JSON file.
        assert len(os.listdir(str(tmpdir))) == 1
        with open(old_filename) as f:
            new_config_value = json.load(f)
        assert new_config_value == old_config

        # And the values should be unchanged
        assert generated_config.log.level == "INFO"
Beispiel #9
0
 def test_load_application_config_no_file_given(self, spec):
     config = bg_utils.load_application_config(spec, {})
     assert type(config) == Box
     assert len(spec.sources) == 2