From 7bb53c64da2dcf88894bfd31503accdd81498f3d Mon Sep 17 00:00:00 2001 From: Thomas Duval Date: Wed, 3 Jun 2020 10:06:52 +0200 Subject: Update to new version 5.4 Signed-off-by: Thomas Duval Change-Id: Idcd868133d75928a1ffd74d749ce98503e0555ea --- moon_engine/tests/performance_tests/utils.py | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 moon_engine/tests/performance_tests/utils.py (limited to 'moon_engine/tests/performance_tests/utils.py') diff --git a/moon_engine/tests/performance_tests/utils.py b/moon_engine/tests/performance_tests/utils.py new file mode 100644 index 00000000..21ac78bb --- /dev/null +++ b/moon_engine/tests/performance_tests/utils.py @@ -0,0 +1,60 @@ +# Software Name: MOON + +# Version: 5.4 + +# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors +# SPDX-License-Identifier: Apache-2.0 + +# This software is distributed under the 'Apache License 2.0', +# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt' +# or see the "LICENSE" file for more details. + + +import json + + +def login(taskset): + req = taskset.client.get("/auth", auth=("admin", "admin")) + taskset.token = req.content.decode("utf-8").strip('"') + + +def logout(taskset): + pass + + +def log(msg): + open("/tmp/tests.log", 'a').write(str(msg) + "\n") + + +def import_policy(client, token): + import_data = open("policy_rbac.json").read() + req = client.post("/import", headers={"X-Api-Key": token}, data=json.loads(import_data)) + print(req) + content = json.loads(req.content.decode("utf-8")) + for policy_key, policy_value in content.get("policies", {}).items(): + if policy_value.get("name") == "Policy for Locust": + return policy_key + + +def create_pdp(client, token, policy_id, vim_project_id=111111111111): + req = client.post("/pdp", headers={"X-Api-Key": token}, data={ + "name": "PDP for Locust", + "vim_project_id": vim_project_id, + "security_pipeline": [policy_id] + }) + content = json.loads(req.content.decode("utf-8")) + for pdp_key, pdp_value in content.get("pdp", {}).items(): + if pdp_value.get("name") == "PDP for Locust": + return pdp_key + + +def delete_policy(client, token, policy_id): + print("deleting Policy {}".format(policy_id)) + client.delete("/policies/{}".format(policy_id), headers={"X-Api-Key": token}) + + +def delete_pdp(client, token, pdp_id): + print("deleting PDP {}".format(pdp_id)) + client.delete("/pdp/{}".format(pdp_id), headers={"X-Api-Key": token}) + + -- cgit 1.2.3-korg