From 34ddc8498e79d0dd4f3ddd2489a95f7578b4af00 Mon Sep 17 00:00:00 2001 From: Ivan Lozgachev Date: Mon, 16 May 2016 20:19:36 +0300 Subject: [PATCH] Add Murano environments context Murano scenario list_environments just measures time of API call at this moment because there are no environments created by default. To fix it new context has been added to make possible generate Murano environments before Rally iterations. Change-Id: Ide0c928fd608503f4916f84d81c942c0ce5fec28 --- rally-jobs/rally-murano.yaml | 2 + .../context/murano/murano_environments.py | 63 +++++++++++++ .../scenarios/murano/list-environments.json | 3 + .../scenarios/murano/list-environments.yaml | 2 + .../murano/test_murano_environments.py | 93 +++++++++++++++++++ .../context/murano/test_murano_packages.py | 4 +- 6 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 rally/plugins/openstack/context/murano/murano_environments.py create mode 100644 tests/unit/plugins/openstack/context/murano/test_murano_environments.py diff --git a/rally-jobs/rally-murano.yaml b/rally-jobs/rally-murano.yaml index eab2c943..aa554f98 100644 --- a/rally-jobs/rally-murano.yaml +++ b/rally-jobs/rally-murano.yaml @@ -9,6 +9,8 @@ users: tenants: 2 users_per_tenant: 2 + murano_environments: + environments_per_tenant: 2 sla: failure_rate: max: 0 diff --git a/rally/plugins/openstack/context/murano/murano_environments.py b/rally/plugins/openstack/context/murano/murano_environments.py new file mode 100644 index 00000000..def583f5 --- /dev/null +++ b/rally/plugins/openstack/context/murano/murano_environments.py @@ -0,0 +1,63 @@ +# Copyright 2016: Mirantis Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from rally.common.i18n import _ +from rally.common import logging +from rally.common import utils +from rally import consts +from rally.plugins.openstack.cleanup import manager as resource_manager +from rally.plugins.openstack.scenarios.murano import utils as murano_utils +from rally.task import context + + +LOG = logging.getLogger(__name__) + + +@context.configure(name="murano_environments", order=402) +class EnvironmentGenerator(context.Context): + """Context class for creating murano environments.""" + + CONFIG_SCHEMA = { + "type": "object", + "$schema": consts.JSON_SCHEMA, + "properties": { + "environments_per_tenant": { + "type": "integer", + "minimum": 1 + }, + }, + "required": ["environments_per_tenant"], + "additionalProperties": False + } + + @logging.log_task_wrapper(LOG.info, + _("Enter context: `Murano environments`")) + def setup(self): + for user, tenant_id in utils.iterate_per_tenants( + self.context["users"]): + self.context["tenants"][tenant_id]["environments"] = [] + for i in range(self.config["environments_per_tenant"]): + murano_util = murano_utils.MuranoScenario( + {"user": user, + "task": self.context["task"], + "config": self.context["config"]}) + env = murano_util._create_environment() + self.context["tenants"][tenant_id]["environments"].append(env) + + @logging.log_task_wrapper(LOG.info, + _("Exit context: `Murano environments`")) + def cleanup(self): + resource_manager.cleanup(names=["murano.environments"], + users=self.context.get("users", [])) diff --git a/samples/tasks/scenarios/murano/list-environments.json b/samples/tasks/scenarios/murano/list-environments.json index 551c7f06..2494a42e 100644 --- a/samples/tasks/scenarios/murano/list-environments.json +++ b/samples/tasks/scenarios/murano/list-environments.json @@ -10,6 +10,9 @@ "users": { "tenants": 2, "users_per_tenant": 2 + }, + "murano_environments": { + "environments_per_tenant": 2 } } } diff --git a/samples/tasks/scenarios/murano/list-environments.yaml b/samples/tasks/scenarios/murano/list-environments.yaml index d914ee19..f7c43fe4 100644 --- a/samples/tasks/scenarios/murano/list-environments.yaml +++ b/samples/tasks/scenarios/murano/list-environments.yaml @@ -9,3 +9,5 @@ users: tenants: 2 users_per_tenant: 2 + murano_environments: + environments_per_tenant: 2 \ No newline at end of file diff --git a/tests/unit/plugins/openstack/context/murano/test_murano_environments.py b/tests/unit/plugins/openstack/context/murano/test_murano_environments.py new file mode 100644 index 00000000..8285c8c9 --- /dev/null +++ b/tests/unit/plugins/openstack/context/murano/test_murano_environments.py @@ -0,0 +1,93 @@ +# Copyright 2015: Mirantis Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import mock + +from rally.plugins.openstack.context.murano import murano_environments +from tests.unit import test + +CTX = "rally.plugins.openstack.context.murano.murano_environments" +SCN = "rally.plugins.openstack.scenarios" + + +class MuranoEnvironmentGeneratorTestCase(test.TestCase): + + def setUp(self): + super(MuranoEnvironmentGeneratorTestCase, self).setUp() + + @staticmethod + def _get_context(): + return { + "config": { + "users": { + "tenants": 2, + "users_per_tenant": 1, + "concurrent": 1, + }, + "murano_environments": { + "environments_per_tenant": 1 + } + }, + "admin": { + "credential": mock.MagicMock() + }, + "task": mock.MagicMock(), + "users": [ + { + "id": "user_0", + "tenant_id": "tenant_0", + "credential": "credential" + }, + { + "id": "user_1", + "tenant_id": "tenant_1", + "credential": "credential" + } + ], + "tenants": { + "tenant_0": {"name": "tenant_0_name"}, + "tenant_1": {"name": "tenant_1_name"} + } + } + + @mock.patch("%s.murano.utils.MuranoScenario._create_environment" % SCN) + def test_setup(self, mock_murano_scenario__create_environment): + mock_env = mock.MagicMock() + mock_murano_scenario__create_environment.return_value = mock_env + + murano_ctx = murano_environments.EnvironmentGenerator( + self._get_context()) + murano_ctx.setup() + + self.assertEqual(2, len(murano_ctx.context["tenants"])) + tenant_id = murano_ctx.context["users"][0]["tenant_id"] + self.assertEqual([mock_env], + murano_ctx.context["tenants"][tenant_id][ + "environments"]) + + @mock.patch("%s.murano.utils.MuranoScenario._create_environment" % SCN) + @mock.patch("%s.resource_manager.cleanup" % CTX) + def test_cleanup(self, mock_cleanup, + mock_murano_scenario__create_environment): + mock_env = mock.Mock() + mock_murano_scenario__create_environment.return_value = mock_env + + murano_ctx = murano_environments.EnvironmentGenerator( + self._get_context()) + murano_ctx.setup() + murano_ctx.cleanup() + + mock_cleanup.assert_called_once_with(names=["murano.environments"], + users=murano_ctx.context["users"]) diff --git a/tests/unit/plugins/openstack/context/murano/test_murano_packages.py b/tests/unit/plugins/openstack/context/murano/test_murano_packages.py index bbb8257d..56e42261 100644 --- a/tests/unit/plugins/openstack/context/murano/test_murano_packages.py +++ b/tests/unit/plugins/openstack/context/murano/test_murano_packages.py @@ -21,10 +21,10 @@ from tests.unit import test CTX = "rally.plugins.openstack.context.murano.murano_packages" -class MuranoGeneratorTestCase(test.TestCase): +class MuranoPackageGeneratorTestCase(test.TestCase): def setUp(self): - super(MuranoGeneratorTestCase, self).setUp() + super(MuranoPackageGeneratorTestCase, self).setUp() @staticmethod def _get_context():