diff --git a/gravity/state.py b/gravity/state.py index 992fbc1..bcb1af9 100644 --- a/gravity/state.py +++ b/gravity/state.py @@ -11,6 +11,9 @@ from gravity.util import AttributeDict +GALAXY_YML_SAMPLE_PATH = "lib/galaxy/config/sample/galaxy.yml.sample" + + class GracefulMethod(enum.Enum): DEFAULT = 0 SIGHUP = 1 @@ -144,6 +147,11 @@ def __init__(self, *args, **kwargs): for config_file, config_dict in self[key].items(): # resolve path, so we always deal with absolute and symlink-resolved paths config_file = os.path.realpath(config_file) + if config_file.endswith(GALAXY_YML_SAMPLE_PATH): + root_dir = config_dict['attribs']['galaxy_root'] + non_sample_path = os.path.join(root_dir, 'config', 'galaxy.yml') + if os.path.exists(non_sample_path): + config_file = non_sample_path normalized_state[key][config_file] = ConfigFile(config_dict) self.update(normalized_state) diff --git a/tests/conftest.py b/tests/conftest.py index f11099d..d49e027 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -46,7 +46,7 @@ def galaxy_root_dir(galaxy_git_dir, tmpdir_factory): @pytest.fixture() def galaxy_yml(galaxy_root_dir): - config = galaxy_root_dir / 'config' / 'galaxy.yml' + config = galaxy_root_dir / 'config' / 'galaxy123.yml' sample_config = galaxy_root_dir / 'config' / 'galaxy.yml.sample' sample_config.copy(config) try: diff --git a/tests/test_config_manager.py b/tests/test_config_manager.py index 60f23c4..41818ca 100644 --- a/tests/test_config_manager.py +++ b/tests/test_config_manager.py @@ -65,7 +65,7 @@ def test_deregister(galaxy_yml, default_config_manager): def test_rename(galaxy_root_dir, state_dir, default_config_manager): galaxy_yml_sample = galaxy_root_dir / "config" / "galaxy.yml.sample" default_config_manager.add([str(galaxy_yml_sample)]) - galaxy_yml = galaxy_root_dir / "config" / "galaxy.yml" + galaxy_yml = galaxy_root_dir / "config" / "galaxy123.yml" galaxy_yml_sample.copy(galaxy_yml) assert default_config_manager.is_registered(str(galaxy_yml_sample.realpath())) assert not default_config_manager.is_registered(str(galaxy_yml)) @@ -79,3 +79,12 @@ def test_auto_register(galaxy_yml, default_config_manager, monkeypatch): assert not default_config_manager.is_registered(str(galaxy_yml)) default_config_manager.auto_register() assert default_config_manager.is_registered(str(galaxy_yml)) + + +def test_register_sample_update_to_non_sample(galaxy_root_dir, state_dir, default_config_manager): + galaxy_yml_sample = galaxy_root_dir / "config" / "galaxy.yml.sample" + default_config_manager.add([str(galaxy_yml_sample)]) + galaxy_yml = galaxy_root_dir / "config" / "galaxy.yml" + galaxy_yml_sample.copy(galaxy_yml) + default_config_manager.instance_count == 1 + assert default_config_manager.get_registered_config(str(galaxy_yml)) diff --git a/tests/test_operations.py b/tests/test_operations.py index e97ff22..f13865e 100644 --- a/tests/test_operations.py +++ b/tests/test_operations.py @@ -1,6 +1,7 @@ import json import re import time +from pathlib import Path import requests from click.testing import CliRunner @@ -121,7 +122,8 @@ def test_cmd_show_config_does_not_exist(state_dir, galaxy_yml): assert "Registered config files are:" not in result.output assert f'To register this config file run "galaxyctl register {str(galaxy_yml)}"' in result.output # register the sample file, but ask for galaxy.yml - result = runner.invoke(galaxyctl, ['--state-dir', state_dir, 'register', str(galaxy_yml + '.sample')]) + sample_file = Path(galaxy_yml).parent / 'galaxy.yml.sample' + result = runner.invoke(galaxyctl, ['--state-dir', state_dir, 'register', str(sample_file)]) assert result.exit_code == 0, result.output result = runner.invoke(galaxyctl, ['--state-dir', state_dir, 'show', str(galaxy_yml)]) assert result.exit_code == 1 diff --git a/tests/test_process_manager.py b/tests/test_process_manager.py index 26d3a46..fbd76c2 100644 --- a/tests/test_process_manager.py +++ b/tests/test_process_manager.py @@ -107,10 +107,10 @@ def test_static_handlers(default_config_manager, galaxy_yml, job_conf): instance_conf_dir = Path(default_config_manager.state_dir) / 'supervisor' / 'supervisord.conf.d' / '_default_.d' handler0_config_path = instance_conf_dir / 'galaxy_standalone_handler0.conf' assert handler0_config_path.exists() - assert 'galaxy.yml --server-name=handler0 --pid-file=' in handler0_config_path.open().read() + assert f'{str(galaxy_yml)} --server-name=handler0 --pid-file=' in handler0_config_path.open().read() handler1_config_path = instance_conf_dir / 'galaxy_standalone_handler1.conf' assert handler1_config_path.exists() - assert 'galaxy.yml --server-name=handler1 --pid-file=' in handler1_config_path.open().read() + assert f'{str(galaxy_yml)} --server-name=handler1 --pid-file=' in handler1_config_path.open().read() def test_gxit_handler(default_config_manager, galaxy_yml, gxit_config):