From e43b0728c8772d6a140b2a19c94f94919ca8cdab Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Wed, 25 Mar 2020 21:07:42 +0200 Subject: [PATCH] Introduce a base class for all OpenStack context Currently this class is a new home for _iterate_per_tenants method that was deprecated at rally framework. Change-Id: I1f301455dc32c78270ed0411c6a79a5f2c68e827 --- CHANGELOG.rst | 6 +++ rally_openstack/contexts/api_versions.py | 4 +- .../contexts/ceilometer/samples.py | 8 ++-- .../contexts/cinder/volume_types.py | 4 +- rally_openstack/contexts/cinder/volumes.py | 9 ++-- rally_openstack/contexts/cleanup/admin.py | 4 +- rally_openstack/contexts/cleanup/user.py | 4 +- rally_openstack/contexts/dataplane/heat.py | 7 ++- rally_openstack/contexts/designate/zones.py | 7 ++- rally_openstack/contexts/glance/images.py | 7 ++- rally_openstack/contexts/heat/stacks.py | 8 ++-- rally_openstack/contexts/keystone/roles.py | 4 +- rally_openstack/contexts/keystone/users.py | 8 ++-- rally_openstack/contexts/magnum/ca_certs.py | 7 ++- .../contexts/magnum/cluster_templates.py | 8 ++-- rally_openstack/contexts/magnum/clusters.py | 8 ++-- .../manila/manila_security_services.py | 7 ++- .../contexts/manila/manila_share_networks.py | 7 ++- .../contexts/manila/manila_shares.py | 8 ++-- rally_openstack/contexts/monasca/metrics.py | 7 ++- .../contexts/murano/murano_environments.py | 8 ++-- .../contexts/murano/murano_packages.py | 8 ++-- rally_openstack/contexts/network/allow_ssh.py | 8 ++-- .../contexts/network/existing_network.py | 8 ++-- .../contexts/network/networking_agents.py | 4 +- rally_openstack/contexts/network/networks.py | 8 ++-- rally_openstack/contexts/network/routers.py | 8 ++-- rally_openstack/contexts/neutron/lbaas.py | 9 ++-- rally_openstack/contexts/nova/flavors.py | 4 +- rally_openstack/contexts/nova/keypairs.py | 4 +- rally_openstack/contexts/nova/servers.py | 8 ++-- rally_openstack/contexts/quotas/quotas.py | 4 +- .../contexts/sahara/sahara_cluster.py | 8 ++-- .../contexts/sahara/sahara_image.py | 11 ++--- .../sahara/sahara_input_data_sources.py | 8 ++-- .../contexts/sahara/sahara_job_binaries.py | 8 ++-- .../sahara/sahara_output_data_sources.py | 8 ++-- rally_openstack/contexts/senlin/profiles.py | 11 ++--- rally_openstack/contexts/swift/objects.py | 15 +++--- rally_openstack/contexts/swift/utils.py | 44 ++++++++--------- rally_openstack/contexts/vm/custom_image.py | 8 ++-- .../contexts/vm/image_command_customizer.py | 2 +- .../contexts/watcher/audit_templates.py | 4 +- rally_openstack/task/__init__.py | 0 rally_openstack/task/context.py | 37 +++++++++++++++ tests/unit/contexts/keystone/test_users.py | 18 +++---- .../test_existing_network.py | 0 tests/unit/contexts/network/test_network.py | 17 ++++--- .../test_networking_agents.py | 0 tests/unit/contexts/neutron/test_lbaas.py | 39 ++++++++------- tests/unit/contexts/swift/test_utils.py | 28 +++++++---- tests/unit/task/__init__.py | 0 tests/unit/task/test_context.py | 47 +++++++++++++++++++ 53 files changed, 284 insertions(+), 242 deletions(-) create mode 100644 rally_openstack/task/__init__.py create mode 100644 rally_openstack/task/context.py rename tests/unit/contexts/{neutron => network}/test_existing_network.py (100%) rename tests/unit/contexts/{neutron => network}/test_networking_agents.py (100%) create mode 100644 tests/unit/task/__init__.py create mode 100644 tests/unit/task/test_context.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6b54a02d..e20f492b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -19,6 +19,12 @@ Changelog [unreleased] ------------ +Added +~~~~~ + +* The *rally_openstack.task.context.OpenStackContext* class which provides + helpers for all OpenStack context. + Changed ~~~~~~~ diff --git a/rally_openstack/contexts/api_versions.py b/rally_openstack/contexts/api_versions.py index 98eeb37d..e0c25330 100644 --- a/rally_openstack/contexts/api_versions.py +++ b/rally_openstack/contexts/api_versions.py @@ -14,10 +14,10 @@ import random from rally.common import validation from rally import exceptions -from rally.task import context from rally_openstack import consts from rally_openstack import osclients +from rally_openstack.task import context @validation.configure("check_api_versions") @@ -44,7 +44,7 @@ class CheckOpenStackAPIVersionsValidator(validation.Validator): @validation.add("check_api_versions") @context.configure(name="api_versions", platform="openstack", order=150) -class OpenStackAPIVersions(context.Context): +class OpenStackAPIVersions(context.OpenStackContext): """Context for specifying OpenStack clients versions and service types. Some OpenStack services support several API versions. To recognize diff --git a/rally_openstack/contexts/ceilometer/samples.py b/rally_openstack/contexts/ceilometer/samples.py index 1351bf43..667f5e22 100644 --- a/rally_openstack/contexts/ceilometer/samples.py +++ b/rally_openstack/contexts/ceilometer/samples.py @@ -15,13 +15,12 @@ import time from rally.common import logging -from rally.common import utils as rutils from rally.common import validation from rally import exceptions -from rally.task import context from rally_openstack import consts from rally_openstack.scenarios.ceilometer import utils as ceilo_utils +from rally_openstack.task import context LOG = logging.getLogger(__name__) @@ -29,7 +28,7 @@ LOG = logging.getLogger(__name__) @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="ceilometer", platform="openstack", order=450) -class CeilometerSampleGenerator(context.Context): +class CeilometerSampleGenerator(context.OpenStackContext): """Creates ceilometer samples and resources.""" CONFIG_SCHEMA = { @@ -128,8 +127,7 @@ class CeilometerSampleGenerator(context.Context): } resources = [] - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): self.context["tenants"][tenant_id]["samples"] = [] self.context["tenants"][tenant_id]["resources"] = [] scenario = ceilo_utils.CeilometerScenario( diff --git a/rally_openstack/contexts/cinder/volume_types.py b/rally_openstack/contexts/cinder/volume_types.py index 71d7c906..ca317cb5 100644 --- a/rally_openstack/contexts/cinder/volume_types.py +++ b/rally_openstack/contexts/cinder/volume_types.py @@ -15,12 +15,12 @@ from rally.common import logging from rally.common import utils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack import osclients from rally_openstack.services.storage import block +from rally_openstack.task import context LOG = logging.getLogger(__name__) @@ -28,7 +28,7 @@ LOG = logging.getLogger(__name__) @validation.add("required_platform", platform="openstack", admin=True) @context.configure(name="volume_types", platform="openstack", order=410) -class VolumeTypeGenerator(context.Context): +class VolumeTypeGenerator(context.OpenStackContext): """Adds cinder volumes types.""" CONFIG_SCHEMA = { diff --git a/rally_openstack/contexts/cinder/volumes.py b/rally_openstack/contexts/cinder/volumes.py index 1daf451f..2be0f036 100644 --- a/rally_openstack/contexts/cinder/volumes.py +++ b/rally_openstack/contexts/cinder/volumes.py @@ -12,17 +12,15 @@ # License for the specific language governing permissions and limitations # under the License. -from rally.common import utils as rutils -from rally.task import context - from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack import osclients from rally_openstack.services.storage import block +from rally_openstack.task import context @context.configure(name="volumes", platform="openstack", order=420) -class VolumeGenerator(context.Context): +class VolumeGenerator(context.OpenStackContext): """Creates volumes for each tenant.""" CONFIG_SCHEMA = { @@ -59,8 +57,7 @@ class VolumeGenerator(context.Context): volume_type = self.config.get("type", None) volumes_per_tenant = self.config["volumes_per_tenant"] - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): self.context["tenants"][tenant_id].setdefault("volumes", []) clients = osclients.Clients(user["credential"]) cinder_service = block.BlockStorage( diff --git a/rally_openstack/contexts/cleanup/admin.py b/rally_openstack/contexts/cleanup/admin.py index 8d3daea2..c4668500 100644 --- a/rally_openstack/contexts/cleanup/admin.py +++ b/rally_openstack/contexts/cleanup/admin.py @@ -16,18 +16,18 @@ import sys from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager from rally_openstack.contexts.cleanup import base from rally_openstack import scenario +from rally_openstack.task import context @validation.add(name="check_cleanup_resources", admin_required=True) # NOTE(amaretskiy): Set order to run this just before UserCleanup @context.configure(name="admin_cleanup", platform="openstack", order=(sys.maxsize - 1), hidden=True) -class AdminCleanup(base.CleanupMixin, context.Context): +class AdminCleanup(base.CleanupMixin, context.OpenStackContext): """Context class for admin resources cleanup.""" def cleanup(self): diff --git a/rally_openstack/contexts/cleanup/user.py b/rally_openstack/contexts/cleanup/user.py index 32f61a95..32f7fd19 100644 --- a/rally_openstack/contexts/cleanup/user.py +++ b/rally_openstack/contexts/cleanup/user.py @@ -16,18 +16,18 @@ import sys from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager from rally_openstack.contexts.cleanup import base from rally_openstack import scenario +from rally_openstack.task import context @validation.add(name="check_cleanup_resources", admin_required=False) # NOTE(amaretskiy): Set maximum order to run this last @context.configure(name="cleanup", platform="openstack", order=sys.maxsize, hidden=True) -class UserCleanup(base.CleanupMixin, context.Context): +class UserCleanup(base.CleanupMixin, context.OpenStackContext): """Context class for user resources cleanup.""" def cleanup(self): diff --git a/rally_openstack/contexts/dataplane/heat.py b/rally_openstack/contexts/dataplane/heat.py index e3a65ca5..1bd6f7bf 100644 --- a/rally_openstack/contexts/dataplane/heat.py +++ b/rally_openstack/contexts/dataplane/heat.py @@ -18,12 +18,12 @@ import pkgutil from rally.common import utils as rutils from rally.common import validation from rally import exceptions -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack import osclients from rally_openstack.scenarios.heat import utils as heat_utils +from rally_openstack.task import context def get_data(filename_or_resource): @@ -34,7 +34,7 @@ def get_data(filename_or_resource): @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="heat_dataplane", platform="openstack", order=435) -class HeatDataplane(context.Context): +class HeatDataplane(context.OpenStackContext): """Context class for create stack by given template. This context will create stacks by given template for each tenant and @@ -125,8 +125,7 @@ class HeatDataplane(context.Context): with parameters.unlocked(): if "network_id" not in parameters: parameters["network_id"] = self._get_public_network_id() - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): for name, path in self.config.get("context_parameters", {}).items(): parameters[name] = self._get_context_parameter(user, diff --git a/rally_openstack/contexts/designate/zones.py b/rally_openstack/contexts/designate/zones.py index 31308932..f32dc43b 100644 --- a/rally_openstack/contexts/designate/zones.py +++ b/rally_openstack/contexts/designate/zones.py @@ -12,18 +12,17 @@ # License for the specific language governing permissions and limitations # under the License. -from rally.common import utils as rutils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack.scenarios.designate import utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="zones", platform="openstack", order=600) -class ZoneGenerator(context.Context): +class ZoneGenerator(context.OpenStackContext): """Context to add `zones_per_tenant` zones for each tenant.""" CONFIG_SCHEMA = { @@ -43,7 +42,7 @@ class ZoneGenerator(context.Context): } def setup(self): - for user, tenant_id in rutils.iterate_per_tenants( + for user, tenant_id in self._iterate_per_tenants( self.context["users"]): self.context["tenants"][tenant_id].setdefault("zones", []) designate_util = utils.DesignateScenario( diff --git a/rally_openstack/contexts/glance/images.py b/rally_openstack/contexts/glance/images.py index 59309bd4..54372432 100644 --- a/rally_openstack/contexts/glance/images.py +++ b/rally_openstack/contexts/glance/images.py @@ -16,12 +16,12 @@ from rally.common import cfg from rally.common import logging from rally.common import utils as rutils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack import osclients from rally_openstack.services.image import image +from rally_openstack.task import context CONF = cfg.CONF @@ -31,7 +31,7 @@ LOG = logging.getLogger(__name__) @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="images", platform="openstack", order=410) -class ImageGenerator(context.Context): +class ImageGenerator(context.OpenStackContext): """Uploads specified Glance images to every tenant.""" CONFIG_SCHEMA = { @@ -159,8 +159,7 @@ class ImageGenerator(context.Context): if "image_name" in self.config and images_per_tenant == 1: image_name = self.config["image_name"] - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): current_images = [] clients = osclients.Clients(user["credential"]) image_service = image.Image( diff --git a/rally_openstack/contexts/heat/stacks.py b/rally_openstack/contexts/heat/stacks.py index aa870fba..9f957640 100644 --- a/rally_openstack/contexts/heat/stacks.py +++ b/rally_openstack/contexts/heat/stacks.py @@ -13,18 +13,17 @@ # License for the specific language governing permissions and limitations # under the License. -from rally.common import utils as rutils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack.scenarios.heat import utils as heat_utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="stacks", platform="openstack", order=435) -class StackGenerator(context.Context): +class StackGenerator(context.OpenStackContext): """Context class for create temporary stacks with resources. Stack generator allows to generate arbitrary number of stacks for @@ -72,8 +71,7 @@ class StackGenerator(context.Context): def setup(self): template = self._prepare_stack_template( self.config["resources_per_stack"]) - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): heat_scenario = heat_utils.HeatScenario( {"user": user, "task": self.context["task"], "owner_id": self.context["owner_id"]}) diff --git a/rally_openstack/contexts/keystone/roles.py b/rally_openstack/contexts/keystone/roles.py index b7b4fd30..f3b8e11b 100644 --- a/rally_openstack/contexts/keystone/roles.py +++ b/rally_openstack/contexts/keystone/roles.py @@ -18,11 +18,11 @@ from rally.common import cfg from rally.common import logging from rally.common import validation from rally import exceptions -from rally.task import context from rally_openstack import consts from rally_openstack import osclients from rally_openstack.services.identity import identity +from rally_openstack.task import context LOG = logging.getLogger(__name__) @@ -32,7 +32,7 @@ CONF = cfg.CONF @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="roles", platform="openstack", order=330) -class RoleGenerator(context.Context): +class RoleGenerator(context.OpenStackContext): """Context class for assigning roles for users.""" CONFIG_SCHEMA = { diff --git a/rally_openstack/contexts/keystone/users.py b/rally_openstack/contexts/keystone/users.py index 329b3883..6513bfa0 100644 --- a/rally_openstack/contexts/keystone/users.py +++ b/rally_openstack/contexts/keystone/users.py @@ -20,15 +20,14 @@ import uuid from rally.common import broker from rally.common import cfg from rally.common import logging -from rally.common import utils as rutils from rally.common import validation from rally import exceptions -from rally.task import context from rally_openstack import consts from rally_openstack import credential from rally_openstack import osclients from rally_openstack.services.identity import identity +from rally_openstack.task import context from rally_openstack.wrappers import network @@ -44,7 +43,7 @@ USER_DOMAIN_DESCR = "ID of domain in which users will be created." @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="users", platform="openstack", order=100) -class UserGenerator(context.Context): +class UserGenerator(context.OpenStackContext): """Creates specified amount of keystone users and tenants.""" CONFIG_SCHEMA = { @@ -149,8 +148,7 @@ class UserGenerator(context.Context): LOG.debug("Security group context is disabled: %s" % msg) return - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): with logging.ExceptionLogger( LOG, "Unable to delete default security group"): uclients = osclients.Clients(user["credential"]) diff --git a/rally_openstack/contexts/magnum/ca_certs.py b/rally_openstack/contexts/magnum/ca_certs.py index ce01dd59..93ae43b2 100644 --- a/rally_openstack/contexts/magnum/ca_certs.py +++ b/rally_openstack/contexts/magnum/ca_certs.py @@ -16,15 +16,15 @@ import os from rally.common import utils as rutils from rally.common import validation -from rally.task import context from rally_openstack import consts from rally_openstack.scenarios.magnum import utils as magnum_utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="ca_certs", platform="openstack", order=490) -class CaCertGenerator(context.Context): +class CaCertGenerator(context.OpenStackContext): """Creates ca certs.""" CONFIG_SCHEMA = { @@ -70,8 +70,7 @@ class CaCertGenerator(context.Context): return result def setup(self): - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): magnum_scenario = magnum_utils.MagnumScenario({ "user": user, diff --git a/rally_openstack/contexts/magnum/cluster_templates.py b/rally_openstack/contexts/magnum/cluster_templates.py index c4e1e5b5..ed7b696d 100644 --- a/rally_openstack/contexts/magnum/cluster_templates.py +++ b/rally_openstack/contexts/magnum/cluster_templates.py @@ -12,18 +12,17 @@ # License for the specific language governing permissions and limitations # under the License. -from rally.common import utils as rutils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack.scenarios.magnum import utils as magnum_utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="cluster_templates", platform="openstack", order=470) -class ClusterTemplateGenerator(context.Context): +class ClusterTemplateGenerator(context.OpenStackContext): """Creates Magnum cluster template.""" CONFIG_SCHEMA = { @@ -102,8 +101,7 @@ class ClusterTemplateGenerator(context.Context): } def setup(self): - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): magnum_scenario = magnum_utils.MagnumScenario({ "user": user, diff --git a/rally_openstack/contexts/magnum/clusters.py b/rally_openstack/contexts/magnum/clusters.py index 11f4febd..34b2957b 100644 --- a/rally_openstack/contexts/magnum/clusters.py +++ b/rally_openstack/contexts/magnum/clusters.py @@ -12,19 +12,18 @@ # License for the specific language governing permissions and limitations # under the License. -from rally.common import utils as rutils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack.scenarios.magnum import utils as magnum_utils from rally_openstack.scenarios.nova import utils as nova_utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="clusters", platform="openstack", order=480) -class ClusterGenerator(context.Context): +class ClusterGenerator(context.OpenStackContext): """Creates specified amount of Magnum clusters.""" CONFIG_SCHEMA = { @@ -45,8 +44,7 @@ class ClusterGenerator(context.Context): DEFAULT_CONFIG = {"node_count": 1} def setup(self): - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): nova_scenario = nova_utils.NovaScenario({ "user": user, diff --git a/rally_openstack/contexts/manila/manila_security_services.py b/rally_openstack/contexts/manila/manila_security_services.py index 967fe199..9f88af27 100644 --- a/rally_openstack/contexts/manila/manila_security_services.py +++ b/rally_openstack/contexts/manila/manila_security_services.py @@ -14,14 +14,13 @@ # under the License. from rally.common import cfg -from rally.common import utils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts as rally_consts from rally_openstack.contexts.manila import consts from rally_openstack.scenarios.manila import utils as manila_utils +from rally_openstack.task import context CONF = cfg.CONF @@ -30,7 +29,7 @@ CONTEXT_NAME = consts.SECURITY_SERVICES_CONTEXT_NAME @validation.add("required_platform", platform="openstack", users=True) @context.configure(name=CONTEXT_NAME, platform="openstack", order=445) -class SecurityServices(context.Context): +class SecurityServices(context.OpenStackContext): """This context creates 'security services' for Manila project.""" CONFIG_SCHEMA = { @@ -65,7 +64,7 @@ class SecurityServices(context.Context): } def setup(self): - for user, tenant_id in (utils.iterate_per_tenants( + for user, tenant_id in (self._iterate_per_tenants( self.context.get("users", []))): self.context["tenants"][tenant_id][CONTEXT_NAME] = { "security_services": [], diff --git a/rally_openstack/contexts/manila/manila_share_networks.py b/rally_openstack/contexts/manila/manila_share_networks.py index b907aaa5..16d627e4 100644 --- a/rally_openstack/contexts/manila/manila_share_networks.py +++ b/rally_openstack/contexts/manila/manila_share_networks.py @@ -15,15 +15,14 @@ from rally.common import cfg from rally.common import logging -from rally.common import utils from rally.common import validation from rally import exceptions -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts as rally_consts from rally_openstack.contexts.manila import consts from rally_openstack.scenarios.manila import utils as manila_utils +from rally_openstack.task import context CONF = cfg.CONF @@ -63,7 +62,7 @@ users that does not satisfy criteria. @validation.add("required_platform", platform="openstack", users=True) @context.configure(name=CONTEXT_NAME, platform="openstack", order=450) -class ShareNetworks(context.Context): +class ShareNetworks(context.OpenStackContext): """This context creates share networks for Manila project.""" CONFIG_SCHEMA = { "type": "object", @@ -141,7 +140,7 @@ class ShareNetworks(context.Context): def _setup_for_autocreated_users(self): # Create share network for each network of tenant - for user, tenant_id in (utils.iterate_per_tenants( + for user, tenant_id in (self._iterate_per_tenants( self.context.get("users", []))): networks = self.context["tenants"][tenant_id].get("networks") manila_scenario = manila_utils.ManilaScenario({ diff --git a/rally_openstack/contexts/manila/manila_shares.py b/rally_openstack/contexts/manila/manila_shares.py index 9bab99e0..d1560a22 100644 --- a/rally_openstack/contexts/manila/manila_shares.py +++ b/rally_openstack/contexts/manila/manila_shares.py @@ -14,14 +14,13 @@ # under the License. from rally.common import cfg -from rally.common import utils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts as rally_consts from rally_openstack.contexts.manila import consts from rally_openstack.scenarios.manila import utils as manila_utils +from rally_openstack.task import context CONF = cfg.CONF CONTEXT_NAME = consts.SHARES_CONTEXT_NAME @@ -29,7 +28,7 @@ CONTEXT_NAME = consts.SHARES_CONTEXT_NAME @validation.add("required_platform", platform="openstack", users=True) @context.configure(name=CONTEXT_NAME, platform="openstack", order=455) -class Shares(context.Context): +class Shares(context.OpenStackContext): """This context creates shares for Manila project.""" CONFIG_SCHEMA = { @@ -78,8 +77,7 @@ class Shares(context.Context): tenant_ctxt["shares"].append(share.to_dict()) def setup(self): - for user, tenant_id in ( - utils.iterate_per_tenants(self.context.get("users", []))): + for user, tenant_id in self._iterate_per_tenants(): manila_scenario = manila_utils.ManilaScenario({ "task": self.task, "owner_id": self.context["owner_id"], diff --git a/rally_openstack/contexts/monasca/metrics.py b/rally_openstack/contexts/monasca/metrics.py index 49f07599..f9672665 100644 --- a/rally_openstack/contexts/monasca/metrics.py +++ b/rally_openstack/contexts/monasca/metrics.py @@ -14,15 +14,15 @@ from rally.common import utils as rutils from rally.common import validation -from rally.task import context from rally_openstack import consts from rally_openstack.scenarios.monasca import utils as monasca_utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="monasca_metrics", platform="openstack", order=510) -class MonascaMetricGenerator(context.Context): +class MonascaMetricGenerator(context.OpenStackContext): """Creates Monasca Metrics.""" CONFIG_SCHEMA = { @@ -85,8 +85,7 @@ class MonascaMetricGenerator(context.Context): "dimensions": self.config["dimensions"] } - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): scenario = monasca_utils.MonascaScenario( context={"user": user, "task": self.context["task"]} ) diff --git a/rally_openstack/contexts/murano/murano_environments.py b/rally_openstack/contexts/murano/murano_environments.py index 34f64b33..27f87d03 100644 --- a/rally_openstack/contexts/murano/murano_environments.py +++ b/rally_openstack/contexts/murano/murano_environments.py @@ -13,18 +13,17 @@ # License for the specific language governing permissions and limitations # under the License. -from rally.common import utils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack.scenarios.murano import utils as murano_utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="murano_environments", platform="openstack", order=402) -class EnvironmentGenerator(context.Context): +class EnvironmentGenerator(context.OpenStackContext): """Context class for creating murano environments.""" CONFIG_SCHEMA = { @@ -41,8 +40,7 @@ class EnvironmentGenerator(context.Context): } def setup(self): - for user, tenant_id in utils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): self.context["tenants"][tenant_id]["environments"] = [] for i in range(self.config["environments_per_tenant"]): murano_util = murano_utils.MuranoScenario( diff --git a/rally_openstack/contexts/murano/murano_packages.py b/rally_openstack/contexts/murano/murano_packages.py index 9fd28b81..edf88a51 100644 --- a/rally_openstack/contexts/murano/murano_packages.py +++ b/rally_openstack/contexts/murano/murano_packages.py @@ -16,20 +16,19 @@ import os import zipfile -from rally.common import utils from rally.common import validation from rally import exceptions -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack import osclients from rally_openstack.scenarios.murano import utils as mutils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="murano_packages", platform="openstack", order=401) -class PackageGenerator(context.Context): +class PackageGenerator(context.OpenStackContext): """Context class for uploading applications for murano.""" CONFIG_SCHEMA = { @@ -57,8 +56,7 @@ class PackageGenerator(context.Context): raise exceptions.ContextSetupFailure(msg=msg % pckg_path, ctx_name=self.get_name()) - for user, tenant_id in utils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): clients = osclients.Clients(user["credential"]) self.context["tenants"][tenant_id]["packages"] = [] if is_config_app_dir: diff --git a/rally_openstack/contexts/network/allow_ssh.py b/rally_openstack/contexts/network/allow_ssh.py index 01d4762e..5e5ee91c 100644 --- a/rally_openstack/contexts/network/allow_ssh.py +++ b/rally_openstack/contexts/network/allow_ssh.py @@ -14,11 +14,10 @@ # under the License. from rally.common import logging -from rally.common import utils from rally.common import validation -from rally.task import context from rally_openstack import osclients +from rally_openstack.task import context from rally_openstack.wrappers import network @@ -117,7 +116,7 @@ def _prepare_open_secgroup(credential, secgroup_name): @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="allow_ssh", platform="openstack", order=320) -class AllowSSH(context.Context): +class AllowSSH(context.OpenStackContext): """Sets up security groups for all users to access VM via SSH.""" def setup(self): @@ -138,8 +137,7 @@ class AllowSSH(context.Context): secgroup_name) def cleanup(self): - for user, tenant_id in utils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): with logging.ExceptionLogger( LOG, "Unable to delete security group: %s." diff --git a/rally_openstack/contexts/network/existing_network.py b/rally_openstack/contexts/network/existing_network.py index 45c81dfc..00c10494 100644 --- a/rally_openstack/contexts/network/existing_network.py +++ b/rally_openstack/contexts/network/existing_network.py @@ -12,18 +12,17 @@ # License for the specific language governing permissions and limitations # under the License. -from rally.common import utils from rally.common import validation -from rally.task import context from rally_openstack import consts from rally_openstack import osclients +from rally_openstack.task import context from rally_openstack.wrappers import network as network_wrapper @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="existing_network", platform="openstack", order=349) -class ExistingNetwork(context.Context): +class ExistingNetwork(context.OpenStackContext): """This context supports using existing networks in Rally. This context should be used on a deployment with existing users. @@ -36,8 +35,7 @@ class ExistingNetwork(context.Context): } def setup(self): - for user, tenant_id in utils.iterate_per_tenants( - self.context.get("users", [])): + for user, tenant_id in self._iterate_per_tenants(): net_wrapper = network_wrapper.wrap( osclients.Clients(user["credential"]), self, config=self.config) diff --git a/rally_openstack/contexts/network/networking_agents.py b/rally_openstack/contexts/network/networking_agents.py index 64ffb448..b5ee4401 100644 --- a/rally_openstack/contexts/network/networking_agents.py +++ b/rally_openstack/contexts/network/networking_agents.py @@ -14,17 +14,17 @@ from rally.common import logging from rally.common import validation -from rally.task import context from rally_openstack import consts from rally_openstack import osclients +from rally_openstack.task import context LOG = logging.getLogger(__name__) @validation.add("required_platform", platform="openstack", admin=True) @context.configure(name="networking_agents", platform="openstack", order=349) -class NetworkingAgents(context.Context): +class NetworkingAgents(context.OpenStackContext): """This context supports querying Neutron agents in Rally.""" CONFIG_SCHEMA = { diff --git a/rally_openstack/contexts/network/networks.py b/rally_openstack/contexts/network/networks.py index e7d201a6..08382189 100644 --- a/rally_openstack/contexts/network/networks.py +++ b/rally_openstack/contexts/network/networks.py @@ -14,12 +14,11 @@ # under the License. from rally.common import logging -from rally.common import utils from rally.common import validation -from rally.task import context from rally_openstack import consts from rally_openstack import osclients +from rally_openstack.task import context from rally_openstack.wrappers import network as network_wrapper @@ -30,7 +29,7 @@ LOG = logging.getLogger(__name__) @validation.add("required_platform", platform="openstack", admin=True, users=True) @context.configure(name="network", platform="openstack", order=350) -class Network(context.Context): +class Network(context.OpenStackContext): """Create networking resources. This creates networks for all tenants, and optionally creates @@ -107,8 +106,7 @@ class Network(context.Context): kwargs = {} if self.config["dns_nameservers"] is not None: kwargs["dns_nameservers"] = self.config["dns_nameservers"] - for user, tenant_id in (utils.iterate_per_tenants( - self.context.get("users", []))): + for user, tenant_id in self._iterate_per_tenants(): self.context["tenants"][tenant_id]["networks"] = [] for i in range(self.config["networks_per_tenant"]): # NOTE(amaretskiy): router_create_args and subnets_num take diff --git a/rally_openstack/contexts/network/routers.py b/rally_openstack/contexts/network/routers.py index 861d3424..c6251944 100644 --- a/rally_openstack/contexts/network/routers.py +++ b/rally_openstack/contexts/network/routers.py @@ -13,19 +13,18 @@ # License for the specific language governing permissions and limitations # under the License. -from rally.common import utils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack.scenarios.neutron import utils as neutron_utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", admin=True, users=True) @context.configure(name="router", platform="openstack", order=351) -class Router(context.Context): +class Router(context.OpenStackContext): """Create networking resources. This creates router for all tenants. @@ -96,8 +95,7 @@ class Router(context.Context): for parameter in parameters: if parameter in self.config: kwargs[parameter] = self.config[parameter] - for user, tenant_id in (utils.iterate_per_tenants( - self.context.get("users", []))): + for user, tenant_id in self._iterate_per_tenants(): self.context["tenants"][tenant_id]["routers"] = [] scenario = neutron_utils.NeutronScenario( context={"user": user, "task": self.context["task"], diff --git a/rally_openstack/contexts/neutron/lbaas.py b/rally_openstack/contexts/neutron/lbaas.py index 37ad6216..614c39a2 100644 --- a/rally_openstack/contexts/neutron/lbaas.py +++ b/rally_openstack/contexts/neutron/lbaas.py @@ -11,13 +11,11 @@ # under the License. from rally.common import logging -from rally.common import utils - from rally.common import validation -from rally.task import context from rally_openstack import consts from rally_openstack import osclients +from rally_openstack.task import context from rally_openstack.wrappers import network as network_wrapper @@ -27,7 +25,7 @@ LOG = logging.getLogger(__name__) @validation.add("required_platform", platform="openstack", admin=True, users=True) @context.configure(name="lbaas", platform="openstack", order=360) -class Lbaas(context.Context): +class Lbaas(context.OpenStackContext): """Creates a lb-pool for every subnet created in network context.""" CONFIG_SCHEMA = { "type": "object", @@ -64,8 +62,7 @@ class Lbaas(context.Context): return # Creates a lb-pool for every subnet created in network context. - for user, tenant_id in (utils.iterate_per_tenants( - self.context.get("users", []))): + for user, tenant_id in self._iterate_per_tenants(): for network in self.context["tenants"][tenant_id]["networks"]: for subnet in network.get("subnets", []): if self.config["lbaas_version"] == 1: diff --git a/rally_openstack/contexts/nova/flavors.py b/rally_openstack/contexts/nova/flavors.py index 63932d2a..61192335 100644 --- a/rally_openstack/contexts/nova/flavors.py +++ b/rally_openstack/contexts/nova/flavors.py @@ -16,11 +16,11 @@ from rally.common import logging from rally.common import utils as rutils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack import osclients +from rally_openstack.task import context LOG = logging.getLogger(__name__) @@ -28,7 +28,7 @@ LOG = logging.getLogger(__name__) @validation.add("required_platform", platform="openstack", admin=True) @context.configure(name="flavors", platform="openstack", order=340) -class FlavorsGenerator(context.Context): +class FlavorsGenerator(context.OpenStackContext): """Context creates a list of flavors.""" CONFIG_SCHEMA = { diff --git a/rally_openstack/contexts/nova/keypairs.py b/rally_openstack/contexts/nova/keypairs.py index e0663154..8b4d53df 100644 --- a/rally_openstack/contexts/nova/keypairs.py +++ b/rally_openstack/contexts/nova/keypairs.py @@ -14,15 +14,15 @@ # under the License. from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import osclients +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="keypair", platform="openstack", order=310) -class Keypair(context.Context): +class Keypair(context.OpenStackContext): """Create Nova KeyPair for each user.""" # NOTE(andreykurilin): "type" != "null", since we need to support backward diff --git a/rally_openstack/contexts/nova/servers.py b/rally_openstack/contexts/nova/servers.py index 15aa6757..567117f1 100755 --- a/rally_openstack/contexts/nova/servers.py +++ b/rally_openstack/contexts/nova/servers.py @@ -13,12 +13,11 @@ # under the License. from rally.common import logging -from rally.common import utils as rutils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack.scenarios.nova import utils as nova_utils +from rally_openstack.task import context from rally_openstack import types @@ -27,7 +26,7 @@ LOG = logging.getLogger(__name__) @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="servers", platform="openstack", order=430) -class ServerGenerator(context.Context): +class ServerGenerator(context.OpenStackContext): """Creates specified amount of Nova Servers per each tenant.""" CONFIG_SCHEMA = { @@ -105,8 +104,7 @@ class ServerGenerator(context.Context): flavor_id = types.Flavor(self.context).pre_process( resource_spec=flavor, config={}) - for iter_, (user, tenant_id) in enumerate(rutils.iterate_per_tenants( - self.context["users"])): + for iter_, (user, tenant_id) in enumerate(self._iterate_per_tenants()): LOG.debug("Booting servers for user tenant %s" % user["tenant_id"]) tmp_context = {"user": user, "tenant": self.context["tenants"][tenant_id], diff --git a/rally_openstack/contexts/quotas/quotas.py b/rally_openstack/contexts/quotas/quotas.py index a4e6fa8d..fe271220 100644 --- a/rally_openstack/contexts/quotas/quotas.py +++ b/rally_openstack/contexts/quotas/quotas.py @@ -15,7 +15,6 @@ from rally.common import logging from rally.common import validation -from rally.task import context from rally_openstack import consts from rally_openstack.contexts.quotas import cinder_quotas @@ -24,6 +23,7 @@ from rally_openstack.contexts.quotas import manila_quotas from rally_openstack.contexts.quotas import neutron_quotas from rally_openstack.contexts.quotas import nova_quotas from rally_openstack import osclients +from rally_openstack.task import context LOG = logging.getLogger(__name__) @@ -31,7 +31,7 @@ LOG = logging.getLogger(__name__) @validation.add("required_platform", platform="openstack", admin=True) @context.configure(name="quotas", platform="openstack", order=300) -class Quotas(context.Context): +class Quotas(context.OpenStackContext): """Sets OpenStack Tenants quotas.""" CONFIG_SCHEMA = { diff --git a/rally_openstack/contexts/sahara/sahara_cluster.py b/rally_openstack/contexts/sahara/sahara_cluster.py index 006ae5cc..6494fe49 100644 --- a/rally_openstack/contexts/sahara/sahara_cluster.py +++ b/rally_openstack/contexts/sahara/sahara_cluster.py @@ -14,15 +14,14 @@ # under the License. from rally.common import cfg -from rally.common import utils as rutils from rally.common import validation from rally import exceptions -from rally.task import context from rally.task import utils as bench_utils from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack.scenarios.sahara import utils +from rally_openstack.task import context CONF = cfg.CONF @@ -30,7 +29,7 @@ CONF = cfg.CONF @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="sahara_cluster", platform="openstack", order=441) -class SaharaCluster(context.Context): +class SaharaCluster(context.OpenStackContext): """Context class for setting up the Cluster an EDP job.""" CONFIG_SCHEMA = { @@ -105,8 +104,7 @@ class SaharaCluster(context.Context): wait_dict = {} - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): image_id = self.context["tenants"][tenant_id]["sahara"]["image"] diff --git a/rally_openstack/contexts/sahara/sahara_image.py b/rally_openstack/contexts/sahara/sahara_image.py index b18aecc1..eb916360 100644 --- a/rally_openstack/contexts/sahara/sahara_image.py +++ b/rally_openstack/contexts/sahara/sahara_image.py @@ -12,21 +12,20 @@ # License for the specific language governing permissions and limitations # under the License. -from rally.common import utils as rutils from rally.common import validation from rally import exceptions -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack import osclients from rally_openstack.scenarios.sahara import utils from rally_openstack.services.image import image as image_services +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="sahara_image", platform="openstack", order=440) -class SaharaImage(context.Context): +class SaharaImage(context.OpenStackContext): """Context class for adding and tagging Sahara images.""" CONFIG_SCHEMA = { @@ -103,13 +102,11 @@ class SaharaImage(context.Context): ) image_id = image_uuid - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): self.context["tenants"][tenant_id]["sahara"]["image"] = ( image_id) else: - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): image_id = self._create_image( hadoop_version=self.config["hadoop_version"], diff --git a/rally_openstack/contexts/sahara/sahara_input_data_sources.py b/rally_openstack/contexts/sahara/sahara_input_data_sources.py index fa0de223..ad819fd0 100644 --- a/rally_openstack/contexts/sahara/sahara_input_data_sources.py +++ b/rally_openstack/contexts/sahara/sahara_input_data_sources.py @@ -17,21 +17,20 @@ from urllib.parse import urlparse import requests -from rally.common import utils as rutils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack import osclients from rally_openstack.scenarios.sahara import utils from rally_openstack.scenarios.swift import utils as swift_utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="sahara_input_data_sources", platform="openstack", order=443) -class SaharaInputDataSources(context.Context): +class SaharaInputDataSources(context.OpenStackContext): """Context class for setting up Input Data Sources for an EDP job.""" CONFIG_SCHEMA = { @@ -70,8 +69,7 @@ class SaharaInputDataSources(context.Context): self.context["sahara"]["swift_objects"] = [] self.context["sahara"]["container_name"] = None - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): clients = osclients.Clients(user["credential"]) if self.config["input_type"] == "swift": self.setup_inputs_swift(clients, tenant_id, diff --git a/rally_openstack/contexts/sahara/sahara_job_binaries.py b/rally_openstack/contexts/sahara/sahara_job_binaries.py index 3e2970af..cece0ba2 100644 --- a/rally_openstack/contexts/sahara/sahara_job_binaries.py +++ b/rally_openstack/contexts/sahara/sahara_job_binaries.py @@ -15,20 +15,19 @@ import requests -from rally.common import utils as rutils from rally.common import validation from rally import exceptions -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack import osclients from rally_openstack.scenarios.sahara import utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="sahara_job_binaries", platform="openstack", order=442) -class SaharaJobBinaries(context.Context): +class SaharaJobBinaries(context.OpenStackContext): """Context class for setting up Job Binaries for an EDP job.""" CONFIG_SCHEMA = { @@ -77,8 +76,7 @@ class SaharaJobBinaries(context.Context): def setup(self): utils.init_sahara_context(self) - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): clients = osclients.Clients(user["credential"]) sahara = clients.sahara() diff --git a/rally_openstack/contexts/sahara/sahara_output_data_sources.py b/rally_openstack/contexts/sahara/sahara_output_data_sources.py index 4a5dbcac..89079b92 100644 --- a/rally_openstack/contexts/sahara/sahara_output_data_sources.py +++ b/rally_openstack/contexts/sahara/sahara_output_data_sources.py @@ -13,21 +13,20 @@ # License for the specific language governing permissions and limitations # under the License. -from rally.common import utils as rutils from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack import osclients from rally_openstack.scenarios.sahara import utils from rally_openstack.scenarios.swift import utils as swift_utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="sahara_output_data_sources", platform="openstack", order=444) -class SaharaOutputDataSources(context.Context): +class SaharaOutputDataSources(context.OpenStackContext): """Context class for setting up Output Data Sources for an EDP job.""" CONFIG_SCHEMA = { @@ -47,8 +46,7 @@ class SaharaOutputDataSources(context.Context): def setup(self): utils.init_sahara_context(self) - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): clients = osclients.Clients(user["credential"]) sahara = clients.sahara() diff --git a/rally_openstack/contexts/senlin/profiles.py b/rally_openstack/contexts/senlin/profiles.py index 8eb7b91f..38a8b32d 100644 --- a/rally_openstack/contexts/senlin/profiles.py +++ b/rally_openstack/contexts/senlin/profiles.py @@ -10,17 +10,16 @@ # License for the specific language governing permissions and limitations # under the License. -from rally.common import utils as rutils from rally.common import validation -from rally.task import context from rally_openstack import consts from rally_openstack.scenarios.senlin import utils as senlin_utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="profiles", platform="openstack", order=190) -class ProfilesGenerator(context.Context): +class ProfilesGenerator(context.OpenStackContext): """Context creates a temporary profile for Senlin test.""" CONFIG_SCHEMA = { @@ -44,8 +43,7 @@ class ProfilesGenerator(context.Context): def setup(self): """Create test profiles.""" - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): senlin_scenario = senlin_utils.SenlinScenario({ "user": user, @@ -57,8 +55,7 @@ class ProfilesGenerator(context.Context): def cleanup(self): """Delete created test profiles.""" - for user, tenant_id in rutils.iterate_per_tenants( - self.context["users"]): + for user, tenant_id in self._iterate_per_tenants(): senlin_scenario = senlin_utils.SenlinScenario({ "user": user, diff --git a/rally_openstack/contexts/swift/objects.py b/rally_openstack/contexts/swift/objects.py index 07f04f31..eba99dff 100644 --- a/rally_openstack/contexts/swift/objects.py +++ b/rally_openstack/contexts/swift/objects.py @@ -16,17 +16,18 @@ from rally.common import logging from rally.common import validation from rally import exceptions -from rally.task import context from rally_openstack import consts from rally_openstack.contexts.swift import utils as swift_utils +from rally_openstack.task import context LOG = logging.getLogger(__name__) @validation.add("required_platform", platform="openstack", users=True) @context.configure(name="swift_objects", platform="openstack", order=360) -class SwiftObjectGenerator(swift_utils.SwiftObjectMixin, context.Context): +class SwiftObjectGenerator(swift_utils.SwiftObjectMixin, + context.OpenStackContext): """Create containers and objects in each tenant.""" CONFIG_SCHEMA = { "type": "object", @@ -67,8 +68,7 @@ class SwiftObjectGenerator(swift_utils.SwiftObjectMixin, context.Context): containers_num = len(self.context["tenants"]) * containers_per_tenant LOG.debug("Creating %d containers using %d threads." % (containers_num, threads)) - containers_count = len(self._create_containers(self.context, - containers_per_tenant, + containers_count = len(self._create_containers(containers_per_tenant, threads)) if containers_count != containers_num: raise exceptions.ContextSetupFailure( @@ -81,8 +81,7 @@ class SwiftObjectGenerator(swift_utils.SwiftObjectMixin, context.Context): objects_num = containers_num * objects_per_container LOG.debug("Creating %d objects using %d threads." % (objects_num, threads)) - objects_count = len(self._create_objects(self.context, - objects_per_container, + objects_count = len(self._create_objects(objects_per_container, self.config["object_size"], threads)) if objects_count != objects_num: @@ -96,5 +95,5 @@ class SwiftObjectGenerator(swift_utils.SwiftObjectMixin, context.Context): """Delete containers and objects, using the broker pattern.""" threads = self.config["resource_management_workers"] - self._delete_objects(self.context, threads) - self._delete_containers(self.context, threads) + self._delete_objects(threads) + self._delete_containers(threads) diff --git a/rally_openstack/contexts/swift/utils.py b/rally_openstack/contexts/swift/utils.py index a1bf5d0f..d787900e 100644 --- a/rally_openstack/contexts/swift/utils.py +++ b/rally_openstack/contexts/swift/utils.py @@ -16,7 +16,6 @@ import tempfile from rally.common import broker -from rally.common import utils as rutils from rally_openstack.scenarios.swift import utils as swift_utils @@ -24,10 +23,9 @@ from rally_openstack.scenarios.swift import utils as swift_utils class SwiftObjectMixin(object): """Mix-in method for Swift Object Context.""" - def _create_containers(self, context, containers_per_tenant, threads): + def _create_containers(self, containers_per_tenant, threads): """Create containers and store results in Rally context. - :param context: dict, Rally context environment :param containers_per_tenant: int, number of containers to create per tenant :param threads: int, number of threads to use for broker pattern @@ -37,18 +35,18 @@ class SwiftObjectMixin(object): containers = [] def publish(queue): - for user, tenant_id in (rutils.iterate_per_tenants( - context.get("users", []))): - context["tenants"][tenant_id]["containers"] = [] + for user, tenant_id in self._iterate_per_tenants(): + self.context["tenants"][tenant_id]["containers"] = [] for i in range(containers_per_tenant): - args = (user, context["tenants"][tenant_id]["containers"]) + args = (user, + self.context["tenants"][tenant_id]["containers"]) queue.append(args) def consume(cache, args): user, tenant_containers = args if user["id"] not in cache: cache[user["id"]] = swift_utils.SwiftScenario( - {"user": user, "task": context.get("task", {})}) + {"user": user, "task": self.context.get("task", {})}) container_name = cache[user["id"]]._create_container() tenant_containers.append({"user": user, "container": container_name, @@ -59,11 +57,9 @@ class SwiftObjectMixin(object): return containers - def _create_objects(self, context, objects_per_container, object_size, - threads): + def _create_objects(self, objects_per_container, object_size, threads): """Create objects and store results in Rally context. - :param context: dict, Rally context environment :param objects_per_container: int, number of objects to create per container :param object_size: int, size of created swift objects in byte @@ -78,9 +74,9 @@ class SwiftObjectMixin(object): dummy_file.truncate(object_size) def publish(queue): - for tenant_id in context["tenants"]: - containers = context["tenants"][tenant_id]["containers"] - for container in containers: + for tenant_id in self.context["tenants"]: + items = self.context["tenants"][tenant_id]["containers"] + for container in items: for i in range(objects_per_container): queue.append(container) @@ -88,7 +84,7 @@ class SwiftObjectMixin(object): user = container["user"] if user["id"] not in cache: cache[user["id"]] = swift_utils.SwiftScenario( - {"user": user, "task": context.get("task", {})}) + {"user": user, "task": self.context.get("task", {})}) dummy_file.seek(0) object_name = cache[user["id"]]._upload_object( container["container"], @@ -101,15 +97,14 @@ class SwiftObjectMixin(object): return objects - def _delete_containers(self, context, threads): + def _delete_containers(self, threads): """Delete containers created by Swift context and update Rally context. - :param context: dict, Rally context environment :param threads: int, number of threads to use for broker pattern """ def publish(queue): - for tenant_id in context["tenants"]: - containers = context["tenants"][tenant_id]["containers"] + for tenant_id in self.context["tenants"]: + containers = self.context["tenants"][tenant_id]["containers"] for container in containers[:]: args = container, containers queue.append(args) @@ -119,21 +114,20 @@ class SwiftObjectMixin(object): user = container["user"] if user["id"] not in cache: cache[user["id"]] = swift_utils.SwiftScenario( - {"user": user, "task": context.get("task", {})}) + {"user": user, "task": self.context.get("task", {})}) cache[user["id"]]._delete_container(container["container"]) tenant_containers.remove(container) broker.run(publish, consume, threads) - def _delete_objects(self, context, threads): + def _delete_objects(self, threads): """Delete objects created by Swift context and update Rally context. - :param context: dict, Rally context environment :param threads: int, number of threads to use for broker pattern """ def publish(queue): - for tenant_id in context["tenants"]: - containers = context["tenants"][tenant_id]["containers"] + for tenant_id in self.context["tenants"]: + containers = self.context["tenants"][tenant_id]["containers"] for container in containers: for object_name in container["objects"][:]: args = object_name, container @@ -144,7 +138,7 @@ class SwiftObjectMixin(object): user = container["user"] if user["id"] not in cache: cache[user["id"]] = swift_utils.SwiftScenario( - {"user": user, "task": context.get("task", {})}) + {"user": user, "task": self.context.get("task", {})}) cache[user["id"]]._delete_object(container["container"], object_name) container["objects"].remove(object_name) diff --git a/rally_openstack/contexts/vm/custom_image.py b/rally_openstack/contexts/vm/custom_image.py index d0ef71fd..5c4ce435 100644 --- a/rally_openstack/contexts/vm/custom_image.py +++ b/rally_openstack/contexts/vm/custom_image.py @@ -18,19 +18,20 @@ import abc from rally.common import broker from rally.common import logging from rally.common import utils -from rally.task import context from rally_openstack import consts from rally_openstack import osclients from rally_openstack.scenarios.vm import vmtasks from rally_openstack.services.image import image +from rally_openstack.task import context from rally_openstack import types LOG = logging.getLogger(__name__) -class BaseCustomImageGenerator(context.Context, metaclass=abc.ABCMeta): +class BaseCustomImageGenerator(context.OpenStackContext, + metaclass=abc.ABCMeta): """Base plugin for the contexts providing customized image with. Every context plugin for the specific customization must implement @@ -131,8 +132,7 @@ class BaseCustomImageGenerator(context.Context, metaclass=abc.ABCMeta): tenant["custom_image"] = custom_image else: def publish(queue): - users = self.context.get("users", []) - for user, tenant_id in utils.iterate_per_tenants(users): + for user, tenant_id in self._iterate_per_tenants(): queue.append((user, tenant_id)) def consume(cache, args): diff --git a/rally_openstack/contexts/vm/image_command_customizer.py b/rally_openstack/contexts/vm/image_command_customizer.py index 97521a13..356a69da 100644 --- a/rally_openstack/contexts/vm/image_command_customizer.py +++ b/rally_openstack/contexts/vm/image_command_customizer.py @@ -17,10 +17,10 @@ import copy from rally.common import validation from rally import exceptions -import rally.task.context as context from rally_openstack.contexts.vm import custom_image from rally_openstack.scenarios.vm import utils as vm_utils +from rally_openstack.task import context @validation.add("required_platform", platform="openstack", users=True) diff --git a/rally_openstack/contexts/watcher/audit_templates.py b/rally_openstack/contexts/watcher/audit_templates.py index c45dc878..7a684e0c 100644 --- a/rally_openstack/contexts/watcher/audit_templates.py +++ b/rally_openstack/contexts/watcher/audit_templates.py @@ -15,17 +15,17 @@ import random from rally.common import validation -from rally.task import context from rally_openstack.cleanup import manager as resource_manager from rally_openstack import consts from rally_openstack.scenarios.watcher import utils as watcher_utils +from rally_openstack.task import context from rally_openstack import types @validation.add("required_platform", platform="openstack", admin=True) @context.configure(name="audit_templates", platform="openstack", order=550) -class AuditTemplateGenerator(context.Context): +class AuditTemplateGenerator(context.OpenStackContext): """Creates Watcher audit templates for tenants.""" CONFIG_SCHEMA = { diff --git a/rally_openstack/task/__init__.py b/rally_openstack/task/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/rally_openstack/task/context.py b/rally_openstack/task/context.py new file mode 100644 index 00000000..94458f3f --- /dev/null +++ b/rally_openstack/task/context.py @@ -0,0 +1,37 @@ +# 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 functools + +from rally.task import context + + +configure = functools.partial(context.configure, platform="openstack") + + +class OpenStackContext(context.Context): + """A base class for all OpenStack context classes.""" + + def _iterate_per_tenants(self, users=None): + """Iterate of a single arbitrary user from each tenant + + :type users: list of users + :return: iterator of a single user from each tenant + """ + if users is None: + users = self.context.get("users", []) + + processed_tenants = set() + for user in users: + if user["tenant_id"] not in processed_tenants: + processed_tenants.add(user["tenant_id"]) + yield user, user["tenant_id"] diff --git a/tests/unit/contexts/keystone/test_users.py b/tests/unit/contexts/keystone/test_users.py index abc7cfc0..43762070 100644 --- a/tests/unit/contexts/keystone/test_users.py +++ b/tests/unit/contexts/keystone/test_users.py @@ -292,10 +292,8 @@ class UserGeneratorForNewUsersTestCase(test.ScenarioTestCase): net_wrapper.supports_extension.assert_called_once_with( "security-group") - @mock.patch("rally.common.utils.iterate_per_tenants") @mock.patch("%s.network" % CTX) - def test__remove_default_security_group( - self, mock_network, mock_iterate_per_tenants): + def test__remove_default_security_group(self, mock_network): net_wrapper = mock.Mock(SERVICE_IMPL=consts.Service.NEUTRON) net_wrapper.supports_extension.return_value = (True, None) mock_network.wrap.return_value = net_wrapper @@ -317,20 +315,22 @@ class UserGeneratorForNewUsersTestCase(test.ScenarioTestCase): user_clients = [user1, user2] self.osclients.Clients.side_effect = [admin_clients] + user_clients - mock_iterate_per_tenants.return_value = [ - (mock.MagicMock(), "t1"), - (mock.MagicMock(), "t2")] + user_generator._iterate_per_tenants = mock.MagicMock( + return_value=[ + (mock.MagicMock(), "t1"), + (mock.MagicMock(), "t2") + ] + ) user_generator._remove_default_security_group() mock_network.wrap.assert_called_once_with(admin_clients, user_generator) - mock_iterate_per_tenants.assert_called_once_with( - user_generator.context["users"]) + user_generator._iterate_per_tenants.assert_called_once_with() expected = [mock.call(user_generator.credential)] + [ mock.call(u["credential"]) - for u, t in mock_iterate_per_tenants.return_value] + for u, t in user_generator._iterate_per_tenants.return_value] self.osclients.Clients.assert_has_calls(expected, any_order=True) user_net = user1.neutron.return_value diff --git a/tests/unit/contexts/neutron/test_existing_network.py b/tests/unit/contexts/network/test_existing_network.py similarity index 100% rename from tests/unit/contexts/neutron/test_existing_network.py rename to tests/unit/contexts/network/test_existing_network.py diff --git a/tests/unit/contexts/network/test_network.py b/tests/unit/contexts/network/test_network.py index 82bfcd6f..e877843a 100644 --- a/tests/unit/contexts/network/test_network.py +++ b/tests/unit/contexts/network/test_network.py @@ -66,20 +66,20 @@ class NetworkTestCase(test.TestCase): {"dns_nameservers": ["1.2.3.4", "5.6.7.8"]}) @ddt.unpack @mock.patch(NET + "wrap") - @mock.patch("rally_openstack.contexts.network.networks.utils") @mock.patch("rally_openstack.osclients.Clients") - def test_setup(self, mock_clients, mock_utils, mock_wrap, **dns_kwargs): - mock_utils.iterate_per_tenants.return_value = [ - ("foo_user", "foo_tenant"), - ("bar_user", "bar_tenant")] + def test_setup(self, mock_clients, mock_wrap, **dns_kwargs): mock_create = mock.Mock(side_effect=lambda t, **kw: t + "-net") - mock_utils.generate_random_name = mock.Mock() mock_wrap.return_value = mock.Mock(create_network=mock_create) nets_per_tenant = 2 net_context = network_context.Network( self.get_context(networks_per_tenant=nets_per_tenant, network_create_args={"fakearg": "fake"}, **dns_kwargs)) + net_context._iterate_per_tenants = mock.MagicMock( + return_value=[ + ("foo_user", "foo_tenant"), + ("bar_user", "bar_tenant")] + ) net_context.setup() @@ -91,11 +91,10 @@ class NetworkTestCase(test.TestCase): subnets_num=1, network_create_args={"fakearg": "fake"}, router_create_args={"external": True}, **dns_kwargs) - for user, tenant in mock_utils.iterate_per_tenants.return_value] + for user, tenant in net_context._iterate_per_tenants.return_value] mock_create.assert_has_calls(create_calls) - mock_utils.iterate_per_tenants.assert_called_once_with( - net_context.context["users"]) + net_context._iterate_per_tenants.assert_called_once_with() expected_networks = ["bar_tenant-net", "foo_tenant-net"] * nets_per_tenant actual_networks = [] diff --git a/tests/unit/contexts/neutron/test_networking_agents.py b/tests/unit/contexts/network/test_networking_agents.py similarity index 100% rename from tests/unit/contexts/neutron/test_networking_agents.py rename to tests/unit/contexts/network/test_networking_agents.py diff --git a/tests/unit/contexts/neutron/test_lbaas.py b/tests/unit/contexts/neutron/test_lbaas.py index 97321e5a..8e8d554d 100644 --- a/tests/unit/contexts/neutron/test_lbaas.py +++ b/tests/unit/contexts/neutron/test_lbaas.py @@ -57,12 +57,8 @@ class LbaasTestCase(test.TestCase): "LEAST_CONNECTIONS") @mock.patch(NET + "wrap") - @mock.patch("rally_openstack.contexts.neutron.lbaas.utils") @mock.patch("rally_openstack.osclients.Clients") - def test_setup_with_lbaas(self, mock_clients, mock_utils, mock_wrap): - mock_utils.iterate_per_tenants.return_value = [ - ("foo_user", "foo_tenant"), - ("bar_user", "bar_tenant")] + def test_setup_with_lbaas(self, mock_clients, mock_wrap): foo_net = {"id": "foo_net", "tenant_id": "foo_tenant", "subnets": ["foo_subnet"], @@ -83,10 +79,17 @@ class LbaasTestCase(test.TestCase): net_wrapper = mock_wrap(mock_clients.return_value) net_wrapper.supports_extension.return_value = (True, None) fake_args = {"lbaas_version": 1} + lb_context = lbaas_context.Lbaas(self.get_context(**fake_args)) + lb_context._iterate_per_tenants = mock.MagicMock( + return_value=[ + ("foo_user", "foo_tenant"), + ("bar_user", "bar_tenant")] + ) + lb_context.setup() - mock_utils.iterate_per_tenants.assert_called_once_with( - lb_context.context["users"]) + + lb_context._iterate_per_tenants.assert_called_once_with() net_wrapper.supports_extension.assert_called_once_with("lbaas") for tenant_id, tenant_ctx in ( sorted(lb_context.context["tenants"].items())): @@ -95,33 +98,35 @@ class LbaasTestCase(test.TestCase): self.assertEqual(expected_net, actual_net) @mock.patch(NET + "wrap") - @mock.patch("rally_openstack.contexts.neutron.lbaas.utils") @mock.patch("rally_openstack.osclients.Clients") - def test_setup_with_no_lbaas(self, mock_clients, mock_utils, mock_wrap): - mock_utils.iterate_per_tenants.return_value = [ - ("bar_user", "bar_tenant")] + def test_setup_with_no_lbaas(self, mock_clients, mock_wrap): mock_create = mock.Mock(side_effect=lambda t, **kw: t + "-net") mock_wrap.return_value = mock.Mock(create_v1_pool=mock_create) fake_args = {"lbaas_version": 1} lb_context = lbaas_context.Lbaas(self.get_context(**fake_args)) net_wrapper = mock_wrap(mock_clients.return_value) net_wrapper.supports_extension.return_value = (False, None) + + lb_context._iterate_per_tenants = mock.MagicMock( + return_value=[("bar_user", "bar_tenant")] + ) lb_context.setup() - mock_utils.iterate_per_tenants.assert_not_called() + + lb_context._iterate_per_tenants.assert_not_called() net_wrapper.supports_extension.assert_called_once_with("lbaas") assert not net_wrapper.create_v1_pool.called @mock.patch(NET + "wrap") - @mock.patch("rally_openstack.contexts.neutron.lbaas.utils") @mock.patch("rally_openstack.osclients.Clients") - def test_setup_with_lbaas_version_not_one(self, mock_clients, - mock_utils, mock_wrap): - mock_utils.iterate_per_tenants.return_value = [ - ("bar_user", "bar_tenant")] + def test_setup_with_lbaas_version_not_one(self, mock_clients, mock_wrap): mock_create = mock.Mock(side_effect=lambda t, **kw: t + "-net") mock_wrap.return_value = mock.Mock(create_v1_pool=mock_create) fake_args = {"lbaas_version": 2} + lb_context = lbaas_context.Lbaas(self.get_context(**fake_args)) + lb_context._iterate_per_tenants = mock.MagicMock( + return_value=[("bar_user", "bar_tenant")] + ) net_wrapper = mock_wrap(mock_clients.return_value) net_wrapper.supports_extension.return_value = (True, None) self.assertRaises(NotImplementedError, lb_context.setup) diff --git a/tests/unit/contexts/swift/test_utils.py b/tests/unit/contexts/swift/test_utils.py index 4b339755..5d5a4c5f 100644 --- a/tests/unit/contexts/swift/test_utils.py +++ b/tests/unit/contexts/swift/test_utils.py @@ -16,9 +16,21 @@ from unittest import mock from rally_openstack.contexts.swift import utils +from rally_openstack.task import context from tests.unit import test +class SwiftContext(utils.SwiftObjectMixin, context.OpenStackContext): + def __init__(self, context): + self.context = context + + def setup(self): + pass + + def cleanup(self): + pass + + class SwiftObjectMixinTestCase(test.TestCase): @mock.patch("rally_openstack.osclients.Clients") @@ -38,9 +50,8 @@ class SwiftObjectMixinTestCase(test.TestCase): ] }) - mixin = utils.SwiftObjectMixin() - containers = mixin._create_containers(context, containers_per_tenant, - 15) + mixin = SwiftContext(context) + containers = mixin._create_containers(containers_per_tenant, 15) self.assertEqual(tenants * containers_per_tenant, len(containers)) for index, container in enumerate(sorted(containers)): @@ -87,9 +98,8 @@ class SwiftObjectMixinTestCase(test.TestCase): } }) - mixin = utils.SwiftObjectMixin() - objects_list = mixin._create_objects(context, objects_per_container, - 1024, 25) + mixin = SwiftContext(context) + objects_list = mixin._create_objects(objects_per_container, 1024, 25) self.assertEqual( tenants * containers_per_tenant * objects_per_container, @@ -133,8 +143,7 @@ class SwiftObjectMixinTestCase(test.TestCase): } }) - mixin = utils.SwiftObjectMixin() - mixin._delete_containers(context, 1) + SwiftContext(context)._delete_containers(1) mock_swift = mock_clients.return_value.swift.return_value expected_containers = ["c1", "c2"] @@ -173,8 +182,7 @@ class SwiftObjectMixinTestCase(test.TestCase): } }) - mixin = utils.SwiftObjectMixin() - mixin._delete_objects(context, 1) + SwiftContext(context)._delete_objects(1) mock_swift = mock_clients.return_value.swift.return_value expected_objects = [("c1", "o1"), ("c1", "o2"), ("c1", "o3"), diff --git a/tests/unit/task/__init__.py b/tests/unit/task/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit/task/test_context.py b/tests/unit/task/test_context.py new file mode 100644 index 00000000..afee8acd --- /dev/null +++ b/tests/unit/task/test_context.py @@ -0,0 +1,47 @@ +# Copyright 2013: 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_openstack.task import context +from tests.unit import test + + +class TenantIteratorTestCase(test.TestCase): + + def test__iterate_per_tenant(self): + + class DummyContext(context.OpenStackContext): + def __init__(self, ctx): + self.context = ctx + + def setup(self): + pass + + def cleanup(self): + pass + + users = [] + tenants_count = 2 + users_per_tenant = 5 + for tenant_id in range(tenants_count): + for user_id in range(users_per_tenant): + users.append({"id": str(user_id), + "tenant_id": str(tenant_id)}) + + expected_result = [ + ({"id": "0", "tenant_id": str(i)}, str(i)) for i in range( + tenants_count)] + real_result = [ + i for i in DummyContext({"users": users})._iterate_per_tenants()] + + self.assertEqual(expected_result, real_result)