-
Notifications
You must be signed in to change notification settings - Fork 39
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
Fix CI tests #208
Merged
Merged
Fix CI tests #208
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7a7d0fd
Update CI workflows
mvdbeek 2e2d80c
Run on push
mvdbeek 5a81656
Remove nostetest
mvdbeek 4941f72
Use galaxy-test-driver to setup test instance
mvdbeek 57185ea
Replace bash tests with pytest
mvdbeek 47d0a0e
Introduce single constant for job sleep delay
mvdbeek 1195107
Drop unused nosetests section in setup.cfg
mvdbeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ tox | |
coverage | ||
pytest | ||
pytest-cov | ||
docker | ||
galaxy-test-driver | ||
|
||
#Building Docs | ||
sphinx_rtd_theme | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,58 @@ | ||
from collections import namedtuple | ||
|
||
import docker | ||
import pytest | ||
from bioblend.galaxy import GalaxyInstance | ||
|
||
from ephemeris.sleep import galaxy_wait | ||
|
||
# It needs to work well with dev. Alternatively we can pin this to 'master' or another stable branch. | ||
# Preferably a branch that updates with each stable release | ||
GALAXY_IMAGE = "bgruening/galaxy-stable:20.05" | ||
GALAXY_ADMIN_KEY = "fakekey" | ||
GALAXY_ADMIN_PASSWORD = "password" | ||
GALAXY_ADMIN_USER = "[email protected]" | ||
|
||
client = docker.from_env() | ||
from galaxy.tool_util.verify.interactor import GalaxyInteractorApi | ||
from galaxy_test.driver.driver_util import GalaxyTestDriver | ||
|
||
GalaxyContainer = namedtuple( | ||
"GalaxyContainer", ["url", "container", "attributes", "gi"] | ||
"GalaxyContainer", ["url", "gi", "password", "username", "api_key"] | ||
) | ||
|
||
|
||
# Class scope is chosen here so we can group tests on the same galaxy in a class. | ||
@pytest.fixture(scope="class") | ||
def start_container(**kwargs): | ||
"""Starts a docker container with the galaxy image. Returns a named tuple with the url, a GalaxyInstance object, | ||
the container attributes, and the container itself.""" | ||
# We start a container from the galaxy image. We detach it. Port 80 is exposed to the host at a random port. | ||
# The random port is because we need mac compatibility. On GNU/linux a better option would be not to expose it | ||
# and use the internal ip address instead. | ||
# But alas, the trappings of a proprietary BSD kernel compel us to do ugly workarounds. | ||
key = kwargs.get("api_key", GALAXY_ADMIN_KEY) | ||
ensure_admin = kwargs.get("ensure_admin", True) | ||
|
||
container = client.containers.run( | ||
GALAXY_IMAGE, detach=True, ports={"80/tcp": None}, **kwargs | ||
) | ||
container_id = container.attrs.get("Id") | ||
print(container_id) | ||
|
||
# This seems weird as we also can just get container.attrs but for some reason | ||
# the network settings are not loaded in container.attrs. With the get request | ||
# these attributes are loaded | ||
container_attributes = client.containers.get(container_id).attrs | ||
|
||
# Venturing into deep nested dictionaries. | ||
exposed_port = ( | ||
container_attributes.get("NetworkSettings") | ||
.get("Ports") | ||
.get("80/tcp")[0] | ||
.get("HostPort") | ||
) | ||
|
||
container_url = "http://localhost:{0}".format(exposed_port) | ||
assert key | ||
ready = galaxy_wait( | ||
container_url, timeout=180, api_key=key, ensure_admin=ensure_admin | ||
) | ||
if not ready: | ||
raise Exception("Failed to wait on Galaxy to start.") | ||
gi = GalaxyInstance(container_url, key=key) | ||
yield GalaxyContainer( | ||
url=container_url, container=container, attributes=container_attributes, gi=gi | ||
def start_container(tmpdir_factory): | ||
config_dir = tmpdir_factory.mktemp("config") | ||
database = config_dir.join("universe.sqlite") | ||
test_driver = GalaxyTestDriver() | ||
test_driver.galaxy_config = { | ||
"job_config": { | ||
"runners": { | ||
"local": { | ||
"load": "galaxy.jobs.runners.local:LocalJobRunner", | ||
"workers": 1, | ||
} | ||
}, | ||
"execution": { | ||
"default": "local_docker", | ||
"environments": { | ||
"local_docker": {"runner": "local", "docker_enabled": True}, | ||
}, | ||
}, | ||
}, | ||
"admin_users": "[email protected]", | ||
"bootstrap_admin_api_key": "123456789", | ||
"conda_auto_init": False, | ||
"config_dir": str(config_dir), | ||
"database_connection": f"sqlite:///{database}?isolation_level=IMMEDIATE", | ||
} | ||
test_driver.setup() | ||
server_wrapper = test_driver.server_wrappers[0] | ||
host = server_wrapper.host | ||
port = server_wrapper.port | ||
prefix = server_wrapper.prefix or "" | ||
url = f"http://{host}:{port}{prefix.rstrip('/')}/" | ||
interactor = GalaxyInteractorApi( | ||
galaxy_url=url, master_api_key="123456789", test_user="[email protected]" | ||
) | ||
container.remove(force=True) | ||
gi = GalaxyInstance(url, key=interactor.api_key, password="testpass") | ||
try: | ||
yield GalaxyContainer( | ||
url=url, | ||
gi=gi, | ||
password="testpass", | ||
username="[email protected]", | ||
api_key=interactor.api_key, | ||
) | ||
finally: | ||
test_driver.stop_servers() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole config as one JSON blob is randomly very pretty and very rewarding.