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
This commit is contained in:
Ivan Lozgachev 2016-05-16 20:19:36 +03:00
parent abfca1d01a
commit 651a585018
6 changed files with 165 additions and 2 deletions

View File

@ -9,6 +9,8 @@
users:
tenants: 2
users_per_tenant: 2
murano_environments:
environments_per_tenant: 2
sla:
failure_rate:
max: 0

View File

@ -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", []))

View File

@ -10,6 +10,9 @@
"users": {
"tenants": 2,
"users_per_tenant": 2
},
"murano_environments": {
"environments_per_tenant": 2
}
}
}

View File

@ -9,3 +9,5 @@
users:
tenants: 2
users_per_tenant: 2
murano_environments:
environments_per_tenant: 2

View File

@ -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"])

View File

@ -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():