Add HEAD api response for test s3 server BucketHandler

Current nova test s3 server lacks HEAD for BucketHandler. And it becomes
an issue for Boto after version 2.25.0 [1], which changes underlying
implementation of get_bucket method from GET to HEAD request.

This change fixes this gap by adding HEAD response to test s3 server.
And also added cases for testing bucket existence per Boto document
suggestion[2], which applies for both Boto prior to or after version
2.25.0

[1] http://docs.pythonboto.org/en/latest/releasenotes/v2.25.0.html
[2] http://docs.pythonboto.org/en/latest/s3_tut.html#accessing-a-bucket

Change-Id: If992efa40f7f36d337d1b9b1f52859aa0ae51874
Closes-bug: #1277790
(cherry picked from commit 033f3776c4)
This commit is contained in:
Qiu Yu 2014-02-08 23:32:34 +08:00 committed by Gary Kotton
parent abacc290ca
commit 2abcc4e04c
2 changed files with 27 additions and 0 deletions

View File

@ -310,6 +310,16 @@ class BucketHandler(BaseRequestHandler):
self.set_status(204)
self.finish()
def head(self, bucket_name):
path = os.path.abspath(os.path.join(self.application.directory,
bucket_name))
if (not path.startswith(self.application.directory) or
not os.path.isdir(path)):
self.set_404()
return
self.set_status(200)
self.finish()
class ObjectHandler(BaseRequestHandler):
def get(self, bucket, object_name):

View File

@ -135,10 +135,27 @@ class S3APITestCase(test.NoDBTestCase):
self._ensure_no_buckets(bucket.get_all_keys())
def test_unknown_bucket(self):
# NOTE(unicell): Since Boto v2.25.0, the underlying implementation
# of get_bucket method changed from GET to HEAD.
#
# Prior to v2.25.0, default validate=True fetched a list of keys in the
# bucket and raises S3ResponseError. As a side effect of switching to
# HEAD request, get_bucket call now generates less error message.
#
# To keep original semantics, additional get_all_keys call is
# suggestted per Boto document. This case tests both validate=False and
# validate=True case for completeness.
#
# http://docs.pythonboto.org/en/latest/releasenotes/v2.25.0.html
# http://docs.pythonboto.org/en/latest/s3_tut.html#accessing-a-bucket
bucket_name = 'falalala'
self.assertRaises(boto_exception.S3ResponseError,
self.conn.get_bucket,
bucket_name)
bucket = self.conn.get_bucket(bucket_name, validate=False)
self.assertRaises(boto_exception.S3ResponseError,
bucket.get_all_keys,
maxkeys=0)
def tearDown(self):
"""Tear down test server."""