From d9491739fd907db660b70985d14c663f07ab5725 Mon Sep 17 00:00:00 2001 From: Anton Studenov Date: Mon, 3 Apr 2017 17:16:11 +0300 Subject: [PATCH] [cleanup] Use workload uuid in resource names * Added superclass where it was missing. Change-Id: I8460737386166f8eda2cd1665592c490b369f932 --- rally/common/utils.py | 11 ++++--- .../openstack/context/cinder/volumes.py | 2 +- .../openstack/context/cleanup/admin.py | 2 +- .../plugins/openstack/context/cleanup/user.py | 2 +- .../openstack/context/dataplane/heat.py | 7 ++-- .../openstack/context/designate/zones.py | 5 +-- .../plugins/openstack/context/ec2/servers.py | 8 +++-- .../openstack/context/glance/images.py | 2 +- .../plugins/openstack/context/heat/stacks.py | 5 +-- .../context/magnum/cluster_templates.py | 13 ++++++-- .../openstack/context/magnum/clusters.py | 5 ++- .../manila/manila_security_services.py | 4 ++- .../openstack/context/manila/manila_shares.py | 4 ++- .../context/murano/murano_environments.py | 5 ++- .../context/murano/murano_packages.py | 6 ++-- .../openstack/context/nova/keypairs.py | 2 +- .../plugins/openstack/context/nova/servers.py | 3 +- .../context/sahara/sahara_cluster.py | 5 +-- .../openstack/context/sahara/sahara_image.py | 2 +- .../sahara/sahara_input_data_sources.py | 19 ++++++----- .../sahara/sahara_output_data_sources.py | 12 ++++--- .../context/watcher/audit_templates.py | 5 ++- rally/task/context.py | 5 +++ rally/task/engine.py | 6 ++-- rally/task/scenario.py | 5 +++ .../openstack/context/cinder/test_volumes.py | 4 +-- .../openstack/context/designate/test_zones.py | 2 +- .../openstack/context/ec2/test_servers.py | 3 +- .../openstack/context/glance/test_images.py | 2 +- .../openstack/context/heat/test_stacks.py | 2 +- .../context/magnum/test_cluster_templates.py | 16 ++++++++-- .../openstack/context/magnum/test_clusters.py | 5 ++- .../manila/test_manila_security_services.py | 8 ++++- .../context/manila/test_manila_shares.py | 5 ++- .../murano/test_murano_environments.py | 9 ++++-- .../context/murano/test_murano_packages.py | 10 +++--- .../openstack/context/nova/test_servers.py | 2 +- .../context/sahara/test_sahara_cluster.py | 2 +- .../context/sahara/test_sahara_image.py | 2 +- .../sahara/test_sahara_input_data_sources.py | 32 ++++++++++++------- .../sahara/test_sahara_output_data_sources.py | 17 ++++++---- .../context/watcher/test_audit_templates.py | 5 ++- tests/unit/task/test_context.py | 11 +++++++ tests/unit/task/test_engine.py | 6 ++-- tests/unit/task/test_scenario.py | 10 ++++++ tests/unit/test.py | 1 + 46 files changed, 209 insertions(+), 90 deletions(-) diff --git a/rally/common/utils.py b/rally/common/utils.py index 439dfb1aa4..cb488b1f84 100644 --- a/rally/common/utils.py +++ b/rally/common/utils.py @@ -309,6 +309,12 @@ class RandomNameGeneratorMixin(object): finally: random.seed() + def get_owner_id(self): + if hasattr(self, "task"): + return self.task["uuid"] + elif hasattr(self, "verification"): + return self.verification["uuid"] + def generate_random_name(self): """Generate pseudo-random resource name for scenarios. @@ -323,10 +329,7 @@ class RandomNameGeneratorMixin(object): :returns: str, pseudo-random name """ - if hasattr(self, "task"): - task_id = self.task["uuid"] - elif hasattr(self, "verification"): - task_id = self.verification["uuid"] + task_id = self.get_owner_id() match = self._resource_name_placeholder_re.match( self.RESOURCE_NAME_FORMAT) diff --git a/rally/plugins/openstack/context/cinder/volumes.py b/rally/plugins/openstack/context/cinder/volumes.py index e407dcbed4..1dba40d6b0 100644 --- a/rally/plugins/openstack/context/cinder/volumes.py +++ b/rally/plugins/openstack/context/cinder/volumes.py @@ -85,4 +85,4 @@ class VolumeGenerator(context.Context): users=self.context.get("users", []), api_versions=self.context["config"].get("api_versions"), superclass=self.__class__, - task_id=self.context["task"]["uuid"]) + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/cleanup/admin.py b/rally/plugins/openstack/context/cleanup/admin.py index 1f7bd4f53f..af40279e0f 100644 --- a/rally/plugins/openstack/context/cleanup/admin.py +++ b/rally/plugins/openstack/context/cleanup/admin.py @@ -52,4 +52,4 @@ class AdminCleanup(base.CleanupMixin, context.Context): users=self.context.get("users", []), api_versions=self.context["config"].get("api_versions"), superclass=scenario.OpenStackScenario, - task_id=self.context["task"]["uuid"]) + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/cleanup/user.py b/rally/plugins/openstack/context/cleanup/user.py index d8b4a96698..692210d2c8 100644 --- a/rally/plugins/openstack/context/cleanup/user.py +++ b/rally/plugins/openstack/context/cleanup/user.py @@ -51,5 +51,5 @@ class UserCleanup(base.CleanupMixin, context.Context): users=self.context.get("users", []), api_versions=self.context["config"].get("api_versions"), superclass=scenario.OpenStackScenario, - task_id=self.context["task"]["uuid"] + task_id=self.get_owner_id() ) diff --git a/rally/plugins/openstack/context/dataplane/heat.py b/rally/plugins/openstack/context/dataplane/heat.py index 8e87963191..829e0449df 100644 --- a/rally/plugins/openstack/context/dataplane/heat.py +++ b/rally/plugins/openstack/context/dataplane/heat.py @@ -134,7 +134,8 @@ class HeatDataplane(context.Context): if "key_name" not in parameters: parameters["key_name"] = user["keypair"]["name"] heat_scenario = heat_utils.HeatScenario( - {"user": user, "task": self.context["task"]}) + {"user": user, "task": self.context["task"], + "owner_id": self.context["owner_id"]}) self.context["tenants"][tenant_id]["stack_dataplane"] = [] for i in range(self.config["stacks_per_tenant"]): stack = heat_scenario._create_stack(template, files=files, @@ -146,4 +147,6 @@ class HeatDataplane(context.Context): @logging.log_task_wrapper(LOG.info, _("Exit context: `HeatDataplane`")) def cleanup(self): resource_manager.cleanup(names=["heat.stacks"], - users=self.context.get("users", [])) + users=self.context.get("users", []), + superclass=heat_utils.HeatScenario, + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/designate/zones.py b/rally/plugins/openstack/context/designate/zones.py index 53c50be20c..8b78586a2d 100644 --- a/rally/plugins/openstack/context/designate/zones.py +++ b/rally/plugins/openstack/context/designate/zones.py @@ -51,7 +51,8 @@ class ZoneGenerator(context.Context): self.context["tenants"][tenant_id].setdefault("zones", []) designate_util = utils.DesignateScenario( {"user": user, - "task": self.context["task"]}) + "task": self.context["task"], + "owner_id": self.context["owner_id"]}) for i in range(self.config["zones_per_tenant"]): zone = designate_util._create_zone() self.context["tenants"][tenant_id]["zones"].append(zone) @@ -61,4 +62,4 @@ class ZoneGenerator(context.Context): resource_manager.cleanup(names=["designate.zones"], users=self.context.get("users", []), superclass=utils.DesignateScenario, - task_id=self.context["task"]["uuid"]) + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/ec2/servers.py b/rally/plugins/openstack/context/ec2/servers.py index d35314a86c..8fb49be4f6 100644 --- a/rally/plugins/openstack/context/ec2/servers.py +++ b/rally/plugins/openstack/context/ec2/servers.py @@ -75,8 +75,10 @@ class EC2ServerGenerator(context.Context): self.context["users"]): LOG.debug("Booting servers for tenant %s " % (user["tenant_id"])) - user_clients = osclients.Clients(user["credential"]) - ec2_scenario = ec2_utils.EC2Scenario(clients=user_clients) + ec2_scenario = ec2_utils.EC2Scenario({ + "user": user, + "task": self.context["task"], + "owner_id": self.context["owner_id"]}) LOG.debug( "Calling _boot_servers with " @@ -97,4 +99,4 @@ class EC2ServerGenerator(context.Context): resource_manager.cleanup(names=["ec2.servers"], users=self.context.get("users", []), superclass=ec2_utils.EC2Scenario, - task_id=self.context["task"]["uuid"]) + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/glance/images.py b/rally/plugins/openstack/context/glance/images.py index 5a36b7dbe8..5a2c63cee5 100644 --- a/rally/plugins/openstack/context/glance/images.py +++ b/rally/plugins/openstack/context/glance/images.py @@ -175,4 +175,4 @@ class ImageGenerator(context.Context): api_versions=self.context["config"].get( "api_versions"), superclass=self.__class__, - task_id=self.context["task"]["uuid"]) + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/heat/stacks.py b/rally/plugins/openstack/context/heat/stacks.py index 826c521368..9c10fb5632 100644 --- a/rally/plugins/openstack/context/heat/stacks.py +++ b/rally/plugins/openstack/context/heat/stacks.py @@ -77,7 +77,8 @@ class StackGenerator(context.Context): for user, tenant_id in rutils.iterate_per_tenants( self.context["users"]): heat_scenario = heat_utils.HeatScenario( - {"user": user, "task": self.context["task"]}) + {"user": user, "task": self.context["task"], + "owner_id": self.context["owner_id"]}) self.context["tenants"][tenant_id]["stacks"] = [] for i in range(self.config["stacks_per_tenant"]): stack = heat_scenario._create_stack(template) @@ -88,4 +89,4 @@ class StackGenerator(context.Context): resource_manager.cleanup(names=["heat.stacks"], users=self.context.get("users", []), superclass=heat_utils.HeatScenario, - task_id=self.context["task"]["uuid"]) + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/magnum/cluster_templates.py b/rally/plugins/openstack/context/magnum/cluster_templates.py index 3bd6df0b4f..1443b58a08 100644 --- a/rally/plugins/openstack/context/magnum/cluster_templates.py +++ b/rally/plugins/openstack/context/magnum/cluster_templates.py @@ -109,6 +109,7 @@ class ClusterTemplateGenerator(context.Context): nova_scenario = nova_utils.NovaScenario({ "user": user, "task": self.context["task"], + "owner_id": self.context["owner_id"], "config": {"api_versions": self.context["config"].get( "api_versions", [])} }) @@ -117,6 +118,7 @@ class ClusterTemplateGenerator(context.Context): magnum_scenario = magnum_utils.MagnumScenario({ "user": user, "task": self.context["task"], + "owner_id": self.context["owner_id"], "config": {"api_versions": self.context["config"].get( "api_versions", [])} }) @@ -130,5 +132,12 @@ class ClusterTemplateGenerator(context.Context): @logging.log_task_wrapper(LOG.info, _("Exit context: `ClusterTemplate`")) def cleanup(self): resource_manager.cleanup( - names=["magnum.cluster_templates", "nova.keypairs"], - users=self.context.get("users", [])) + names=["nova.keypairs"], + users=self.context.get("users", []), + superclass=nova_utils.NovaScenario, + task_id=self.get_owner_id()) + resource_manager.cleanup( + names=["magnum.cluster_templates"], + users=self.context.get("users", []), + superclass=magnum_utils.MagnumScenario, + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/magnum/clusters.py b/rally/plugins/openstack/context/magnum/clusters.py index 946ff294f8..73848d8d1f 100644 --- a/rally/plugins/openstack/context/magnum/clusters.py +++ b/rally/plugins/openstack/context/magnum/clusters.py @@ -53,6 +53,7 @@ class ClusterGenerator(context.Context): magnum_scenario = magnum_utils.MagnumScenario({ "user": user, "task": self.context["task"], + "owner_id": self.context["owner_id"], "config": {"api_versions": self.context["config"].get( "api_versions", [])} }) @@ -71,4 +72,6 @@ class ClusterGenerator(context.Context): def cleanup(self): resource_manager.cleanup( names=["magnum.clusters"], - users=self.context.get("users", [])) + users=self.context.get("users", []), + superclass=magnum_utils.MagnumScenario, + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/manila/manila_security_services.py b/rally/plugins/openstack/context/manila/manila_security_services.py index 04e2bffad0..c832ae1813 100644 --- a/rally/plugins/openstack/context/manila/manila_security_services.py +++ b/rally/plugins/openstack/context/manila/manila_security_services.py @@ -76,6 +76,7 @@ class SecurityServices(context.Context): if self.config["security_services"]: manila_scenario = manila_utils.ManilaScenario({ "task": self.task, + "owner_id": self.context["owner_id"], "user": user, "config": { "api_versions": self.context["config"].get( @@ -92,4 +93,5 @@ class SecurityServices(context.Context): resource_manager.cleanup( names=["manila.security_services"], users=self.context.get("users", []), - ) + superclass=manila_utils.ManilaScenario, + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/manila/manila_shares.py b/rally/plugins/openstack/context/manila/manila_shares.py index 86d39d873b..804773c680 100644 --- a/rally/plugins/openstack/context/manila/manila_shares.py +++ b/rally/plugins/openstack/context/manila/manila_shares.py @@ -86,6 +86,7 @@ class Shares(context.Context): utils.iterate_per_tenants(self.context.get("users", []))): manila_scenario = manila_utils.ManilaScenario({ "task": self.task, + "owner_id": self.context["owner_id"], "user": user, "config": { "api_versions": self.context["config"].get( @@ -104,4 +105,5 @@ class Shares(context.Context): resource_manager.cleanup( names=["manila.shares"], users=self.context.get("users", []), - ) + superclass=manila_utils.ManilaScenario, + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/murano/murano_environments.py b/rally/plugins/openstack/context/murano/murano_environments.py index def583f533..80af136409 100644 --- a/rally/plugins/openstack/context/murano/murano_environments.py +++ b/rally/plugins/openstack/context/murano/murano_environments.py @@ -52,6 +52,7 @@ class EnvironmentGenerator(context.Context): murano_util = murano_utils.MuranoScenario( {"user": user, "task": self.context["task"], + "owner_id": self.context["owner_id"], "config": self.context["config"]}) env = murano_util._create_environment() self.context["tenants"][tenant_id]["environments"].append(env) @@ -60,4 +61,6 @@ class EnvironmentGenerator(context.Context): _("Exit context: `Murano environments`")) def cleanup(self): resource_manager.cleanup(names=["murano.environments"], - users=self.context.get("users", [])) + users=self.context.get("users", []), + superclass=murano_utils.MuranoScenario, + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/murano/murano_packages.py b/rally/plugins/openstack/context/murano/murano_packages.py index dbf59a05df..1f6152f2be 100644 --- a/rally/plugins/openstack/context/murano/murano_packages.py +++ b/rally/plugins/openstack/context/murano/murano_packages.py @@ -25,7 +25,6 @@ from rally import consts from rally import exceptions from rally import osclients 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 @@ -69,6 +68,7 @@ class PackageGenerator(context.Context): self.context["tenants"][tenant_id]["packages"] = [] if is_config_app_dir: self.context["tenants"][tenant_id]["murano_ctx"] = zip_name + # TODO(astudenov): use self.generate_random_name() package = clients.murano().packages.create( {"categories": ["Web"], "tags": ["tag"]}, {"file": open(zip_name)}) @@ -79,5 +79,5 @@ class PackageGenerator(context.Context): def cleanup(self): resource_manager.cleanup(names=["murano.packages"], users=self.context.get("users", []), - superclass=murano_utils.MuranoScenario, - task_id=self.context["task"]["uuid"]) + superclass=self.__class__, + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/nova/keypairs.py b/rally/plugins/openstack/context/nova/keypairs.py index 2d544ff7e5..8c20926eb5 100644 --- a/rally/plugins/openstack/context/nova/keypairs.py +++ b/rally/plugins/openstack/context/nova/keypairs.py @@ -59,4 +59,4 @@ class Keypair(context.Context): resource_manager.cleanup(names=["nova.keypairs"], users=self.context.get("users", []), superclass=self.__class__, - task_id=self.context["task"]["uuid"]) + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/nova/servers.py b/rally/plugins/openstack/context/nova/servers.py index f135d722f2..e60d6a5e2f 100755 --- a/rally/plugins/openstack/context/nova/servers.py +++ b/rally/plugins/openstack/context/nova/servers.py @@ -107,6 +107,7 @@ class ServerGenerator(context.Context): tmp_context = {"user": user, "tenant": self.context["tenants"][tenant_id], "task": self.context["task"], + "owner_id": self.context["owner_id"], "iteration": iter_} nova_scenario = nova_utils.NovaScenario(tmp_context) @@ -135,4 +136,4 @@ class ServerGenerator(context.Context): resource_manager.cleanup(names=["nova.servers"], users=self.context.get("users", []), superclass=nova_utils.NovaScenario, - task_id=self.context["task"]["uuid"]) + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/sahara/sahara_cluster.py b/rally/plugins/openstack/context/sahara/sahara_cluster.py index c836b07181..832d638162 100644 --- a/rally/plugins/openstack/context/sahara/sahara_cluster.py +++ b/rally/plugins/openstack/context/sahara/sahara_cluster.py @@ -115,7 +115,8 @@ class SaharaCluster(context.Context): temporary_context = { "user": user, "tenant": self.context["tenants"][tenant_id], - "task": self.context["task"] + "task": self.context["task"], + "owner_id": self.context["owner_id"] } scenario = utils.SaharaScenario(context=temporary_context) @@ -179,4 +180,4 @@ class SaharaCluster(context.Context): resource_manager.cleanup(names=["sahara.clusters"], users=self.context.get("users", []), superclass=utils.SaharaScenario, - task_id=self.context["task"]["uuid"]) + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/sahara/sahara_image.py b/rally/plugins/openstack/context/sahara/sahara_image.py index 02fb80fe8d..995c676e97 100644 --- a/rally/plugins/openstack/context/sahara/sahara_image.py +++ b/rally/plugins/openstack/context/sahara/sahara_image.py @@ -130,4 +130,4 @@ class SaharaImage(context.Context): resource_manager.cleanup(names=["glance.images"], users=self.context.get("users", []), superclass=self.__class__, - task_id=self.context["task"]["uuid"]) + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/sahara/sahara_input_data_sources.py b/rally/plugins/openstack/context/sahara/sahara_input_data_sources.py index b480c45577..f9e373e636 100644 --- a/rally/plugins/openstack/context/sahara/sahara_input_data_sources.py +++ b/rally/plugins/openstack/context/sahara/sahara_input_data_sources.py @@ -22,7 +22,6 @@ from rally.common import utils as rutils from rally import consts from rally import osclients from rally.plugins.openstack.cleanup import manager as resource_manager -from rally.plugins.openstack.cleanup import resources as res_cleanup from rally.plugins.openstack.scenarios.sahara import utils from rally.plugins.openstack.scenarios.swift import utils as swift_utils from rally.task import context @@ -100,6 +99,7 @@ class SaharaInputDataSources(context.Context): swift_files, username, password): swift_scenario = swift_utils.SwiftScenario(clients=clients, context=self.context) + # TODO(astudenov): use self.generate_random_name() container_name = "rally_" + parse.urlparse(input_url).netloc.rstrip( ".sahara") self.context["sahara"]["container_name"] = ( @@ -121,14 +121,13 @@ class SaharaInputDataSources(context.Context): @logging.log_task_wrapper(LOG.info, _("Exit context: `Sahara Input Data" "Sources`")) def cleanup(self): - resources = ["data_sources"] - for swift_object in self.context["sahara"]["swift_objects"]: - res_cleanup.SwiftObject(resource=swift_object[1]) - res_cleanup.SwiftContainer( - resource=self.context["sahara"]["container_name"]) - resource_manager.cleanup( - names=["sahara.%s" % res for res in resources], + names=["swift.object", "swift.container"], users=self.context.get("users", []), - superclass=utils.SaharaScenario, - task_id=self.context["task"]["uuid"]) + superclass=swift_utils.SwiftScenario, + task_id=self.get_owner_id()) + resource_manager.cleanup( + names=["sahara.data_sources"], + users=self.context.get("users", []), + superclass=self.__class__, + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/sahara/sahara_output_data_sources.py b/rally/plugins/openstack/context/sahara/sahara_output_data_sources.py index 41a379b592..827a61d6d6 100644 --- a/rally/plugins/openstack/context/sahara/sahara_output_data_sources.py +++ b/rally/plugins/openstack/context/sahara/sahara_output_data_sources.py @@ -99,9 +99,13 @@ class SaharaOutputDataSources(context.Context): @logging.log_task_wrapper(LOG.info, _("Exit context: `Sahara Output Data Sources`")) def cleanup(self): - resources = ["data_sources"] resource_manager.cleanup( - names=["sahara.%s" % res for res in resources], + names=["swift.object", "swift.container"], users=self.context.get("users", []), - superclass=utils.SaharaScenario, - task_id=self.context["task"]["uuid"]) + superclass=self.__class__, + task_id=self.get_owner_id()) + resource_manager.cleanup( + names=["sahara.data_sources"], + users=self.context.get("users", []), + superclass=self.__class__, + task_id=self.get_owner_id()) diff --git a/rally/plugins/openstack/context/watcher/audit_templates.py b/rally/plugins/openstack/context/watcher/audit_templates.py index 3f7a7d2872..06ae3e7d18 100644 --- a/rally/plugins/openstack/context/watcher/audit_templates.py +++ b/rally/plugins/openstack/context/watcher/audit_templates.py @@ -79,6 +79,7 @@ class AuditTemplateGenerator(context.Context): def setup(self): watcher_scenario = watcher_utils.WatcherScenario( {"admin": self.context["admin"], "task": self.context["task"], + "owner_id": self.context["owner_id"], "config": { "api_versions": self.context["config"].get( "api_versions", [])} @@ -109,4 +110,6 @@ class AuditTemplateGenerator(context.Context): def cleanup(self): resource_manager.cleanup(names=["watcher.action_plan", "watcher.audit_template"], - admin=self.context.get("admin", [])) + admin=self.context.get("admin", []), + superclass=watcher_utils.WatcherScenario, + task_id=self.get_owner_id()) diff --git a/rally/task/context.py b/rally/task/context.py index f3e922c0d7..2bbb33843c 100644 --- a/rally/task/context.py +++ b/rally/task/context.py @@ -146,6 +146,11 @@ class Context(BaseContext): super(Context, self).__init__(ctx) self.task = self.context.get("task", {}) + def get_owner_id(self): + if "owner_id" in self.context: + return self.context["owner_id"] + return super(Context, self).get_owner_id() + class ContextManager(object): """Create context environment and run method inside it.""" diff --git a/rally/task/engine.py b/rally/task/engine.py index f1d0665a78..c1bda5ebfa 100644 --- a/rally/task/engine.py +++ b/rally/task/engine.py @@ -388,7 +388,7 @@ class TaskEngine(object): config = config or {"type": "serial"} return runner.ScenarioRunner.get(config["type"])(self.task, config) - def _prepare_context(self, ctx, name): + def _prepare_context(self, ctx, name, owner_id): scenario_cls = scenario.Scenario.get(name) namespace = scenario_cls.get_namespace() @@ -404,6 +404,7 @@ class TaskEngine(object): scenario_context.update(ctx) context_obj = { "task": self.task, + "owner_id": owner_id, "admin": {"credential": creds["admin"]}, "scenario_name": name, "scenario_namespace": namespace, @@ -465,7 +466,8 @@ class TaskEngine(object): LOG.info("Running benchmark with key: \n%s" % json.dumps(key, indent=2)) runner_obj = self._get_runner(workload.runner) - context_obj = self._prepare_context(workload.context, workload.name) + context_obj = self._prepare_context( + workload.context, workload.name, workload_obj["uuid"]) try: with ResultConsumer(key, self.task, subtask_obj, workload_obj, runner_obj, self.abort_on_sla_failure): diff --git a/rally/task/scenario.py b/rally/task/scenario.py index 7044773789..fb2886833b 100644 --- a/rally/task/scenario.py +++ b/rally/task/scenario.py @@ -123,6 +123,11 @@ class Scenario(plugin.Plugin, self._idle_duration = 0.0 self._output = {"additive": [], "complete": []} + def get_owner_id(self): + if "owner_id" in self.context: + return self.context["owner_id"] + return super(Scenario, self).get_owner_id() + @classmethod def get_default_context(cls): return cls._meta_get("default_context") diff --git a/tests/unit/plugins/openstack/context/cinder/test_volumes.py b/tests/unit/plugins/openstack/context/cinder/test_volumes.py index 8d86b61868..68ea1bbeb0 100644 --- a/tests/unit/plugins/openstack/context/cinder/test_volumes.py +++ b/tests/unit/plugins/openstack/context/cinder/test_volumes.py @@ -144,7 +144,7 @@ class VolumeGeneratorTestCase(test.ScenarioTestCase): mock_cleanup.assert_called_once_with( names=["cinder.volumes"], users=self.context["users"], api_versions=None, superclass=volumes_ctx.__class__, - task_id=self.context["task"]["uuid"]) + task_id=self.context["owner_id"]) @mock.patch("%s.cinder.volumes.resource_manager.cleanup" % CTX) def test_cleanup_api_versions(self, mock_cleanup): @@ -198,4 +198,4 @@ class VolumeGeneratorTestCase(test.ScenarioTestCase): users=self.context["users"], api_versions=api_version, superclass=volumes_ctx.__class__, - task_id=self.context["task"]["uuid"]) + task_id=self.context["owner_id"]) diff --git a/tests/unit/plugins/openstack/context/designate/test_zones.py b/tests/unit/plugins/openstack/context/designate/test_zones.py index 6413458074..76b2b218ae 100644 --- a/tests/unit/plugins/openstack/context/designate/test_zones.py +++ b/tests/unit/plugins/openstack/context/designate/test_zones.py @@ -129,4 +129,4 @@ class ZoneGeneratorTestCase(test.ScenarioTestCase): names=["designate.zones"], users=self.context["users"], superclass=utils.DesignateScenario, - task_id=self.context["task"]["uuid"]) + task_id=self.context["owner_id"]) diff --git a/tests/unit/plugins/openstack/context/ec2/test_servers.py b/tests/unit/plugins/openstack/context/ec2/test_servers.py index 44e1a10b6b..5f20c6eeb2 100644 --- a/tests/unit/plugins/openstack/context/ec2/test_servers.py +++ b/tests/unit/plugins/openstack/context/ec2/test_servers.py @@ -55,6 +55,7 @@ class EC2ServerGeneratorTestCase(test.TestCase): }, "admin": {"credential": mock.MagicMock()}, "task": mock.MagicMock(), + "owner_id": "foo_uuid", "users": users, "tenants": tenants } @@ -110,4 +111,4 @@ class EC2ServerGeneratorTestCase(test.TestCase): names=["ec2.servers"], users=context["users"], superclass=ec2_utils.EC2Scenario, - task_id=context["task"]["uuid"]) + task_id="foo_uuid") diff --git a/tests/unit/plugins/openstack/context/glance/test_images.py b/tests/unit/plugins/openstack/context/glance/test_images.py index 31997cf950..231c90e1a9 100644 --- a/tests/unit/plugins/openstack/context/glance/test_images.py +++ b/tests/unit/plugins/openstack/context/glance/test_images.py @@ -208,4 +208,4 @@ class ImageGeneratorTestCase(test.ScenarioTestCase): users=self.context["users"], api_versions=self.context["config"].get("api_versions"), superclass=images_ctx.__class__, - task_id=self.context["task"]["uuid"]) + task_id=self.context["owner_id"]) diff --git a/tests/unit/plugins/openstack/context/heat/test_stacks.py b/tests/unit/plugins/openstack/context/heat/test_stacks.py index d311228f15..1a5e1c7a72 100644 --- a/tests/unit/plugins/openstack/context/heat/test_stacks.py +++ b/tests/unit/plugins/openstack/context/heat/test_stacks.py @@ -95,4 +95,4 @@ class TestStackGenerator(test.ScenarioTestCase): names=["heat.stacks"], users=self.context["users"], superclass=heat_utils.HeatScenario, - task_id=self.context["task"]["uuid"]) + task_id=self.context["owner_id"]) diff --git a/tests/unit/plugins/openstack/context/magnum/test_cluster_templates.py b/tests/unit/plugins/openstack/context/magnum/test_cluster_templates.py index 8aa572bbee..64debe452f 100644 --- a/tests/unit/plugins/openstack/context/magnum/test_cluster_templates.py +++ b/tests/unit/plugins/openstack/context/magnum/test_cluster_templates.py @@ -13,6 +13,8 @@ import mock from rally.plugins.openstack.context.magnum import cluster_templates +from rally.plugins.openstack.scenarios.magnum import utils as magnum_utils +from rally.plugins.openstack.scenarios.nova import utils as nova_utils from tests.unit import fakes from tests.unit import test @@ -103,6 +105,14 @@ class ClusterTemplatesGeneratorTestCase(test.ScenarioTestCase): }) ct_ctx = cluster_templates.ClusterTemplateGenerator(self.context) ct_ctx.cleanup() - mock_cleanup.assert_called_once_with(names=["magnum.cluster_templates", - "nova.keypairs"], - users=self.context["users"]) + mock_cleanup.assert_has_calls(( + mock.call( + names=["nova.keypairs"], + users=self.context["users"], + superclass=nova_utils.NovaScenario, + task_id=self.context["owner_id"]), + mock.call( + names=["magnum.cluster_templates"], + users=self.context["users"], + superclass=magnum_utils.MagnumScenario, + task_id=self.context["owner_id"]))) diff --git a/tests/unit/plugins/openstack/context/magnum/test_clusters.py b/tests/unit/plugins/openstack/context/magnum/test_clusters.py index c777e148da..b66190eb98 100644 --- a/tests/unit/plugins/openstack/context/magnum/test_clusters.py +++ b/tests/unit/plugins/openstack/context/magnum/test_clusters.py @@ -18,6 +18,7 @@ import copy import mock from rally.plugins.openstack.context.magnum import clusters +from rally.plugins.openstack.scenarios.magnum import utils as magnum_utils from tests.unit import test CTX = "rally.plugins.openstack.context.magnum" @@ -147,4 +148,6 @@ class ClustersGeneratorTestCase(test.ScenarioTestCase): clusters_ctx.cleanup() mock_cleanup.assert_called_once_with( names=["magnum.clusters"], - users=self.context["users"]) + users=self.context["users"], + superclass=magnum_utils.MagnumScenario, + task_id=self.context["owner_id"]) diff --git a/tests/unit/plugins/openstack/context/manila/test_manila_security_services.py b/tests/unit/plugins/openstack/context/manila/test_manila_security_services.py index 3e1a1a10c0..534fef1e4b 100644 --- a/tests/unit/plugins/openstack/context/manila/test_manila_security_services.py +++ b/tests/unit/plugins/openstack/context/manila/test_manila_security_services.py @@ -19,6 +19,7 @@ import six from rally.plugins.openstack.context.manila import consts from rally.plugins.openstack.context.manila import manila_security_services +from rally.plugins.openstack.scenarios.manila import utils as manila_utils from tests.unit import test CONTEXT_NAME = consts.SECURITY_SERVICES_CONTEXT_NAME @@ -71,6 +72,7 @@ class SecurityServicesTestCase(test.ScenarioTestCase): "endpoint": mock.MagicMock(), }, "task": mock.MagicMock(), + "owner_id": "foo_uuid", "users": users, "tenants": tenants, } @@ -108,6 +110,7 @@ class SecurityServicesTestCase(test.ScenarioTestCase): mock_manila_scenario.call_args_list, [mock.call({ "task": inst.task, + "owner_id": "foo_uuid", "config": {"api_versions": []}, "user": user}) for user in inst.context["users"] if user["id"] == 0] @@ -162,4 +165,7 @@ class SecurityServicesTestCase(test.ScenarioTestCase): inst.cleanup() mock_resource_manager.cleanup.assert_called_once_with( - names=["manila.security_services"], users=ctxt["users"]) + names=["manila.security_services"], + users=ctxt["users"], + superclass=manila_utils.ManilaScenario, + task_id="foo_uuid") diff --git a/tests/unit/plugins/openstack/context/manila/test_manila_shares.py b/tests/unit/plugins/openstack/context/manila/test_manila_shares.py index 3fcd9c063e..6f023533d3 100644 --- a/tests/unit/plugins/openstack/context/manila/test_manila_shares.py +++ b/tests/unit/plugins/openstack/context/manila/test_manila_shares.py @@ -22,6 +22,7 @@ import six from rally import consts as rally_consts from rally.plugins.openstack.context.manila import consts from rally.plugins.openstack.context.manila import manila_shares +from rally.plugins.openstack.scenarios.manila import utils as manila_utils from tests.unit import test MANILA_UTILS_PATH = ( @@ -80,6 +81,7 @@ class SharesTestCase(test.TestCase): "credential": mock.MagicMock(), }, "task": mock.MagicMock(), + "owner_id": "foo_uuid", "users": users, "tenants": tenants, } @@ -199,4 +201,5 @@ class SharesTestCase(test.TestCase): mock_cleanup_manager_cleanup.assert_called_once_with( names=["manila.shares"], users=inst.context.get("users", []), - ) + superclass=manila_utils.ManilaScenario, + task_id="foo_uuid") diff --git a/tests/unit/plugins/openstack/context/murano/test_murano_environments.py b/tests/unit/plugins/openstack/context/murano/test_murano_environments.py index 40eed37f2c..69fe47fb25 100644 --- a/tests/unit/plugins/openstack/context/murano/test_murano_environments.py +++ b/tests/unit/plugins/openstack/context/murano/test_murano_environments.py @@ -16,6 +16,7 @@ import mock from rally.plugins.openstack.context.murano import murano_environments +from rally.plugins.openstack.scenarios.murano import utils as murano_utils from tests.unit import test CTX = "rally.plugins.openstack.context.murano.murano_environments" @@ -44,6 +45,7 @@ class MuranoEnvironmentGeneratorTestCase(test.TestCase): "credential": mock.MagicMock() }, "task": mock.MagicMock(), + "owner_id": "foo_uuid", "users": [ { "id": "user_0", @@ -82,5 +84,8 @@ class MuranoEnvironmentGeneratorTestCase(test.TestCase): murano_ctx.setup() murano_ctx.cleanup() - mock_cleanup.assert_called_once_with(names=["murano.environments"], - users=murano_ctx.context["users"]) + mock_cleanup.assert_called_once_with( + names=["murano.environments"], + users=murano_ctx.context["users"], + superclass=murano_utils.MuranoScenario, + task_id="foo_uuid") diff --git a/tests/unit/plugins/openstack/context/murano/test_murano_packages.py b/tests/unit/plugins/openstack/context/murano/test_murano_packages.py index 0815e27c09..200c7c60ad 100644 --- a/tests/unit/plugins/openstack/context/murano/test_murano_packages.py +++ b/tests/unit/plugins/openstack/context/murano/test_murano_packages.py @@ -16,7 +16,6 @@ import mock from rally.plugins.openstack.context.murano import murano_packages -from rally.plugins.openstack.scenarios.murano import utils as murano_utils from tests.unit import test CTX = "rally.plugins.openstack.context.murano.murano_packages" @@ -47,6 +46,7 @@ class MuranoPackageGeneratorTestCase(test.TestCase): "credential": mock.MagicMock() }, "task": mock.MagicMock(), + "owner_id": "foo_uuid", "users": [ { "id": "user_0", @@ -93,8 +93,8 @@ class MuranoPackageGeneratorTestCase(test.TestCase): mock_cleanup.assert_called_once_with( names=["murano.packages"], users=murano_ctx.context["users"], - superclass=murano_utils.MuranoScenario, - task_id=murano_ctx.context["task"]["uuid"]) + superclass=murano_packages.PackageGenerator, + task_id="foo_uuid") @mock.patch("%s.osclients" % CTX) @mock.patch("%s.resource_manager.cleanup" % CTX) @@ -114,5 +114,5 @@ class MuranoPackageGeneratorTestCase(test.TestCase): mock_cleanup.assert_called_once_with( names=["murano.packages"], users=murano_ctx.context["users"], - superclass=murano_utils.MuranoScenario, - task_id=ctx_dict["task"]["uuid"]) + superclass=murano_packages.PackageGenerator, + task_id="foo_uuid") diff --git a/tests/unit/plugins/openstack/context/nova/test_servers.py b/tests/unit/plugins/openstack/context/nova/test_servers.py index 2bddcc0948..f867504178 100755 --- a/tests/unit/plugins/openstack/context/nova/test_servers.py +++ b/tests/unit/plugins/openstack/context/nova/test_servers.py @@ -174,4 +174,4 @@ class ServerGeneratorTestCase(test.ScenarioTestCase): names=["nova.servers"], users=self.context["users"], superclass=nova_utils.NovaScenario, - task_id=self.context["task"]["uuid"]) + task_id=self.context["owner_id"]) diff --git a/tests/unit/plugins/openstack/context/sahara/test_sahara_cluster.py b/tests/unit/plugins/openstack/context/sahara/test_sahara_cluster.py index df81caaa01..2d310c8c38 100644 --- a/tests/unit/plugins/openstack/context/sahara/test_sahara_cluster.py +++ b/tests/unit/plugins/openstack/context/sahara/test_sahara_cluster.py @@ -111,7 +111,7 @@ class SaharaClusterTestCase(test.ScenarioTestCase): names=["sahara.clusters"], users=self.context["users"], superclass=sahara_utils.SaharaScenario, - task_id=self.context["task"]["uuid"]) + task_id=self.context["owner_id"]) @mock.patch("%s.sahara_cluster.utils.SaharaScenario._launch_cluster" % CTX, return_value=mock.MagicMock(id=42)) diff --git a/tests/unit/plugins/openstack/context/sahara/test_sahara_image.py b/tests/unit/plugins/openstack/context/sahara/test_sahara_image.py index cb8a4d3de4..6414db467c 100644 --- a/tests/unit/plugins/openstack/context/sahara/test_sahara_image.py +++ b/tests/unit/plugins/openstack/context/sahara/test_sahara_image.py @@ -133,7 +133,7 @@ class SaharaImageTestCase(test.ScenarioTestCase): names=["glance.images"], users=ctx["users"], superclass=sahara_ctx.__class__, - task_id=ctx["task"]["uuid"]) + task_id=ctx["owner_id"]) @mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN, return_value=mock.MagicMock(id=42)) diff --git a/tests/unit/plugins/openstack/context/sahara/test_sahara_input_data_sources.py b/tests/unit/plugins/openstack/context/sahara/test_sahara_input_data_sources.py index 47d45c7f28..9bad87064b 100644 --- a/tests/unit/plugins/openstack/context/sahara/test_sahara_input_data_sources.py +++ b/tests/unit/plugins/openstack/context/sahara/test_sahara_input_data_sources.py @@ -15,7 +15,7 @@ import mock from rally.plugins.openstack.context.sahara import sahara_input_data_sources -from rally.plugins.openstack.scenarios.sahara import utils as sahara_utils +from rally.plugins.openstack.scenarios.swift import utils as swift_utils from tests.unit import test CTX = "rally.plugins.openstack.context.sahara" @@ -88,11 +88,16 @@ class SaharaInputDataSourcesTestCase(test.ScenarioTestCase): sahara_ctx.cleanup() - mock_cleanup.assert_called_once_with( - names=["sahara.data_sources"], - users=self.context["users"], - superclass=sahara_utils.SaharaScenario, - task_id=self.context["task"]["uuid"]) + mock_cleanup.assert_has_calls(( + mock.call(names=["swift.object", "swift.container"], + users=self.context["users"], + superclass=swift_utils.SwiftScenario, + task_id=self.context["owner_id"]), + mock.call( + names=["sahara.data_sources"], + users=self.context["users"], + superclass=sahara_input_data_sources.SaharaInputDataSources, + task_id=self.context["owner_id"]))) @mock.patch("requests.get") @mock.patch("%s.sahara_input_data_sources.osclients" % CTX) @@ -156,8 +161,13 @@ class SaharaInputDataSourcesTestCase(test.ScenarioTestCase): sahara_ctx.cleanup() - mock_resource_manager.cleanup.assert_called_once_with( - names=["sahara.data_sources"], - users=self.context["users"], - superclass=sahara_utils.SaharaScenario, - task_id=self.context["task"]["uuid"]) + mock_resource_manager.cleanup.assert_has_calls(( + mock.call(names=["swift.object", "swift.container"], + users=self.context["users"], + superclass=mock_swift_utils.SwiftScenario, + task_id=self.context["owner_id"]), + mock.call( + names=["sahara.data_sources"], + users=self.context["users"], + superclass=sahara_input_data_sources.SaharaInputDataSources, + task_id=self.context["owner_id"]))) diff --git a/tests/unit/plugins/openstack/context/sahara/test_sahara_output_data_sources.py b/tests/unit/plugins/openstack/context/sahara/test_sahara_output_data_sources.py index 0659e1549d..e48390001f 100644 --- a/tests/unit/plugins/openstack/context/sahara/test_sahara_output_data_sources.py +++ b/tests/unit/plugins/openstack/context/sahara/test_sahara_output_data_sources.py @@ -16,7 +16,6 @@ import mock from rally.plugins.openstack.context.sahara import sahara_output_data_sources from rally.plugins.openstack import credential as oscredential -from rally.plugins.openstack.scenarios.sahara import utils as sahara_utils from tests.unit import test CTX = "rally.plugins.openstack.context.sahara" @@ -98,11 +97,17 @@ class SaharaOutputDataSourcesTestCase(test.ScenarioTestCase): sahara_ctx.cleanup() - mock_cleanup.assert_called_once_with( - names=["sahara.data_sources"], - users=self.context["users"], - superclass=sahara_utils.SaharaScenario, - task_id=self.context["task"]["uuid"]) + mock_cleanup.assert_has_calls(( + mock.call( + names=["swift.object", "swift.container"], + users=self.context["users"], + superclass=sahara_output_data_sources.SaharaOutputDataSources, + task_id=self.context["owner_id"]), + mock.call( + names=["sahara.data_sources"], + users=self.context["users"], + superclass=sahara_output_data_sources.SaharaOutputDataSources, + task_id=self.context["owner_id"]))) @mock.patch("%s.sahara_output_data_sources.osclients" % CTX) def test_setup_inputs_swift(self, mock_osclients): diff --git a/tests/unit/plugins/openstack/context/watcher/test_audit_templates.py b/tests/unit/plugins/openstack/context/watcher/test_audit_templates.py index 31b9542138..751373c0c3 100644 --- a/tests/unit/plugins/openstack/context/watcher/test_audit_templates.py +++ b/tests/unit/plugins/openstack/context/watcher/test_audit_templates.py @@ -15,6 +15,7 @@ import mock from rally.plugins.openstack.context.watcher import audit_templates +from rally.plugins.openstack.scenarios.watcher import utils as watcher_utils from tests.unit import fakes from tests.unit import test @@ -91,4 +92,6 @@ class AuditTemplateTestCase(test.ScenarioTestCase): audit_templates_ctx.cleanup() mock_cleanup.assert_called_once_with( names=["watcher.action_plan", "watcher.audit_template"], - admin=self.context["admin"]) + admin=self.context["admin"], + superclass=watcher_utils.WatcherScenario, + task_id=self.context["owner_id"]) diff --git a/tests/unit/task/test_context.py b/tests/unit/task/test_context.py index 004d14120b..023db8bbde 100644 --- a/tests/unit/task/test_context.py +++ b/tests/unit/task/test_context.py @@ -135,6 +135,17 @@ class BaseContextTestCase(test.TestCase): self.assertFalse(FakeOtherContext(ctx) == fakes.FakeContext(ctx)) self.assertTrue(FakeOtherContext(ctx) == FakeOtherContext(ctx)) + def test_get_owner_id_from_task(self): + ctx = {"config": {"fake": {"test": 10}}, "task": {"uuid": "task_uuid"}} + ins = fakes.FakeContext(ctx) + self.assertEqual("task_uuid", ins.get_owner_id()) + + def test_get_owner_id(self): + ctx = {"config": {"fake": {"test": 10}}, "task": {"uuid": "task_uuid"}, + "owner_id": "foo_uuid"} + ins = fakes.FakeContext(ctx) + self.assertEqual("foo_uuid", ins.get_owner_id()) + class ContextManagerTestCase(test.TestCase): diff --git a/tests/unit/task/test_engine.py b/tests/unit/task/test_engine.py index c91f5f748d..4937ff6eb8 100644 --- a/tests/unit/task/test_engine.py +++ b/tests/unit/task/test_engine.py @@ -516,9 +516,10 @@ class TaskEngineTestCase(test.TestCase): deployment = fakes.FakeDeployment( uuid="deployment_uuid", admin=admin) eng = engine.TaskEngine(config, task, deployment) - result = eng._prepare_context(context, name) + result = eng._prepare_context(context, name, "foo_uuid") expected_result = { "task": task, + "owner_id": "foo_uuid", "admin": {"credential": admin}, "scenario_name": name, "scenario_namespace": "openstack", @@ -545,9 +546,10 @@ class TaskEngineTestCase(test.TestCase): deployment = fakes.FakeDeployment(uuid="deployment_uuid", admin=admin, users=users) eng = engine.TaskEngine(config, task, deployment) - result = eng._prepare_context(context, name) + result = eng._prepare_context(context, name, "foo_uuid") expected_result = { "task": task, + "owner_id": "foo_uuid", "admin": {"credential": admin}, "scenario_name": name, "scenario_namespace": "openstack", diff --git a/tests/unit/task/test_scenario.py b/tests/unit/task/test_scenario.py index aa71463aeb..cdb5302f37 100644 --- a/tests/unit/task/test_scenario.py +++ b/tests/unit/task/test_scenario.py @@ -88,6 +88,16 @@ class ScenarioTestCase(test.TestCase): self.assertRaises(exceptions.InvalidArgumentsException, scenario.Scenario().sleep_between, 0, -2) + def test_get_owner_id_from_task(self): + scenario_inst = scenario.Scenario( + context={"task": {"uuid": "task_uuid"}}) + self.assertEqual("task_uuid", scenario_inst.get_owner_id()) + + def test_get_owner_id(self): + scenario_inst = scenario.Scenario( + context={"task": {"uuid": "task_uuid"}, "owner_id": "foo_uuid"}) + self.assertEqual("foo_uuid", scenario_inst.get_owner_id()) + def test_sleep_between(self): scenario_inst = scenario.Scenario() scenario_inst.sleep_between(0.001, 0.002) diff --git a/tests/unit/test.py b/tests/unit/test.py index 865c5d58d4..558820e3ea 100644 --- a/tests/unit/test.py +++ b/tests/unit/test.py @@ -208,4 +208,5 @@ class FakeClientsScenarioTestCase(ScenarioTestCase): def get_test_context(**kwargs): kwargs["task"] = {"uuid": str(uuid.uuid4())} + kwargs["owner_id"] = str(uuid.uuid4()) return kwargs