From 48a4866e144d6ceb2e886f790149adfe77e4c41f Mon Sep 17 00:00:00 2001 From: John Wu Date: Tue, 26 May 2015 17:21:17 -0700 Subject: [PATCH] [Swift] Add additional Swift scenarios This patch adds additional swift scenarios to use what was created during swift context. Swift Scenarios: - list_and_download_objects_in_containers - list_objects_in_containers Blueprint benchmark-scenarios-for-swift Change-Id: I6d615889a1acfcd4686eb061f1041f5b22fd09f0 --- rally-jobs/rally.yaml | 41 ++++++++++++- .../openstack/scenarios/swift/objects.py | 47 +++++++++++++++ ...st-and-download-objects-in-containers.json | 25 ++++++++ ...st-and-download-objects-in-containers.yaml | 17 ++++++ .../swift/list-objects-in-containers.json | 25 ++++++++ .../swift/list-objects-in-containers.yaml | 17 ++++++ .../openstack/scenarios/swift/test_objects.py | 59 +++++++++++++++++++ 7 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 samples/tasks/scenarios/swift/list-and-download-objects-in-containers.json create mode 100644 samples/tasks/scenarios/swift/list-and-download-objects-in-containers.yaml create mode 100644 samples/tasks/scenarios/swift/list-objects-in-containers.json create mode 100644 samples/tasks/scenarios/swift/list-objects-in-containers.yaml diff --git a/rally-jobs/rally.yaml b/rally-jobs/rally.yaml index aa529de685..87204792d9 100644 --- a/rally-jobs/rally.yaml +++ b/rally-jobs/rally.yaml @@ -948,7 +948,6 @@ failure_rate: max: 0 - SwiftObjects.create_container_and_object_then_list_objects: - args: @@ -1037,3 +1036,43 @@ sla: failure_rate: max: 0 + + SwiftObjects.list_and_download_objects_in_containers: + - + runner: + type: "constant" + times: 2 + concurrency: 2 + context: + users: + tenants: 1 + users_per_tenant: 1 + roles: + - "admin" + swift_objects: + containers_per_tenant: 1 + objects_per_container: 5 + object_size: 10240 + sla: + failure_rate: + max: 0 + + SwiftObjects.list_objects_in_containers: + - + runner: + type: "constant" + times: 6 + concurrency: 3 + context: + users: + tenants: 1 + users_per_tenant: 1 + roles: + - "admin" + swift_objects: + containers_per_tenant: 1 + objects_per_container: 10 + object_size: 1024 + sla: + failure_rate: + max: 0 diff --git a/rally/plugins/openstack/scenarios/swift/objects.py b/rally/plugins/openstack/scenarios/swift/objects.py index 09b48b8c5c..5e5c8a98f6 100644 --- a/rally/plugins/openstack/scenarios/swift/objects.py +++ b/rally/plugins/openstack/scenarios/swift/objects.py @@ -123,3 +123,50 @@ class SwiftObjects(utils.SwiftScenario): for object_name in objects_list: self._download_object(container_name, object_name, atomic_action=False) + + @validation.required_services(consts.Service.SWIFT) + @validation.required_openstack(users=True) + @scenario.configure(context={"swift_objects": {}}) + def list_objects_in_containers(self): + """List objects in all containers.""" + containers = self._list_containers()[1] + + key_suffix = "container" + if len(containers) > 1: + key_suffix = "%i_containers" % len(containers) + + with atomic.ActionTimer(self, "swift.list_objects_in_%s" % key_suffix): + for container in containers: + self._list_objects(container["name"], atomic_action=False) + + @validation.required_services(consts.Service.SWIFT) + @validation.required_openstack(users=True) + @scenario.configure(context={"swift_objects": {}}) + def list_and_download_objects_in_containers(self): + """List and download objects in all containers.""" + containers = self._list_containers()[1] + + list_key_suffix = "container" + if len(containers) > 1: + list_key_suffix = "%i_containers" % len(containers) + + objects_dict = {} + with atomic.ActionTimer(self, + "swift.list_objects_in_%s" % list_key_suffix): + for container in containers: + container_name = container["name"] + objects_dict[container_name] = self._list_objects( + container_name, + atomic_action=False)[1] + + objects_total = sum(map(len, objects_dict.values())) + download_key_suffix = "object" + if objects_total > 1: + download_key_suffix = "%i_objects" % objects_total + + with atomic.ActionTimer(self, + "swift.download_%s" % download_key_suffix): + for container_name, objects in objects_dict.items(): + for obj in objects: + self._download_object(container_name, obj["name"], + atomic_action=False) diff --git a/samples/tasks/scenarios/swift/list-and-download-objects-in-containers.json b/samples/tasks/scenarios/swift/list-and-download-objects-in-containers.json new file mode 100644 index 0000000000..8ed1b0eee2 --- /dev/null +++ b/samples/tasks/scenarios/swift/list-and-download-objects-in-containers.json @@ -0,0 +1,25 @@ +{ + "SwiftObjects.list_and_download_objects_in_containers": [ + { + "runner": { + "type": "constant", + "times": 2, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 1, + "users_per_tenant": 1 + }, + "roles": [ + "admin" + ], + "swift_objects": { + "containers_per_tenant": 2, + "objects_per_container": 5, + "object_size": 10240 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/swift/list-and-download-objects-in-containers.yaml b/samples/tasks/scenarios/swift/list-and-download-objects-in-containers.yaml new file mode 100644 index 0000000000..a11aa6b8fd --- /dev/null +++ b/samples/tasks/scenarios/swift/list-and-download-objects-in-containers.yaml @@ -0,0 +1,17 @@ +--- + SwiftObjects.list_and_download_objects_in_containers: + - + runner: + type: "constant" + times: 2 + concurrency: 2 + context: + users: + tenants: 1 + users_per_tenant: 1 + roles: + - "admin" + swift_objects: + containers_per_tenant: 2 + objects_per_container: 5 + object_size: 10240 diff --git a/samples/tasks/scenarios/swift/list-objects-in-containers.json b/samples/tasks/scenarios/swift/list-objects-in-containers.json new file mode 100644 index 0000000000..576561dc87 --- /dev/null +++ b/samples/tasks/scenarios/swift/list-objects-in-containers.json @@ -0,0 +1,25 @@ +{ + "SwiftObjects.list_objects_in_containers": [ + { + "runner": { + "type": "constant", + "times": 6, + "concurrency": 3 + }, + "context": { + "users": { + "tenants": 1, + "users_per_tenant": 1 + }, + "roles": [ + "admin" + ], + "swift_objects": { + "containers_per_tenant": 1, + "objects_per_container": 10, + "object_size": 1024 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/swift/list-objects-in-containers.yaml b/samples/tasks/scenarios/swift/list-objects-in-containers.yaml new file mode 100644 index 0000000000..2f27638d5c --- /dev/null +++ b/samples/tasks/scenarios/swift/list-objects-in-containers.yaml @@ -0,0 +1,17 @@ +--- + SwiftObjects.list_objects_in_containers: + - + runner: + type: "constant" + times: 6 + concurrency: 3 + context: + users: + tenants: 1 + users_per_tenant: 1 + roles: + - "admin" + swift_objects: + containers_per_tenant: 1 + objects_per_container: 10 + object_size: 1024 diff --git a/tests/unit/plugins/openstack/scenarios/swift/test_objects.py b/tests/unit/plugins/openstack/scenarios/swift/test_objects.py index 8c275edbd1..b6fd8e5319 100644 --- a/tests/unit/plugins/openstack/scenarios/swift/test_objects.py +++ b/tests/unit/plugins/openstack/scenarios/swift/test_objects.py @@ -13,12 +13,14 @@ # License for the specific language governing permissions and limitations # under the License. +import ddt import mock from rally.plugins.openstack.scenarios.swift import objects from tests.unit import test +@ddt.ddt class SwiftObjectsTestCase(test.ScenarioTestCase): def test_create_container_and_object_then_list_objects(self): @@ -84,6 +86,63 @@ class SwiftObjectsTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(scenario.atomic_actions(), "swift.download_2_objects") + @ddt.data(1, 5) + def test_list_objects_in_containers(self, num_cons): + con_list = [{"name": "cooon_%s" % i} for i in range(num_cons)] + scenario = objects.SwiftObjects() + scenario._list_containers = mock.MagicMock(return_value=("header", + con_list)) + scenario._list_objects = mock.MagicMock() + + scenario.list_objects_in_containers() + scenario._list_containers.assert_called_once_with() + con_calls = [mock.call(container["name"], atomic_action=False) + for container in con_list] + scenario._list_objects.assert_has_calls(con_calls) + + key_suffix = "container" + if num_cons > 1: + key_suffix = "%i_containers" % num_cons + self._test_atomic_action_timer(scenario.atomic_actions(), + "swift.list_objects_in_%s" % key_suffix) + + @ddt.data([1, 1], [1, 2], [2, 1], [3, 5]) + @ddt.unpack + def test_list_and_download_objects_in_containers(self, num_cons, num_objs): + con_list = [{"name": "connn_%s" % i} for i in range(num_cons)] + obj_list = [{"name": "ooobj_%s" % i} for i in range(num_objs)] + scenario = objects.SwiftObjects() + scenario._list_containers = mock.MagicMock(return_value=("header", + con_list)) + scenario._list_objects = mock.MagicMock(return_value=("header", + obj_list)) + scenario._download_object = mock.MagicMock() + + scenario.list_and_download_objects_in_containers() + scenario._list_containers.assert_called_once_with() + con_calls = [mock.call(container["name"], atomic_action=False) + for container in con_list] + scenario._list_objects.assert_has_calls(con_calls) + obj_calls = [] + for container in con_list: + for obj in obj_list: + obj_calls.append(mock.call(container["name"], obj["name"], + atomic_action=False)) + scenario._download_object.assert_has_calls(obj_calls, any_order=True) + + list_key_suffix = "container" + if num_cons > 1: + list_key_suffix = "%i_containers" % num_cons + self._test_atomic_action_timer( + scenario.atomic_actions(), + "swift.list_objects_in_%s" % list_key_suffix) + download_key_suffix = "object" + if num_cons * num_objs > 1: + download_key_suffix = "%i_objects" % (num_cons * num_objs) + self._test_atomic_action_timer( + scenario.atomic_actions(), + "swift.download_%s" % download_key_suffix) + def test_functional_create_container_and_object_then_list_objects(self): names_list = ["AA", "BB", "CC", "DD"]