Skip to content

Commit

Permalink
Test configstate conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
natefoo committed Sep 13, 2022
1 parent fb234d4 commit 91dd7e5
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
72 changes: 72 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,69 @@
"""


# old-style string formatting is used because of curly braces in the YAML
CONFIGSTATE_YAML_0_X = """
config_files:
%(galaxy_yml)s:
config_type: galaxy
instance_name: gravity-0-x
attribs:
galaxy_infrastructure_url: ''
app_server: gunicorn
log_dir: %(state_dir)s/log
virtualenv:
gunicorn:
enable: true
bind: localhost:8080
workers: 1
timeout: 300
extra_args: ''
preload: true
environment: {}
tusd:
enable: false
tusd_path: tusd
host: localhost
port: 1080
upload_dir: ''
hooks_enabled_events: pre-create
extra_args: ''
environment: {}
celery:
enable: true
enable_beat: true
concurrency: 2
loglevel: DEBUG
queues: celery,galaxy.internal,galaxy.external
pool: threads
extra_args: ''
environment: {}
handlers: {}
gravity_version: 0.13.4
galaxy_root: %(galaxy_root_dir)s
gx_it_proxy:
enable: false
ip: localhost
port: 4002
sessions: database/interactivetools_map.sqlite
verbose: true
forward_ip:
forward_port:
reverse_proxy: false
environment: {}
services:
- config_type: galaxy
service_type: gunicorn
service_name: gunicorn
- config_type: galaxy
service_type: celery
service_name: celery
- config_type: galaxy
service_type: celery-beat
service_name: celery-beat
"""


@pytest.fixture(scope='session')
def galaxy_git_dir():
galaxy_dir = TEST_DIR / 'galaxy.git'
Expand Down Expand Up @@ -75,6 +138,15 @@ def default_config_manager(state_dir):
yield cm


@pytest.fixture
def configstate_yaml_0_x(galaxy_root_dir, state_dir, galaxy_yml):
return CONFIGSTATE_YAML_0_X % {
"galaxy_root_dir": galaxy_root_dir,
"state_dir": state_dir,
"galaxy_yml": str(galaxy_yml)
}


@pytest.fixture()
def job_conf(request, galaxy_root_dir):
conf = yaml.safe_load(request.param[0])
Expand Down
12 changes: 12 additions & 0 deletions tests/test_config_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from pathlib import Path

from gravity import __version__, config_manager
from gravity.settings import Settings


Expand Down Expand Up @@ -102,3 +103,14 @@ def test_register_sample_update_to_non_sample(galaxy_root_dir, state_dir, defaul
galaxy_yml_sample.copy(galaxy_yml)
default_config_manager.instance_count == 1
assert default_config_manager.get_registered_config(str(galaxy_yml))


def test_convert_0_x_config(state_dir, galaxy_yml, configstate_yaml_0_x):
configstate_yaml = state_dir / "configstate.yaml"
open(configstate_yaml, "w").write(configstate_yaml_0_x)
with config_manager.config_manager(state_dir=state_dir) as cm:
assert cm.state.gravity_version == __version__
config = cm.state.config_files[str(galaxy_yml)]
assert config.config_type == "galaxy"
assert config.instance_name == "gravity-0-x"
assert "attribs" not in config
15 changes: 14 additions & 1 deletion tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def test_cmd_start_with_gxit(state_dir, galaxy_yml, gxit_startup_config, free_po
assert result.exit_code == 0, result.output
start_instance(state_dir, free_port)
result = runner.invoke(galaxyctl, ['--state-dir', state_dir, 'status'])
assert result.exit_code == 0, result.output
assert result.exit_code == 0, f"{result.output}\ngx-it-proxy startup failed. " \
f"gx-it-proxy startup logs:\n{open(state_dir / 'log' / 'gx-it-proxy.log').read()}"
startup_done = wait_for_gxit_proxy(state_dir)
assert startup_done is True, f"gx-it-proxy startup failed. gx-it-proxy startup logs:\n {startup_done}"

Expand All @@ -124,6 +125,18 @@ def test_cmd_restart_with_update(state_dir, galaxy_yml, startup_config, free_por
assert startup_done is True, f"Startup failed. Application startup logs:\n {startup_done}"


def test_cmd_update_with_0_x_config(state_dir, configstate_yaml_0_x):
runner = CliRunner()
configstate_yaml = state_dir / "configstate.yaml"
open(configstate_yaml, "w").write(configstate_yaml_0_x)
result = runner.invoke(galaxyctl, ['--state-dir', state_dir, 'update'])
assert result.exit_code == 0, result.output
assert "Converting Gravity config state to 1.0 format" in result.output
assert "Adding service gunicorn" in result.output
assert "Adding service celery" in result.output
assert "Adding service celery-beat" in result.output


def test_cmd_show(state_dir, galaxy_yml):
test_cmd_register(state_dir, galaxy_yml)
runner = CliRunner()
Expand Down

0 comments on commit 91dd7e5

Please sign in to comment.