Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically switch to non-sample galaxy.yml if it exists #39

Merged
merged 2 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gravity/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion tests/test_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
4 changes: 3 additions & 1 deletion tests/test_operations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import re
import time
from pathlib import Path

import requests
from click.testing import CliRunner
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down