2013-09-20 01:00:54 +08:00
|
|
|
# Copyright (c) 2010-2012 OpenStack Foundation
|
2010-07-12 17:03:45 -05:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
|
|
# implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import unittest
|
Enhance log msg to report referer and user-agent
Enhance internally logged messages to report referer and user-agent.
Pass the referering URL and METHOD between internal servers (when
known), and set the user-agent to be the server type (obj-server,
container-server, proxy-server, obj-updater, obj-replicator,
container-updater, direct-client, etc.) with the process PID. In
conjunction with the transaction ID, it helps to track down which PID
from a given system was responsible for initiating the request and
what that server was working on to make this request.
This has been helpful in tracking down interactions between object,
container and account servers.
We also take things a bit further performaing a bit of refactoring to
consolidate calls to transfer_headers() now that we have a helper
method for constructing them.
Finally we performed further changes to avoid header key duplication
due to string literal header key values and the various objects
representing headers for requests and responses. See below for more
details.
====
Header Keys
There seems to be a bit of a problem with the case of the various
string literals used for header keys and the interchangable way
standard Python dictionaries, HeaderKeyDict() and HeaderEnvironProxy()
objects are used.
If one is not careful, a header object of some sort (one that does not
normalize its keys, and that is not necessarily a dictionary) can be
constructed containing header keys which differ only by the case of
their string literals. E.g.:
{ 'x-trans-id': '1234', 'X-Trans-Id': '5678' }
Such an object, when passed to http_connect() will result in an
on-the-wire header where the key values are merged together, comma
separated, that looks something like:
HTTP_X_TRANS_ID: 1234,5678
For some headers in some contexts, this is behavior is desirable. For
example, one can also use a list of tuples which enumerate the multiple
values a single header should have.
However, in almost all of the contexts used in the code base, this is
not desirable.
This behavior arises from a combination of factors:
1. Header strings are not constants and different lower-case and
title-case header strings values are used interchangably in the
code at times
It might be worth the effort to make a pass through the code to
stop using string literals and use constants instead, but there
are plusses and minuses to doing that, so this was not attempted
in this effort
2. HeaderEnvironProxy() objects report their keys in ".title()"
case, but normalize all other key references to the form
expected by the Request class's environ field
swob.Request.headers fields are HeaderEnvironProxy() objects.
3. HeaderKeyDict() objects report their keys in ".lower()" case,
and normalize all other key references to ".lower()" case
swob.Response.headers fields are HeaderKeyDict() objects.
Depending on which object is used and how it is used, one can end up
with such a mismatch.
This commit takes the following steps as a (PROPOSED) solution:
1. Change HeaderKeyDict() to normalize using ".title()" case to
match HeaderEnvironProxy()
2. Replace standard python dictionary objects with HeaderKeyDict()
objects where possible
This gives us an object that normalizes key references to avoid
fixing the code to normalize the string literals.
3. Fix up a few places to use title case string literals to match
the new defaults
Change-Id: Ied56a1df83ffac793ee85e796424d7d20f18f469
Signed-off-by: Peter Portante <peter.portante@redhat.com>
2012-11-15 16:34:45 -05:00
|
|
|
import os
|
2010-07-12 17:03:45 -05:00
|
|
|
|
2013-06-18 15:07:59 +08:00
|
|
|
import StringIO
|
|
|
|
from hashlib import md5
|
|
|
|
|
2010-10-07 08:23:17 -07:00
|
|
|
from swift.common import direct_client
|
2013-07-23 16:41:45 -07:00
|
|
|
from swiftclient import json_loads
|
2013-06-18 15:07:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
def mock_http_connect(status, fake_headers=None, body=None):
|
|
|
|
|
|
|
|
class FakeConn(object):
|
|
|
|
|
|
|
|
def __init__(self, status, fake_headers, body, *args, **kwargs):
|
|
|
|
self.status = status
|
|
|
|
self.reason = 'Fake'
|
|
|
|
self.body = body
|
|
|
|
self.host = args[0]
|
|
|
|
self.port = args[1]
|
|
|
|
self.method = args[4]
|
|
|
|
self.path = args[5]
|
|
|
|
self.with_exc = False
|
|
|
|
self.headers = kwargs.get('headers', {})
|
|
|
|
self.fake_headers = fake_headers
|
|
|
|
self.etag = md5()
|
|
|
|
|
|
|
|
def getresponse(self):
|
|
|
|
if self.with_exc:
|
|
|
|
raise Exception('test')
|
|
|
|
|
|
|
|
if self.fake_headers is not None and self.method == 'POST':
|
2013-07-23 16:41:45 -07:00
|
|
|
self.fake_headers.append(self.headers)
|
2013-06-18 15:07:59 +08:00
|
|
|
return self
|
|
|
|
|
|
|
|
def getheader(self, header, default=None):
|
|
|
|
return self.headers.get(header.lower(), default)
|
|
|
|
|
|
|
|
def getheaders(self):
|
|
|
|
if self.fake_headers is not None:
|
|
|
|
for key in self.fake_headers:
|
2013-07-23 16:41:45 -07:00
|
|
|
self.headers.update({key: self.fake_headers[key]})
|
2013-06-18 15:07:59 +08:00
|
|
|
return self.headers.items()
|
|
|
|
|
|
|
|
def read(self):
|
|
|
|
return self.body
|
|
|
|
|
|
|
|
def send(self, data):
|
|
|
|
self.etag.update(data)
|
|
|
|
self.headers['etag'] = str(self.etag.hexdigest())
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
return
|
|
|
|
return lambda *args, **kwargs: FakeConn(status, fake_headers, body,
|
|
|
|
*args, **kwargs)
|
2010-10-07 08:23:17 -07:00
|
|
|
|
|
|
|
|
|
|
|
class TestDirectClient(unittest.TestCase):
|
2010-07-12 17:03:45 -05:00
|
|
|
|
Enhance log msg to report referer and user-agent
Enhance internally logged messages to report referer and user-agent.
Pass the referering URL and METHOD between internal servers (when
known), and set the user-agent to be the server type (obj-server,
container-server, proxy-server, obj-updater, obj-replicator,
container-updater, direct-client, etc.) with the process PID. In
conjunction with the transaction ID, it helps to track down which PID
from a given system was responsible for initiating the request and
what that server was working on to make this request.
This has been helpful in tracking down interactions between object,
container and account servers.
We also take things a bit further performaing a bit of refactoring to
consolidate calls to transfer_headers() now that we have a helper
method for constructing them.
Finally we performed further changes to avoid header key duplication
due to string literal header key values and the various objects
representing headers for requests and responses. See below for more
details.
====
Header Keys
There seems to be a bit of a problem with the case of the various
string literals used for header keys and the interchangable way
standard Python dictionaries, HeaderKeyDict() and HeaderEnvironProxy()
objects are used.
If one is not careful, a header object of some sort (one that does not
normalize its keys, and that is not necessarily a dictionary) can be
constructed containing header keys which differ only by the case of
their string literals. E.g.:
{ 'x-trans-id': '1234', 'X-Trans-Id': '5678' }
Such an object, when passed to http_connect() will result in an
on-the-wire header where the key values are merged together, comma
separated, that looks something like:
HTTP_X_TRANS_ID: 1234,5678
For some headers in some contexts, this is behavior is desirable. For
example, one can also use a list of tuples which enumerate the multiple
values a single header should have.
However, in almost all of the contexts used in the code base, this is
not desirable.
This behavior arises from a combination of factors:
1. Header strings are not constants and different lower-case and
title-case header strings values are used interchangably in the
code at times
It might be worth the effort to make a pass through the code to
stop using string literals and use constants instead, but there
are plusses and minuses to doing that, so this was not attempted
in this effort
2. HeaderEnvironProxy() objects report their keys in ".title()"
case, but normalize all other key references to the form
expected by the Request class's environ field
swob.Request.headers fields are HeaderEnvironProxy() objects.
3. HeaderKeyDict() objects report their keys in ".lower()" case,
and normalize all other key references to ".lower()" case
swob.Response.headers fields are HeaderKeyDict() objects.
Depending on which object is used and how it is used, one can end up
with such a mismatch.
This commit takes the following steps as a (PROPOSED) solution:
1. Change HeaderKeyDict() to normalize using ".title()" case to
match HeaderEnvironProxy()
2. Replace standard python dictionary objects with HeaderKeyDict()
objects where possible
This gives us an object that normalizes key references to avoid
fixing the code to normalize the string literals.
3. Fix up a few places to use title case string literals to match
the new defaults
Change-Id: Ied56a1df83ffac793ee85e796424d7d20f18f469
Signed-off-by: Peter Portante <peter.portante@redhat.com>
2012-11-15 16:34:45 -05:00
|
|
|
def test_gen_headers(self):
|
|
|
|
hdrs = direct_client.gen_headers()
|
|
|
|
assert 'user-agent' in hdrs
|
|
|
|
assert hdrs['user-agent'] == 'direct-client %s' % os.getpid()
|
|
|
|
assert len(hdrs.keys()) == 1
|
|
|
|
|
|
|
|
hdrs = direct_client.gen_headers(add_ts=True)
|
|
|
|
assert 'user-agent' in hdrs
|
|
|
|
assert 'x-timestamp' in hdrs
|
|
|
|
assert len(hdrs.keys()) == 2
|
|
|
|
|
|
|
|
hdrs = direct_client.gen_headers(hdrs_in={'foo-bar': '47'})
|
|
|
|
assert 'user-agent' in hdrs
|
|
|
|
assert 'foo-bar' in hdrs
|
|
|
|
assert hdrs['foo-bar'] == '47'
|
|
|
|
assert len(hdrs.keys()) == 2
|
|
|
|
|
|
|
|
hdrs = direct_client.gen_headers(hdrs_in={'user-agent': '47'})
|
|
|
|
assert 'user-agent' in hdrs
|
|
|
|
assert hdrs['user-agent'] == 'direct-client %s' % os.getpid()
|
|
|
|
assert len(hdrs.keys()) == 1
|
2010-07-12 17:03:45 -05:00
|
|
|
|
2013-06-18 15:07:59 +08:00
|
|
|
def test_direct_get_account(self):
|
2013-07-23 16:41:45 -07:00
|
|
|
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
2013-06-18 15:07:59 +08:00
|
|
|
part = '0'
|
|
|
|
account = 'a'
|
|
|
|
headers = {
|
|
|
|
'X-Account-Container-Count': '1',
|
|
|
|
'X-Account-Object-Count': '1',
|
|
|
|
'X-Account-Bytes-Used': '1',
|
|
|
|
'X-Timestamp': '1234567890',
|
|
|
|
'X-PUT-Timestamp': '1234567890'}
|
|
|
|
|
|
|
|
body = '[{"count": 1, "bytes": 20971520, "name": "c1"}]'
|
|
|
|
|
|
|
|
fake_headers = {}
|
|
|
|
for header, value in headers.items():
|
|
|
|
fake_headers[header.lower()] = value
|
2013-07-23 16:41:45 -07:00
|
|
|
|
2013-06-18 15:07:59 +08:00
|
|
|
was_http_connector = direct_client.http_connect
|
|
|
|
direct_client.http_connect = mock_http_connect(200, fake_headers, body)
|
|
|
|
|
2013-08-31 23:42:43 -04:00
|
|
|
resp_headers, resp = direct_client.direct_get_account(node, part,
|
|
|
|
account)
|
2013-06-18 15:07:59 +08:00
|
|
|
|
2013-07-23 16:41:45 -07:00
|
|
|
fake_headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
2013-06-18 15:07:59 +08:00
|
|
|
self.assertEqual(fake_headers, resp_headers)
|
|
|
|
self.assertEqual(json_loads(body), resp)
|
|
|
|
|
|
|
|
direct_client.http_connect = mock_http_connect(204, fake_headers, body)
|
|
|
|
|
2013-08-31 23:42:43 -04:00
|
|
|
resp_headers, resp = direct_client.direct_get_account(node, part,
|
|
|
|
account)
|
2013-06-18 15:07:59 +08:00
|
|
|
|
2013-07-23 16:41:45 -07:00
|
|
|
fake_headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
2013-06-18 15:07:59 +08:00
|
|
|
self.assertEqual(fake_headers, resp_headers)
|
|
|
|
self.assertEqual([], resp)
|
|
|
|
|
|
|
|
direct_client.http_connect = was_http_connector
|
|
|
|
|
|
|
|
def test_direct_head_container(self):
|
2013-07-23 16:41:45 -07:00
|
|
|
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
2013-06-18 15:07:59 +08:00
|
|
|
part = '0'
|
|
|
|
account = 'a'
|
|
|
|
container = 'c'
|
2013-07-23 16:41:45 -07:00
|
|
|
headers = {'key': 'value'}
|
2013-06-18 15:07:59 +08:00
|
|
|
|
|
|
|
was_http_connector = direct_client.http_connect
|
|
|
|
direct_client.http_connect = mock_http_connect(200, headers)
|
|
|
|
|
2013-08-31 23:42:43 -04:00
|
|
|
resp = direct_client.direct_head_container(node, part, account,
|
|
|
|
container)
|
2013-06-18 15:07:59 +08:00
|
|
|
|
2013-07-23 16:41:45 -07:00
|
|
|
headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
2013-06-18 15:07:59 +08:00
|
|
|
self.assertEqual(headers, resp)
|
|
|
|
|
|
|
|
direct_client.http_connect = was_http_connector
|
|
|
|
|
|
|
|
def test_direct_get_container(self):
|
2013-07-23 16:41:45 -07:00
|
|
|
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
2013-06-18 15:07:59 +08:00
|
|
|
part = '0'
|
|
|
|
account = 'a'
|
|
|
|
container = 'c'
|
2013-07-23 16:41:45 -07:00
|
|
|
headers = {'key': 'value'}
|
2013-06-18 15:07:59 +08:00
|
|
|
body = '[{"hash": "8f4e3", "last_modified": "317260", "bytes": 209}]'
|
|
|
|
|
|
|
|
was_http_connector = direct_client.http_connect
|
|
|
|
direct_client.http_connect = mock_http_connect(200, headers, body)
|
|
|
|
|
2013-07-23 16:41:45 -07:00
|
|
|
resp_headers, resp = (
|
|
|
|
direct_client.direct_get_container(node, part, account, container))
|
2013-06-18 15:07:59 +08:00
|
|
|
|
2013-07-23 16:41:45 -07:00
|
|
|
headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
2013-06-18 15:07:59 +08:00
|
|
|
self.assertEqual(headers, resp_headers)
|
|
|
|
self.assertEqual(json_loads(body), resp)
|
|
|
|
|
|
|
|
direct_client.http_connect = mock_http_connect(204, headers, body)
|
|
|
|
|
2013-07-23 16:41:45 -07:00
|
|
|
resp_headers, resp = (
|
|
|
|
direct_client.direct_get_container(node, part, account, container))
|
2013-06-18 15:07:59 +08:00
|
|
|
|
2013-07-23 16:41:45 -07:00
|
|
|
headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
2013-06-18 15:07:59 +08:00
|
|
|
self.assertEqual(headers, resp_headers)
|
|
|
|
self.assertEqual([], resp)
|
|
|
|
|
|
|
|
direct_client.http_connect = was_http_connector
|
|
|
|
|
|
|
|
def test_direct_delete_container(self):
|
2013-07-23 16:41:45 -07:00
|
|
|
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
2013-06-18 15:07:59 +08:00
|
|
|
part = '0'
|
|
|
|
account = 'a'
|
|
|
|
container = 'c'
|
|
|
|
|
|
|
|
was_http_connector = direct_client.http_connect
|
|
|
|
direct_client.http_connect = mock_http_connect(200)
|
|
|
|
|
|
|
|
direct_client.direct_delete_container(node, part, account, container)
|
|
|
|
|
|
|
|
direct_client.http_connect = was_http_connector
|
|
|
|
|
|
|
|
def test_direct_head_object(self):
|
2013-07-23 16:41:45 -07:00
|
|
|
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
2013-06-18 15:07:59 +08:00
|
|
|
part = '0'
|
|
|
|
account = 'a'
|
|
|
|
container = 'c'
|
|
|
|
name = 'o'
|
2013-07-23 16:41:45 -07:00
|
|
|
headers = {'key': 'value'}
|
2013-06-18 15:07:59 +08:00
|
|
|
|
|
|
|
was_http_connector = direct_client.http_connect
|
|
|
|
direct_client.http_connect = mock_http_connect(200, headers)
|
|
|
|
|
|
|
|
resp = direct_client.direct_head_object(node, part, account,
|
|
|
|
container, name)
|
2013-07-23 16:41:45 -07:00
|
|
|
headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
2013-06-18 15:07:59 +08:00
|
|
|
self.assertEqual(headers, resp)
|
|
|
|
|
|
|
|
direct_client.http_connect = was_http_connector
|
|
|
|
|
|
|
|
def test_direct_get_object(self):
|
2013-07-23 16:41:45 -07:00
|
|
|
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
2013-06-18 15:07:59 +08:00
|
|
|
part = '0'
|
|
|
|
account = 'a'
|
|
|
|
container = 'c'
|
|
|
|
name = 'o'
|
|
|
|
contents = StringIO.StringIO('123456')
|
|
|
|
|
|
|
|
was_http_connector = direct_client.http_connect
|
|
|
|
direct_client.http_connect = mock_http_connect(200, body=contents)
|
|
|
|
|
2013-07-23 16:41:45 -07:00
|
|
|
resp_header, obj_body = (
|
2013-08-31 23:42:43 -04:00
|
|
|
direct_client.direct_get_object(node, part, account, container,
|
|
|
|
name))
|
2013-06-18 15:07:59 +08:00
|
|
|
self.assertEqual(obj_body, contents)
|
|
|
|
|
|
|
|
direct_client.http_connect = was_http_connector
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_direct_post_object(self):
|
2013-07-23 16:41:45 -07:00
|
|
|
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
2013-06-18 15:07:59 +08:00
|
|
|
part = '0'
|
|
|
|
account = 'a'
|
|
|
|
container = 'c'
|
|
|
|
name = 'o'
|
2013-07-23 16:41:45 -07:00
|
|
|
headers = {'Key': 'value'}
|
2013-06-18 15:07:59 +08:00
|
|
|
|
|
|
|
fake_headers = []
|
|
|
|
|
|
|
|
was_http_connector = direct_client.http_connect
|
|
|
|
direct_client.http_connect = mock_http_connect(200, fake_headers)
|
|
|
|
|
|
|
|
direct_client.direct_post_object(node, part, account,
|
2013-08-31 23:42:43 -04:00
|
|
|
container, name, headers)
|
2013-06-18 15:07:59 +08:00
|
|
|
self.assertEqual(headers['Key'], fake_headers[0].get('Key'))
|
|
|
|
|
|
|
|
direct_client.http_connect = was_http_connector
|
|
|
|
|
|
|
|
def test_direct_delete_object(self):
|
2013-07-23 16:41:45 -07:00
|
|
|
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
2013-06-18 15:07:59 +08:00
|
|
|
part = '0'
|
|
|
|
account = 'a'
|
|
|
|
container = 'c'
|
|
|
|
name = 'o'
|
|
|
|
|
|
|
|
was_http_connector = direct_client.http_connect
|
|
|
|
direct_client.http_connect = mock_http_connect(200)
|
|
|
|
|
2013-08-31 23:42:43 -04:00
|
|
|
direct_client.direct_delete_object(node, part, account, container,
|
|
|
|
name)
|
2013-06-18 15:07:59 +08:00
|
|
|
|
|
|
|
direct_client.http_connect = was_http_connector
|
|
|
|
|
|
|
|
def test_direct_put_object(self):
|
2013-07-23 16:41:45 -07:00
|
|
|
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
2013-06-18 15:07:59 +08:00
|
|
|
part = '0'
|
|
|
|
account = 'a'
|
|
|
|
container = 'c'
|
|
|
|
name = 'o'
|
|
|
|
contents = StringIO.StringIO('123456')
|
|
|
|
|
|
|
|
was_http_connector = direct_client.http_connect
|
|
|
|
direct_client.http_connect = mock_http_connect(200)
|
|
|
|
|
|
|
|
resp = direct_client.direct_put_object(node, part, account,
|
2013-08-31 23:42:43 -04:00
|
|
|
container, name, contents, 6)
|
2013-06-18 15:07:59 +08:00
|
|
|
self.assertEqual(md5('123456').hexdigest(), resp)
|
|
|
|
|
|
|
|
direct_client.http_connect = was_http_connector
|
|
|
|
|
|
|
|
def test_direct_put_object_fail(self):
|
2013-07-23 16:41:45 -07:00
|
|
|
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
2013-06-18 15:07:59 +08:00
|
|
|
part = '0'
|
|
|
|
account = 'a'
|
|
|
|
container = 'c'
|
|
|
|
name = 'o'
|
|
|
|
contents = StringIO.StringIO('123456')
|
|
|
|
|
|
|
|
was_http_connector = direct_client.http_connect
|
|
|
|
direct_client.http_connect = mock_http_connect(500)
|
|
|
|
|
2013-07-23 16:41:45 -07:00
|
|
|
self.assertRaises(direct_client.ClientException,
|
2013-08-31 23:42:43 -04:00
|
|
|
direct_client.direct_put_object, node, part, account,
|
|
|
|
container, name, contents)
|
2013-06-18 15:07:59 +08:00
|
|
|
|
|
|
|
direct_client.http_connect = was_http_connector
|
|
|
|
|
|
|
|
def test_direct_put_object_chunked(self):
|
2013-07-23 16:41:45 -07:00
|
|
|
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
2013-06-18 15:07:59 +08:00
|
|
|
part = '0'
|
|
|
|
account = 'a'
|
|
|
|
container = 'c'
|
|
|
|
name = 'o'
|
|
|
|
contents = StringIO.StringIO('123456')
|
|
|
|
|
|
|
|
was_http_connector = direct_client.http_connect
|
|
|
|
direct_client.http_connect = mock_http_connect(200)
|
|
|
|
|
2013-07-23 16:41:45 -07:00
|
|
|
resp = direct_client.direct_put_object(node, part, account,
|
2013-08-31 23:42:43 -04:00
|
|
|
container, name, contents)
|
2013-06-18 15:07:59 +08:00
|
|
|
self.assertEqual(md5('6\r\n123456\r\n0\r\n\r\n').hexdigest(), resp)
|
|
|
|
|
|
|
|
direct_client.http_connect = was_http_connector
|
|
|
|
|
|
|
|
def test_retry(self):
|
2013-07-23 16:41:45 -07:00
|
|
|
node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'}
|
2013-06-18 15:07:59 +08:00
|
|
|
part = '0'
|
|
|
|
account = 'a'
|
|
|
|
container = 'c'
|
|
|
|
name = 'o'
|
2013-07-23 16:41:45 -07:00
|
|
|
headers = {'key': 'value'}
|
2013-06-18 15:07:59 +08:00
|
|
|
|
|
|
|
was_http_connector = direct_client.http_connect
|
|
|
|
direct_client.http_connect = mock_http_connect(200, headers)
|
|
|
|
|
2013-07-23 16:41:45 -07:00
|
|
|
attempts, resp = direct_client.retry(direct_client.direct_head_object,
|
2013-08-31 23:42:43 -04:00
|
|
|
node, part, account, container,
|
|
|
|
name)
|
2013-07-23 16:41:45 -07:00
|
|
|
headers.update({'user-agent': 'direct-client %s' % os.getpid()})
|
2013-06-18 15:07:59 +08:00
|
|
|
self.assertEqual(headers, resp)
|
|
|
|
self.assertEqual(attempts, 1)
|
|
|
|
|
|
|
|
direct_client.http_connect = was_http_connector
|
2010-07-12 17:03:45 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|