def test_cleanup(self, mock_cinder_remover, mock_osclients): ctx_volumes = [{ 'volume_id': 'uuid', 'endpoint': mock.MagicMock(), '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, }, "volumes": { "size": 1, } }, "admin": { "endpoint": mock.MagicMock() }, "task": mock.MagicMock(), "users": user_key, "volumes": ctx_volumes, } volumes_ctx = volumes.VolumeGenerator(context) volumes_ctx.cleanup() self.assertEqual(2, len(mock_cinder_remover.mock_calls))
def test_init(self): context = {} context["task"] = mock.MagicMock() context["config"] = { "volumes": { "size": 1, "volumes_per_tenant": 5, } } inst = volumes.VolumeGenerator(context) self.assertEqual(inst.config, context["config"]["volumes"])
def test_init(self): context = {} context["task"] = mock.MagicMock() context["config"] = { "volumes": { "size": 1, } } new_context = copy.deepcopy(context) new_context["volumes"] = [] volumes.VolumeGenerator(context) self.assertEqual(new_context, context)
def test_setup(self, mock_osclients, mock_volume_create): fc = fakes.FakeClients() mock_osclients.Clients.return_value = fc tenants_count = 2 users_per_tenant = 5 volumes_per_tenant = 5 tenants = self._gen_tenants(tenants_count) users = list() for id in tenants.keys(): for i in range(users_per_tenant): users.append({"id": i, "tenant_id": id, "endpoint": "endpoint"}) real_context = { "config": { "users": { "tenants": 2, "users_per_tenant": 5, "concurrent": 10, }, "volumes": { "size": 1, "volumes_per_tenant": 5, } }, "admin": { "endpoint": mock.MagicMock() }, "task": mock.MagicMock(), "users": users, "tenants": tenants } new_context = copy.deepcopy(real_context) for id in tenants.keys(): new_context["tenants"][id].setdefault("volumes", list()) for i in range(volumes_per_tenant): new_context["tenants"][id]["volumes"].append({"id": "uuid"}) volumes_ctx = volumes.VolumeGenerator(real_context) volumes_ctx.setup() self.assertEqual(new_context, real_context)
def test_cleanup(self, mock_cleanup, mock_osclients): tenants_count = 2 users_per_tenant = 5 volumes_per_tenant = 5 tenants = self._gen_tenants(tenants_count) users = list() for id in tenants.keys(): for i in range(users_per_tenant): users.append({"id": i, "tenant_id": id, "endpoint": "endpoint"}) tenants[id].setdefault("volumes", list()) for j in range(volumes_per_tenant): tenants[id]["volumes"].append({"id": "uuid"}) context = { "config": { "users": { "tenants": 2, "users_per_tenant": 5, "concurrent": 10, }, "volumes": { "size": 1, "volumes_per_tenant": 5, } }, "admin": { "endpoint": mock.MagicMock() }, "task": mock.MagicMock(), "users": users, "tenants": tenants } volumes_ctx = volumes.VolumeGenerator(context) volumes_ctx.cleanup() mock_cleanup.assert_called_once_with(names=["cinder.volumes"], users=context["users"])
def test_setup(self, mock_osclients, mock_volume_create): fc = fakes.FakeClients() mock_osclients.Clients.return_value = fc ctx_volumes = [{ 'volume_id': 'uuid', '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, }, "volumes": { "size": 1, } }, "admin": { "endpoint": mock.MagicMock() }, "task": mock.MagicMock(), "users": user_key, } new_context = copy.deepcopy(real_context) new_context["volumes"] = ctx_volumes volumes_ctx = volumes.VolumeGenerator(real_context) volumes_ctx.setup() self.assertEqual(new_context, real_context)