From c8cc0b0908e9f4f4e1a2114c3ffc5f770db02a36 Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Tue, 5 Mar 2024 16:54:08 +0100 Subject: [PATCH 1/3] handled environment variables to be consistent --- README.md | 2 +- app-config/calculator-app/app.sh | 3 ++- app-config/docker-compose.yml | 6 ++++-- app-config/openshift/deploymentconfig.yaml | 8 ++++++-- caimira/apps/calculator/__init__.py | 5 ++--- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a2684aed..e6f01033 100644 --- a/README.md +++ b/README.md @@ -361,7 +361,7 @@ $ oc create secret generic \ The CERN data service collects data from various sources and expose them via a REST API endpoint. -To enable the service set the environment variable `DATA_SERVICE_ENABLED` as `True`. +The service is enabled when the environment variable `DATA_SERVICE_ENABLED` is set to 1. ## Update configuration diff --git a/app-config/calculator-app/app.sh b/app-config/calculator-app/app.sh index 8292627b..505067b7 100755 --- a/app-config/calculator-app/app.sh +++ b/app-config/calculator-app/app.sh @@ -23,7 +23,8 @@ if [[ "$APP_NAME" == "calculator-app" ]]; then export "EXTRA_PAGES"="$EXTRA_PAGES" - export "DATA_SERVICE_ENABLED"="${DATA_SERVICE_ENABLED:=False}" + export "DATA_SERVICE_ENABLED"="${DATA_SERVICE_ENABLED:=0}" + export "CAIMIRA_PROFILER_ENABLED"="${CAIMIRA_PROFILER_ENABLED:=0}" echo "Starting the caimira webservice with: python -m caimira.apps.calculator ${args[@]}" python -m caimira.apps.calculator "${args[@]}" diff --git a/app-config/docker-compose.yml b/app-config/docker-compose.yml index 1be361b2..2d41dcc1 100644 --- a/app-config/docker-compose.yml +++ b/app-config/docker-compose.yml @@ -20,7 +20,8 @@ services: - APPLICATION_ROOT=/ - CAIMIRA_CALCULATOR_PREFIX=/calculator-cern - CAIMIRA_THEME=caimira/apps/templates/cern - - DATA_SERVICE_ENABLED=False + - DATA_SERVICE_ENABLED=0 + - CAIMIRA_PROFILER_ENABLED=0 user: ${CURRENT_UID} calculator-open-app: @@ -30,7 +31,8 @@ services: - APP_NAME=calculator-app - APPLICATION_ROOT=/ - CAIMIRA_CALCULATOR_PREFIX=/calculator-open - - DATA_SERVICE_ENABLED=False + - DATA_SERVICE_ENABLED=0 + - CAIMIRA_PROFILER_ENABLED=0 user: ${CURRENT_UID} auth-service: diff --git a/app-config/openshift/deploymentconfig.yaml b/app-config/openshift/deploymentconfig.yaml index ac58a1ea..638fb6b4 100644 --- a/app-config/openshift/deploymentconfig.yaml +++ b/app-config/openshift/deploymentconfig.yaml @@ -284,7 +284,9 @@ key: ARVE_API_KEY name: arve-api - name: DATA_SERVICE_ENABLED - value: 'True' + value: '1' + - name: CAIMIRA_PROFILER_ENABLED + value: '1' image: '${PROJECT_NAME}/calculator-app' ports: - containerPort: 8080 @@ -363,7 +365,9 @@ - name: CAIMIRA_CALCULATOR_PREFIX value: /calculator-open - name: DATA_SERVICE_ENABLED - value: 'True' + value: '1' + - name: CAIMIRA_PROFILER_ENABLED + value: '1' image: '${PROJECT_NAME}/calculator-app' ports: - containerPort: 8080 diff --git a/caimira/apps/calculator/__init__.py b/caimira/apps/calculator/__init__.py index 8898f272..67de471c 100644 --- a/caimira/apps/calculator/__init__.py +++ b/caimira/apps/calculator/__init__.py @@ -563,9 +563,8 @@ def make_app( data_registry = DataRegistry() data_service = None - data_service_enabled = os.environ.get("DATA_SERVICE_ENABLED", "False") - is_enabled = data_service_enabled.lower() == "true" - if is_enabled: data_service = DataService.create() + data_service_enabled = os.environ.get('DATA_SERVICE_ENABLED', 0) + if data_service_enabled: data_service = DataService.create() return Application( urls, From c5963a978abb76ca4cf19ddd4438813de16da203 Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Wed, 6 Mar 2024 14:26:35 +0100 Subject: [PATCH 2/3] Added timeout to fetch method --- caimira/tests/apps/calculator/test_webapp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/caimira/tests/apps/calculator/test_webapp.py b/caimira/tests/apps/calculator/test_webapp.py index dc6ea769..a9fd52f3 100644 --- a/caimira/tests/apps/calculator/test_webapp.py +++ b/caimira/tests/apps/calculator/test_webapp.py @@ -41,7 +41,7 @@ class TestBasicApp(tornado.testing.AsyncHTTPTestCase): @tornado.testing.gen_test(timeout=_TIMEOUT) def test_report(self): requests = [ - self.http_client.fetch(self.get_url('/calculator/baseline-model/result')), + self.http_client.fetch(self.get_url('/calculator/baseline-model/result'), request_timeout=_TIMEOUT), # At the same time, request a non-report page (to check whether the report is blocking). self.http_client.fetch(self.get_url('/calculator/')), ] @@ -69,7 +69,7 @@ class TestCernApp(tornado.testing.AsyncHTTPTestCase): @tornado.testing.gen_test(timeout=_TIMEOUT) def test_report(self): - response = yield self.http_client.fetch(self.get_url('/calculator/baseline-model/result')) + response = yield self.http_client.fetch(self.get_url('/calculator/baseline-model/result'), request_timeout=_TIMEOUT) self.assertEqual(response.code, 200) assert 'expected number of new cases is' in response.body.decode() @@ -80,7 +80,7 @@ class TestOpenApp(tornado.testing.AsyncHTTPTestCase): @tornado.testing.gen_test(timeout=_TIMEOUT) def test_report(self): - response = yield self.http_client.fetch(self.get_url('/mycalc/baseline-model/result')) + response = yield self.http_client.fetch(self.get_url('/mycalc/baseline-model/result'), request_timeout=_TIMEOUT) self.assertEqual(response.code, 200) def test_calculator_404(self): From b0c9aefe34ed0c3e17d57b3ca2b093badf9d0a83 Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Fri, 8 Mar 2024 09:29:57 +0100 Subject: [PATCH 3/3] disabled data service (OKD template) --- app-config/openshift/deploymentconfig.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app-config/openshift/deploymentconfig.yaml b/app-config/openshift/deploymentconfig.yaml index 638fb6b4..82d8974b 100644 --- a/app-config/openshift/deploymentconfig.yaml +++ b/app-config/openshift/deploymentconfig.yaml @@ -284,7 +284,7 @@ key: ARVE_API_KEY name: arve-api - name: DATA_SERVICE_ENABLED - value: '1' + value: '0' - name: CAIMIRA_PROFILER_ENABLED value: '1' image: '${PROJECT_NAME}/calculator-app' @@ -365,7 +365,7 @@ - name: CAIMIRA_CALCULATOR_PREFIX value: /calculator-open - name: DATA_SERVICE_ENABLED - value: '1' + value: '0' - name: CAIMIRA_PROFILER_ENABLED value: '1' image: '${PROJECT_NAME}/calculator-app'