Skip to content

Cleanup test and add mock server #56

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

Open
wants to merge 9 commits into
base: callback_module
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
run: |
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install mock-server
make mock
docker pull kbase/runtester
docker tag kbase/runtester test/runtester
Expand All @@ -55,6 +56,10 @@ jobs:
export KB_AUTH_TOKEN=bogus
export KB_ADMIN_AUTH_TOKEN=bogus
export KB_BASE_URL=https://ci.kbase.us/services
IP=$(ip route get 8.8.8.8 | head -1 |cut -d' ' -f7)
echo $IP
export TEST_URL="$IP:8888"
mock-server --dir=./test/mock-server --address=0.0.0.0 &
make test

- name: Failure logs
Expand Down
26 changes: 17 additions & 9 deletions JobRunner/SpecialRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from subprocess import Popen, PIPE
from time import sleep, time
from select import select
import sys
import logging


class SpecialRunner:
Expand Down Expand Up @@ -135,14 +137,21 @@ def _batch_submit(self, stype, config, data, job_id, fin_q):
submit = "%s_submit" % (stype)
if "submit_script" not in params:
raise ValueError("Missing submit script")
os.chdir(self.shareddir)
scr = params["submit_script"]
scr = os.path.join(self.shareddir, params["submit_script"])
if not os.path.exists(scr):
raise OSError("Submit script not found at %s" % (scr))
outfile = "%s.out" % (job_id)
errfile = "%s.err" % (job_id)
outfile = f"{self.shareddir}{job_id}.out"
errfile = f"{self.shareddir}{job_id}.err"
cmd = [submit, scr, outfile, errfile]
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
logging.info(f"Submitting: {cmd}")
try:
proc = Popen(cmd, cwd=self.shareddir, stdout=PIPE, stderr=PIPE)
except Exception as e:
for q in fin_q:
q.put(["finished_special", job_id, {}])
sys.stderr.write(str(e))
return None

stdout, stderr = proc.communicate()
slurm_jobid = stdout.decode("utf-8").rstrip()
out = Thread(
Expand Down Expand Up @@ -191,16 +200,15 @@ def _wdl_run(self, stype, config, data, job_id, queues):
raise ValueError("Missing workflow script")
if "inputs" not in params:
raise ValueError("Missing inputs")
os.chdir(self.shareddir)
wdl = params["workflow"]
wdl = os.path.join(self.shareddir, params["workflow"])
if not os.path.exists(wdl):
raise OSError("Workflow script not found at %s" % (wdl))

inputs = params["inputs"]
inputs = os.path.join(self.shareddir, params["inputs"])
if not os.path.exists(inputs):
raise OSError("Inputs file not found at %s" % (inputs))
cmd = ["wdl_run", inputs, wdl]
proc = Popen(cmd, bufsize=0, stdout=PIPE, stderr=PIPE)
proc = Popen(cmd, cwd=self.shareddir, bufsize=0, stdout=PIPE, stderr=PIPE)
out = Thread(target=self._readio, args=[proc, job_id, queues])
self.threads.append(out)
out.start()
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ mock:
docker build -t mock_app ./test/mock_app

test:
nosetests -A "not online" -s -v --with-coverage --cover-package=JobRunner --cover-erase --cover-html --cover-html-dir=./test_coverage .
nosetests -A "not fullonline" -s -v --with-coverage --cover-package=JobRunner --cover-erase --cover-html --cover-html-dir=./test_coverage .


Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"user_id": "canon"
}
28 changes: 28 additions & 0 deletions test/mock-server/services/catalog/POST_200.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"version": "1.1",
"result": [
{
"registration_id": "1529602194173_fab31f45-9465-4e59-b65d-89040a54396f",
"released": 1,
"timestamp": 1529602194173,
"notes": "",
"docker_img_name": "dockerhub-ci.kbase.us/kbase:echo_test.4b5a37e6fed857c199df65191ba3344a467b8aa",
"git_commit_hash": "4b5a37e6fed857c199df65191ba3344a467b8aab",
"version": "0.0.1",
"narrative_methods": [
"example_method"
],
"released_timestamp": null,
"module_name": "echo_test",
"dynamic_service": 0,
"local_functions": [],
"git_commit_message": "Add the message in the return dict",
"release_timestamp": 1665086800987,
"git_url": "https://github.com/jayrbolton/kb_echo_test",
"release_tags": [
"release"
]
}
],
"id": "24087040852079133"
}
56 changes: 32 additions & 24 deletions test/mock_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os


_IMAGE = "dockerhub-prod.kbase.us/kbase:rast_sdk."
_IMAGE += "50b012d9b41b71ba31b30355627cf85f2611bc3e"
_BASE = u"https://ci.kbase.us/services/"


CATALOG_GET_MODULE_VERSION = {
"registration_id": "1553870236585_bab74ed6-4699-47b5-b865-d7130b90f542",
Expand Down Expand Up @@ -45,29 +48,34 @@
u"service_ver": u"4b5a37e6fed857c199df65191ba3344a467b8aab",
u"wsid": 42906,
}
EE2_LIST_CONFIG = {
u"auth-service-url": _BASE + u"auth/api/legacy/KBase/Sessions/Login",
u"auth-service-url-allow-insecure": u"false",
u"auth-service-url-v2": _BASE + u"auth/api/V2/token",
u"awe.client.callback.networks": u"docker0,eth0",
u"awe.client.docker.uri": u"unix:///var/run/docker.sock",
u"catalog.srv.url": _BASE + u"catalog",
u"condor.docker.job.timeout.seconds": u"604800",
u"condor.job.shutdown.minutes": u"10080",
u"docker.registry.url": u"dockerhub-prod.kbase.us",
u"ee.server.version": u"0.2.11",
u"handle-url": _BASE + u"handle_service",
u"kbase-endpoint": u"https://ci.kbase.us/services",
u"ref.data.base": u"/kb/data",
u"ref_data_base": u"/kb/data",
u"external-url": _BASE + u"ee2",
u"shock-url": _BASE + u"shock-api",
u"srv.wiz.url": _BASE + u"service_wizard",
u"srv-wiz-url": _BASE + u"service_wizard",
u"time.before.expiration": u"10",
u"workspace-url": _BASE + u"ws",
u"scratch": "/tmp",
}


def ee2_list_config(base):
refdata = os.environ.get("KB_REF_DATA", "/kb/data")
res = {
u"auth-service-url": base + u"auth/api/legacy/KBase/Sessions/Login",
u"auth-service-url-allow-insecure": u"false",
u"auth-service-url-v2": base + u"auth/api/V2/token",
u"awe.client.callback.networks": u"docker0,eth0",
u"awe.client.docker.uri": u"unix:///var/run/docker.sock",
u"catalog.srv.url": base + u"catalog",
u"condor.docker.job.timeout.seconds": u"604800",
u"condor.job.shutdown.minutes": u"10080",
u"docker.registry.url": u"dockerhub-prod.kbase.us",
u"ee.server.version": u"0.2.11",
u"handle-url": base + u"handle_service",
u"kbase-endpoint": u"https://ci.kbase.us/services",
u"ref.data.base": refdata,
u"ref_data_base": refdata,
u"external-url": base + u"ee2",
u"shock-url": base + u"shock-api",
u"srv.wiz.url": base + u"service_wizard",
u"srv-wiz-url": base + u"service_wizard",
u"time.before.expiration": u"10",
u"workspace-url": base + u"ws",
u"scratch": "/tmp",
}
return res

CATALOG_LIST_VOLUME_MOUNTS = [
{
Expand Down
Loading