From 0088d588e1a64841a62afc778a6cdbab61e0c8ae Mon Sep 17 00:00:00 2001 From: Alexey Bezhan Date: Tue, 9 Jan 2018 14:41:36 +0000 Subject: [PATCH] Use VCAP_APPLICATION to detect CloudFoundry environment VCAP_SERVICES is not set on PaaS if no services are bound to the application, so we need to check for VCAP_APPLICATION to parse the application name and environment. --- app/config.py | 4 ++-- tests/app/test_config.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/config.py b/app/config.py index 3fe195776..c4443ee1f 100644 --- a/app/config.py +++ b/app/config.py @@ -1,8 +1,8 @@ import os -if os.environ.get('VCAP_SERVICES'): - # on cloudfoundry, config is a json blob in VCAP_SERVICES - unpack it, and populate +if os.environ.get('VCAP_APPLICATION'): + # on cloudfoundry, config is a json blob in VCAP_APPLICATION - unpack it, and populate # standard environment variables from it from app.cloudfoundry_config import extract_cloudfoundry_config extract_cloudfoundry_config() diff --git a/tests/app/test_config.py b/tests/app/test_config.py index 87cc10aed..9ea0f3c72 100644 --- a/tests/app/test_config.py +++ b/tests/app/test_config.py @@ -26,7 +26,7 @@ def reload_config(): def test_load_cloudfoundry_config_if_available(monkeypatch, reload_config): os.environ['API_HOST_NAME'] = 'env' - monkeypatch.setenv('VCAP_SERVICES', 'some json blob') + monkeypatch.setenv('VCAP_APPLICATION', 'some json blob') with mock.patch('app.cloudfoundry_config.extract_cloudfoundry_config', side_effect=cf_conf) as cf_config: # reload config so that its module level code (ie: all of it) is re-instantiated @@ -41,7 +41,7 @@ def test_load_cloudfoundry_config_if_available(monkeypatch, reload_config): def test_load_config_if_cloudfoundry_not_available(monkeypatch, reload_config): os.environ['API_HOST_NAME'] = 'env' - monkeypatch.delenv('VCAP_SERVICES', raising=False) + monkeypatch.delenv('VCAP_APPLICATION', raising=False) with mock.patch('app.cloudfoundry_config.extract_cloudfoundry_config') as cf_config: # reload config so that its module level code (ie: all of it) is re-instantiated