Rename Manila context
Make Manila context named in the same way as all existing contexts - having resource name in context name. Also move manila-related stuff from top of 'self.context' to appropriate subcatalogs. Change-Id: I3e8e660151d6a4c119738681b65ce42e32bdddd4
This commit is contained in:
parent
5a0cc7428f
commit
a107ce1710
0
rally/plugins/openstack/context/manila/__init__.py
Normal file
0
rally/plugins/openstack/context/manila/__init__.py
Normal file
16
rally/plugins/openstack/context/manila/consts.py
Normal file
16
rally/plugins/openstack/context/manila/consts.py
Normal file
@ -0,0 +1,16 @@
|
||||
# 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.
|
||||
|
||||
SHARE_NETWORKS_CONTEXT_NAME = "manila_share_networks"
|
141
rally/plugins/openstack/context/manila/manila_share_networks.py
Normal file
141
rally/plugins/openstack/context/manila/manila_share_networks.py
Normal file
@ -0,0 +1,141 @@
|
||||
# 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.
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log
|
||||
from rally.common import utils
|
||||
from rally import consts as rally_consts
|
||||
from rally import exceptions
|
||||
from rally.plugins.openstack.context.manila import consts
|
||||
from rally.plugins.openstack.scenarios.manila import utils as manila_utils
|
||||
from rally.task import context
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
CONTEXT_NAME = consts.SHARE_NETWORKS_CONTEXT_NAME
|
||||
|
||||
|
||||
@context.configure(name=CONTEXT_NAME, order=450)
|
||||
class ManilaShareNetworks(context.Context):
|
||||
"""This context creates resources specific for Manila project."""
|
||||
CONFIG_SCHEMA = {
|
||||
"type": "object",
|
||||
"$schema": rally_consts.JSON_SCHEMA,
|
||||
"properties": {
|
||||
# NOTE(vponomaryov): specifies whether manila should use
|
||||
# share networks for share creation or not.
|
||||
"use_share_networks": {"type": "boolean"},
|
||||
|
||||
# NOTE(vponomaryov): this context arg will be used only when
|
||||
# context arg "use_share_networks" is set to True and context
|
||||
# 'existing_users' is not empty, considering usage of existing
|
||||
# users.
|
||||
# Expected value is dict of lists where tenant Name or ID is key
|
||||
# and list of share_network Names or IDs is value. Example:
|
||||
# share_networks = [
|
||||
# {"tenant_1_name_or_id": ["share_network_1_name_or_id",
|
||||
# "share_network_2_name_or_id"]},
|
||||
# {"tenant_2_name_or_id": ["share_network_3_name_or_id"]}
|
||||
# ]
|
||||
# Also, make sure that all 'existing users' in appropriate
|
||||
# registered deployment have share networks if its usage is
|
||||
# enbaled, else Rally will randomly take users that does not
|
||||
# satisfy criteria.
|
||||
"share_networks": {"type": "object"},
|
||||
},
|
||||
"additionalProperties": False
|
||||
}
|
||||
DEFAULT_CONFIG = {
|
||||
"use_share_networks": False,
|
||||
"share_networks": {},
|
||||
}
|
||||
|
||||
def _setup_for_existing_users(self):
|
||||
if (self.config["use_share_networks"] and
|
||||
not self.config["share_networks"]):
|
||||
msg = _("Usage of share networks was enabled but for deployment "
|
||||
"with existing users share networks also should be "
|
||||
"specified via arg 'share_networks'")
|
||||
raise exceptions.ContextSetupFailure(
|
||||
ctx_name=self.get_name(), msg=msg)
|
||||
|
||||
# Set flag that says we will not delete/cleanup share networks
|
||||
self.context[CONTEXT_NAME]["delete_share_networks"] = False
|
||||
|
||||
for tenant_name_or_id, share_networks in self.config[
|
||||
"share_networks"].items():
|
||||
# Verify project existence
|
||||
for tenant in self.context["tenants"].values():
|
||||
if tenant_name_or_id in (tenant["id"], tenant["name"]):
|
||||
tenant_id = tenant["id"]
|
||||
existing_user = None
|
||||
for user in self.context["users"]:
|
||||
if user["tenant_id"] == tenant_id:
|
||||
existing_user = user
|
||||
break
|
||||
break
|
||||
else:
|
||||
msg = _("Provided tenant Name or ID '%s' was not found in "
|
||||
"existing tenants.") % tenant_name_or_id
|
||||
raise exceptions.ContextSetupFailure(
|
||||
ctx_name=self.get_name(), msg=msg)
|
||||
self.context["tenants"][tenant_id][CONTEXT_NAME] = {}
|
||||
self.context["tenants"][tenant_id][CONTEXT_NAME][
|
||||
"share_networks"] = []
|
||||
|
||||
manila_scenario = manila_utils.ManilaScenario(
|
||||
{"user": existing_user})
|
||||
existing_sns = manila_scenario._list_share_networks(
|
||||
detailed=False, search_opts={"project_id": tenant_id})
|
||||
|
||||
for sn_name_or_id in share_networks:
|
||||
# Verify share network existence
|
||||
for sn in existing_sns:
|
||||
if sn_name_or_id in (sn.id, sn.name):
|
||||
break
|
||||
else:
|
||||
msg = _("Specified share network '%(sn)s' does not "
|
||||
"exist for tenant '%(tenant_id)s'") % {
|
||||
"sn": sn_name_or_id, "tenant_id": tenant_id}
|
||||
raise exceptions.ContextSetupFailure(
|
||||
ctx_name=self.get_name(), msg=msg)
|
||||
|
||||
# Set share network for project
|
||||
self.context["tenants"][tenant_id][CONTEXT_NAME][
|
||||
"share_networks"].append(sn)
|
||||
|
||||
# Add shared integer var per project that will be used as index
|
||||
# for list with share networks. It is required for balancing.
|
||||
self.context["tenants"][tenant_id][CONTEXT_NAME]["sn_iterator"] = (
|
||||
utils.RAMInt())
|
||||
|
||||
@utils.log_task_wrapper(LOG.info, _("Enter context: `%s`") % CONTEXT_NAME)
|
||||
def setup(self):
|
||||
self.context[CONTEXT_NAME] = {}
|
||||
if not self.config["use_share_networks"]:
|
||||
return
|
||||
elif self.context["config"].get("existing_users"):
|
||||
self._setup_for_existing_users()
|
||||
else:
|
||||
# TODO(vponomaryov): add support of autocreated resources
|
||||
pass
|
||||
|
||||
@utils.log_task_wrapper(LOG.info, _("Exit context: `%s`") % CONTEXT_NAME)
|
||||
def cleanup(self):
|
||||
# TODO(vponomaryov): add cleanup for autocreated resources when appear.
|
||||
return
|
@ -17,6 +17,7 @@ import time
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from rally.plugins.openstack.context.manila import consts
|
||||
from rally.plugins.openstack import scenario
|
||||
from rally.task import atomic
|
||||
from rally.task import utils
|
||||
@ -74,10 +75,12 @@ class ManilaScenario(scenario.OpenStackScenario):
|
||||
"""
|
||||
if self.context:
|
||||
share_networks = self.context.get("tenant", {}).get(
|
||||
"share_networks", [])
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME, {}).get(
|
||||
"share_networks", [])
|
||||
if share_networks and not kwargs.get("share_network"):
|
||||
index = next(self.context.get("tenant", {}).get(
|
||||
"sn_iterator")) % len(share_networks)
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME, {}).get(
|
||||
"sn_iterator")) % len(share_networks)
|
||||
kwargs["share_network"] = share_networks[index]
|
||||
|
||||
if not kwargs.get("name"):
|
||||
|
@ -0,0 +1,184 @@
|
||||
# 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 copy
|
||||
|
||||
import mock
|
||||
|
||||
from rally.common import utils
|
||||
from rally import consts as rally_consts
|
||||
from rally import exceptions
|
||||
from rally.plugins.openstack.context.manila import consts
|
||||
from rally.plugins.openstack.context.manila import manila_share_networks
|
||||
from tests.unit import test
|
||||
|
||||
MANILA_UTILS_PATH = ("rally.plugins.openstack.scenarios.manila.utils."
|
||||
"ManilaScenario.")
|
||||
|
||||
|
||||
class ManilaSampleGeneratorTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(ManilaSampleGeneratorTestCase, self).setUp()
|
||||
self.ctxt_use_existing = {
|
||||
"task": mock.MagicMock(),
|
||||
"config": {
|
||||
"existing_users": {"foo": "bar"},
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME: {
|
||||
"use_share_networks": True,
|
||||
"share_networks": {
|
||||
"tenant_1_id": ["sn_1_id", "sn_2_name"],
|
||||
"tenant_2_name": ["sn_3_id", "sn_4_name", "sn_5_id"],
|
||||
},
|
||||
},
|
||||
},
|
||||
"tenants": {
|
||||
"tenant_1_id": {"id": "tenant_1_id", "name": "tenant_1_name"},
|
||||
"tenant_2_id": {"id": "tenant_2_id", "name": "tenant_2_name"},
|
||||
},
|
||||
"users": [
|
||||
{"tenant_id": "tenant_1_id", "endpoint": {"e1": "foo"}},
|
||||
{"tenant_id": "tenant_2_id", "endpoint": {"e2": "bar"}},
|
||||
],
|
||||
}
|
||||
self.existing_sns = [
|
||||
type("ShareNetwork", (object, ), {
|
||||
"id": "sn_%s_id" % i, "name": "sn_%s_name" % i})()
|
||||
for i in range(1, 6)
|
||||
]
|
||||
|
||||
def test_init(self):
|
||||
context = {
|
||||
"task": mock.MagicMock(),
|
||||
"config": {
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME: {"foo": "bar"},
|
||||
"not_manila": {"not_manila_key": "not_manila_value"},
|
||||
},
|
||||
}
|
||||
|
||||
inst = manila_share_networks.ManilaShareNetworks(context)
|
||||
|
||||
self.assertEqual(
|
||||
context["config"][consts.SHARE_NETWORKS_CONTEXT_NAME],
|
||||
inst.config)
|
||||
self.assertIn(
|
||||
rally_consts.JSON_SCHEMA, inst.CONFIG_SCHEMA.get("$schema"))
|
||||
self.assertEqual(False, inst.CONFIG_SCHEMA.get("additionalProperties"))
|
||||
self.assertEqual("object", inst.CONFIG_SCHEMA.get("type"))
|
||||
props = inst.CONFIG_SCHEMA.get("properties", {})
|
||||
self.assertEqual({"type": "object"}, props.get("share_networks"))
|
||||
self.assertEqual({"type": "boolean"}, props.get("use_share_networks"))
|
||||
self.assertEqual(450, inst.get_order())
|
||||
self.assertEqual(
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME,
|
||||
inst.get_name())
|
||||
|
||||
def test_setup_share_networks_disabled(self):
|
||||
ctxt = {
|
||||
"task": mock.MagicMock(),
|
||||
"config": {
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME: {
|
||||
"use_share_networks": False,
|
||||
},
|
||||
},
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME: {},
|
||||
}
|
||||
inst = manila_share_networks.ManilaShareNetworks(ctxt)
|
||||
|
||||
expected_ctxt = copy.deepcopy(inst.context)
|
||||
|
||||
inst.setup()
|
||||
|
||||
self.assertEqual(expected_ctxt, inst.context)
|
||||
|
||||
@mock.patch("rally.osclients.Clients")
|
||||
@mock.patch(MANILA_UTILS_PATH + "_list_share_networks")
|
||||
def test_setup_use_existing_share_networks(
|
||||
self, mock_manila_scenario__list_share_networks, mock_clients):
|
||||
existing_sns = self.existing_sns
|
||||
inst = manila_share_networks.ManilaShareNetworks(
|
||||
self.ctxt_use_existing)
|
||||
mock_manila_scenario__list_share_networks.return_value = (
|
||||
self.existing_sns)
|
||||
expected_ctxt = copy.deepcopy(self.ctxt_use_existing)
|
||||
expected_ctxt.update({
|
||||
"delete_share_networks": False,
|
||||
"tenants": {
|
||||
"tenant_1_id": {
|
||||
"id": "tenant_1_id",
|
||||
"name": "tenant_1_name",
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME: {
|
||||
"share_networks": [sn for sn in existing_sns[0:2]],
|
||||
"sn_iterator": mock.ANY,
|
||||
},
|
||||
},
|
||||
"tenant_2_id": {
|
||||
"id": "tenant_2_id",
|
||||
"name": "tenant_2_name",
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME: {
|
||||
"share_networks": [sn for sn in existing_sns[2:5]],
|
||||
"sn_iterator": mock.ANY,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
inst.setup()
|
||||
|
||||
self.assertEqual(expected_ctxt["task"], inst.context.get("task"))
|
||||
self.assertEqual(expected_ctxt["config"], inst.context.get("config"))
|
||||
self.assertEqual(expected_ctxt["users"], inst.context.get("users"))
|
||||
self.assertEqual(
|
||||
False,
|
||||
inst.context.get(consts.SHARE_NETWORKS_CONTEXT_NAME, {}).get(
|
||||
"delete_share_networks"))
|
||||
self.assertEqual(expected_ctxt["tenants"], inst.context.get("tenants"))
|
||||
for i, sns in ((1, existing_sns[0:2]), (2, existing_sns[2:5])):
|
||||
self.assertIsInstance(
|
||||
inst.context["tenants"]["tenant_%s_id" % i][
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME]["sn_iterator"],
|
||||
utils.RAMInt)
|
||||
for j in range(12):
|
||||
self.assertEqual(
|
||||
j,
|
||||
next(inst.context["tenants"]["tenant_%s_id" % i][
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME]["sn_iterator"]))
|
||||
|
||||
def test_setup_use_existing_share_networks_tenant_not_found(self):
|
||||
ctxt = copy.deepcopy(self.ctxt_use_existing)
|
||||
ctxt.update({"tenants": {}})
|
||||
inst = manila_share_networks.ManilaShareNetworks(ctxt)
|
||||
|
||||
self.assertRaises(exceptions.ContextSetupFailure, inst.setup)
|
||||
|
||||
@mock.patch("rally.osclients.Clients")
|
||||
@mock.patch(MANILA_UTILS_PATH + "_list_share_networks")
|
||||
def test_setup_use_existing_share_networks_sn_not_found(
|
||||
self, mock_manila_scenario__list_share_networks, mock_clients):
|
||||
ctxt = copy.deepcopy(self.ctxt_use_existing)
|
||||
ctxt["config"][consts.SHARE_NETWORKS_CONTEXT_NAME][
|
||||
"share_networks"] = {"tenant_1_id": ["foo"]}
|
||||
inst = manila_share_networks.ManilaShareNetworks(ctxt)
|
||||
mock_manila_scenario__list_share_networks.return_value = (
|
||||
self.existing_sns)
|
||||
|
||||
self.assertRaises(exceptions.ContextSetupFailure, inst.setup)
|
||||
|
||||
def test_setup_use_existing_share_networks_with_empty_list(self):
|
||||
ctxt = copy.deepcopy(self.ctxt_use_existing)
|
||||
ctxt["config"][consts.SHARE_NETWORKS_CONTEXT_NAME][
|
||||
"share_networks"] = {}
|
||||
inst = manila_share_networks.ManilaShareNetworks(ctxt)
|
||||
|
||||
self.assertRaises(exceptions.ContextSetupFailure, inst.setup)
|
@ -16,6 +16,7 @@
|
||||
import ddt
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.context.manila import consts
|
||||
from rally.plugins.openstack.scenarios.manila import utils
|
||||
from tests.unit import test
|
||||
|
||||
@ -35,17 +36,21 @@ class ManilaScenarioTestCase(test.ScenarioTestCase):
|
||||
self.clients("manila").shares.create.return_value = fake_share
|
||||
self.scenario.context = {
|
||||
"tenant": {
|
||||
"share_networks": ["sn_1_id", "sn_2_id", ],
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME: {
|
||||
"share_networks": ["sn_1_id", "sn_2_id", ],
|
||||
}
|
||||
}
|
||||
}
|
||||
self.scenario.context["tenant"]["sn_iterator"] = iter((0, ))
|
||||
self.scenario.context["tenant"][consts.SHARE_NETWORKS_CONTEXT_NAME][
|
||||
"sn_iterator"] = iter((0, ))
|
||||
self.scenario._generate_random_name = mock.Mock(return_value=fake_name)
|
||||
|
||||
self.scenario._create_share("nfs")
|
||||
|
||||
self.clients("manila").shares.create.assert_called_once_with(
|
||||
"nfs", 1, name=fake_name,
|
||||
share_network=self.scenario.context["tenant"]["share_networks"][0])
|
||||
share_network=self.scenario.context["tenant"][
|
||||
consts.SHARE_NETWORKS_CONTEXT_NAME]["share_networks"][0])
|
||||
|
||||
self.mock_wait_for.mock.assert_called_once_with(
|
||||
fake_share,
|
||||
|
Loading…
x
Reference in New Issue
Block a user