Skip to content

Commit

Permalink
Merge "[Swift] Add base for Swift API Benchmarks: Patch-2"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Apr 22, 2015
2 parents e933ebd + 42d6606 commit 87315ae
Show file tree
Hide file tree
Showing 18 changed files with 914 additions and 3 deletions.
57 changes: 57 additions & 0 deletions rally-jobs/rally-neutron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,60 @@
users:
tenants: 2
users_per_tenant: 2

SwiftObjects.create_container_and_object_then_list_objects:
-
args:
objects_per_container: 2
object_size: 5120
runner:
type: "constant"
times: 2
concurrency: 2
context:
users:
tenants: 1
users_per_tenant: 1
roles:
- "admin"
sla:
failure_rate:
max: 0

SwiftObjects.create_container_and_object_then_delete_all:
-
args:
objects_per_container: 5
object_size: 102400
runner:
type: "constant"
times: 4
concurrency: 2
context:
users:
tenants: 1
users_per_tenant: 1
roles:
- "admin"
sla:
failure_rate:
max: 0

SwiftObjects.create_container_and_object_then_download_object:
-
args:
objects_per_container: 5
object_size: 1024
runner:
type: "constant"
times: 6
concurrency: 3
context:
users:
tenants: 1
users_per_tenant: 1
roles:
- "admin"
sla:
failure_rate:
max: 0
47 changes: 47 additions & 0 deletions rally/benchmark/context/cleanup/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,53 @@ class DesignateServer(SynchronizedDeletion, base.ResourceManager):
pass


# SWIFT

_swift_order = get_order(1000)


class SwiftMixin(SynchronizedDeletion, base.ResourceManager):

def _manager(self):
client = self._admin_required and self.admin or self.user
return getattr(client, self._service)()

def id(self):
return self.raw_resource

def delete(self):
delete_method = getattr(self._manager(), "delete_%s" % self._resource)
# NOTE(weiwu): *self.raw_resource is required because for deleting
# container we are passing only container name, to delete object we
# should pass as first argument container and second is object name.
delete_method(*self.raw_resource)


@base.resource("swift", "object", order=next(_swift_order),
tenant_resource=True)
class SwiftObject(SwiftMixin):

def list(self):
object_list = []
containers = self._manager().get_account(full_listing=True)[1]
for con in containers:
objects = self._manager().get_container(con["name"],
full_listing=True)[1]
for obj in objects:
raw_resource = [con["name"], obj["name"]]
object_list.append(raw_resource)
return object_list


@base.resource("swift", "container", order=next(_swift_order),
tenant_resource=True)
class SwiftContainer(SwiftMixin):

def list(self):
containers = self._manager().get_account(full_listing=True)[1]
return [[con["name"]] for con in containers]


# MISTRAL

@base.resource("mistral", "workbooks", order=1100, tenant_resource=True)
Expand Down
Empty file.
124 changes: 124 additions & 0 deletions rally/benchmark/scenarios/swift/objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Copyright 2015: Cisco Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import tempfile

from rally.benchmark.scenarios import base
from rally.benchmark.scenarios.swift import utils
from rally.benchmark import validation
from rally import consts


class SwiftObjects(utils.SwiftScenario):
"""Benchmark scenarios for Swift Objects."""

@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@base.scenario(context={"cleanup": ["swift"]})
def create_container_and_object_then_list_objects(
self, objects_per_container=1,
object_size=1024, **kwargs):
"""Create container and objects then list all objects.
:param objects_per_container: int, number of objects to upload
:param object_size: int, temporary local object size
:param kwargs: dict, optional parameters to create container
"""
key_suffix = "object"
if objects_per_container > 1:
key_suffix = "%i_objects" % objects_per_container

container_name = None
with tempfile.TemporaryFile() as dummy_file:
# set dummy file to specified object size
dummy_file.truncate(object_size)
container_name = self._create_container(**kwargs)
with base.AtomicAction(self, "swift.create_%s" % key_suffix):
for i in range(objects_per_container):
dummy_file.seek(0)
self._upload_object(container_name, dummy_file,
atomic_action=False)
self._list_objects(container_name)

@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@base.scenario(context={"cleanup": ["swift"]})
def create_container_and_object_then_delete_all(
self, objects_per_container=1,
object_size=1024, **kwargs):
"""Create container and objects then delete everything created.
:param objects_per_container: int, number of objects to upload
:param object_size: int, temporary local object size
:param kwargs: dict, optional parameters to create container
"""
key_suffix = "object"
if objects_per_container > 1:
key_suffix = "%i_objects" % objects_per_container

container_name = None
objects_list = []
with tempfile.TemporaryFile() as dummy_file:
# set dummy file to specified object size
dummy_file.truncate(object_size)
container_name = self._create_container(**kwargs)
with base.AtomicAction(self, "swift.create_%s" % key_suffix):
for i in range(objects_per_container):
dummy_file.seek(0)
object_name = self._upload_object(container_name,
dummy_file,
atomic_action=False)[1]
objects_list.append(object_name)

with base.AtomicAction(self, "swift.delete_%s" % key_suffix):
for object_name in objects_list:
self._delete_object(container_name, object_name,
atomic_action=False)
self._delete_container(container_name)

@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@base.scenario(context={"cleanup": ["swift"]})
def create_container_and_object_then_download_object(
self, objects_per_container=1,
object_size=1024, **kwargs):
"""Create container and objects then download all objects.
:param objects_per_container: int, number of objects to upload
:param object_size: int, temporary local object size
:param kwargs: dict, optional parameters to create container
"""
key_suffix = "object"
if objects_per_container > 1:
key_suffix = "%i_objects" % objects_per_container

container_name = None
objects_list = []
with tempfile.TemporaryFile() as dummy_file:
# set dummy file to specified object size
dummy_file.truncate(object_size)
container_name = self._create_container(**kwargs)
with base.AtomicAction(self, "swift.create_%s" % key_suffix):
for i in range(objects_per_container):
dummy_file.seek(0)
object_name = self._upload_object(container_name,
dummy_file,
atomic_action=False)[1]
objects_list.append(object_name)

with base.AtomicAction(self, "swift.download_%s" % key_suffix):
for object_name in objects_list:
self._download_object(container_name, object_name,
atomic_action=False)
Loading

0 comments on commit 87315ae

Please sign in to comment.