Skip to content

Commit

Permalink
Merge pull request #839 from ITISFoundation/master
Browse files Browse the repository at this point in the history
Fix/swarm published port (#838)

retries to get published port for services in swarm (integration tests)
updates isan portal demo
adds samples of invitations
  • Loading branch information
mguidon authored Jun 4, 2019
2 parents 7df1d0a + ee3f3a3 commit da36955
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 20 deletions.
26 changes: 16 additions & 10 deletions services/web/server/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
26 changes: 22 additions & 4 deletions services/web/server/tests/sandbox/create_portal_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
37 changes: 31 additions & 6 deletions services/web/server/tests/sandbox/study_access_demo.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<!-- Generated by create_portal_markdown.py on 2019-05-09 16:24:03.994535 -->
<!-- Generated by create_portal_markdown.py on 2019-06-04 17:34:25.051383 -->
# 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)
Expand All @@ -19,13 +17,40 @@ 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

- [ISAN: 2D Plot](https://osparc.io/study/template-uuid-4d5e-b80e-401c8066782f)
- [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)

0 comments on commit da36955

Please sign in to comment.