Skip to content

Commit

Permalink
Rework conditions for running Kubernetes staging tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Apr 23, 2020
1 parent 731ccfb commit 069f794
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
8 changes: 8 additions & 0 deletions lib/galaxy_test/driver/integration_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from .driver_util import GalaxyTestDriver

NO_APP_MESSAGE = "test_case._app called though no Galaxy has been configured."
# Following should be for Homebrew Rabbitmq and Docker on Mac "amqp://guest:guest@localhost:5672//"
AMQP_URL = os.environ.get("GALAXY_TEST_AMQP_URL", None)


def _identity(func):
Expand All @@ -28,6 +30,12 @@ def skip_if_jenkins(cls):
return cls


def skip_unless_amqp():
if AMQP_URL is not None:
return _identity
return pytest.mark.skip("AMQP_URL is not set, required for this test.")


def skip_unless_executable(executable):
if which(executable):
return _identity
Expand Down
28 changes: 18 additions & 10 deletions test/integration/test_kubernetes_staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
import string
import tempfile

from galaxy.jobs.runners.util.pykube_util import (
Job,
pykube_client_from_dict,
)
from galaxy_test.base.populators import skip_without_tool
from galaxy_test.driver import integration_util
from .test_containerized_jobs import EXTENDED_TIMEOUT, MulledJobTestCases
from .test_job_environments import BaseJobEnvironmentIntegrationTestCase
from .test_local_job_cancellation import CancelsJob

TOOL_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'tools'))
AMQP_URL = os.environ.get("GALAXY_TEST_AMQP_URL", "amqp://guest:guest@localhost:5672//")
GALAXY_TEST_KUBERNETES_INFRASTRUCTURE_HOST = os.environ.get("GALAXY_TEST_KUBERNETES_INFRASTRUCTURE_HOST", "host.docker.internal")
AMQP_URL = integration_util.AMQP_URL


CONTAINERIZED_TEMPLATE = """
Expand All @@ -32,7 +37,6 @@
workers: 1
pulsar_k8s:
load: galaxy.jobs.runners.pulsar:PulsarKubernetesJobRunner
galaxy_url: ${infrastructure_url}
amqp_url: ${amqp_url}
execution:
Expand Down Expand Up @@ -63,7 +67,6 @@
workers: 1
pulsar_k8s:
load: galaxy.jobs.runners.pulsar:PulsarKubernetesJobRunner
galaxy_url: ${infrastructure_url}
amqp_url: ${amqp_url}
execution:
Expand All @@ -87,35 +90,33 @@

def job_config(template_str, jobs_directory):
job_conf_template = string.Template(template_str)
port = os.environ.get('GALAXY_TEST_PORT')
assert port
infrastructure_url = "http://%s:%s" % (GALAXY_TEST_KUBERNETES_INFRASTRUCTURE_HOST, port)
container_amqp_url = to_infrastructure_uri(AMQP_URL)
job_conf_str = job_conf_template.substitute(jobs_directory=jobs_directory,
tool_directory=TOOL_DIR,
k8s_config_path=integration_util.k8s_config_path(),
amqp_url=AMQP_URL,
container_amqp_url=container_amqp_url,
infrastructure_url=infrastructure_url,
)
with tempfile.NamedTemporaryFile(suffix="_kubernetes_integration_job_conf.yml", mode="w", delete=False) as job_conf:
job_conf.write(job_conf_str)
return job_conf.name


@integration_util.skip_unless_kubernetes()
@integration_util.skip_unless_fixed_port()
@integration_util.skip_unless_amqp()
class BaseKubernetesStagingTest(BaseJobEnvironmentIntegrationTestCase, MulledJobTestCases):
# Test leverages $UWSGI_PORT in job code, need to set this up.
require_uwsgi = True

def setUp(self):
super(KubernetesStagingContainerIntegrationTestCase, self).setUp()
super(BaseKubernetesStagingTest, self).setUp()
self.history_id = self.dataset_populator.new_history()

@classmethod
def setUpClass(cls):
# realpath for docker deployed in a VM on Mac, also done in driver_util.
cls.jobs_directory = os.path.realpath(tempfile.mkdtemp())
super(KubernetesStagingContainerIntegrationTestCase, cls).setUpClass()
super(BaseKubernetesStagingTest, cls).setUpClass()


class KubernetesStagingContainerIntegrationTestCase(BaseKubernetesStagingTest):
Expand All @@ -128,6 +129,7 @@ def handle_galaxy_config_kwds(cls, config):
config["default_job_shell"] = '/bin/sh'
# Disable local tool dependency resolution.
config["tool_dependency_dir"] = "none"
set_infrastucture_url(config)

@skip_without_tool("job_environment_default")
def test_job_environment(self):
Expand All @@ -149,6 +151,7 @@ def handle_galaxy_config_kwds(cls, config):
# Disable tool dependency resolution.
config["tool_dependency_dir"] = "none"
config["enable_beta_mulled_containers"] = "true"
set_infrastucture_url(config)

def test_mulled_simple(self):
self.dataset_populator.run_tool("mulled_example_simple", {}, self.history_id)
Expand All @@ -157,6 +160,11 @@ def test_mulled_simple(self):
assert "0.7.15-r1140" in output


def set_infrastucture_url(config):
infrastructure_url = "http://%s:$UWSGI_PORT" % GALAXY_TEST_KUBERNETES_INFRASTRUCTURE_HOST
config["galaxy_infrastructure_url"] = infrastructure_url


def to_infrastructure_uri(uri):
# remap MQ or file server URI hostnames for in-container versions, this is sloppy
# should actually parse the URI and rebuild with correct host
Expand Down

0 comments on commit 069f794

Please sign in to comment.