Merge "Clean up some proxy tests"
This commit is contained in:
commit
a47d5a1152
@ -21,7 +21,8 @@ from swift.common.middleware.acl import format_acl
|
|||||||
from swift.proxy import server as proxy_server
|
from swift.proxy import server as proxy_server
|
||||||
from swift.proxy.controllers.base import headers_to_account_info
|
from swift.proxy.controllers.base import headers_to_account_info
|
||||||
from swift.common import constraints
|
from swift.common import constraints
|
||||||
from test.unit import fake_http_connect, FakeRing, FakeMemcache
|
from test.unit import fake_http_connect, FakeRing, FakeMemcache, \
|
||||||
|
mocked_http_conn
|
||||||
from swift.common.storage_policy import StoragePolicy
|
from swift.common.storage_policy import StoragePolicy
|
||||||
from swift.common.request_helpers import get_sys_meta_prefix
|
from swift.common.request_helpers import get_sys_meta_prefix
|
||||||
import swift.proxy.controllers.base
|
import swift.proxy.controllers.base
|
||||||
@ -32,6 +33,9 @@ from test.unit import patch_policies
|
|||||||
|
|
||||||
@patch_policies([StoragePolicy(0, 'zero', True, object_ring=FakeRing())])
|
@patch_policies([StoragePolicy(0, 'zero', True, object_ring=FakeRing())])
|
||||||
class TestAccountController(unittest.TestCase):
|
class TestAccountController(unittest.TestCase):
|
||||||
|
|
||||||
|
ACCOUNT_REPLICAS = 3
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.app = proxy_server.Application(
|
self.app = proxy_server.Application(
|
||||||
None, FakeMemcache(),
|
None, FakeMemcache(),
|
||||||
@ -64,22 +68,28 @@ class TestAccountController(unittest.TestCase):
|
|||||||
|
|
||||||
def test_account_info_in_response_env(self):
|
def test_account_info_in_response_env(self):
|
||||||
controller = proxy_server.AccountController(self.app, 'AUTH_bob')
|
controller = proxy_server.AccountController(self.app, 'AUTH_bob')
|
||||||
with mock.patch('swift.proxy.controllers.base.http_connect',
|
with mocked_http_conn(200) as mock_conn:
|
||||||
fake_http_connect(200, body='')):
|
req = Request.blank('/v1/AUTH_bob')
|
||||||
req = Request.blank('/v1/AUTH_bob', {'PATH_INFO': '/v1/AUTH_bob'})
|
|
||||||
resp = controller.HEAD(req)
|
resp = controller.HEAD(req)
|
||||||
self.assertEqual(2, resp.status_int // 100)
|
self.assertEqual(2, resp.status_int // 100)
|
||||||
|
self.assertEqual(['/AUTH_bob'],
|
||||||
|
# requests are like /sdX/0/..
|
||||||
|
[r['path'][6:] for r in mock_conn.requests])
|
||||||
info_cache = resp.environ['swift.infocache']
|
info_cache = resp.environ['swift.infocache']
|
||||||
self.assertIn('account/AUTH_bob', info_cache)
|
self.assertIn('account/AUTH_bob', info_cache)
|
||||||
header_info = headers_to_account_info(resp.headers)
|
header_info = headers_to_account_info(resp.headers)
|
||||||
self.assertEqual(header_info, info_cache['account/AUTH_bob'])
|
self.assertEqual(header_info, info_cache['account/AUTH_bob'])
|
||||||
|
|
||||||
with mock.patch('swift.proxy.controllers.base.http_connect',
|
# The failure doesn't lead to cache eviction
|
||||||
fake_http_connect(500, body='')):
|
errors = [500] * self.ACCOUNT_REPLICAS
|
||||||
|
with mocked_http_conn(*errors) as mock_conn:
|
||||||
req = Request.blank('/v1/AUTH_bob', {
|
req = Request.blank('/v1/AUTH_bob', {
|
||||||
'PATH_INFO': '/v1/AUTH_bob', 'swift.infocache': info_cache})
|
'PATH_INFO': '/v1/AUTH_bob', 'swift.infocache': info_cache})
|
||||||
resp = controller.HEAD(req)
|
resp = controller.HEAD(req)
|
||||||
self.assertEqual(5, resp.status_int // 100)
|
self.assertEqual(5, resp.status_int // 100)
|
||||||
|
self.assertEqual(['/AUTH_bob'] * self.ACCOUNT_REPLICAS,
|
||||||
|
# requests are like /sdX/0/..
|
||||||
|
[r['path'][6:] for r in mock_conn.requests])
|
||||||
self.assertIs(info_cache, resp.environ['swift.infocache'])
|
self.assertIs(info_cache, resp.environ['swift.infocache'])
|
||||||
# The *old* header info is all still there
|
# The *old* header info is all still there
|
||||||
self.assertIn('account/AUTH_bob', info_cache)
|
self.assertIn('account/AUTH_bob', info_cache)
|
||||||
@ -328,6 +338,9 @@ class TestAccountController(unittest.TestCase):
|
|||||||
@patch_policies(
|
@patch_policies(
|
||||||
[StoragePolicy(0, 'zero', True, object_ring=FakeRing(replicas=4))])
|
[StoragePolicy(0, 'zero', True, object_ring=FakeRing(replicas=4))])
|
||||||
class TestAccountController4Replicas(TestAccountController):
|
class TestAccountController4Replicas(TestAccountController):
|
||||||
|
|
||||||
|
ACCOUNT_REPLICAS = 4
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.app = proxy_server.Application(
|
self.app = proxy_server.Application(
|
||||||
None,
|
None,
|
||||||
|
@ -107,11 +107,13 @@ class TestContainerController(TestRingBase):
|
|||||||
|
|
||||||
def test_container_info_got_cached(self):
|
def test_container_info_got_cached(self):
|
||||||
controller = proxy_server.ContainerController(self.app, 'a', 'c')
|
controller = proxy_server.ContainerController(self.app, 'a', 'c')
|
||||||
with mock.patch('swift.proxy.controllers.base.http_connect',
|
with mocked_http_conn(200, 200) as mock_conn:
|
||||||
fake_http_connect(200, 200, body='')):
|
req = Request.blank('/v1/a/c')
|
||||||
req = Request.blank('/v1/a/c', {'PATH_INFO': '/v1/a/c'})
|
|
||||||
resp = controller.HEAD(req)
|
resp = controller.HEAD(req)
|
||||||
self.assertEqual(2, resp.status_int // 100)
|
self.assertEqual(2, resp.status_int // 100)
|
||||||
|
self.assertEqual(['/a', '/a/c'],
|
||||||
|
# requests are like /sdX/0/..
|
||||||
|
[r['path'][6:] for r in mock_conn.requests])
|
||||||
# Make sure it's in both swift.infocache and memcache
|
# Make sure it's in both swift.infocache and memcache
|
||||||
header_info = headers_to_container_info(resp.headers)
|
header_info = headers_to_container_info(resp.headers)
|
||||||
info_cache = resp.environ['swift.infocache']
|
info_cache = resp.environ['swift.infocache']
|
||||||
@ -119,14 +121,15 @@ class TestContainerController(TestRingBase):
|
|||||||
self.assertEqual(header_info, info_cache['container/a/c'])
|
self.assertEqual(header_info, info_cache['container/a/c'])
|
||||||
self.assertEqual(header_info, self.app.memcache.get('container/a/c'))
|
self.assertEqual(header_info, self.app.memcache.get('container/a/c'))
|
||||||
|
|
||||||
controller = proxy_server.ContainerController(self.app, 'a', 'c')
|
# The failure doesn't lead to cache eviction
|
||||||
with mock.patch('swift.proxy.controllers.base.http_connect',
|
errors = [500] * self.CONTAINER_REPLICAS * 2
|
||||||
fake_http_connect(500, body='')):
|
with mocked_http_conn(*errors) as mock_conn:
|
||||||
req = Request.blank('/v1/a/c', {
|
req = Request.blank('/v1/a/c', {'swift.infocache': info_cache})
|
||||||
'PATH_INFO': '/v1/a/c', 'swift.infocache': info_cache})
|
|
||||||
resp = controller.HEAD(req)
|
resp = controller.HEAD(req)
|
||||||
self.assertEqual(5, resp.status_int // 100)
|
self.assertEqual(5, resp.status_int // 100)
|
||||||
# The failure doesn't lead to cache eviction
|
self.assertEqual(['/a/c'] * self.CONTAINER_REPLICAS * 2,
|
||||||
|
# requests are like /sdX/0/..
|
||||||
|
[r['path'][6:] for r in mock_conn.requests])
|
||||||
self.assertIs(info_cache, resp.environ['swift.infocache'])
|
self.assertIs(info_cache, resp.environ['swift.infocache'])
|
||||||
self.assertIn("container/a/c", resp.environ['swift.infocache'])
|
self.assertIn("container/a/c", resp.environ['swift.infocache'])
|
||||||
# NB: this is the *old* header_info, from the good req
|
# NB: this is the *old* header_info, from the good req
|
||||||
|
Loading…
Reference in New Issue
Block a user