Separate object-storage bulk operation service clients

Swift support bulk operation for upload archive file and bulk
delete. Service client methods for those API request are
present in account_client.py

This patch separate those methods in new client and use accordingly.

Partially implements blueprint consistent-service-method-names

Change-Id: Icceaf1bf4eddd2cf6501e76e52b54de2e105a165
This commit is contained in:
ghanshyam 2016-12-12 15:39:02 +09:00 committed by Ghanshyam Mann
parent 82a278e88c
commit 3608544b6f
6 changed files with 75 additions and 53 deletions

View File

@ -80,6 +80,7 @@ class BaseObjectTest(tempest.test.BaseTestCase):
def setup_clients(cls):
super(BaseObjectTest, cls).setup_clients()
cls.object_client = cls.os.object_client
cls.bulk_client = cls.os.bulk_client
cls.container_client = cls.os.container_client
cls.account_client = cls.os.account_client
cls.capabilities_client = cls.os.capabilities_client

View File

@ -56,11 +56,10 @@ class BulkTest(base.BaseObjectTest):
def _upload_archive(self, filepath):
# upload an archived file
params = {'extract-archive': 'tar'}
with open(filepath) as fh:
mydata = fh.read()
resp, body = self.account_client.create_account(data=mydata,
params=params)
resp, body = self.bulk_client.upload_archive(
upload_path='', data=mydata, archive_file_format='tar')
return resp, body
def _check_contents_deleted(self, container_name):
@ -113,9 +112,7 @@ class BulkTest(base.BaseObjectTest):
self._upload_archive(filepath)
data = '%s/%s\n%s' % (container_name, object_name, container_name)
params = {'bulk-delete': ''}
resp, body = self.account_client.delete_account(data=data,
params=params)
resp, body = self.bulk_client.delete_bulk_data(data=data)
# When deleting multiple files using the bulk operation, the response
# does not contain 'content-length' header. This is the special case,
@ -140,10 +137,8 @@ class BulkTest(base.BaseObjectTest):
self._upload_archive(filepath)
data = '%s/%s\n%s' % (container_name, object_name, container_name)
params = {'bulk-delete': ''}
resp, body = self.account_client.create_account_metadata(
{}, data=data, params=params)
resp, body = self.bulk_client.delete_bulk_data_with_post(data=data)
# When deleting multiple files using the bulk operation, the response
# does not contain 'content-length' header. This is the special case,

View File

@ -290,6 +290,8 @@ class Manager(clients.ServiceClients):
self.account_client = object_storage.AccountClient(self.auth_provider,
**params)
self.bulk_client = object_storage.BulkMiddlewareClient(
self.auth_provider, **params)
self.capabilities_client = object_storage.CapabilitiesClient(
self.auth_provider, **params)
self.container_client = object_storage.ContainerClient(

View File

@ -13,10 +13,12 @@
# the License.
from tempest.services.object_storage.account_client import AccountClient
from tempest.services.object_storage.bulk_middleware_client import \
BulkMiddlewareClient
from tempest.services.object_storage.capabilities_client import \
CapabilitiesClient
from tempest.services.object_storage.container_client import ContainerClient
from tempest.services.object_storage.object_client import ObjectClient
__all__ = ['AccountClient', 'CapabilitiesClient', 'ContainerClient',
'ObjectClient']
__all__ = ['AccountClient', 'BulkMiddlewareClient', 'CapabilitiesClient',
'ContainerClient', 'ObjectClient']

View File

@ -23,41 +23,6 @@ from tempest.lib.common import rest_client
class AccountClient(rest_client.RestClient):
def create_account(self, data=None,
params=None,
metadata=None,
remove_metadata=None,
metadata_prefix='X-Account-Meta-',
remove_metadata_prefix='X-Remove-Account-Meta-'):
"""Create an account."""
if metadata is None:
metadata = {}
if remove_metadata is None:
remove_metadata = {}
url = ''
if params:
url += '?%s' % urllib.urlencode(params)
headers = {}
for key in metadata:
headers[metadata_prefix + key] = metadata[key]
for key in remove_metadata:
headers[remove_metadata_prefix + key] = remove_metadata[key]
resp, body = self.put(url, data, headers)
self.expected_success(200, resp.status)
return resp, body
def delete_account(self, data=None, params=None):
"""Delete an account."""
url = ''
if params:
url = '?%s%s' % (url, urllib.urlencode(params))
resp, body = self.delete(url, headers={}, body=data)
self.expected_success(200, resp.status)
return resp, body
def list_account_metadata(self):
"""HEAD on the storage URL
@ -68,19 +33,14 @@ class AccountClient(rest_client.RestClient):
return resp, body
def create_account_metadata(self, metadata,
metadata_prefix='X-Account-Meta-',
data=None, params=None):
metadata_prefix='X-Account-Meta-'):
"""Creates an account metadata entry."""
headers = {}
if metadata:
for key in metadata:
headers[metadata_prefix + key] = metadata[key]
url = ''
if params:
url = '?%s%s' % (url, urllib.urlencode(params))
resp, body = self.post(url, headers=headers, body=data)
resp, body = self.post('', headers=headers, body=None)
self.expected_success([200, 204], resp.status)
return resp, body

View File

@ -0,0 +1,62 @@
# Copyright 2012 OpenStack Foundation
# 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.
from tempest.lib.common import rest_client
class BulkMiddlewareClient(rest_client.RestClient):
def upload_archive(self, upload_path, data,
archive_file_format='tar', headers=None):
"""Expand tar files into a Swift cluster.
To extract containers and objects on Swift cluster from
uploaded archived file. For More information please check:
http://docs.openstack.org/developer/swift/middleware.html#module-swift.common.middleware.bulk
"""
url = '%s?extract-archive=%s' % (upload_path, archive_file_format)
if headers is None:
headers = {}
resp, body = self.put(url, data, headers)
self.expected_success(200, resp.status)
return resp, body
def delete_bulk_data(self, data=None, headers=None):
"""Delete multiple objects or containers from their account.
For More information please check:
http://docs.openstack.org/developer/swift/middleware.html#module-swift.common.middleware.bulk
"""
url = '?bulk-delete'
if headers is None:
headers = {}
resp, body = self.delete(url, headers=headers, body=data)
self.expected_success(200, resp.status)
return resp, body
def delete_bulk_data_with_post(self, data=None, headers=None):
"""Delete multiple objects or containers with POST request.
For More information please check:
http://docs.openstack.org/developer/swift/middleware.html#module-swift.common.middleware.bulk
"""
url = '?bulk-delete'
if headers is None:
headers = {}
resp, body = self.post(url, headers=headers, body=data)
self.expected_success([200, 204], resp.status)
return resp, body