Skip to content
Snippets Groups Projects
Commit c0c5b6a0 authored by Auke Klazema's avatar Auke Klazema
Browse files

TMSS-362: Merge remote-tracking branch 'origin/master' into TMSS-362

parents 6ec08a82 b4d3e5e7
No related branches found
No related tags found
1 merge request!215TMSS-362: Raise timeout on Django Server check
...@@ -31,18 +31,18 @@ def populate_schemas(schema_dir: str=None, templates_filename: str=None): ...@@ -31,18 +31,18 @@ def populate_schemas(schema_dir: str=None, templates_filename: str=None):
with open(templates_filepath) as templates_file: with open(templates_filepath) as templates_file:
templates = json.loads(templates_file.read()) templates = json.loads(templates_file.read())
for template in templates: with TMSSsession.create_from_dbcreds_for_ldap() as client:
try: for template in templates:
with open(os.path.join(schema_dir, template.pop('file_name'))) as schema_file: try:
try: with open(os.path.join(schema_dir, template.pop('file_name'))) as schema_file:
json_schema = json.loads(schema_file.read()) try:
json_schema = json.loads(schema_file.read())
template_path = template.pop('template') template_path = template.pop('template')
name = template.pop('name', json_schema.get('title', '<no name>')) name = template.pop('name', json_schema.get('title', '<no name>'))
description = template.pop('description', json_schema.get('description', '<no description>')) description = template.pop('description', json_schema.get('description', '<no description>'))
version = template.pop('version', '1') version = template.pop('version', '1')
with TMSSsession.create_from_dbcreds_for_ldap() as client:
if template_path == 'subtask_template' and 'type' in template: if template_path == 'subtask_template' and 'type' in template:
# override plain-text type by its url # override plain-text type by its url
template['type'] = client.get_path_as_json_object('subtask_type/'+template.pop('type'))['url'] template['type'] = client.get_path_as_json_object('subtask_type/'+template.pop('type'))['url']
...@@ -66,8 +66,8 @@ def populate_schemas(schema_dir: str=None, templates_filename: str=None): ...@@ -66,8 +66,8 @@ def populate_schemas(schema_dir: str=None, templates_filename: str=None):
description=description, description=description,
version=version, version=version,
**template) **template)
except Exception as e: except Exception as e:
logger.error(e) logger.error(e)
except Exception as e: except Exception as e:
logger.error(e) logger.error(e)
...@@ -6,7 +6,7 @@ services: ...@@ -6,7 +6,7 @@ services:
restart: on-failure restart: on-failure
env_file: env_file:
- ./.env - ./.env
command: bash -c 'source /opt/lofar/lofarinit.sh && ALLOWED_HOSTS=* tmss_test_environment -H 0.0.0.0 -p 8008' command: bash -c 'source /opt/lofar/lofarinit.sh && ALLOWED_HOSTS=* tmss_test_environment -H 0.0.0.0 -p 8008 --data'
ports: ports:
- "8008:8008" - "8008:8008"
testprovider: testprovider:
......
...@@ -58,7 +58,7 @@ def populate_test_data(): ...@@ -58,7 +58,7 @@ def populate_test_data():
# create a Test Scheduling Set UC1 under project TMSS-Commissioning # create a Test Scheduling Set UC1 under project TMSS-Commissioning
tmss_project = models.Project.objects.get(name="TMSS-Commissioning") tmss_project = models.Project.objects.get(name="TMSS-Commissioning")
for set_nr in range(1): for set_nr in range(2):
scheduling_set_data = SchedulingSet_test_data(name="Test Scheduling Set UC1 example %s" % (set_nr,), project=tmss_project) scheduling_set_data = SchedulingSet_test_data(name="Test Scheduling Set UC1 example %s" % (set_nr,), project=tmss_project)
scheduling_set = models.SchedulingSet.objects.create(**scheduling_set_data) scheduling_set = models.SchedulingSet.objects.create(**scheduling_set_data)
scheduling_set.tags = ["TEST", "UC1"] scheduling_set.tags = ["TEST", "UC1"]
...@@ -66,7 +66,7 @@ def populate_test_data(): ...@@ -66,7 +66,7 @@ def populate_test_data():
logger.info('created test scheduling_set: %s', scheduling_set.name) logger.info('created test scheduling_set: %s', scheduling_set.name)
for unit_nr in range(1): for unit_nr in range(5):
strategy_template = models.SchedulingUnitObservingStrategyTemplate.objects.get(name="UC1 CTC+pipelines") strategy_template = models.SchedulingUnitObservingStrategyTemplate.objects.get(name="UC1 CTC+pipelines")
......
...@@ -208,7 +208,7 @@ class TMSSDjangoServerInstance(): ...@@ -208,7 +208,7 @@ class TMSSDjangoServerInstance():
# wait for server to be up and running.... # wait for server to be up and running....
# or exit via TimeoutError # or exit via TimeoutError
self.check_running_server(timeout=60) self.check_running_server(timeout=30)
def stop(self): def stop(self):
''' '''
...@@ -226,31 +226,29 @@ class TMSSDjangoServerInstance(): ...@@ -226,31 +226,29 @@ class TMSSDjangoServerInstance():
def check_running_server(self, timeout: float = 10) -> bool: def check_running_server(self, timeout: float = 10) -> bool:
'''Check the running django server for a valid response''' '''Check the running django server for a valid response'''
try: import requests
import requests, urllib3 from _datetime import datetime, timedelta
from _datetime import datetime, timedelta start = datetime.utcnow()
start = datetime.utcnow() while True:
while True: try:
try: logger.info("Checking if TMSS Django server is up and running at %s with database: %s and LDAP: %s ....",
response = requests.get(self.url, auth=(self.ldap_dbcreds.user, self.ldap_dbcreds.password), timeout=max(1, timeout/10)) self.url, self.database_dbcreds, self.ldap_dbcreds)
response = requests.get(self.url, auth=(self.ldap_dbcreds.user, self.ldap_dbcreds.password), timeout=max(1, timeout/10))
if response.status_code in [200, 401, 403]:
logger.info("TMSS Django server is up and running at %s with database: %s and LDAP: %s", if response.status_code in [200, 401, 403]:
self.url, self.database_dbcreds, self.ldap_dbcreds) logger.info("TMSS Django server is up and running at %s with database: %s and LDAP: %s",
self.url, self.database_dbcreds, self.ldap_dbcreds)
if response.status_code in [401, 403]:
logger.warning("TMSS Django server at %s could not autenticate with LDAP creds: %s", self.url, self.ldap_dbcreds) if response.status_code in [401, 403]:
logger.warning("TMSS Django server at %s could not autenticate with LDAP creds: %s", self.url, self.ldap_dbcreds)
# TODO: logout, otherwise django remembers our login session.
return True # TODO: logout, otherwise django remembers our login session.
except Exception as e: return True
time.sleep(0.25) except Exception as e:
time.sleep(0.5)
if datetime.utcnow() - start > timedelta(seconds=timeout):
raise TimeoutError("Could not get a valid response from the django server at %s" % self.url) if datetime.utcnow() - start > timedelta(seconds=timeout):
except Exception as e: raise TimeoutError("Could not get a valid response from the django server at %s within %s seconds" % (self.url,timeout))
logger.error(e)
return False
def __enter__(self): def __enter__(self):
try: try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment