From 7972e5142b7c6c5f8ae73ef73092e0285d388786 Mon Sep 17 00:00:00 2001 From: Pedro Crespo <32402063+pcrespov@users.noreply.github.com> Date: Tue, 4 Jun 2019 20:01:43 +0200 Subject: [PATCH] Fix/swarm published port (#838) retries to get published port for services in swarm (integration tests) updates isan portal demo adds samples of invitations --- .../web/server/tests/integration/conftest.py | 26 ++++++++----- .../tests/sandbox/create_portal_markdown.py | 26 +++++++++++-- .../server/tests/sandbox/study_access_demo.md | 37 ++++++++++++++++--- 3 files changed, 69 insertions(+), 20 deletions(-) diff --git a/services/web/server/tests/integration/conftest.py b/services/web/server/tests/integration/conftest.py index 09c90c4a8ef..22857be1a13 100644 --- a/services/web/server/tests/integration/conftest.py +++ b/services/web/server/tests/integration/conftest.py @@ -5,12 +5,15 @@ import logging import sys from pathlib import Path +from pprint import pprint from typing import Dict import docker import pytest import trafaret_config import yaml +from tenacity import after_log, retry, stop_after_attempt, wait_fixed + from simcore_service_webserver.application_config import app_schema from simcore_service_webserver.cli import create_environ from simcore_service_webserver.resources import resources as app_resources @@ -29,10 +32,8 @@ log = logging.getLogger(__name__) sys.path.append(str(Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent.parent / 'helpers')) - API_VERSION = "v0" - @pytest.fixture(scope='session') def here(): return Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent @@ -59,18 +60,19 @@ def webserver_environ(request, devel_environ, services_docker_compose, docker_st # version tha loads only the subsystems under test. For that reason, # the test webserver is built-up in webserver_service fixture that runs # on the host. - for name in core_services: - if 'ports' not in services_docker_compose['services'][name]: - continue + + services_with_published_ports = [name for name in core_services + if 'ports' in services_docker_compose['services'][name] ] + + for name in services_with_published_ports: # published port is sometimes dynamically defined by the swarm published_port = get_service_published_port(name) - assert published_port != "-1" environ['%s_HOST' % name.upper()] = '127.0.0.1' environ['%s_PORT' % name.upper()] = published_port # to swarm boundary since webserver is installed in the host and therefore outside the swarm's network - from pprint import pprint + pprint(environ) return environ @@ -116,16 +118,20 @@ def resolve_environ(service, environ): _environs[key] = value return _environs + + +@retry(wait=wait_fixed(2), stop=stop_after_attempt(10), after=after_log(log, logging.WARN)) def get_service_published_port(service_name: str) -> str: - published_port = "-1" + # WARNING: ENSURE that service name defines a port + # NOTE: retries since services can take some time to start client = docker.from_env() services = [x for x in client.services.list() if service_name in x.name] if not services: - return published_port + raise RuntimeError("Cannot find published port for service '%s'. Probably services still not up" % service_name) service_endpoint = services[0].attrs["Endpoint"] if "Ports" not in service_endpoint or not service_endpoint["Ports"]: - return published_port + raise RuntimeError("Cannot find published port for service '%s' in endpoint. Probably services still not up" % service_name) published_port = service_endpoint["Ports"][0]["PublishedPort"] return str(published_port) diff --git a/services/web/server/tests/sandbox/create_portal_markdown.py b/services/web/server/tests/sandbox/create_portal_markdown.py index 4746cb5d12a..2306603ed66 100644 --- a/services/web/server/tests/sandbox/create_portal_markdown.py +++ b/services/web/server/tests/sandbox/create_portal_markdown.py @@ -10,12 +10,21 @@ from pathlib import Path from simcore_service_webserver.resources import resources +from simcore_service_webserver.login.utils import get_random_string +from simcore_service_webserver.login.registration import get_invitation_url, URL MARKDOWN_FILENAME = "study_access_demo.md" ISSUE = r"https://github.com/ITISFoundation/osparc-simcore/issues/" current_path = Path( sys.argv[0] if __name__ == "__main__" else __file__).resolve() +HOST_URLS_MAPS = [ + ('localhost', r'http://127.0.0.1:9081'), + ('master', r'http://osparc01.itis.ethz.ch:9081'), + ('staging', r'https://staging.osparc.io'), + ('osparc.io', r'https://osparc.io') +] + def write_list(hostname, url, data, fh): print("## studies available @{}".format(hostname), file=fh) @@ -33,11 +42,20 @@ def main(): print("# THE PORTAL Emulator\n", file=fh) print("This pages is for testing purposes for issue [#{1}]({0}{1})\n".format(ISSUE, 715), file=fh) - write_list('localhost', r'http://127.0.0.1:9081', data, fh) - write_list('master', r'http://osparc01.itis.ethz.ch:9081', data, fh) - write_list('staging', r'https://staging.io:9081', data, fh) - write_list('osparc.io', r'https://osparc.io', data, fh) + for hostname, url in HOST_URLS_MAPS: + write_list(hostname, url, data, fh) + + print("---", file=fh) + + print("# INVITATIONS Samples:", file=fh) + codes = [ get_random_string(30) for n in range(5)] + + for hostname, url in HOST_URLS_MAPS: + print("## urls for @{}".format(hostname), file=fh) + for code in codes: + print("- [{code}]({base_url})".format(base_url=get_invitation_url({'code':code, 'action':"INVITATION"}, URL(url)), code=code), file=fh) + print("", file=fh) if __name__ == "__main__": main() diff --git a/services/web/server/tests/sandbox/study_access_demo.md b/services/web/server/tests/sandbox/study_access_demo.md index e4b4a305fb9..50539a4cfd4 100644 --- a/services/web/server/tests/sandbox/study_access_demo.md +++ b/services/web/server/tests/sandbox/study_access_demo.md @@ -1,10 +1,8 @@ - + # THE PORTAL Emulator This pages is for testing purposes for issue [#715](https://github.com/ITISFoundation/osparc-simcore/issues/715) -Emulator of the actual [NIH/Sparc Portal](https://data.sparc.science) - ## studies available @localhost - [ISAN: 2D Plot](http://127.0.0.1:9081/study/template-uuid-4d5e-b80e-401c8066782f) @@ -19,9 +17,9 @@ Emulator of the actual [NIH/Sparc Portal](https://data.sparc.science) ## studies available @staging -- [ISAN: 2D Plot](https://staging.io:9081/study/template-uuid-4d5e-b80e-401c8066782f) -- [ISAN: 3D Paraview](https://staging.io:9081/study/template-uuid-4d5e-b80e-401c8066781f) -- [ISAN: MattWard use case](https://staging.io:9081/study/template-uuid-420d-b82d-e80bfa272ebd) +- [ISAN: 2D Plot](https://staging.osparc.io/study/template-uuid-4d5e-b80e-401c8066782f) +- [ISAN: 3D Paraview](https://staging.osparc.io/study/template-uuid-4d5e-b80e-401c8066781f) +- [ISAN: MattWard use case](https://staging.osparc.io/study/template-uuid-420d-b82d-e80bfa272ebd) ## studies available @osparc.io @@ -29,3 +27,30 @@ Emulator of the actual [NIH/Sparc Portal](https://data.sparc.science) - [ISAN: 3D Paraview](https://osparc.io/study/template-uuid-4d5e-b80e-401c8066781f) - [ISAN: MattWard use case](https://osparc.io/study/template-uuid-420d-b82d-e80bfa272ebd) +--- +# INVITATIONS Samples: +## urls for @localhost +- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](http://127.0.0.1:9081/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B) +- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](http://127.0.0.1:9081/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p) +- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](http://127.0.0.1:9081/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy) +- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](http://127.0.0.1:9081/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21) +- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](http://127.0.0.1:9081/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM) +## urls for @master +- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B) +- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p) +- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy) +- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21) +- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM) +## urls for @staging +- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](https://staging.osparc.io/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B) +- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](https://staging.osparc.io/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p) +- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](https://staging.osparc.io/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy) +- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](https://staging.osparc.io/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21) +- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](https://staging.osparc.io/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM) +## urls for @osparc.io +- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](https://osparc.io/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B) +- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](https://osparc.io/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p) +- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](https://osparc.io/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy) +- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](https://osparc.io/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21) +- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](https://osparc.io/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM) +