diff options
author | 2017-07-25 17:46:31 +0200 | |
---|---|---|
committer | 2017-07-25 17:46:31 +0200 | |
commit | 000ba3d0d4ac08a59a3f8a78faa450e565bae0c3 (patch) | |
tree | 8389b35d5b0dfb08514ade86b236989576c6c8d1 /moonv4/moon_interface/tests | |
parent | 8cbf11c78259540f9a2b0661842bb82558ea2648 (diff) |
Get the configuration from moon.conf
Change-Id: I27c86af24adc5ee4661943a9cab5e4a54ca02b3d
Diffstat (limited to 'moonv4/moon_interface/tests')
-rw-r--r-- | moonv4/moon_interface/tests/apitests/utils/models.py | 25 | ||||
-rw-r--r-- | moonv4/moon_interface/tests/apitests/utils/pdp.py | 34 | ||||
-rw-r--r-- | moonv4/moon_interface/tests/apitests/utils/policies.py | 24 |
3 files changed, 63 insertions, 20 deletions
diff --git a/moonv4/moon_interface/tests/apitests/utils/models.py b/moonv4/moon_interface/tests/apitests/utils/models.py index 5039d185..68133b5b 100644 --- a/moonv4/moon_interface/tests/apitests/utils/models.py +++ b/moonv4/moon_interface/tests/apitests/utils/models.py @@ -1,12 +1,27 @@ +import os +import yaml import requests import copy -import configparser -config = configparser.ConfigParser() -if not config.read("moon.conf"): - config.read("/etc/moon/moon.conf") -URL = "http://{}:{}".format(config['interface']['host'], config['interface']['port']) +for path in ( + "moon.conf", + "../moon.conf", + "{}/moon_orchestrator/conf/moon.conf".format(os.getenv("MOON_HOME")), + "/etc/moon/moon.conf" +): + try: + config = yaml.safe_load(open(path)) + except FileNotFoundError: + config = None + continue + else: + print("Using {}".format(path)) + break +if not config: + raise Exception("Configuration file not found...") + +URL = "http://{}:{}".format(config['components']['interface']['hostname'], config['components']['interface']['port']) URL = URL + "{}" HEADERS = {"content-type": "application/json"} diff --git a/moonv4/moon_interface/tests/apitests/utils/pdp.py b/moonv4/moon_interface/tests/apitests/utils/pdp.py index 6a27224e..03259818 100644 --- a/moonv4/moon_interface/tests/apitests/utils/pdp.py +++ b/moonv4/moon_interface/tests/apitests/utils/pdp.py @@ -1,16 +1,30 @@ +import os +import yaml import requests -import configparser -config = configparser.ConfigParser() -if not config.read("moon.conf"): - config.read("/etc/moon/moon.conf") - -URL = "http://{}:{}".format(config['interface']['host'], config['interface']['port']) +for path in ( + "moon.conf", + "../moon.conf", + "{}/moon_orchestrator/conf/moon.conf".format(os.getenv("MOON_HOME")), + "/etc/moon/moon.conf" +): + try: + config = yaml.safe_load(open(path)) + except FileNotFoundError: + config = None + continue + else: + print("Using {}".format(path)) + break +if not config: + raise Exception("Configuration file not found...") + +URL = "http://{}:{}".format(config['components']['interface']['hostname'], config['components']['interface']['port']) HEADERS = {"content-type": "application/json"} -KEYSTONE_USER = config['keystone']['user'] -KEYSTONE_PASSWORD = config['keystone']['password'] -KEYSTONE_PROJECT = config['keystone']['project'] -KEYSTONE_SERVER = config['keystone']['url'] +KEYSTONE_USER = config['openstack']['keystone']['user'] +KEYSTONE_PASSWORD = config['openstack']['keystone']['password'] +KEYSTONE_PROJECT = config['openstack']['keystone']['project'] +KEYSTONE_SERVER = config['openstack']['keystone']['url'] pdp_template = { "name": "test_pdp", diff --git a/moonv4/moon_interface/tests/apitests/utils/policies.py b/moonv4/moon_interface/tests/apitests/utils/policies.py index 444f34d7..fdde92ef 100644 --- a/moonv4/moon_interface/tests/apitests/utils/policies.py +++ b/moonv4/moon_interface/tests/apitests/utils/policies.py @@ -1,11 +1,25 @@ +import os +import yaml import requests -import configparser -config = configparser.ConfigParser() -if not config.read("moon.conf"): - config.read("/etc/moon/moon.conf") +for path in ( + "moon.conf", + "../moon.conf", + "{}/moon_orchestrator/conf/moon.conf".format(os.getenv("MOON_HOME")), + "/etc/moon/moon.conf" +): + try: + config = yaml.safe_load(open(path)) + except FileNotFoundError: + config = None + continue + else: + print("Using {}".format(path)) + break +if not config: + raise Exception("Configuration file not found...") -URL = "http://{}:{}".format(config['interface']['host'], config['interface']['port']) +URL = "http://{}:{}".format(config['components']['interface']['hostname'], config['components']['interface']['port']) URL = URL + "{}" HEADERS = {"content-type": "application/json"} FILE = open("/tmp/test.log", "w") |