Remove AccountClientCustomizedHeader class

AccountClientCustomizedHeader contains list_account_containers and
request(). However, they are almost duplicated with AccountClient and
we can use AccountClient instead.
This patch removes AccountClientCustomizedHeader and makes some tests
use AccountClient instead.

Change-Id: I0d933440f788e0d111e6e4c9b883e736a7d08362
This commit is contained in:
Ken'ichi Ohmichi 2015-01-01 14:03:32 +00:00
parent f5cddf29bf
commit 4b8ebadae1
7 changed files with 35 additions and 112 deletions

View File

@ -49,7 +49,6 @@ class BaseObjectTest(tempest.test.BaseTestCase):
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.custom_account_client = cls.os.custom_account_client
cls.object_client_alt = cls.os_alt.object_client
cls.container_client_alt = cls.os_alt.container_client
cls.identity_client_alt = cls.os_alt.identity_client
@ -59,7 +58,6 @@ class BaseObjectTest(tempest.test.BaseTestCase):
cls.container_client.auth_provider.clear_auth()
cls.account_client.auth_provider.clear_auth()
cls.custom_object_client.auth_provider.clear_auth()
cls.custom_account_client.auth_provider.clear_auth()
cls.object_client_alt.auth_provider.clear_auth()
cls.container_client_alt.auth_provider.clear_auth()

View File

@ -43,30 +43,30 @@ class AccountQuotasTest(base.BaseObjectTest):
def setUp(self):
super(AccountQuotasTest, self).setUp()
# Set the reselleradmin auth in headers for next custom_account_client
# Set the reselleradmin auth in headers for next account_client
# request
self.custom_account_client.auth_provider.set_alt_auth_data(
self.account_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.reselleradmin_auth_data
)
# Set a quota of 20 bytes on the user's account before each test
headers = {"X-Account-Meta-Quota-Bytes": "20"}
self.os.custom_account_client.request("POST", url="", headers=headers,
body="")
self.os.account_client.request("POST", url="", headers=headers,
body="")
def tearDown(self):
# Set the reselleradmin auth in headers for next custom_account_client
# Set the reselleradmin auth in headers for next account_client
# request
self.custom_account_client.auth_provider.set_alt_auth_data(
self.account_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.reselleradmin_auth_data
)
# remove the quota from the container
headers = {"X-Remove-Account-Meta-Quota-Bytes": "x"}
self.os.custom_account_client.request("POST", url="", headers=headers,
body="")
self.os.account_client.request("POST", url="", headers=headers,
body="")
super(AccountQuotasTest, self).tearDown()
@classmethod
@ -91,7 +91,7 @@ class AccountQuotasTest(base.BaseObjectTest):
"""Test that the ResellerAdmin is able to modify and remove the quota
on a user's account.
Using the custom_account client, the test modifies the quota
Using the account client, the test modifies the quota
successively to:
* "25": a random value different from the initial quota value.
@ -100,15 +100,15 @@ class AccountQuotasTest(base.BaseObjectTest):
"""
for quota in ("25", "", "20"):
self.custom_account_client.auth_provider.set_alt_auth_data(
self.account_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.reselleradmin_auth_data
)
headers = {"X-Account-Meta-Quota-Bytes": quota}
resp, _ = self.os.custom_account_client.request("POST", url="",
headers=headers,
body="")
resp, _ = self.os.account_client.request("POST", url="",
headers=headers,
body="")
self.assertEqual(resp["status"], "204")
self.assertHeaders(resp, 'Account', 'POST')

View File

@ -43,30 +43,30 @@ class AccountQuotasNegativeTest(base.BaseObjectTest):
def setUp(self):
super(AccountQuotasNegativeTest, self).setUp()
# Set the reselleradmin auth in headers for next custom_account_client
# Set the reselleradmin auth in headers for next account_client
# request
self.custom_account_client.auth_provider.set_alt_auth_data(
self.account_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.reselleradmin_auth_data
)
# Set a quota of 20 bytes on the user's account before each test
headers = {"X-Account-Meta-Quota-Bytes": "20"}
self.os.custom_account_client.request("POST", url="", headers=headers,
body="")
self.os.account_client.request("POST", url="", headers=headers,
body="")
def tearDown(self):
# Set the reselleradmin auth in headers for next custom_account_client
# Set the reselleradmin auth in headers for next account_client
# request
self.custom_account_client.auth_provider.set_alt_auth_data(
self.account_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=self.reselleradmin_auth_data
)
# remove the quota from the container
headers = {"X-Remove-Account-Meta-Quota-Bytes": "x"}
self.os.custom_account_client.request("POST", url="", headers=headers,
body="")
self.os.account_client.request("POST", url="", headers=headers,
body="")
super(AccountQuotasNegativeTest, self).tearDown()
@classmethod

View File

@ -34,10 +34,10 @@ class AccountNegativeTest(base.BaseObjectTest):
test_auth_provider.auth_data
# Get fresh auth for test user and set it to next auth request for
# custom_account_client
# account_client
delattr(test_auth_provider, 'auth_data')
test_auth_new_data = test_auth_provider.auth_data
self.custom_account_client.auth_provider.set_alt_auth_data(
self.account_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=test_auth_new_data
)
@ -45,5 +45,5 @@ class AccountNegativeTest(base.BaseObjectTest):
params = {'format': 'json'}
# list containers with non-authorized user token
self.assertRaises(exceptions.Unauthorized,
self.custom_account_client.list_account_containers,
self.account_client.list_account_containers,
params=params)

View File

@ -58,15 +58,16 @@ class StaticWebTest(base.BaseObjectTest):
self.container_name, metadata=headers)
# Maintain original headers, no auth added
self.custom_account_client.auth_provider.set_alt_auth_data(
self.account_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=None
)
# test GET on http://account_url/container_name
# we should retrieve the self.object_name file
resp, body = self.custom_account_client.request("GET",
self.container_name)
resp, body = self.account_client.request("GET",
self.container_name,
headers={})
# This request is equivalent to GET object
self.assertHeaders(resp, 'Object', 'GET')
self.assertEqual(body, self.object_data)
@ -89,8 +90,9 @@ class StaticWebTest(base.BaseObjectTest):
# test GET on http://account_url/container_name
# we should retrieve a listing of objects
resp, body = self.custom_account_client.request("GET",
self.container_name)
resp, body = self.account_client.request("GET",
self.container_name,
headers={})
# The target of the request is not any Swift resource. Therefore, the
# existence of response header is checked without a custom matcher.
self.assertIn('content-length', resp)
@ -120,15 +122,16 @@ class StaticWebTest(base.BaseObjectTest):
self.container_name, metadata=headers)
# Maintain original headers, no auth added
self.custom_account_client.auth_provider.set_alt_auth_data(
self.account_client.auth_provider.set_alt_auth_data(
request_part='headers',
auth_data=None
)
# test GET on http://account_url/container_name
# we should retrieve a listing of objects
resp, body = self.custom_account_client.request("GET",
self.container_name)
resp, body = self.account_client.request("GET",
self.container_name,
headers={})
self.assertIn(self.object_name, body)
css = '<link rel="stylesheet" type="text/css" href="listings.css" />'
self.assertIn(css, body)

View File

@ -83,8 +83,6 @@ from tempest.services.messaging.json.messaging_client import \
MessagingClientJSON
from tempest.services.network.json.network_client import NetworkClientJSON
from tempest.services.object_storage.account_client import AccountClient
from tempest.services.object_storage.account_client import \
AccountClientCustomizedHeader
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 \
@ -179,8 +177,6 @@ class Manager(manager.Manager):
self.s3_client = botoclients.ObjectClientS3(*ec2_client_args)
self.custom_object_client = ObjectClientCustomizedHeader(
self.auth_provider)
self.custom_account_client = \
AccountClientCustomizedHeader(self.auth_provider)
self.data_processing_client = DataProcessingClient(
self.auth_provider)

View File

@ -17,9 +17,7 @@ import json
import urllib
from xml.etree import ElementTree as etree
from tempest.common import http
from tempest import config
from tempest import exceptions
from tempest.services.object_storage import base
CONF = config.CONF
@ -162,75 +160,3 @@ class AccountClient(base.ObjectStorageClient):
body = json.loads(body)
self.expected_success(200, resp.status)
return resp, body
class AccountClientCustomizedHeader(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 body
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 list_account_containers(self, params=None, metadata=None):
"""
GET on the (base) storage URL
Given a valid X-Auth-Token, returns a list of all containers for the
account.
Optional Arguments:
limit=[integer value N]
Limits the number of results to at most N values
DEFAULT: 10,000
marker=[string value X]
Given string value X, return object names greater in value
than the specified marker.
DEFAULT: No Marker
format=[string value, either 'json' or 'xml']
Specify either json or xml to return the respective serialized
response.
DEFAULT: Python-List returned in response body
"""
url = '?format=%s' % self.format
if params:
url += '&%s' % urllib.urlencode(params)
headers = {}
if metadata:
for key in metadata:
headers[str(key)] = metadata[key]
resp, body = self.get(url, headers=headers)
self.expected_success(200, resp.status)
return resp, body