Remove ObjectClientCustomizedHeader class

ObjectClientCustomizedHeader contains some API methods, and most of
them are duplicated with ObjectClient and we can replace them with
ObjectClient methods in many cases.
This patch removes ObjectClientCustomizedHeader and makes some tests
use ObjectClient instead.

Change-Id: I548cade87fdd719f71ffdd87950831e2b7c2287e
This commit is contained in:
Ken'ichi Ohmichi 2015-01-01 14:04:49 +00:00
parent 4b8ebadae1
commit 179ea57f7a
7 changed files with 41 additions and 124 deletions

View File

@ -46,7 +46,6 @@ class BaseObjectTest(tempest.test.BaseTestCase):
cls.object_client = cls.os.object_client
cls.container_client = cls.os.container_client
cls.account_client = cls.os.account_client
cls.custom_object_client = cls.os.custom_object_client
cls.token_client = cls.os_admin.token_client
cls.identity_admin_client = cls.os_admin.identity_client
cls.object_client_alt = cls.os_alt.object_client
@ -57,7 +56,6 @@ class BaseObjectTest(tempest.test.BaseTestCase):
cls.object_client.auth_provider.clear_auth()
cls.container_client.auth_provider.clear_auth()
cls.account_client.auth_provider.clear_auth()
cls.custom_object_client.auth_provider.clear_auth()
cls.object_client_alt.auth_provider.clear_auth()
cls.container_client_alt.auth_provider.clear_auth()

View File

@ -52,11 +52,11 @@ class ObjectTestACLs(base.BaseObjectTest):
object_name, 'data')
self.assertHeaders(resp, 'Object', 'PUT')
# Trying to read the object with rights
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.test_auth_data
)
resp, _ = self.custom_object_client.get_object(
resp, _ = self.object_client.get_object(
self.container_name, object_name)
self.assertHeaders(resp, 'Object', 'GET')
@ -71,12 +71,12 @@ class ObjectTestACLs(base.BaseObjectTest):
metadata_prefix='')
self.assertHeaders(resp_meta, 'Container', 'POST')
# Trying to write the object with rights
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.test_auth_data
)
object_name = data_utils.rand_name(name='Object')
resp, _ = self.custom_object_client.create_object(
resp, _ = self.object_client.create_object(
self.container_name,
object_name, 'data')
object_name, 'data', headers={})
self.assertHeaders(resp, 'Object', 'PUT')

View File

@ -43,13 +43,13 @@ class ObjectACLsNegativeTest(base.BaseObjectTest):
# trying to create object with empty headers
# X-Auth-Token is not provided
object_name = data_utils.rand_name(name='Object')
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=None
)
self.assertRaises(exceptions.Unauthorized,
self.custom_object_client.create_object,
self.container_name, object_name, 'data')
self.object_client.create_object,
self.container_name, object_name, 'data', headers={})
@test.attr(type=['negative', 'gate'])
def test_delete_object_without_using_creds(self):
@ -59,12 +59,12 @@ class ObjectACLsNegativeTest(base.BaseObjectTest):
object_name, 'data')
# trying to delete object with empty headers
# X-Auth-Token is not provided
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=None
)
self.assertRaises(exceptions.Unauthorized,
self.custom_object_client.delete_object,
self.object_client.delete_object,
self.container_name, object_name)
@test.attr(type=['negative', 'gate'])
@ -73,13 +73,13 @@ class ObjectACLsNegativeTest(base.BaseObjectTest):
# User provided token is forbidden. ACL are not set
object_name = data_utils.rand_name(name='Object')
# trying to create object with non-authorized user
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.test_auth_data
)
self.assertRaises(exceptions.Unauthorized,
self.custom_object_client.create_object,
self.container_name, object_name, 'data')
self.object_client.create_object,
self.container_name, object_name, 'data', headers={})
@test.attr(type=['negative', 'gate'])
def test_read_object_with_non_authorized_user(self):
@ -90,12 +90,12 @@ class ObjectACLsNegativeTest(base.BaseObjectTest):
self.container_name, object_name, 'data')
self.assertHeaders(resp, 'Object', 'PUT')
# trying to get object with non authorized user token
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.test_auth_data
)
self.assertRaises(exceptions.Unauthorized,
self.custom_object_client.get_object,
self.object_client.get_object,
self.container_name, object_name)
@test.attr(type=['negative', 'gate'])
@ -107,12 +107,12 @@ class ObjectACLsNegativeTest(base.BaseObjectTest):
self.container_name, object_name, 'data')
self.assertHeaders(resp, 'Object', 'PUT')
# trying to delete object with non-authorized user token
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.test_auth_data
)
self.assertRaises(exceptions.Unauthorized,
self.custom_object_client.delete_object,
self.object_client.delete_object,
self.container_name, object_name)
@test.attr(type=['negative', 'smoke'])
@ -130,12 +130,12 @@ class ObjectACLsNegativeTest(base.BaseObjectTest):
object_name, 'data')
self.assertHeaders(resp, 'Object', 'PUT')
# Trying to read the object without rights
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.test_auth_data
)
self.assertRaises(exceptions.Unauthorized,
self.custom_object_client.get_object,
self.object_client.get_object,
self.container_name, object_name)
@test.attr(type=['negative', 'smoke'])
@ -148,15 +148,15 @@ class ObjectACLsNegativeTest(base.BaseObjectTest):
metadata_prefix='')
self.assertHeaders(resp_meta, 'Container', 'POST')
# Trying to write the object without rights
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.test_auth_data
)
object_name = data_utils.rand_name(name='Object')
self.assertRaises(exceptions.Unauthorized,
self.custom_object_client.create_object,
self.object_client.create_object,
self.container_name,
object_name, 'data')
object_name, 'data', headers={})
@test.attr(type=['negative', 'smoke'])
def test_write_object_without_write_rights(self):
@ -170,15 +170,15 @@ class ObjectACLsNegativeTest(base.BaseObjectTest):
metadata_prefix='')
self.assertHeaders(resp_meta, 'Container', 'POST')
# Trying to write the object without write rights
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.test_auth_data
)
object_name = data_utils.rand_name(name='Object')
self.assertRaises(exceptions.Unauthorized,
self.custom_object_client.create_object,
self.object_client.create_object,
self.container_name,
object_name, 'data')
object_name, 'data', headers={})
@test.attr(type=['negative', 'smoke'])
def test_delete_object_without_write_rights(self):
@ -197,11 +197,11 @@ class ObjectACLsNegativeTest(base.BaseObjectTest):
object_name, 'data')
self.assertHeaders(resp, 'Object', 'PUT')
# Trying to delete the object without write rights
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.test_auth_data
)
self.assertRaises(exceptions.Unauthorized,
self.custom_object_client.delete_object,
self.object_client.delete_object,
self.container_name,
object_name)

View File

@ -17,6 +17,7 @@
from tempest.api.object_storage import base
from tempest.common import custom_matchers
from tempest.common.utils import data_utils
from tempest import exceptions
from tempest import test
@ -153,13 +154,12 @@ class StaticWebTest(base.BaseObjectTest):
object_data_404)
# Do not set auth in HTTP headers for next request
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=None
)
# Request non-existing object
resp, body = self.custom_object_client.get_object(self.container_name,
"notexisting")
self.assertEqual(resp['status'], '404')
self.assertEqual(body, object_data_404)
self.assertRaises(
exceptions.NotFound, self.object_client.get_object,
self.container_name, "notexisting")

View File

@ -177,7 +177,7 @@ class ObjectTest(base.BaseObjectTest):
object_name = data_utils.rand_name(name='TestObject')
data = data_utils.arbitrary_string()
metadata = {'Expect': '100-continue'}
resp = self.custom_object_client.create_object_continue(
resp = self.object_client.create_object_continue(
self.container_name,
object_name,
data,
@ -186,7 +186,7 @@ class ObjectTest(base.BaseObjectTest):
self.assertIn('status', resp)
self.assertEqual(resp['status'], '100')
self.custom_object_client.create_object_continue(
self.object_client.create_object_continue(
self.container_name,
object_name,
data,
@ -1014,11 +1014,11 @@ class PublicObjectTest(base.BaseObjectTest):
self.assertEqual(resp_meta['x-container-read'], '.r:*,.rlistings')
# trying to get object with empty headers as it is public readable
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=None
)
resp, body = self.custom_object_client.get_object(
resp, body = self.object_client.get_object(
self.container_name, object_name)
self.assertHeaders(resp, 'Object', 'GET')
@ -1052,12 +1052,12 @@ class PublicObjectTest(base.BaseObjectTest):
# get auth token of alternative user
alt_auth_data = self.identity_client_alt.auth_provider.auth_data
self.custom_object_client.auth_provider.set_alt_auth_data(
self.object_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=alt_auth_data
)
# access object using alternate user creds
resp, body = self.custom_object_client.get_object(
resp, body = self.object_client.get_object(
self.container_name, object_name)
self.assertHeaders(resp, 'Object', 'GET')

View File

@ -85,8 +85,6 @@ from tempest.services.network.json.network_client import NetworkClientJSON
from tempest.services.object_storage.account_client import AccountClient
from tempest.services.object_storage.container_client import ContainerClient
from tempest.services.object_storage.object_client import ObjectClient
from tempest.services.object_storage.object_client import \
ObjectClientCustomizedHeader
from tempest.services.orchestration.json.orchestration_client import \
OrchestrationClient
from tempest.services.telemetry.json.telemetry_client import \
@ -175,8 +173,6 @@ class Manager(manager.Manager):
self.auth_provider)
self.ec2api_client = botoclients.APIClientEC2(*ec2_client_args)
self.s3_client = botoclients.ObjectClientS3(*ec2_client_args)
self.custom_object_client = ObjectClientCustomizedHeader(
self.auth_provider)
self.data_processing_client = DataProcessingClient(
self.auth_provider)

View File

@ -17,9 +17,7 @@ import httplib
import urllib
import urlparse
from tempest.common import http
from tempest import config
from tempest import exceptions
from tempest.services.object_storage import base
CONF = config.CONF
@ -28,10 +26,11 @@ CONF = config.CONF
class ObjectClient(base.ObjectStorageClient):
def create_object(self, container, object_name, data,
params=None, metadata=None):
params=None, metadata=None, headers=None):
"""Create storage object."""
headers = self.get_headers()
if headers is None:
headers = self.get_headers()
if not data:
headers['content-length'] = '0'
if metadata:
@ -177,82 +176,6 @@ class ObjectClient(base.ObjectStorageClient):
self.expected_success(201, resp.status)
return resp.status, resp.reason, resp_headers
class ObjectClientCustomizedHeader(base.ObjectStorageClient):
# TODO(andreaf) This class is now redundant, to be removed in next patch
def request(self, method, url, extra_headers=False, headers=None,
body=None):
"""A simple HTTP request interface."""
dscv = CONF.identity.disable_ssl_certificate_validation
ca_certs = CONF.identity.ca_certificates_file
self.http_obj = http.ClosingHttp(
disable_ssl_certificate_validation=dscv,
ca_certs=ca_certs)
if headers is None:
headers = {}
elif extra_headers:
try:
headers.update(self.get_headers())
except (ValueError, TypeError):
headers = {}
# Authorize the request
req_url, req_headers, req_body = self.auth_provider.auth_request(
method=method, url=url, headers=headers, body=body,
filters=self.filters
)
# Use original method
resp, resp_body = self.http_obj.request(req_url, method,
headers=req_headers,
body=req_body)
self._log_request(method, req_url, resp)
if resp.status == 401 or resp.status == 403:
raise exceptions.Unauthorized()
return resp, resp_body
def get_object(self, container, object_name, metadata=None):
"""Retrieve object's data."""
headers = {}
if metadata:
for key in metadata:
headers[str(key)] = metadata[key]
url = "{0}/{1}".format(container, object_name)
resp, body = self.get(url, headers=headers)
self.expected_success(200, resp.status)
return resp, body
def create_object(self, container, object_name, data, metadata=None):
"""Create storage object."""
headers = {}
if metadata:
for key in metadata:
headers[str(key)] = metadata[key]
if not data:
headers['content-length'] = '0'
url = "%s/%s" % (str(container), str(object_name))
resp, body = self.put(url, data, headers=headers)
self.expected_success(201, resp.status)
return resp, body
def delete_object(self, container, object_name, metadata=None):
"""Delete storage object."""
headers = {}
if metadata:
for key in metadata:
headers[str(key)] = metadata[key]
url = "%s/%s" % (str(container), str(object_name))
resp, body = self.delete(url, headers=headers)
self.expected_success(200, resp.status)
return resp, body
def create_object_continue(self, container, object_name,
data, metadata=None):
"""Create storage object."""