From de6b097ccaa12bf62323a184f1543e8a27ace2c8 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 22 Sep 2015 09:16:57 -0500 Subject: [PATCH] Implement new random name generator for context plugins This changes all context plugins to use the new consistent random name generator. Change-Id: I99a94f98a58be5354f41160973c872216c79ba0f --- .../openstack/context/ceilometer/samples.py | 3 +- .../openstack/context/cinder/volumes.py | 8 +-- .../openstack/context/glance/images.py | 3 +- .../plugins/openstack/context/heat/stacks.py | 3 +- .../openstack/context/keystone/users.py | 7 +-- .../openstack/context/network/allow_ssh.py | 6 +-- .../openstack/context/network/networks.py | 6 +-- .../openstack/context/neutron/lbaas.py | 6 +-- .../openstack/context/nova/keypairs.py | 4 +- .../plugins/openstack/context/nova/servers.py | 9 ++-- .../context/sahara/sahara_cluster.py | 3 +- .../openstack/context/sahara/sahara_image.py | 5 +- .../plugins/openstack/context/swift/utils.py | 11 ++-- .../openstack/context/vm/custom_image.py | 2 +- .../openstack/context/keystone/test_users.py | 8 ++- .../context/network/test_allow_ssh.py | 1 - .../openstack/context/nova/test_keypairs.py | 53 +++++++++++-------- .../context/sahara/test_sahara_image.py | 15 +++--- .../openstack/context/swift/test_objects.py | 39 +++++++------- .../openstack/context/swift/test_utils.py | 29 +++++----- .../openstack/context/vm/test_custom_image.py | 13 ++--- 21 files changed, 114 insertions(+), 120 deletions(-) diff --git a/rally/plugins/openstack/context/ceilometer/samples.py b/rally/plugins/openstack/context/ceilometer/samples.py index 8f76f1dc..7a788da8 100644 --- a/rally/plugins/openstack/context/ceilometer/samples.py +++ b/rally/plugins/openstack/context/ceilometer/samples.py @@ -73,7 +73,8 @@ class CeilometerSampleGenerator(context.Context): self.context["users"]): self.context["tenants"][tenant_id]["samples"] = [] self.context["tenants"][tenant_id]["resources"] = [] - scenario = ceilo_utils.CeilometerScenario({"user": user}) + scenario = ceilo_utils.CeilometerScenario( + context={"user": user, "task": self.context["task"]}) for i in range(self.config["resources_per_tenant"]): for j in range(self.config["samples_per_resource"]): sample = scenario._create_sample(counter_name, diff --git a/rally/plugins/openstack/context/cinder/volumes.py b/rally/plugins/openstack/context/cinder/volumes.py index 6433abe1..43caf00d 100644 --- a/rally/plugins/openstack/context/cinder/volumes.py +++ b/rally/plugins/openstack/context/cinder/volumes.py @@ -19,7 +19,6 @@ from rally import consts from rally.plugins.openstack.context.cleanup import manager as resource_manager from rally.plugins.openstack.scenarios.cinder import utils as cinder_utils from rally.task import context -from rally.task import scenario LOG = logging.getLogger(__name__) @@ -58,10 +57,11 @@ class VolumeGenerator(context.Context): for user, tenant_id in rutils.iterate_per_tenants( self.context["users"]): self.context["tenants"][tenant_id].setdefault("volumes", []) - cinder_util = cinder_utils.CinderScenario({"user": user}) + cinder_util = cinder_utils.CinderScenario( + {"user": user, + "task": self.context["task"]}) for i in range(volumes_per_tenant): - rnd_name = scenario.Scenario._generate_random_name( - prefix="ctx_rally_volume_") + rnd_name = self.generate_random_name() vol = cinder_util._create_volume(size, display_name=rnd_name) self.context["tenants"][tenant_id]["volumes"].append(vol._info) diff --git a/rally/plugins/openstack/context/glance/images.py b/rally/plugins/openstack/context/glance/images.py index 8584ccee..a3642f1a 100644 --- a/rally/plugins/openstack/context/glance/images.py +++ b/rally/plugins/openstack/context/glance/images.py @@ -74,7 +74,8 @@ class ImageGenerator(context.Context): for user, tenant_id in rutils.iterate_per_tenants( self.context["users"]): current_images = [] - glance_scenario = glance_utils.GlanceScenario({"user": user}) + glance_scenario = glance_utils.GlanceScenario( + {"user": user, "task": self.context["task"]}) for i in range(images_per_tenant): if image_name and i > 0: cur_name = image_name + str(i) diff --git a/rally/plugins/openstack/context/heat/stacks.py b/rally/plugins/openstack/context/heat/stacks.py index 8efd7e35..c954bde7 100644 --- a/rally/plugins/openstack/context/heat/stacks.py +++ b/rally/plugins/openstack/context/heat/stacks.py @@ -76,7 +76,8 @@ class StackGenerator(context.Context): self.config["resources_per_stack"]) for user, tenant_id in rutils.iterate_per_tenants( self.context["users"]): - heat_scenario = heat_utils.HeatScenario({"user": user}) + heat_scenario = heat_utils.HeatScenario( + {"user": user, "task": self.context["task"]}) self.context["tenants"][tenant_id]["stacks"] = [] for i in range(self.config["stacks_per_tenant"]): stack = heat_scenario._create_stack(template) diff --git a/rally/plugins/openstack/context/keystone/users.py b/rally/plugins/openstack/context/keystone/users.py index fdec583b..4e77aa56 100644 --- a/rally/plugins/openstack/context/keystone/users.py +++ b/rally/plugins/openstack/context/keystone/users.py @@ -103,8 +103,6 @@ class UserGenerator(UserContextMixin, context.Context): }, "additionalProperties": False } - PATTERN_TENANT = "ctx_rally_%(task_id)s_tenant_%(iter)i" - PATTERN_USER = "ctx_rally_%(tenant_id)s_user_%(uid)d" DEFAULT_CONFIG = { "tenants": 1, @@ -181,7 +179,7 @@ class UserGenerator(UserContextMixin, context.Context): clients = osclients.Clients(self.endpoint) cache["client"] = keystone.wrap(clients.keystone()) tenant = cache["client"].create_project( - self.PATTERN_TENANT % {"task_id": task_id, "iter": i}, domain) + self.generate_random_name(), domain) tenant_dict = {"id": tenant.id, "name": tenant.name} tenants.append(tenant_dict) @@ -203,8 +201,7 @@ class UserGenerator(UserContextMixin, context.Context): def publish(queue): for tenant_id in self.context["tenants"]: for user_id in range(users_per_tenant): - username = self.PATTERN_USER % {"tenant_id": tenant_id, - "uid": user_id} + username = self.generate_random_name() password = str(uuid.uuid4()) args = (username, password, self.config["project_domain"], self.config["user_domain"], tenant_id) diff --git a/rally/plugins/openstack/context/network/allow_ssh.py b/rally/plugins/openstack/context/network/allow_ssh.py index 7c97c350..e7d19abc 100644 --- a/rally/plugins/openstack/context/network/allow_ssh.py +++ b/rally/plugins/openstack/context/network/allow_ssh.py @@ -25,8 +25,6 @@ from rally.task import context LOG = logging.getLogger(__name__) -SSH_GROUP_NAME = "rally_ssh_open" - def _prepare_open_secgroup(endpoint, secgroup_name): """Generate secgroup allowing all tcp/udp/icmp access. @@ -103,9 +101,7 @@ class AllowSSH(context.Context): LOG.info(_("Security group context is disabled: %s") % msg) return - secgroup_name = "%s_%s" % (SSH_GROUP_NAME, - self.context["task"]["uuid"]) - + secgroup_name = self.generate_random_name() for user in self.context["users"]: user["secgroup"] = _prepare_open_secgroup(user["endpoint"], secgroup_name) diff --git a/rally/plugins/openstack/context/network/networks.py b/rally/plugins/openstack/context/network/networks.py index 51a176cc..82a9bd9b 100644 --- a/rally/plugins/openstack/context/network/networks.py +++ b/rally/plugins/openstack/context/network/networks.py @@ -67,8 +67,7 @@ class Network(context.Context): # creating a connection in setup and cleanup separately. net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["endpoint"]), - self.context["task"], - config=self.config) + self.task, config=self.config) for user, tenant_id in (utils.iterate_per_tenants( self.context.get("users", []))): self.context["tenants"][tenant_id]["networks"] = [] @@ -86,8 +85,7 @@ class Network(context.Context): def cleanup(self): net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["endpoint"]), - self.context["task"], - config=self.config) + self.task, config=self.config) for tenant_id, tenant_ctx in six.iteritems(self.context["tenants"]): for network in tenant_ctx.get("networks", []): with logging.ExceptionLogger( diff --git a/rally/plugins/openstack/context/neutron/lbaas.py b/rally/plugins/openstack/context/neutron/lbaas.py index ab29baf0..e72f6ccf 100644 --- a/rally/plugins/openstack/context/neutron/lbaas.py +++ b/rally/plugins/openstack/context/neutron/lbaas.py @@ -53,8 +53,7 @@ class Lbaas(context.Context): def setup(self): net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["endpoint"]), - self.context["task"], - config=self.config) + self.task, config=self.config) use_lb, msg = net_wrapper.supports_extension("lbaas") if not use_lb: @@ -81,8 +80,7 @@ class Lbaas(context.Context): def cleanup(self): net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["endpoint"]), - self.context["task"], - config=self.config) + self.task, config=self.config) for tenant_id, tenant_ctx in six.iteritems(self.context["tenants"]): for network in tenant_ctx.get("networks", []): for pool in network.get("lb_pools", []): diff --git a/rally/plugins/openstack/context/nova/keypairs.py b/rally/plugins/openstack/context/nova/keypairs.py index f713c752..fb6fbc0d 100644 --- a/rally/plugins/openstack/context/nova/keypairs.py +++ b/rally/plugins/openstack/context/nova/keypairs.py @@ -28,11 +28,9 @@ LOG = logging.getLogger(__name__) @context.configure(name="keypair", order=310) class Keypair(context.Context): - KEYPAIR_NAME = "rally_ssh_key" def _generate_keypair(self, endpoint): - keypair_name = "%s_%s" % ( - self.KEYPAIR_NAME, self.context["task"]["uuid"]) + keypair_name = self.generate_random_name() nova_client = osclients.Clients(endpoint).nova() diff --git a/rally/plugins/openstack/context/nova/servers.py b/rally/plugins/openstack/context/nova/servers.py index ef234406..f287739b 100644 --- a/rally/plugins/openstack/context/nova/servers.py +++ b/rally/plugins/openstack/context/nova/servers.py @@ -87,10 +87,11 @@ class ServerGenerator(context.Context): self.context["users"])): LOG.debug("Booting servers for user tenant %s " % (user["tenant_id"])) - tenant = self.context["tenants"][tenant_id] - nova_scenario = nova_utils.NovaScenario({"user": user, - "tenant": tenant, - "iteration": iter_}) + tmp_context = {"user": user, + "tenant": self.context["tenants"][tenant_id], + "task": self.context["task"], + "iteration": iter_} + nova_scenario = nova_utils.NovaScenario(tmp_context) LOG.debug("Calling _boot_servers with image_id=%(image_id)s " "flavor_id=%(flavor_id)s " diff --git a/rally/plugins/openstack/context/sahara/sahara_cluster.py b/rally/plugins/openstack/context/sahara/sahara_cluster.py index 7c134e9b..a5193e7e 100644 --- a/rally/plugins/openstack/context/sahara/sahara_cluster.py +++ b/rally/plugins/openstack/context/sahara/sahara_cluster.py @@ -101,7 +101,8 @@ class SaharaCluster(context.Context): temporary_context = { "user": user, - "tenant": self.context["tenants"][tenant_id] + "tenant": self.context["tenants"][tenant_id], + "task": self.context["task"] } scenario = utils.SaharaScenario(context=temporary_context) diff --git a/rally/plugins/openstack/context/sahara/sahara_image.py b/rally/plugins/openstack/context/sahara/sahara_image.py index 6a9a5aa9..bfe826e0 100644 --- a/rally/plugins/openstack/context/sahara/sahara_image.py +++ b/rally/plugins/openstack/context/sahara/sahara_image.py @@ -60,8 +60,9 @@ class SaharaImage(context.Context): def _create_image(self, hadoop_version, image_url, plugin_name, user, user_name): - scenario = glance_utils.GlanceScenario({"user": user}) - image_name = rutils.generate_random_name(prefix="rally_sahara_image_") + scenario = glance_utils.GlanceScenario( + {"user": user, "task": self.context["task"]}) + image_name = self.generate_random_name() image = scenario._create_image(name=image_name, container_format="bare", image_location=image_url, diff --git a/rally/plugins/openstack/context/swift/utils.py b/rally/plugins/openstack/context/swift/utils.py index b3c1b6ed..127c0a4a 100644 --- a/rally/plugins/openstack/context/swift/utils.py +++ b/rally/plugins/openstack/context/swift/utils.py @@ -46,7 +46,8 @@ class SwiftObjectMixin(object): def consume(cache, args): user, tenant_containers = args if user["id"] not in cache: - cache[user["id"]] = swift_utils.SwiftScenario({"user": user}) + cache[user["id"]] = swift_utils.SwiftScenario( + {"user": user, "task": context.get("task", {})}) container_name = cache[user["id"]]._create_container() tenant_containers.append({"user": user, "container": container_name, @@ -86,7 +87,7 @@ class SwiftObjectMixin(object): user = container["user"] if user["id"] not in cache: cache[user["id"]] = swift_utils.SwiftScenario( - {"user": user}) + {"user": user, "task": context.get("task", {})}) dummy_file.seek(0) object_name = cache[user["id"]]._upload_object( container["container"], @@ -116,7 +117,8 @@ class SwiftObjectMixin(object): container, tenant_containers = args user = container["user"] if user["id"] not in cache: - cache[user["id"]] = swift_utils.SwiftScenario({"user": user}) + cache[user["id"]] = swift_utils.SwiftScenario( + {"user": user, "task": context.get("task", {})}) cache[user["id"]]._delete_container(container["container"]) tenant_containers.remove(container) @@ -140,7 +142,8 @@ class SwiftObjectMixin(object): object_name, container = args user = container["user"] if user["id"] not in cache: - cache[user["id"]] = swift_utils.SwiftScenario({"user": user}) + cache[user["id"]] = swift_utils.SwiftScenario( + {"user": user, "task": context.get("task", {})}) cache[user["id"]]._delete_object(container["container"], object_name) container["objects"].remove(object_name) diff --git a/rally/plugins/openstack/context/vm/custom_image.py b/rally/plugins/openstack/context/vm/custom_image.py index 8365c9bc..a71657de 100644 --- a/rally/plugins/openstack/context/vm/custom_image.py +++ b/rally/plugins/openstack/context/vm/custom_image.py @@ -155,7 +155,7 @@ class BaseCustomImageGenerator(context.Context): vm_scenario = vmtasks.VMTasks(self.context, clients=clients) server, fip = vm_scenario._boot_server_with_fip( - name=vm_scenario._generate_random_name("rally_ctx_custom_image_"), + name=self.generate_random_name(), image=image_id, flavor=flavor_id, floating_network=self.config.get("floating_network"), userdata=self.config.get("userdata"), diff --git a/tests/unit/plugins/openstack/context/keystone/test_users.py b/tests/unit/plugins/openstack/context/keystone/test_users.py index b0e0dc68..523819c9 100644 --- a/tests/unit/plugins/openstack/context/keystone/test_users.py +++ b/tests/unit/plugins/openstack/context/keystone/test_users.py @@ -329,16 +329,14 @@ class UserGeneratorTestCase(test.ScenarioTestCase): wrapped_keystone.create_user.side_effect = user_list with users.UserGenerator(tmp_context) as ctx: + ctx.generate_random_name = mock.Mock() ctx.setup() create_tenant_calls = [] for i, t in enumerate(ctx.context["tenants"]): - pattern = users.UserGenerator.PATTERN_TENANT create_tenant_calls.append( - mock.call( - pattern % {"task_id": tmp_context["task"]["uuid"], - "iter": i}, - ctx.config["project_domain"])) + mock.call(ctx.generate_random_name.return_value, + ctx.config["project_domain"])) for user in ctx.context["users"]: self.assertEqual(set(["id", "endpoint", "tenant_id"]), diff --git a/tests/unit/plugins/openstack/context/network/test_allow_ssh.py b/tests/unit/plugins/openstack/context/network/test_allow_ssh.py index 0a6c6533..8615bc08 100644 --- a/tests/unit/plugins/openstack/context/network/test_allow_ssh.py +++ b/tests/unit/plugins/openstack/context/network/test_allow_ssh.py @@ -28,7 +28,6 @@ class AllowSSHContextTestCase(test.TestCase): def setUp(self): super(AllowSSHContextTestCase, self).setUp() self.users = 2 - self.secgroup_name = allow_ssh.SSH_GROUP_NAME + "_foo" self.secgroup_name = "test-secgroup" self.ctx_with_secgroup = test.get_test_context() diff --git a/tests/unit/plugins/openstack/context/nova/test_keypairs.py b/tests/unit/plugins/openstack/context/nova/test_keypairs.py index 64fc3ba4..b770eb1f 100644 --- a/tests/unit/plugins/openstack/context/nova/test_keypairs.py +++ b/tests/unit/plugins/openstack/context/nova/test_keypairs.py @@ -26,41 +26,47 @@ class KeyPairContextTestCase(test.TestCase): def setUp(self): super(KeyPairContextTestCase, self).setUp() self.users = 2 - self.keypair_name = keypairs.Keypair.KEYPAIR_NAME + "_foo_task_id" task = {"uuid": "foo_task_id"} self.ctx_with_keys = { "users": [ { "keypair": { - "id": "key_id", - "key": "key", - "name": self.keypair_name + "id": "key_id_1", + "key": "key_1", + "name": "key_name_1" }, - "endpoint": "endpoint" + "endpoint": "endpoint_1" }, - ] * self.users, + { + "keypair": { + "id": "key_id_2", + "key": "key_2", + "name": "key_name_2" + }, + "endpoint": "endpoint_2" + }, + ], "task": task } self.ctx_without_keys = { - "users": [{"endpoint": "endpoint"}] * self.users, + "users": [{"endpoint": "endpoint_1"}, + {"endpoint": "endpoint_2"}], "task": task } - @mock.patch("%s.keypairs.Keypair._generate_keypair" % CTX) - def test_keypair_setup(self, mock_keypair__generate_keypair): - mock_keypair__generate_keypair.side_effect = [ - {"id": "key_id", "key": "key", "name": self.keypair_name}, - {"id": "key_id", "key": "key", "name": self.keypair_name}, - ] - + def test_keypair_setup(self): keypair_ctx = keypairs.Keypair(self.ctx_without_keys) - keypair_ctx.setup() - self.assertEqual(self.ctx_with_keys, keypair_ctx.context) + keypair_ctx._generate_keypair = mock.Mock(side_effect=[ + {"id": "key_id_1", "key": "key_1", "name": "key_name_1"}, + {"id": "key_id_2", "key": "key_2", "name": "key_name_2"}, + ]) - self.assertEqual( - [mock.call("endpoint")] * 2, - mock_keypair__generate_keypair.mock_calls) + keypair_ctx.setup() + self.assertEqual(keypair_ctx.context, self.ctx_with_keys) + + keypair_ctx._generate_keypair.assert_has_calls( + [mock.call("endpoint_1"), mock.call("endpoint_2")]) @mock.patch("%s.keypairs.resource_manager.cleanup" % CTX) def test_keypair_cleanup(self, mock_cleanup): @@ -77,16 +83,19 @@ class KeyPairContextTestCase(test.TestCase): mock_keypair.private_key = "private_key" mock_keypair.id = "key_id" keypair_ctx = keypairs.Keypair(self.ctx_without_keys) + keypair_ctx.generate_random_name = mock.Mock() key = keypair_ctx._generate_keypair("endpoint") self.assertEqual({ "id": "key_id", - "name": "rally_ssh_key_foo_task_id", + "name": keypair_ctx.generate_random_name.return_value, "private": "private_key", "public": "public_key" }, key) mock_clients.assert_has_calls([ - mock.call().nova().keypairs.delete("rally_ssh_key_foo_task_id"), - mock.call().nova().keypairs.create("rally_ssh_key_foo_task_id"), + mock.call().nova().keypairs.delete( + keypair_ctx.generate_random_name.return_value), + mock.call().nova().keypairs.create( + keypair_ctx.generate_random_name.return_value) ]) 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 34b3b2d5..0aa6a77e 100644 --- a/tests/unit/plugins/openstack/context/sahara/test_sahara_image.py +++ b/tests/unit/plugins/openstack/context/sahara/test_sahara_image.py @@ -83,25 +83,24 @@ class SaharaImageTestCase(test.ScenarioTestCase): }) return self.context - @mock.patch("%s.rutils.generate_random_name" % CTX, - return_value="sahara_image_42") @mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN, return_value=mock.MagicMock(id=42)) @mock.patch("%s.resource_manager.cleanup" % CTX) def test_setup_and_cleanup_url_image(self, mock_cleanup, - mock_glance_scenario__create_image, - mock_generate_random_name): + mock_glance_scenario__create_image): ctx = self.url_image_context sahara_ctx = sahara_image.SaharaImage(ctx) + sahara_ctx.generate_random_name = mock.Mock() glance_calls = [] for i in range(self.tenants_num): - glance_calls.append(mock.call(container_format="bare", - image_location="http://somewhere", - disk_format="qcow2", - name="sahara_image_42")) + glance_calls.append( + mock.call(container_format="bare", + image_location="http://somewhere", + disk_format="qcow2", + name=sahara_ctx.generate_random_name.return_value)) sahara_update_image_calls = [] sahara_update_tags_calls = [] diff --git a/tests/unit/plugins/openstack/context/swift/test_objects.py b/tests/unit/plugins/openstack/context/swift/test_objects.py index f339022c..5c6396f5 100644 --- a/tests/unit/plugins/openstack/context/swift/test_objects.py +++ b/tests/unit/plugins/openstack/context/swift/test_objects.py @@ -26,7 +26,8 @@ class SwiftObjectGeneratorTestCase(test.TestCase): def test_setup(self, mock_clients): containers_per_tenant = 2 objects_per_container = 7 - context = { + context = test.get_test_context() + context.update({ "config": { "swift_objects": { "containers_per_tenant": containers_per_tenant, @@ -35,7 +36,6 @@ class SwiftObjectGeneratorTestCase(test.TestCase): "resource_management_workers": 10 } }, - "task": {"uuid": "id123"}, "tenants": { "t1": {"name": "t1_name"}, "t2": {"name": "t2_name"} @@ -44,7 +44,7 @@ class SwiftObjectGeneratorTestCase(test.TestCase): {"id": "u1", "tenant_id": "t1", "endpoint": "e1"}, {"id": "u2", "tenant_id": "t2", "endpoint": "e2"} ] - } + }) objects_ctx = objects.SwiftObjectGenerator(context) objects_ctx.setup() @@ -53,23 +53,20 @@ class SwiftObjectGeneratorTestCase(test.TestCase): containers = context["tenants"][tenant_id]["containers"] self.assertEqual(containers_per_tenant, len(containers)) for container in containers: - self.assertIn("rally_container_", container["container"]) self.assertEqual(objects_per_container, len(container["objects"])) - for obj in container["objects"]: - self.assertIn("rally_object_", obj) @mock.patch("rally.osclients.Clients") @mock.patch("rally.plugins.openstack.context.swift.utils." "swift_utils.SwiftScenario") def test_cleanup(self, mock_swift_scenario, mock_clients): - context = { + context = test.get_test_context() + context.update({ "config": { "swift_objects": { "resource_management_workers": 1 } }, - "task": {"uuid": "id123"}, "tenants": { "t1": { "name": "t1_name", @@ -90,7 +87,7 @@ class SwiftObjectGeneratorTestCase(test.TestCase): ] } } - } + }) objects_ctx = objects.SwiftObjectGenerator(context) objects_ctx.cleanup() @@ -111,7 +108,8 @@ class SwiftObjectGeneratorTestCase(test.TestCase): @mock.patch("rally.osclients.Clients") def test_setup_failure_clients_put_container(self, mock_clients): - context = { + context = test.get_test_context() + context.update({ "config": { "swift_objects": { "containers_per_tenant": 2, @@ -119,7 +117,6 @@ class SwiftObjectGeneratorTestCase(test.TestCase): "resource_management_workers": 5 } }, - "task": {"uuid": "id123"}, "tenants": { "t1": {"name": "t1_name"}, "t2": {"name": "t2_name"} @@ -128,7 +125,7 @@ class SwiftObjectGeneratorTestCase(test.TestCase): {"id": "u1", "tenant_id": "t1", "endpoint": "e1"}, {"id": "u2", "tenant_id": "t2", "endpoint": "e2"} ] - } + }) mock_swift = mock_clients.return_value.swift.return_value mock_swift.put_container.side_effect = [Exception, True, Exception, Exception] @@ -139,8 +136,8 @@ class SwiftObjectGeneratorTestCase(test.TestCase): @mock.patch("rally.osclients.Clients") def test_setup_failure_clients_put_object(self, mock_clients): - context = { - "task": {"uuid": "id123"}, + context = test.get_test_context() + context.update({ "tenants": { "t1": {"name": "t1_name"}, "t2": {"name": "t2_name"} @@ -149,7 +146,7 @@ class SwiftObjectGeneratorTestCase(test.TestCase): {"id": "u1", "tenant_id": "t1", "endpoint": "e1"}, {"id": "u2", "tenant_id": "t2", "endpoint": "e2"} ] - } + }) mock_swift = mock_clients.return_value.swift.return_value mock_swift.put_object.side_effect = [Exception, True] objects_ctx = objects.SwiftObjectGenerator(context) @@ -159,8 +156,8 @@ class SwiftObjectGeneratorTestCase(test.TestCase): @mock.patch("rally.osclients.Clients") def test_cleanup_failure_clients_delete_container(self, mock_clients): - context = { - "task": {"uuid": "id123"}, + context = test.get_test_context() + context.update({ "tenants": { "t1": { "name": "t1_name", @@ -171,7 +168,7 @@ class SwiftObjectGeneratorTestCase(test.TestCase): "objects": []}] * 3 } } - } + }) mock_swift = mock_clients.return_value.swift.return_value mock_swift.delete_container.side_effect = [True, True, Exception] objects_ctx = objects.SwiftObjectGenerator(context) @@ -180,8 +177,8 @@ class SwiftObjectGeneratorTestCase(test.TestCase): @mock.patch("rally.osclients.Clients") def test_cleanup_failure_clients_delete_object(self, mock_clients): - context = { - "task": {"uuid": "id123"}, + context = test.get_test_context() + context.update({ "tenants": { "t1": { "name": "t1_name", @@ -193,7 +190,7 @@ class SwiftObjectGeneratorTestCase(test.TestCase): ] } } - } + }) mock_swift = mock_clients.return_value.swift.return_value mock_swift.delete_object.side_effect = [True, Exception, True] objects_ctx = objects.SwiftObjectGenerator(context) diff --git a/tests/unit/plugins/openstack/context/swift/test_utils.py b/tests/unit/plugins/openstack/context/swift/test_utils.py index 047b8b99..365f3d4c 100644 --- a/tests/unit/plugins/openstack/context/swift/test_utils.py +++ b/tests/unit/plugins/openstack/context/swift/test_utils.py @@ -25,8 +25,8 @@ class SwiftObjectMixinTestCase(test.TestCase): def test__create_containers(self, mock_clients): tenants = 2 containers_per_tenant = 2 - context = { - "task": {"uuid": "id123"}, + context = test.get_test_context() + context.update({ "tenants": { "1001": {"name": "t1_name"}, "1002": {"name": "t2_name"} @@ -35,7 +35,7 @@ class SwiftObjectMixinTestCase(test.TestCase): {"id": "u1", "tenant_id": "1001", "endpoint": "e1"}, {"id": "u2", "tenant_id": "1002", "endpoint": "e2"} ] - } + }) mixin = utils.SwiftObjectMixin() containers = mixin._create_containers(context, containers_per_tenant, @@ -45,7 +45,6 @@ class SwiftObjectMixinTestCase(test.TestCase): for index, container in enumerate(sorted(containers)): offset = int(index / containers_per_tenant) + 1 self.assertEqual(str(1000 + offset), container[0]) - self.assertIn("rally_container_", container[1]) for index, tenant_id in enumerate(sorted(context["tenants"]), start=1): containers = context["tenants"][tenant_id]["containers"] @@ -53,7 +52,6 @@ class SwiftObjectMixinTestCase(test.TestCase): for container in containers: self.assertEqual("u%d" % index, container["user"]["id"]) self.assertEqual("e%d" % index, container["user"]["endpoint"]) - self.assertIn("rally_container_", container["container"]) self.assertEqual(0, len(container["objects"])) @mock.patch("rally.osclients.Clients") @@ -61,8 +59,8 @@ class SwiftObjectMixinTestCase(test.TestCase): tenants = 2 containers_per_tenant = 1 objects_per_container = 5 - context = { - "task": {"uuid": "id123"}, + context = test.get_test_context() + context.update({ "tenants": { "1001": { "name": "t1_name", @@ -85,7 +83,7 @@ class SwiftObjectMixinTestCase(test.TestCase): ] } } - } + }) mixin = utils.SwiftObjectMixin() objects_list = mixin._create_objects(context, objects_per_container, @@ -99,19 +97,16 @@ class SwiftObjectMixinTestCase(test.TestCase): offset = int(index / chunk) + 1 self.assertEqual(str(1000 + offset), obj[0]) self.assertEqual("c%d" % offset, obj[1]) - self.assertIn("rally_object_", obj[2]) for tenant_id in context["tenants"]: for container in context["tenants"][tenant_id]["containers"]: self.assertEqual(objects_per_container, len(container["objects"])) - for obj in container["objects"]: - self.assertIn("rally_object_", obj) @mock.patch("rally.osclients.Clients") def test__delete_containers(self, mock_clients): - context = { - "task": {"uuid": "id123"}, + context = test.get_test_context() + context.update({ "tenants": { "1001": { "name": "t1_name", @@ -134,7 +129,7 @@ class SwiftObjectMixinTestCase(test.TestCase): ] } } - } + }) mixin = utils.SwiftObjectMixin() mixin._delete_containers(context, 1) @@ -150,8 +145,8 @@ class SwiftObjectMixinTestCase(test.TestCase): @mock.patch("rally.osclients.Clients") def test__delete_objects(self, mock_clients): - context = { - "task": {"uuid": "id123"}, + context = test.get_test_context() + context.update({ "tenants": { "1001": { "name": "t1_name", @@ -174,7 +169,7 @@ class SwiftObjectMixinTestCase(test.TestCase): ] } } - } + }) mixin = utils.SwiftObjectMixin() mixin._delete_objects(context, 1) diff --git a/tests/unit/plugins/openstack/context/vm/test_custom_image.py b/tests/unit/plugins/openstack/context/vm/test_custom_image.py index 09372ce0..945623f2 100644 --- a/tests/unit/plugins/openstack/context/vm/test_custom_image.py +++ b/tests/unit/plugins/openstack/context/vm/test_custom_image.py @@ -36,8 +36,8 @@ class BaseCustomImageContextVMTestCase(test.TestCase): def setUp(self): super(BaseCustomImageContextVMTestCase, self).setUp() - self.context = { - "task": mock.MagicMock(), + self.context = test.get_test_context() + self.context.update({ "config": { "test_custom_image": { "image": {"name": "image"}, @@ -60,7 +60,7 @@ class BaseCustomImageContextVMTestCase(test.TestCase): "tenant_id1": {}, "tenant_id2": {} } - } + }) @mock.patch("%s.vmtasks.VMTasks" % BASE) @mock.patch("%s.osclients.Clients" % BASE) @@ -80,12 +80,12 @@ class BaseCustomImageContextVMTestCase(test.TestCase): mock_vm_scenario = mock_vm_tasks.return_value = mock.MagicMock( _create_image=mock.MagicMock(return_value=fake_image), _boot_server_with_fip=mock.MagicMock( - return_value=(fake_server, ip)), - _generate_random_name=mock.MagicMock(return_value="foo_name"), + return_value=(fake_server, ip)) ) generator_ctx = TestImageGenerator(self.context) generator_ctx._customize_image = mock.MagicMock() + generator_ctx.generate_random_name = mock.Mock() user = { "endpoint": "endpoint", @@ -107,7 +107,8 @@ class BaseCustomImageContextVMTestCase(test.TestCase): mock_vm_scenario._boot_server_with_fip.assert_called_once_with( image="image", flavor="flavor", - name="foo_name", floating_network="floating", + name=generator_ctx.generate_random_name.return_value, + floating_network="floating", key_name="keypair_name", security_groups=["secgroup_name"], userdata=None, foo_arg="foo_value")