def test__create_objects(self, mock_clients): tenants = 2 containers_per_tenant = 1 objects_per_container = 5 context = { "task": { "uuid": "id123" }, "tenants": { "1001": { "name": "t1_name", "containers": [{ "user": { "id": "u1", "tenant_id": "1001", "endpoint": "e1" }, "container": "c1", "objects": [] }] }, "1002": { "name": "t2_name", "containers": [{ "user": { "id": "u2", "tenant_id": "1002", "endpoint": "e2" }, "container": "c2", "objects": [] }] } } } mixin = utils.SwiftObjectMixin() objects_list = mixin._create_objects(context, objects_per_container, 1024, 25) self.assertEqual( tenants * containers_per_tenant * objects_per_container, len(objects_list)) chunk = containers_per_tenant * objects_per_container for index, obj in enumerate(sorted(objects_list)): 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)
def test__create_objects(self, mock_clients): tenants = 2 containers_per_tenant = 1 objects_per_container = 5 context = test.get_test_context() context.update({ "tenants": { "1001": { "name": "t1_name", "containers": [{ "user": { "id": "u1", "tenant_id": "1001", "credential": mock.MagicMock() }, "container": "c1", "objects": [] }] }, "1002": { "name": "t2_name", "containers": [{ "user": { "id": "u2", "tenant_id": "1002", "credential": mock.MagicMock() }, "container": "c2", "objects": [] }] } } }) mixin = utils.SwiftObjectMixin() objects_list = mixin._create_objects(context, objects_per_container, 1024, 25) self.assertEqual( tenants * containers_per_tenant * objects_per_container, len(objects_list)) chunk = containers_per_tenant * objects_per_container for index, obj in enumerate(sorted(objects_list)): offset = int(index / chunk) + 1 self.assertEqual(str(1000 + offset), obj[0]) self.assertEqual("c%d" % offset, obj[1]) for tenant_id in context["tenants"]: for container in context["tenants"][tenant_id]["containers"]: self.assertEqual(objects_per_container, len(container["objects"]))
def test__delete_objects(self, mock_clients): context = { "task": { "uuid": "id123" }, "tenants": { "1001": { "name": "t1_name", "containers": [{ "user": { "id": "u1", "tenant_id": "1001", "endpoint": "e1" }, "container": "c1", "objects": ["o1", "o2", "o3"] }] }, "1002": { "name": "t2_name", "containers": [{ "user": { "id": "u2", "tenant_id": "1002", "endpoint": "e2" }, "container": "c2", "objects": ["o4", "o5", "o6"] }] } } } mixin = utils.SwiftObjectMixin() mixin._delete_objects(context, 1) mock_swift = mock_clients.return_value.swift.return_value expected_objects = [("c1", "o1"), ("c1", "o2"), ("c1", "o3"), ("c2", "o4"), ("c2", "o5"), ("c2", "o6")] mock_swift.delete_object.assert_has_calls( [mock.call(con, obj) for con, obj in expected_objects], any_order=True) for tenant_id in context["tenants"]: for container in context["tenants"][tenant_id]["containers"]: self.assertEqual(0, len(container["objects"]))
def test__delete_objects(self, mock_clients): context = test.get_test_context() context.update({ "tenants": { "1001": { "name": "t1_name", "containers": [{ "user": { "id": "u1", "tenant_id": "1001", "credential": mock.MagicMock() }, "container": "c1", "objects": ["o1", "o2", "o3"] }] }, "1002": { "name": "t2_name", "containers": [{ "user": { "id": "u2", "tenant_id": "1002", "credential": mock.MagicMock() }, "container": "c2", "objects": ["o4", "o5", "o6"] }] } } }) mixin = utils.SwiftObjectMixin() mixin._delete_objects(context, 1) mock_swift = mock_clients.return_value.swift.return_value expected_objects = [("c1", "o1"), ("c1", "o2"), ("c1", "o3"), ("c2", "o4"), ("c2", "o5"), ("c2", "o6")] mock_swift.delete_object.assert_has_calls( [mock.call(con, obj) for con, obj in expected_objects], any_order=True) for tenant_id in context["tenants"]: for container in context["tenants"][tenant_id]["containers"]: self.assertEqual(0, len(container["objects"]))
def test__delete_containers(self, mock_clients): context = test.get_test_context() context.update({ "tenants": { "1001": { "name": "t1_name", "containers": [{ "user": { "id": "u1", "tenant_id": "1001", "endpoint": "e1" }, "container": "c1", "objects": [] }] }, "1002": { "name": "t2_name", "containers": [{ "user": { "id": "u2", "tenant_id": "1002", "endpoint": "e2" }, "container": "c2", "objects": [] }] } } }) mixin = utils.SwiftObjectMixin() mixin._delete_containers(context, 1) mock_swift = mock_clients.return_value.swift.return_value expected_containers = ["c1", "c2"] mock_swift.delete_container.assert_has_calls( [mock.call(con) for con in expected_containers], any_order=True) for tenant_id in context["tenants"]: self.assertEqual(0, len(context["tenants"][tenant_id]["containers"]))
def test__create_containers(self, mock_clients): tenants = 2 containers_per_tenant = 2 context = { "task": { "uuid": "id123" }, "tenants": { "1001": { "name": "t1_name" }, "1002": { "name": "t2_name" } }, "users": [{ "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, 15) self.assertEqual(tenants * containers_per_tenant, len(containers)) 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"] self.assertEqual(containers_per_tenant, len(containers)) 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"]))
def test__create_containers(self, mock_clients): tenants = 2 containers_per_tenant = 2 context = test.get_test_context() c = [mock.MagicMock(), mock.MagicMock()] context.update({ "tenants": { "1001": { "name": "t1_name" }, "1002": { "name": "t2_name" } }, "users": [{ "id": "u1", "tenant_id": "1001", "credential": c[0] }, { "id": "u2", "tenant_id": "1002", "credential": c[1] }] }) mixin = utils.SwiftObjectMixin() containers = mixin._create_containers(context, containers_per_tenant, 15) self.assertEqual(tenants * containers_per_tenant, len(containers)) for index, container in enumerate(sorted(containers)): offset = int(index / containers_per_tenant) + 1 self.assertEqual(str(1000 + offset), container[0]) for index, tenant_id in enumerate(sorted(context["tenants"]), start=1): containers = context["tenants"][tenant_id]["containers"] self.assertEqual(containers_per_tenant, len(containers)) for container in containers: self.assertEqual("u%d" % index, container["user"]["id"]) self.assertEqual(c[index - 1], container["user"]["credential"]) self.assertEqual(0, len(container["objects"]))