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 --- .../tests/performance_tests_policies/actions.py | 54 +++++++++++++++ .../tests/performance_tests_policies/locustfile.py | 32 +++++++++ .../tests/performance_tests_policies/meta_rules.py | 80 ++++++++++++++++++++++ .../tests/performance_tests_policies/objects.py | 54 +++++++++++++++ .../tests/performance_tests_policies/subjects.py | 57 +++++++++++++++ .../tests/performance_tests_policies/utils.py | 45 ++++++++++++ 6 files changed, 322 insertions(+) create mode 100644 moon_manager/tests/performance_tests_policies/actions.py create mode 100644 moon_manager/tests/performance_tests_policies/locustfile.py create mode 100644 moon_manager/tests/performance_tests_policies/meta_rules.py create mode 100644 moon_manager/tests/performance_tests_policies/objects.py create mode 100644 moon_manager/tests/performance_tests_policies/subjects.py create mode 100644 moon_manager/tests/performance_tests_policies/utils.py (limited to 'moon_manager/tests/performance_tests_policies') diff --git a/moon_manager/tests/performance_tests_policies/actions.py b/moon_manager/tests/performance_tests_policies/actions.py new file mode 100644 index 00000000..0f31d645 --- /dev/null +++ b/moon_manager/tests/performance_tests_policies/actions.py @@ -0,0 +1,54 @@ +# 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 +from locust import TaskSet, task +from uuid import uuid4 +import utils + + +class ActionRequests(TaskSet): + token = "" + + def on_start(self): + """ on_start is called when a Locust start before any task is scheduled """ + utils.login(self) + + def on_stop(self): + """ on_stop is called when the TaskSet is stopping """ + utils.logout(self) + + @task(10) + def actions(self): + policy_id = utils.create_policy(self.client, self.token) + self.client.get("/actions", headers={"X-Api-Key": self.token}) + perimeter_name = "test_action_" + str(uuid4()) + req = self.client.post("/policies/{}/actions".format(policy_id), + headers={"X-Api-Key": self.token}, + data={ + "name": perimeter_name, + "description": "locust test", + }) + content = json.loads(req.content.decode("utf-8")) + subject_id = None + for subject_id, subject_value in content.get("actions", {}).items(): + if subject_value.get("name") == perimeter_name: + break + self.client.delete("/policies/{}/actions/{}".format(policy_id, subject_id), + headers={"X-Api-Key": self.token}) + utils.delete_policy(self.client, self.token, policy_id) + + @task(1) + def status(self): + self.client.get("/status", headers={"X-Api-Key": self.token}) + + diff --git a/moon_manager/tests/performance_tests_policies/locustfile.py b/moon_manager/tests/performance_tests_policies/locustfile.py new file mode 100644 index 00000000..368801b0 --- /dev/null +++ b/moon_manager/tests/performance_tests_policies/locustfile.py @@ -0,0 +1,32 @@ +# 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. + + +from locust import HttpLocust, TaskSet +import subjects +import objects +import actions +import meta_rules + + +class MoonRequests(TaskSet): + tasks = { + subjects.SubjectRequests: 10, + objects.ObjectRequests: 10, + actions.ActionRequests: 10, + meta_rules.MetaRulesRequests: 5 + } + + +class MoonUser(HttpLocust): + task_set = MoonRequests + min_wait = 100 + max_wait = 1000 diff --git a/moon_manager/tests/performance_tests_policies/meta_rules.py b/moon_manager/tests/performance_tests_policies/meta_rules.py new file mode 100644 index 00000000..e9d85944 --- /dev/null +++ b/moon_manager/tests/performance_tests_policies/meta_rules.py @@ -0,0 +1,80 @@ +# 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. + + +from locust import TaskSet, task +import json +from uuid import uuid4 +import utils + + +class MetaRulesRequests(TaskSet): + token = "" + + def on_start(self): + """ on_start is called when a Locust start before any task is scheduled """ + utils.login(self) + + def on_stop(self): + """ on_stop is called when the TaskSet is stopping """ + utils.logout(self) + + def create_category(self, otype="subject"): + self.client.get("/{}_categories".format(otype), headers={"X-Api-Key": self.token}) + category_name = "test_category_" + str(uuid4()) + req = self.client.post("/{}_categories".format(otype), + headers={"X-Api-Key": self.token}, + data={ + "name": category_name, + "description": "locust {} category tests".format(otype), + }) + content = json.loads(req.content.decode("utf-8")) + for category_id, category_value in content.get("{}_categories".format(otype), {}).items(): + if category_value.get("name") == category_name: + return category_id + + def delete_category(self, category_id, otype="subject"): + self.client.delete("/{}_categories/{}".format(otype, category_id), + headers={"X-Api-Key": self.token}) + + @task(10) + def meta_rules(self): + self.client.get("/meta_rules", headers={"X-Api-Key": self.token}) + subject_category_id = self.create_category("subject") + object_category_id = self.create_category("object") + action_category_id = self.create_category("action") + meta_rule_name = "meta_rule_" + str(uuid4()) + data = { + "name": meta_rule_name, + "subject_categories": [subject_category_id], + "object_categories": [object_category_id], + "action_categories": [action_category_id] + } + req = self.client.post("/meta_rules", + headers={"X-Api-Key": self.token, + "Content-Type": "application/json"}, + data=json.dumps(data) + ) + content = json.loads(req.content.decode("utf-8")) + for meta_rule_id, meta_rule_value in content.get("meta_rules", {}).items(): + if meta_rule_value.get("name") == meta_rule_name: + self.client.delete("/meta_rules/{}".format(meta_rule_id), + headers={"X-Api-Key": self.token}) + break + self.delete_category(subject_category_id, "subject") + self.delete_category(object_category_id, "object") + self.delete_category(action_category_id, "action") + + @task(1) + def status(self): + self.client.get("/status", headers={"X-Api-Key": self.token}) + + diff --git a/moon_manager/tests/performance_tests_policies/objects.py b/moon_manager/tests/performance_tests_policies/objects.py new file mode 100644 index 00000000..24932d70 --- /dev/null +++ b/moon_manager/tests/performance_tests_policies/objects.py @@ -0,0 +1,54 @@ +# 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 +from locust import TaskSet, task +from uuid import uuid4 +import utils + + +class ObjectRequests(TaskSet): + token = "" + + def on_start(self): + """ on_start is called when a Locust start before any task is scheduled """ + utils.login(self) + + def on_stop(self): + """ on_stop is called when the TaskSet is stopping """ + utils.logout(self) + + @task(10) + def objects(self): + policy_id = utils.create_policy(self.client, self.token) + self.client.get("/objects", headers={"X-Api-Key": self.token}) + perimeter_name = "test_object_" + str(uuid4()) + req = self.client.post("/policies/{}/objects".format(policy_id), + headers={"X-Api-Key": self.token}, + data={ + "name": perimeter_name, + "description": "locust test", + }) + content = json.loads(req.content.decode("utf-8")) + subject_id = None + for subject_id, subject_value in content.get("objects", {}).items(): + if subject_value.get("name") == perimeter_name: + break + self.client.delete("/policies/{}/objects/{}".format(policy_id, subject_id), + headers={"X-Api-Key": self.token}) + utils.delete_policy(self.client, self.token, policy_id) + + @task(1) + def status(self): + self.client.get("/status", headers={"X-Api-Key": self.token}) + + diff --git a/moon_manager/tests/performance_tests_policies/subjects.py b/moon_manager/tests/performance_tests_policies/subjects.py new file mode 100644 index 00000000..cacf04c8 --- /dev/null +++ b/moon_manager/tests/performance_tests_policies/subjects.py @@ -0,0 +1,57 @@ +# 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. + + +from locust import TaskSet, task +import json +import logging +from uuid import uuid4 +import utils + +LOGGER = logging.getLogger(__name__) + + +class SubjectRequests(TaskSet): + token = "" + + def on_start(self): + """ on_start is called when a Locust start before any task is scheduled """ + utils.login(self) + + def on_stop(self): + """ on_stop is called when the TaskSet is stopping """ + utils.logout(self) + + @task(10) + def subjects(self): + policy_id = utils.create_policy(self.client, self.token) + self.client.get("/subjects", headers={"X-Api-Key": self.token}) + perimeter_name = "test_subject_" + str(uuid4()) + req = self.client.post("/policies/{}/subjects".format(policy_id), + headers={"X-Api-Key": self.token}, + data={ + "name": perimeter_name, + "description": "locust test", + }) + content = json.loads(req.content.decode("utf-8")) + subject_id = None + for subject_id, subject_value in content.get("subjects", {}).items(): + if subject_value.get("name") == perimeter_name: + break + self.client.delete("/policies/{}/subjects/{}".format(policy_id, subject_id), + headers={"X-Api-Key": self.token}) + utils.delete_policy(self.client, self.token, policy_id) + + @task(1) + def status(self): + self.client.get("/status", headers={"X-Api-Key": self.token}) + + diff --git a/moon_manager/tests/performance_tests_policies/utils.py b/moon_manager/tests/performance_tests_policies/utils.py new file mode 100644 index 00000000..4a721b4c --- /dev/null +++ b/moon_manager/tests/performance_tests_policies/utils.py @@ -0,0 +1,45 @@ +# 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 +from uuid import uuid4 + + +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 create_policy(client, token): + policy_name = "test_policy_" + str(uuid4()) + req = client.post("/policies", headers={"X-Api-Key": token}, data={ + "name": policy_name, + "description": "locust test policy", + }) + content = json.loads(req.content.decode("utf-8")) + for policy_key, policy_value in content.get("policies", {}).items(): + if policy_value.get("name") == policy_name: + return policy_key + + +def delete_policy(client, token, policy_id): + client.delete("/policies/{}".format(policy_id), headers={"X-Api-Key": token}) + + -- cgit 1.2.3-korg