Skip to content

Commit 7972e51

Browse files
authored
Fix/swarm published port (#838)
retries to get published port for services in swarm (integration tests) updates isan portal demo adds samples of invitations
1 parent 6b1a26e commit 7972e51

File tree

3 files changed

+69
-20
lines changed

3 files changed

+69
-20
lines changed

services/web/server/tests/integration/conftest.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
import logging
66
import sys
77
from pathlib import Path
8+
from pprint import pprint
89
from typing import Dict
910

1011
import docker
1112
import pytest
1213
import trafaret_config
1314
import yaml
15+
from tenacity import after_log, retry, stop_after_attempt, wait_fixed
16+
1417
from simcore_service_webserver.application_config import app_schema
1518
from simcore_service_webserver.cli import create_environ
1619
from simcore_service_webserver.resources import resources as app_resources
@@ -29,10 +32,8 @@
2932
log = logging.getLogger(__name__)
3033

3134
sys.path.append(str(Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent.parent / 'helpers'))
32-
3335
API_VERSION = "v0"
3436

35-
3637
@pytest.fixture(scope='session')
3738
def here():
3839
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
5960
# version tha loads only the subsystems under test. For that reason,
6061
# the test webserver is built-up in webserver_service fixture that runs
6162
# on the host.
62-
for name in core_services:
63-
if 'ports' not in services_docker_compose['services'][name]:
64-
continue
63+
64+
services_with_published_ports = [name for name in core_services
65+
if 'ports' in services_docker_compose['services'][name] ]
66+
67+
for name in services_with_published_ports:
6568

6669
# published port is sometimes dynamically defined by the swarm
6770
published_port = get_service_published_port(name)
68-
assert published_port != "-1"
6971

7072
environ['%s_HOST' % name.upper()] = '127.0.0.1'
7173
environ['%s_PORT' % name.upper()] = published_port
7274
# to swarm boundary since webserver is installed in the host and therefore outside the swarm's network
73-
from pprint import pprint
75+
7476
pprint(environ)
7577
return environ
7678

@@ -116,16 +118,20 @@ def resolve_environ(service, environ):
116118
_environs[key] = value
117119
return _environs
118120

121+
122+
123+
@retry(wait=wait_fixed(2), stop=stop_after_attempt(10), after=after_log(log, logging.WARN))
119124
def get_service_published_port(service_name: str) -> str:
120-
published_port = "-1"
125+
# WARNING: ENSURE that service name defines a port
126+
# NOTE: retries since services can take some time to start
121127
client = docker.from_env()
122128
services = [x for x in client.services.list() if service_name in x.name]
123129
if not services:
124-
return published_port
130+
raise RuntimeError("Cannot find published port for service '%s'. Probably services still not up" % service_name)
125131
service_endpoint = services[0].attrs["Endpoint"]
126132

127133
if "Ports" not in service_endpoint or not service_endpoint["Ports"]:
128-
return published_port
134+
raise RuntimeError("Cannot find published port for service '%s' in endpoint. Probably services still not up" % service_name)
129135

130136
published_port = service_endpoint["Ports"][0]["PublishedPort"]
131137
return str(published_port)

services/web/server/tests/sandbox/create_portal_markdown.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@
1010
from pathlib import Path
1111

1212
from simcore_service_webserver.resources import resources
13+
from simcore_service_webserver.login.utils import get_random_string
14+
from simcore_service_webserver.login.registration import get_invitation_url, URL
1315

1416
MARKDOWN_FILENAME = "study_access_demo.md"
1517
ISSUE = r"https://github.com/ITISFoundation/osparc-simcore/issues/"
1618

1719
current_path = Path( sys.argv[0] if __name__ == "__main__" else __file__).resolve()
1820

21+
HOST_URLS_MAPS = [
22+
('localhost', r'http://127.0.0.1:9081'),
23+
('master', r'http://osparc01.itis.ethz.ch:9081'),
24+
('staging', r'https://staging.osparc.io'),
25+
('osparc.io', r'https://osparc.io')
26+
]
27+
1928

2029
def write_list(hostname, url, data, fh):
2130
print("## studies available @{}".format(hostname), file=fh)
@@ -33,11 +42,20 @@ def main():
3342
print("# THE PORTAL Emulator\n", file=fh)
3443
print("This pages is for testing purposes for issue [#{1}]({0}{1})\n".format(ISSUE, 715), file=fh)
3544

36-
write_list('localhost', r'http://127.0.0.1:9081', data, fh)
37-
write_list('master', r'http://osparc01.itis.ethz.ch:9081', data, fh)
38-
write_list('staging', r'https://staging.io:9081', data, fh)
39-
write_list('osparc.io', r'https://osparc.io', data, fh)
45+
for hostname, url in HOST_URLS_MAPS:
46+
write_list(hostname, url, data, fh)
47+
48+
print("---", file=fh)
49+
50+
print("# INVITATIONS Samples:", file=fh)
51+
codes = [ get_random_string(30) for n in range(5)]
52+
53+
for hostname, url in HOST_URLS_MAPS:
54+
print("## urls for @{}".format(hostname), file=fh)
55+
for code in codes:
56+
print("- [{code}]({base_url})".format(base_url=get_invitation_url({'code':code, 'action':"INVITATION"}, URL(url)), code=code), file=fh)
4057

58+
print("", file=fh)
4159

4260
if __name__ == "__main__":
4361
main()

services/web/server/tests/sandbox/study_access_demo.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
<!-- Generated by create_portal_markdown.py on 2019-05-09 16:24:03.994535 -->
1+
<!-- Generated by create_portal_markdown.py on 2019-06-04 17:34:25.051383 -->
22
# THE PORTAL Emulator
33

44
This pages is for testing purposes for issue [#715](https://github.com/ITISFoundation/osparc-simcore/issues/715)
55

6-
Emulator of the actual [NIH/Sparc Portal](https://data.sparc.science)
7-
86
## studies available @localhost
97

108
- [ISAN: 2D Plot](http://127.0.0.1:9081/study/template-uuid-4d5e-b80e-401c8066782f)
@@ -19,13 +17,40 @@ Emulator of the actual [NIH/Sparc Portal](https://data.sparc.science)
1917

2018
## studies available @staging
2119

22-
- [ISAN: 2D Plot](https://staging.io:9081/study/template-uuid-4d5e-b80e-401c8066782f)
23-
- [ISAN: 3D Paraview](https://staging.io:9081/study/template-uuid-4d5e-b80e-401c8066781f)
24-
- [ISAN: MattWard use case](https://staging.io:9081/study/template-uuid-420d-b82d-e80bfa272ebd)
20+
- [ISAN: 2D Plot](https://staging.osparc.io/study/template-uuid-4d5e-b80e-401c8066782f)
21+
- [ISAN: 3D Paraview](https://staging.osparc.io/study/template-uuid-4d5e-b80e-401c8066781f)
22+
- [ISAN: MattWard use case](https://staging.osparc.io/study/template-uuid-420d-b82d-e80bfa272ebd)
2523

2624
## studies available @osparc.io
2725

2826
- [ISAN: 2D Plot](https://osparc.io/study/template-uuid-4d5e-b80e-401c8066782f)
2927
- [ISAN: 3D Paraview](https://osparc.io/study/template-uuid-4d5e-b80e-401c8066781f)
3028
- [ISAN: MattWard use case](https://osparc.io/study/template-uuid-420d-b82d-e80bfa272ebd)
3129

30+
---
31+
# INVITATIONS Samples:
32+
## urls for @localhost
33+
- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](http://127.0.0.1:9081/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B)
34+
- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](http://127.0.0.1:9081/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p)
35+
- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](http://127.0.0.1:9081/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy)
36+
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](http://127.0.0.1:9081/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
37+
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](http://127.0.0.1:9081/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
38+
## urls for @master
39+
- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B)
40+
- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p)
41+
- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy)
42+
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
43+
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
44+
## urls for @staging
45+
- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](https://staging.osparc.io/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B)
46+
- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](https://staging.osparc.io/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p)
47+
- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](https://staging.osparc.io/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy)
48+
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](https://staging.osparc.io/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
49+
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](https://staging.osparc.io/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
50+
## urls for @osparc.io
51+
- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](https://osparc.io/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B)
52+
- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](https://osparc.io/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p)
53+
- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](https://osparc.io/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy)
54+
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](https://osparc.io/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
55+
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](https://osparc.io/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
56+

0 commit comments

Comments
 (0)