diff options
author | 2017-04-25 10:11:08 +0200 | |
---|---|---|
committer | 2017-04-25 10:11:08 +0200 | |
commit | 6a808c2a62fdec53eabf445356a5494c3654b894 (patch) | |
tree | b33a4c6c9ba7954fa60560c870af12bc09cf7de2 /moonv4/moon_interface/tests/apitests/utils/pdp.py | |
parent | 623cf53a0a06ac4c3cad6e60b569ccd6418073b6 (diff) |
Read config from moon.conf
Change-Id: I19229ac3b81a2c7858afa7797e3cdeff820edff6
Diffstat (limited to 'moonv4/moon_interface/tests/apitests/utils/pdp.py')
-rw-r--r-- | moonv4/moon_interface/tests/apitests/utils/pdp.py | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/moonv4/moon_interface/tests/apitests/utils/pdp.py b/moonv4/moon_interface/tests/apitests/utils/pdp.py index 81b50e38..c4a1b756 100644 --- a/moonv4/moon_interface/tests/apitests/utils/pdp.py +++ b/moonv4/moon_interface/tests/apitests/utils/pdp.py @@ -1,10 +1,15 @@ import requests +import configparser -URL = "http://172.18.0.11:38001{}" +config = configparser.ConfigParser() +config.read("/etc/moon/moon.conf") + +URL = "http://{}:{}".format(config['interface']['host'], config['interface']['port']) HEADERS = {"content-type": "application/json"} -KEYSTONE_USER = "admin" -KEYSTONE_PASSWORD = "p4ssw0rd" -KEYSTONE_PROJECT = "admin" +KEYSTONE_USER = config['keystone']['user'] +KEYSTONE_PASSWORD = config['keystone']['password'] +KEYSTONE_PROJECT = config['keystone']['project'] +KEYSTONE_SERVER = config['keystone']['url'] pdp_template = { "name": "test_pdp", @@ -15,7 +20,6 @@ pdp_template = { def get_keystone_projects(): - server = "keystone" HEADERS = { "Content-Type": "application/json" @@ -48,18 +52,18 @@ def get_keystone_projects(): } } - req = requests.post("http://{}:5000/v3/auth/tokens".format(server), json=data_auth, headers=HEADERS) + req = requests.post("{}/auth/tokens".format(KEYSTONE_SERVER), json=data_auth, headers=HEADERS) assert req.status_code in (200, 201) TOKEN = req.headers['X-Subject-Token'] HEADERS['X-Auth-Token'] = TOKEN - req = requests.get("http://{}:5000/v3/projects".format(server), headers=HEADERS) + req = requests.get("{}/projects".format(KEYSTONE_SERVER), headers=HEADERS) assert req.status_code in (200, 201) return req.json() def check_pdp(pdp_id=None, keystone_project_id=None): - req = requests.get(URL.format("/pdp")) + req = requests.get(URL + "/pdp") assert req.status_code == 200 result = req.json() assert type(result) is dict @@ -81,7 +85,7 @@ def add_pdp(name="test_pdp", policy_id=None): pdp_template['name'] = name if policy_id: pdp_template['security_pipeline'].append(policy_id) - req = requests.post(URL.format("/pdp"), json=pdp_template, headers=HEADERS) + req = requests.post(URL + "/pdp", json=pdp_template, headers=HEADERS) assert req.status_code == 200 result = req.json() assert type(result) is dict @@ -94,7 +98,7 @@ def add_pdp(name="test_pdp", policy_id=None): def update_pdp(pdp_id, policy_id=None): - req = requests.get(URL.format("/pdp/{}".format(pdp_id))) + req = requests.get(URL + "/pdp/{}".format(pdp_id)) assert req.status_code == 200 result = req.json() assert type(result) is dict @@ -103,7 +107,7 @@ def update_pdp(pdp_id, policy_id=None): pipeline = result['pdps'][pdp_id]["security_pipeline"] if policy_id not in pipeline: pipeline.append(policy_id) - req = requests.patch(URL.format("/pdp/{}".format(pdp_id)), + req = requests.patch(URL + "/pdp/{}".format(pdp_id), json={"security_pipeline": pipeline}) assert req.status_code == 200 result = req.json() @@ -111,7 +115,7 @@ def update_pdp(pdp_id, policy_id=None): assert "pdps" in result assert pdp_id in result['pdps'] - req = requests.get(URL.format("/pdp/{}".format(pdp_id))) + req = requests.get(URL + "/pdp/{}".format(pdp_id)) assert req.status_code == 200 result = req.json() assert type(result) is dict @@ -121,7 +125,7 @@ def update_pdp(pdp_id, policy_id=None): def map_to_keystone(pdp_id, keystone_project_id): - req = requests.patch(URL.format("/pdp/{}".format(pdp_id)), json={"keystone_project_id": keystone_project_id}, + req = requests.patch(URL + "/pdp/{}".format(pdp_id), json={"keystone_project_id": keystone_project_id}, headers=HEADERS) assert req.status_code == 200 result = req.json() @@ -135,7 +139,7 @@ def map_to_keystone(pdp_id, keystone_project_id): def delete_pdp(pdp_id): - req = requests.delete(URL.format("/pdp/{}".format(pdp_id))) + req = requests.delete(URL + "/pdp/{}".format(pdp_id)) assert req.status_code == 200 result = req.json() assert type(result) is dict |