Fix swiftclient mocks
In particular, stop mocking out some internal details like swiftclient.client.Connection._retry Change-Id: If118b9656ae1e87139c0d48dcc97c1daee948a85 Related-Change: I62cc037493af87373a75e37e2d9f33b8aedf9889 Related-Bug: 1556059
This commit is contained in:
parent
187d77da04
commit
9addf29b52
|
@ -67,7 +67,7 @@ SWIFT_CONF = {'swift_store_auth_address': 'localhost:8080',
|
|||
# We stub out as little as possible to ensure that the code paths
|
||||
# between swift and swiftclient are tested
|
||||
# thoroughly
|
||||
def stub_out_swiftclient(stubs, swift_store_auth_version, conf=None):
|
||||
def stub_out_swiftclient(stubs, swift_store_auth_version):
|
||||
fixture_containers = ['glance']
|
||||
fixture_container_headers = {}
|
||||
fixture_headers = {
|
||||
|
@ -141,7 +141,7 @@ def stub_out_swiftclient(stubs, swift_store_auth_version, conf=None):
|
|||
raise swiftclient.ClientException(msg,
|
||||
http_status=http_client.CONFLICT)
|
||||
|
||||
def fake_get_object(url, token, container, name='noexist', **kwargs):
|
||||
def fake_get_object(conn, container, name, **kwargs):
|
||||
# GET returns the tuple (list of headers, file object)
|
||||
fixture_key = "%s/%s" % (container, name)
|
||||
if fixture_key not in fixture_headers:
|
||||
|
@ -212,19 +212,6 @@ def stub_out_swiftclient(stubs, swift_store_auth_version, conf=None):
|
|||
raise swiftclient.ClientException(msg)
|
||||
return None, None
|
||||
|
||||
def _fake_retry(reset_func, func, *args, **kwargs):
|
||||
return func('localhost:80', '00000000000000', *args, **kwargs)
|
||||
|
||||
def fake_connections_get_object(self, container, obj,
|
||||
resp_chunk_size=None, query_string=None,
|
||||
response_dict=None, headers=None):
|
||||
"""Wrapper for :func:`get_object`"""
|
||||
return _fake_retry(None, fake_get_object, container, obj,
|
||||
resp_chunk_size=resp_chunk_size,
|
||||
query_string=query_string,
|
||||
response_dict=response_dict,
|
||||
headers=headers)
|
||||
|
||||
stubs.Set(swiftclient.client,
|
||||
'head_container', fake_head_container)
|
||||
stubs.Set(swiftclient.client,
|
||||
|
@ -237,14 +224,12 @@ def stub_out_swiftclient(stubs, swift_store_auth_version, conf=None):
|
|||
'delete_object', fake_delete_object)
|
||||
stubs.Set(swiftclient.client,
|
||||
'head_object', fake_head_object)
|
||||
stubs.Set(swiftclient.client,
|
||||
stubs.Set(swiftclient.client.Connection,
|
||||
'get_object', fake_get_object)
|
||||
stubs.Set(swiftclient.client,
|
||||
'get_auth', fake_get_auth)
|
||||
stubs.Set(swiftclient.client,
|
||||
'http_connection', fake_http_connection)
|
||||
stubs.Set(swiftclient.client.Connection,
|
||||
'get_object', fake_connections_get_object)
|
||||
|
||||
|
||||
class SwiftTests(object):
|
||||
|
@ -1244,10 +1229,7 @@ class TestStoreAuthV1(base.StoreBaseTest, SwiftTests,
|
|||
|
||||
moxfixture = self.useFixture(moxstubout.MoxStubout())
|
||||
self.stubs = moxfixture.stubs
|
||||
|
||||
stub_out_swiftclient(self.stubs, conf['swift_store_auth_version'],
|
||||
conf)
|
||||
|
||||
stub_out_swiftclient(self.stubs, conf['swift_store_auth_version'])
|
||||
self.mock_keystone_client()
|
||||
self.store = Store(self.conf)
|
||||
self.config(**conf)
|
||||
|
@ -1341,7 +1323,6 @@ class TestSingleTenantStoreConnections(base.StoreBaseTest):
|
|||
def setUp(self):
|
||||
super(TestSingleTenantStoreConnections, self).setUp()
|
||||
moxfixture = self.useFixture(moxstubout.MoxStubout())
|
||||
|
||||
self.stubs = moxfixture.stubs
|
||||
self.stubs.Set(swiftclient, 'Connection', FakeConnection)
|
||||
self.store = swift.SingleTenantStore(self.conf)
|
||||
|
@ -1607,25 +1588,6 @@ class TestMultiTenantStoreConnections(base.StoreBaseTest):
|
|||
self.assertEqual(connection.os_options, {})
|
||||
|
||||
|
||||
def fake_getresponse(self):
|
||||
"""Stubbing out required private function for
|
||||
TestMultiTenantStoreContext.test_download_context
|
||||
"""
|
||||
self.resp.status = self.resp.status_code
|
||||
|
||||
def getheaders():
|
||||
return self.resp.headers.items()
|
||||
|
||||
# Return 0 to set 'Content-Length' in swiftclient.client._RetryBody
|
||||
def getheader(k, v=None):
|
||||
return 0
|
||||
|
||||
self.resp.getheaders = getheaders
|
||||
self.resp.getheader = getheader
|
||||
|
||||
return self.resp
|
||||
|
||||
|
||||
class TestMultiTenantStoreContext(base.StoreBaseTest):
|
||||
|
||||
_CONF = cfg.CONF
|
||||
|
@ -1660,17 +1622,13 @@ class TestMultiTenantStoreContext(base.StoreBaseTest):
|
|||
@requests_mock.mock()
|
||||
def test_download_context(self, m):
|
||||
"""Verify context (ie token) is passed to swift on download."""
|
||||
moxfixture = self.useFixture(moxstubout.MoxStubout())
|
||||
stubs = moxfixture.stubs
|
||||
stubs.Set(swiftclient.client.HTTPConnection,
|
||||
'getresponse', fake_getresponse)
|
||||
self.config(swift_store_multi_tenant=True)
|
||||
store = Store(self.conf)
|
||||
store.configure()
|
||||
uri = "swift+http://127.0.0.1/glance_123/123"
|
||||
loc = location.get_location_from_uri(uri, conf=self.conf)
|
||||
m.get("http://127.0.0.1/glance_123/123")
|
||||
|
||||
m.get("http://127.0.0.1/glance_123/123",
|
||||
headers={'Content-Length': '0'})
|
||||
store.get(loc, context=self.ctx)
|
||||
self.assertEqual(b'0123', m.last_request.headers['X-Auth-Token'])
|
||||
|
||||
|
|
Loading…
Reference in New Issue