def test__discover_image(self, mock_image): client = mock_image.return_value client.list_images.return_value = [fakes.FakeImage(name="Foo"), fakes.FakeImage(name="CirrOS")] image = self.context._discover_image() self.assertEqual("CirrOS", image.name)
def test__set_compute_images(self, mock_glance): mock_glanceclient = mock.MagicMock() mock_glanceclient.images.list.return_value = [ fakes.FakeImage(id="id1", name="cirros1"), fakes.FakeImage(id="id2", name="cirros2")] mock_glance.Client.return_value = mock_glanceclient self.conf_generator._set_compute_images() expected = ("id1", "id2") results = (self.conf_generator.conf.get("compute", "image_ref"), self.conf_generator.conf.get("compute", "image_ref_alt")) self.assertEqual(sorted(expected), sorted(results))
def test__set_compute_images_create(self, mock_open, mock_glance): mock_glanceclient = mock.MagicMock() mock_glanceclient.images.list.return_value = [] mock_glanceclient.images.create.side_effect = [ fakes.FakeImage(id="id1"), fakes.FakeImage(id="id2")] mock_glance.Client.return_value = mock_glanceclient self.conf_generator._set_compute_images() self.assertEqual(mock_glanceclient.images.create.call_count, 2) expected = ("id1", "id2") results = (self.conf_generator.conf.get("compute", "image_ref"), self.conf_generator.conf.get("compute", "image_ref_alt")) self.assertEqual(sorted(expected), sorted(results))
def test__cleanup_images(self): self.context._created_images = [fakes.FakeImage(id="id1"), fakes.FakeImage(id="id2")] self.context.conf.set("compute", "image_ref", "id1") self.context.conf.set("compute", "image_ref_alt", "id2") self.context._cleanup_images() client = self.context.clients.glance() self.assertEqual(client.images.delete.call_count, 2) self.assertEqual("", self.context.conf.get("compute", "image_ref")) self.assertEqual("", self.context.conf.get("compute", "image_ref_alt"))
def test_create_image_and_boot_instances(self, mock_boot_servers): image_service = self.mock_image.return_value fake_image = fakes.FakeImage() fake_servers = [mock.Mock() for i in range(5)] image_service.create_image.return_value = fake_image mock_boot_servers.return_value = fake_servers create_image_kwargs = {"fakeimagearg": "f"} boot_server_kwargs = {"fakeserverarg": "f"} call_args = { "container_format": "cf", "image_location": "url", "disk_format": "df", "fakeimagearg": "f" } images.CreateImageAndBootInstances(self.context).run( "cf", "url", "df", "fid", 5, create_image_kwargs=create_image_kwargs, boot_server_kwargs=boot_server_kwargs) image_service.create_image.assert_called_once_with(**call_args) mock_boot_servers.assert_called_once_with("image-id-0", "fid", 5, **boot_server_kwargs)
def test__discover_or_create_image_when_image_exists(self, mock_wrap): client = self.context.clients.glance() client.images.list.return_value = [fakes.FakeImage(name="CirrOS", status="active")] image = self.context._discover_or_create_image() self.assertEqual("CirrOS", image.name) self.assertEqual(0, len(self.context._created_images))
def test_create_and_download_image(self): image_service = self.mock_image.return_value fake_image = fakes.FakeImage() image_service.create_image.return_value = fake_image properties = {"fakeprop": "fake"} call_args = { "container_format": "cf", "image_location": "url", "disk_format": "df", "visibility": "vs", "min_disk": 0, "min_ram": 0, "properties": properties } images.CreateAndDownloadImage(self.context).run("cf", "url", "df", "vs", 0, 0, properties=properties) image_service.create_image.assert_called_once_with(**call_args) image_service.download_image.assert_called_once_with(fake_image.id)
def test_create_image_and_boot_instances(self, mock_osclients, mock_create_image, mock_boot_servers, mock_random_name): glance_scenario = images.GlanceImages() nova_scenario = servers.NovaServers() fc = fakes.FakeClients() mock_osclients.Clients.return_value = fc fake_glance = fakes.FakeGlanceClient() fc.glance = lambda: fake_glance fake_nova = fakes.FakeNovaClient() fc.nova = lambda: fake_nova user_endpoint = endpoint.Endpoint("url", "user", "password", "tenant") nova_scenario._clients = osclients.Clients(user_endpoint) fake_image = fakes.FakeImage() fake_servers = [object() for i in range(5)] mock_create_image.return_value = fake_image mock_boot_servers.return_value = fake_servers mock_random_name.return_value = "random_name" kwargs = {'fakearg': 'f'} with mock.patch("rally.benchmark.scenarios.glance.utils.time.sleep"): glance_scenario.create_image_and_boot_instances("cf", "url", "df", "fid", 5, **kwargs) mock_create_image.assert_called_once_with("random_name", "cf", "url", "df", **kwargs) mock_boot_servers.assert_called_once_with("random_name", "image-id-0", "fid", 5, **kwargs)
def test_create_image_and_boot_instances(self, mock_boot_servers): image_service = self.mock_image.return_value fake_image = fakes.FakeImage() fake_servers = [mock.Mock() for i in range(5)] image_service.create_image.return_value = fake_image mock_boot_servers.return_value = fake_servers boot_server_kwargs = {"fakeserverarg": "f"} properties = {"fakeprop": "fake"} call_args = { "container_format": "cf", "image_location": "url", "disk_format": "df", "visibility": "vs", "min_disk": 0, "min_ram": 0, "properties": properties } images.CreateImageAndBootInstances(self.context).run( "cf", "url", "df", "fid", 5, visibility="vs", min_disk=0, min_ram=0, properties=properties, boot_server_kwargs=boot_server_kwargs) image_service.create_image.assert_called_once_with(**call_args) mock_boot_servers.assert_called_once_with("image-id-0", "fid", 5, **boot_server_kwargs)
def test_create_and_update_image(self): image_service = self.mock_image.return_value fake_image = fakes.FakeImage(id=1, name="imagexxx") image_service.create_image.return_value = fake_image properties = {"fakeprop": "fake"} create_args = { "container_format": "cf", "image_location": "url", "disk_format": "df", "visibility": "vs", "min_disk": 0, "min_ram": 0, "properties": properties } images.CreateAndUpdateImage(self.context).run("cf", "url", "df", None, "vs", 0, 0, properties, 0, 0) image_service.create_image.assert_called_once_with(**create_args) image_service.update_image.assert_called_once_with(fake_image.id, min_disk=0, min_ram=0, remove_props=None)
def test__create_image(self, mock_open): client = self.context.clients.glance() client.images.create.side_effect = [fakes.FakeImage(id="id1")] image = self.context._create_image() self.assertEqual("id1", image.id) self.assertEqual("id1", self.context._created_images[0].id)
def test__discover_or_create_image_when_image_exists(self, mock_image): client = mock_image.return_value client.list_images.return_value = [fakes.FakeImage(name="CirrOS")] image = self.context._discover_or_create_image() self.assertEqual("CirrOS", image.name) self.assertEqual(0, client.create_image.call_count) self.assertEqual(0, len(self.context._created_images))
def test_create_and_get_image(self): image_service = self.mock_image.return_value fake_image = fakes.FakeImage(id=1, name="img_name1") image_service.create_image.return_value = fake_image fake_image_info = fakes.FakeImage(id=1, name="img_name1", status="active") image_service.get_image.return_value = fake_image_info properties = {"fakeprop": "fake"} call_args = { "container_format": "cf", "image_location": "url", "disk_format": "df", "visibility": "vs", "min_disk": 0, "min_ram": 0, "properties": properties } # Positive case images.CreateAndGetImage(self.context).run("cf", "url", "df", "vs", 0, 0, properties) image_service.create_image.assert_called_once_with(**call_args) image_service.get_image.assert_called_once_with(fake_image) # Negative case: image isn't created image_service.create_image.reset_mock() image_service.create_image.return_value = None self.assertRaises(exceptions.RallyAssertionError, images.CreateAndGetImage(self.context).run, "cf", "url", "df", "vs", 0, 0, properties) image_service.create_image.assert_called_with(**call_args) # Negative case: image obtained in _get_image not the created image image_service.create_image.reset_mock() image_service.get_image.reset_mock() image_service.create_image.return_value = fakes.FakeImage( id=12, name="img_nameN") self.assertRaises(exceptions.RallyAssertionError, images.CreateAndGetImage(self.context).run, "cf", "url", "df", "vs", 0, 0, properties) image_service.create_image.assert_called_with(**call_args) image_service.get_image.assert_called_with( image_service.create_image.return_value)
def test__configure_option_image(self, mock_open): mock_glanceclient = mock.MagicMock() mock_glanceclient.images.create.side_effect = [ fakes.FakeImage(id="id1"), fakes.FakeImage(id="id2")] mock_glance = mock.MagicMock() mock_glance.Client.return_value = mock_glanceclient self.context.conf.set("compute", "image_ref", "") self.context.conf.set("compute", "image_ref_alt", "") with mock.patch.dict("sys.modules", {"glanceclient": mock_glance}): self.context._configure_option("image_ref", mock_glanceclient.images.create) self.context._configure_option("image_ref_alt", mock_glanceclient.images.create) self.assertEqual(mock_glanceclient.images.create.call_count, 2) expected = ("id1", "id2") results = (self.context.conf.get("compute", "image_ref"), self.context.conf.get("compute", "image_ref_alt")) self.assertEqual(sorted(expected), sorted(results))
def test__cleanup_images(self, mock_image): self.context._created_images = [fakes.FakeImage(id="id1"), fakes.FakeImage(id="id2")] self.context.conf.set("compute", "image_ref", "id1") self.context.conf.set("compute", "image_ref_alt", "id2") image_service = mock_image.return_value image_service.get_image.side_effect = [ fakes.FakeImage(id="id1", status="DELETED"), fakes.FakeImage(id="id2"), fakes.FakeImage(id="id2", status="DELETED")] self.context._cleanup_images() client = self.context.clients.glance() client.images.delete.assert_has_calls([mock.call("id1"), mock.call("id2")]) self.assertEqual("", self.context.conf.get("compute", "image_ref")) self.assertEqual("", self.context.conf.get("compute", "image_ref_alt"))
def test_create_image_and_boot_instances(self, mock_create_image, mock_boot_servers): fake_image = fakes.FakeImage() fake_servers = [mock.Mock() for i in range(5)] mock_create_image.return_value = fake_image mock_boot_servers.return_value = fake_servers kwargs = {"fakearg": "f"} images.CreateImageAndBootInstances(self.context).run( "cf", "url", "df", "fid", 5, **kwargs) mock_create_image.assert_called_once_with("cf", "url", "df") mock_boot_servers.assert_called_once_with("image-id-0", "fid", 5, **kwargs)
def test_boot_and_show_server(self): server = fakes.FakeServer() image = fakes.FakeImage() flavor = fakes.FakeFlavor() scenario = servers.NovaServers(self.context) scenario._boot_server = mock.MagicMock(return_value=server) scenario._show_server = mock.MagicMock() scenario.boot_and_show_server(image, flavor, fakearg="fakearg") scenario._boot_server.assert_called_once_with(image, flavor, fakearg="fakearg") scenario._show_server.assert_called_once_with(server)
def test_create_image_and_boot_instances(self, mock__create_image, mock__boot_servers): glance_scenario = images.GlanceImages(self.context) fake_image = fakes.FakeImage() fake_servers = [mock.Mock() for i in range(5)] mock__create_image.return_value = fake_image mock__boot_servers.return_value = fake_servers kwargs = {"fakearg": "f"} glance_scenario.create_image_and_boot_instances( "cf", "url", "df", "fid", 5, **kwargs) mock__create_image.assert_called_once_with("cf", "url", "df") mock__boot_servers.assert_called_once_with("image-id-0", "fid", 5, **kwargs)
def test_boot_server_and_list_interfaces(self): server = fakes.FakeServer() image = fakes.FakeImage() flavor = fakes.FakeFlavor() scenario = servers.BootServerAndListInterfaces(self.context) scenario._boot_server = mock.MagicMock(return_value=server) scenario._list_interfaces = mock.MagicMock() scenario.run(image, flavor, fakearg="fakearg") scenario._boot_server.assert_called_once_with(image, flavor, fakearg="fakearg") scenario._list_interfaces.assert_called_once_with(server)
def test_boot_and_get_console_server(self, length): server = fakes.FakeServer() image = fakes.FakeImage() flavor = fakes.FakeFlavor() kwargs = {"fakearg": "fakearg"} scenario = servers.BootAndGetConsoleOutput(self.context) scenario._boot_server = mock.MagicMock(return_value=server) scenario._get_server_console_output = mock.MagicMock() scenario.run(image, flavor, length, **kwargs) scenario._boot_server.assert_called_once_with(image, flavor, **kwargs) scenario._get_server_console_output.assert_called_once_with( server, length)
def test_boot_and_get_console_url(self): server = fakes.FakeServer() image = fakes.FakeImage() flavor = fakes.FakeFlavor() kwargs = {"fakearg": "fakearg"} scenario = servers.BootAndGetConsoleUrl(self.context) scenario._boot_server = mock.MagicMock(return_value=server) scenario._get_console_url_server = mock.MagicMock() scenario.run(image, flavor, console_type="novnc", **kwargs) scenario._boot_server.assert_called_once_with(image, flavor, **kwargs) scenario._get_console_url_server.assert_called_once_with( server, "novnc")
def test_create_image_and_boot_instances(self, mock__create_image, mock__boot_servers): glance_scenario = images.GlanceImages() fake_image = fakes.FakeImage() fake_servers = [mock.Mock() for i in range(5)] mock__create_image.return_value = fake_image mock__boot_servers.return_value = fake_servers kwargs = {"fakearg": "f"} with mock.patch("rally.plugins.openstack.scenarios." "glance.utils.time.sleep"): glance_scenario.create_image_and_boot_instances( "cf", "url", "df", "fid", 5, **kwargs) mock__create_image.assert_called_once_with("cf", "url", "df") mock__boot_servers.assert_called_once_with("image-id-0", "fid", 5, **kwargs)
def test_create_and_list_image(self, mock_create_image, mock_list_images): fake_image = fakes.FakeImage(id=1, name="img_name1") mock_create_image.return_value = fake_image mock_list_images.return_value = [ fakes.FakeImage(id=0, name="img_name1"), fake_image, fakes.FakeImage(id=2, name="img_name1") ] # Positive case images.CreateAndListImage(self.context).run( "cf", "url", "df", fakearg="f") mock_create_image.assert_called_once_with( "cf", "url", "df", fakearg="f") mock_list_images.assert_called_once_with() # Negative case: image isn't created mock_create_image.return_value = None self.assertRaises(exceptions.RallyAssertionError, images.CreateAndListImage(self.context).run, "cf", "url", "df", fakearg="f") mock_create_image.assert_called_with( "cf", "url", "df", fakearg="f") # Negative case: created image n ot in the list of available images mock_create_image.return_value = fakes.FakeImage( id=12, name="img_nameN") self.assertRaises(exceptions.RallyAssertionError, images.CreateAndListImage(self.context).run, "cf", "url", "df", fakearg="f") mock_create_image.assert_called_with( "cf", "url", "df", fakearg="f") mock_list_images.assert_called_with()
def test_create_and_deactivate_image(self, mock_deactivate_image, mock_create_image): fake_image = fakes.FakeImage(id=1, name="img_name1") mock_create_image.return_value = fake_image call_args = { "container_format": "cf", "image_location": "url", "disk_format": "df", "visibility": "vs", "min_disk": 0, "min_ram": 0 } images.CreateAndDeactivateImage(self.context).run( "cf", "url", "df", "vs", 0, 0) mock_create_image.assert_called_once_with(**call_args) mock_deactivate_image.assert_called_once_with(fake_image.id)
def test_create_and_delete_image(self): image_service = self.mock_image.return_value fake_image = fakes.FakeImage(id=1, name="imagexxx") image_service.create_image.return_value = fake_image call_args = { "container_format": "cf", "image_location": "url", "disk_format": "df", "visibility": "vs", "min_disk": 0, "min_ram": 0 } images.CreateAndDeleteImage(self.context).run("cf", "url", "df", "vs", 0, 0) image_service.create_image.assert_called_once_with(**call_args) image_service.delete_image.assert_called_once_with(fake_image.id)
def test_boot_lock_unlock_and_delete(self): server = fakes.FakeServer() image = fakes.FakeImage() flavor = fakes.FakeFlavor() scenario = servers.NovaServers(self.context) scenario._boot_server = mock.Mock(return_value=server) scenario._lock_server = mock.Mock(side_effect=lambda s: s.lock()) scenario._unlock_server = mock.Mock(side_effect=lambda s: s.unlock()) scenario._delete_server = mock.Mock( side_effect=lambda s, **kwargs: self.assertFalse(getattr(s, "OS-EXT-STS:locked", False))) scenario.boot_lock_unlock_and_delete(image, flavor, fakearg="fakearg") scenario._boot_server.assert_called_once_with(image, flavor, fakearg="fakearg") scenario._lock_server.assert_called_once_with(server) scenario._unlock_server.assert_called_once_with(server) scenario._delete_server.assert_called_once_with(server, force=False)
class ImageGeneratorTestCase(test.TestCase): def test_init(self): context = {} context["task"] = mock.MagicMock() context["config"] = { "images": { "image_url": "mock_url", "image_type": "qcow2", "image_container": "bare", "images_per_tenant": 4, } } new_context = copy.deepcopy(context) new_context["images"] = [] images.ImageGenerator(context) self.assertEqual(new_context, context) def test_init_validation(self): context = {} context["task"] = mock.MagicMock() context["config"] = {"images": {"image_url": "mock_url"}} self.assertRaises(jsonschema.ValidationError, images.ImageGenerator.validate, context) @mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN, return_value=fakes.FakeImage(id="uuid")) @mock.patch("%s.images.osclients" % CTX) def test_setup(self, mock_osclients, mock_image_create): fc = fakes.FakeClients() mock_osclients.Clients.return_value = fc image_list = ["uuid"] * 5 image_key = [{ 'image_id': image_list, 'endpoint': 'endpoint', 'tenant_id': i } for i in range(2)] user_key = [{ 'id': i, 'tenant_id': j, 'endpoint': 'endpoint' } for j in range(2) for i in range(5)] real_context = { "config": { "users": { "tenants": 2, "users_per_tenant": 5, "concurrent": 10, }, "images": { "image_url": "mock_url", "image_type": "qcow2", "image_container": "bare", "images_per_tenant": 5, } }, "admin": { "endpoint": mock.MagicMock() }, "task": mock.MagicMock(), "users": user_key, } new_context = copy.deepcopy(real_context) new_context["images"] = image_key images_ctx = images.ImageGenerator(real_context) images_ctx.setup() self.assertEqual(new_context, real_context) @mock.patch("%s.images.osclients" % CTX) @mock.patch("%s.cleanup.utils.delete_glance_resources" % CTX) def test_cleanup(self, mock_image_remover, mock_osclients): image_list = ["uuid"] * 5 image_key = [{ 'image_id': image_list, 'endpoint': 'endpoint', 'tenant_id': i } for i in range(2)] user_key = [{ 'id': i, 'tenant_id': j, 'endpoint': 'endpoint' } for j in range(2) for i in range(5)] context = { "config": { "users": { "tenants": 2, "users_per_tenant": 5, "concurrent": 10, }, "images": { "image_url": "mock_url", "image_type": "qcow2", "image_container": "bare", "images_per_tenant": 5, } }, "admin": { "endpoint": mock.MagicMock() }, "task": mock.MagicMock(), "users": user_key, "images": image_key, } images_ctx = images.ImageGenerator(context) images_ctx.cleanup() self.assertEqual(2, len(mock_image_remover.mock_calls)) mock_image_remover.side_effect = Exception('failed_deletion') self.assertRaises(exceptions.ImageCleanUpException, images_ctx.cleanup) def test_validate_semantic(self): users = [fakes.FakeClients()] images.ImageGenerator.validate_semantic(None, None, users, None) @mock.patch("%s.images.osclients.Clients.glance" % CTX) def test_validate_semantic_unavailabe(self, mock_glance): mock_glance.side_effect = Exception("list error") self.assertRaises(exceptions.InvalidScenarioArgument, images.ImageGenerator.validate_semantic, None, None, None, None)
class ImageGeneratorTestCase(test.TestCase): def _gen_tenants(self, count): tenants = {} for id_ in range(count): tenants[str(id_)] = dict(name=str(id_)) return tenants @mock.patch("rally.benchmark.context.images.base.Context.__init__") def test_init(self, mock_base_context_init): context = {} context["task"] = mock.MagicMock() context["config"] = { "images": { "image_url": "mock_url", "image_type": "qcow2", "image_container": "bare", "images_per_tenant": 4, "image_name": "some_name", "min_ram": 128, "min_disk": 1, } } images.ImageGenerator(context) mock_base_context_init.assert_called_once_with(context) def test_init_validation(self): context = {} context["task"] = mock.MagicMock() context["config"] = { "images": { "image_url": "mock_url" } } self.assertRaises(jsonschema.ValidationError, images.ImageGenerator.validate, context) @mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN, return_value=fakes.FakeImage(id="uuid")) @mock.patch("%s.images.osclients" % CTX) def test_setup(self, mock_osclients, mock_image_create): tenants_count = 2 users_per_tenant = 5 images_per_tenant = 5 fc = fakes.FakeClients() mock_osclients.Clients.return_value = fc tenants = self._gen_tenants(tenants_count) users = [] for id in tenants: for i in range(users_per_tenant): users.append({"id": i, "tenant_id": id, "endpoint": "endpoint"}) real_context = { "config": { "users": { "tenants": tenants_count, "users_per_tenant": users_per_tenant, "concurrent": 10, }, "images": { "image_url": "mock_url", "image_type": "qcow2", "image_container": "bare", "images_per_tenant": images_per_tenant, "image_name": "some_name", "min_ram": 128, "min_disk": 1, } }, "admin": { "endpoint": mock.MagicMock() }, "task": mock.MagicMock(), "users": users, "tenants": tenants } new_context = copy.deepcopy(real_context) for id in new_context["tenants"].keys(): new_context["tenants"][id].setdefault("images", list()) for j in range(images_per_tenant): new_context["tenants"][id]["images"].append("uuid") images_ctx = images.ImageGenerator(real_context) images_ctx.setup() self.assertEqual(new_context, real_context) @mock.patch("%s.images.osclients" % CTX) @mock.patch("%s.images.resource_manager.cleanup" % CTX) def test_cleanup(self, mock_cleanup, mock_osclients): tenants_count = 2 users_per_tenant = 5 images_per_tenant = 5 tenants = self._gen_tenants(tenants_count) users = [] for id_ in tenants: for i in range(users_per_tenant): users.append({"id": i, "tenant_id": id_, "endpoint": "endpoint"}) tenants[id_].setdefault("images", list()) for j in range(images_per_tenant): tenants[id_]["images"].append("uuid") context = { "config": { "users": { "tenants": 2, "users_per_tenant": 5, "concurrent": 10, }, "images": { "image_url": "mock_url", "image_type": "qcow2", "image_container": "bare", "images_per_tenant": 5, "image_name": "some_name", "min_ram": 128, "min_disk": 1, } }, "admin": { "endpoint": mock.MagicMock() }, "task": mock.MagicMock(), "users": users, "tenants": tenants } images_ctx = images.ImageGenerator(context) images_ctx.cleanup() mock_cleanup.assert_called_once_with(names=["glance.images"], users=context["users"])
class ImageGeneratorTestCase(test.ScenarioTestCase): def _gen_tenants(self, count): tenants = {} for id_ in range(count): tenants[str(id_)] = {"name": str(id_)} return tenants def test_init_validation(self): self.context["config"] = {"images": {"image_url": "mock_url"}} self.assertRaises(jsonschema.ValidationError, images.ImageGenerator.validate, self.context) @mock.patch("%s.utils.GlanceScenario._create_image" % SCN, return_value=fakes.FakeImage(id="uuid")) def test_setup(self, mock_glance_scenario__create_image): tenants_count = 2 users_per_tenant = 5 images_per_tenant = 5 tenants = self._gen_tenants(tenants_count) users = [] for id_ in tenants: for i in range(users_per_tenant): users.append({ "id": i, "tenant_id": id_, "endpoint": mock.MagicMock() }) self.context.update({ "config": { "users": { "tenants": tenants_count, "users_per_tenant": users_per_tenant, "concurrent": 10, }, "images": { "image_url": "mock_url", "image_type": "qcow2", "image_container": "bare", "images_per_tenant": images_per_tenant, "image_name": "some_name", "min_ram": 128, "min_disk": 1, } }, "admin": { "endpoint": mock.MagicMock() }, "users": users, "tenants": tenants }) new_context = copy.deepcopy(self.context) for id_ in new_context["tenants"].keys(): new_context["tenants"][id_].setdefault("images", []) for j in range(images_per_tenant): new_context["tenants"][id_]["images"].append("uuid") images_ctx = images.ImageGenerator(self.context) images_ctx.setup() self.assertEqual(new_context, self.context) @mock.patch("%s.images.resource_manager.cleanup" % CTX) def test_cleanup(self, mock_cleanup): tenants_count = 2 users_per_tenant = 5 images_per_tenant = 5 tenants = self._gen_tenants(tenants_count) users = [] for id_ in tenants: for i in range(users_per_tenant): users.append({ "id": i, "tenant_id": id_, "endpoint": "endpoint" }) tenants[id_].setdefault("images", []) for j in range(images_per_tenant): tenants[id_]["images"].append("uuid") self.context.update({ "config": { "users": { "tenants": 2, "users_per_tenant": 5, "concurrent": 10, }, "images": { "image_url": "mock_url", "image_type": "qcow2", "image_container": "bare", "images_per_tenant": 5, "image_name": "some_name", "min_ram": 128, "min_disk": 1, } }, "admin": { "endpoint": mock.MagicMock() }, "users": users, "tenants": tenants }) images_ctx = images.ImageGenerator(self.context) images_ctx.cleanup() mock_cleanup.assert_called_once_with(names=["glance.images"], users=self.context["users"])