Replace POLICY and POLICY_INDEX with string literals
Replaced throughout code base & tox'd. Functional as well as probe tests pass with and without policies defined. POLICY --> 'X-Storage-Policy' POLICY_INDEX --> 'X-Backend-Storage-Policy-Index' Change-Id: Iea3d06de80210e9e504e296d4572583d7ffabeac
This commit is contained in:
parent
1feaf6e289
commit
873c52e608
@ -31,7 +31,7 @@ from swift.common.ring import Ring
|
|||||||
from swift.common.utils import get_logger, whataremyips, ismount, \
|
from swift.common.utils import get_logger, whataremyips, ismount, \
|
||||||
config_true_value, Timestamp
|
config_true_value, Timestamp
|
||||||
from swift.common.daemon import Daemon
|
from swift.common.daemon import Daemon
|
||||||
from swift.common.storage_policy import POLICIES, POLICY_INDEX
|
from swift.common.storage_policy import POLICIES
|
||||||
|
|
||||||
|
|
||||||
class AccountReaper(Daemon):
|
class AccountReaper(Daemon):
|
||||||
@ -352,7 +352,7 @@ class AccountReaper(Daemon):
|
|||||||
if not objects:
|
if not objects:
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
policy_index = headers.get(POLICY_INDEX, 0)
|
policy_index = headers.get('X-Backend-Storage-Policy-Index', 0)
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
if isinstance(obj['name'], unicode):
|
if isinstance(obj['name'], unicode):
|
||||||
obj['name'] = obj['name'].encode('utf8')
|
obj['name'] = obj['name'].encode('utf8')
|
||||||
@ -442,7 +442,7 @@ class AccountReaper(Daemon):
|
|||||||
headers={'X-Container-Host': '%(ip)s:%(port)s' % cnode,
|
headers={'X-Container-Host': '%(ip)s:%(port)s' % cnode,
|
||||||
'X-Container-Partition': str(container_partition),
|
'X-Container-Partition': str(container_partition),
|
||||||
'X-Container-Device': cnode['device'],
|
'X-Container-Device': cnode['device'],
|
||||||
POLICY_INDEX: policy_index})
|
'X-Backend-Storage-Policy-Index': policy_index})
|
||||||
successes += 1
|
successes += 1
|
||||||
self.stats_return_codes[2] = \
|
self.stats_return_codes[2] = \
|
||||||
self.stats_return_codes.get(2, 0) + 1
|
self.stats_return_codes.get(2, 0) + 1
|
||||||
|
@ -38,7 +38,6 @@ from swift.common.swob import HTTPAccepted, HTTPBadRequest, \
|
|||||||
HTTPPreconditionFailed, HTTPConflict, Request, \
|
HTTPPreconditionFailed, HTTPConflict, Request, \
|
||||||
HTTPInsufficientStorage, HTTPException
|
HTTPInsufficientStorage, HTTPException
|
||||||
from swift.common.request_helpers import is_sys_or_user_meta
|
from swift.common.request_helpers import is_sys_or_user_meta
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
|
|
||||||
|
|
||||||
class AccountController(object):
|
class AccountController(object):
|
||||||
@ -110,7 +109,8 @@ class AccountController(object):
|
|||||||
else:
|
else:
|
||||||
timestamp = valid_timestamp(req)
|
timestamp = valid_timestamp(req)
|
||||||
pending_timeout = None
|
pending_timeout = None
|
||||||
container_policy_index = req.headers.get(POLICY_INDEX, 0)
|
container_policy_index = \
|
||||||
|
req.headers.get('X-Backend-Storage-Policy-Index', 0)
|
||||||
if 'x-trans-id' in req.headers:
|
if 'x-trans-id' in req.headers:
|
||||||
pending_timeout = 3
|
pending_timeout = 3
|
||||||
broker = self._get_account_broker(drive, part, account,
|
broker = self._get_account_broker(drive, part, account,
|
||||||
|
@ -25,7 +25,7 @@ from swift.account.backend import AccountBroker, DATADIR as ABDATADIR
|
|||||||
from swift.container.backend import ContainerBroker, DATADIR as CBDATADIR
|
from swift.container.backend import ContainerBroker, DATADIR as CBDATADIR
|
||||||
from swift.obj.diskfile import get_data_dir, read_metadata, DATADIR_BASE, \
|
from swift.obj.diskfile import get_data_dir, read_metadata, DATADIR_BASE, \
|
||||||
extract_policy_index
|
extract_policy_index
|
||||||
from swift.common.storage_policy import POLICIES, POLICY_INDEX
|
from swift.common.storage_policy import POLICIES
|
||||||
|
|
||||||
|
|
||||||
class InfoSystemExit(Exception):
|
class InfoSystemExit(Exception):
|
||||||
@ -101,14 +101,16 @@ def print_ring_locations(ring, datadir, account, container=None, obj=None,
|
|||||||
% (node['ip'], node['port'], node['device'], part,
|
% (node['ip'], node['port'], node['device'], part,
|
||||||
urllib.quote(target))
|
urllib.quote(target))
|
||||||
if policy_index is not None:
|
if policy_index is not None:
|
||||||
cmd += ' -H "%s: %s"' % (POLICY_INDEX, policy_index)
|
cmd += ' -H "%s: %s"' % ('X-Backend-Storage-Policy-Index',
|
||||||
|
policy_index)
|
||||||
print cmd
|
print cmd
|
||||||
for node in handoff_nodes:
|
for node in handoff_nodes:
|
||||||
cmd = 'curl -I -XHEAD "http://%s:%s/%s/%s/%s"' \
|
cmd = 'curl -I -XHEAD "http://%s:%s/%s/%s/%s"' \
|
||||||
% (node['ip'], node['port'], node['device'], part,
|
% (node['ip'], node['port'], node['device'], part,
|
||||||
urllib.quote(target))
|
urllib.quote(target))
|
||||||
if policy_index is not None:
|
if policy_index is not None:
|
||||||
cmd += ' -H "%s: %s"' % (POLICY_INDEX, policy_index)
|
cmd += ' -H "%s: %s"' % ('X-Backend-Storage-Policy-Index',
|
||||||
|
policy_index)
|
||||||
cmd += ' # [Handoff]'
|
cmd += ' # [Handoff]'
|
||||||
print cmd
|
print cmd
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ from swift.common.exceptions import ListingIterError, SegmentError
|
|||||||
from swift.common.http import is_success, HTTP_SERVICE_UNAVAILABLE
|
from swift.common.http import is_success, HTTP_SERVICE_UNAVAILABLE
|
||||||
from swift.common.swob import HTTPBadRequest, HTTPNotAcceptable
|
from swift.common.swob import HTTPBadRequest, HTTPNotAcceptable
|
||||||
from swift.common.utils import split_path, validate_device_partition
|
from swift.common.utils import split_path, validate_device_partition
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
from swift.common.wsgi import make_subrequest
|
from swift.common.wsgi import make_subrequest
|
||||||
|
|
||||||
|
|
||||||
@ -91,7 +90,7 @@ def get_name_and_placement(request, minsegs=1, maxsegs=None,
|
|||||||
storage_policy_index appended on the end
|
storage_policy_index appended on the end
|
||||||
:raises: HTTPBadRequest
|
:raises: HTTPBadRequest
|
||||||
"""
|
"""
|
||||||
policy_idx = request.headers.get(POLICY_INDEX, '0')
|
policy_idx = request.headers.get('X-Backend-Storage-Policy-Index', '0')
|
||||||
policy_idx = int(policy_idx)
|
policy_idx = int(policy_idx)
|
||||||
results = split_and_validate_path(request, minsegs=minsegs,
|
results = split_and_validate_path(request, minsegs=minsegs,
|
||||||
maxsegs=maxsegs,
|
maxsegs=maxsegs,
|
||||||
|
@ -18,8 +18,6 @@ import string
|
|||||||
from swift.common.utils import config_true_value, SWIFT_CONF_FILE
|
from swift.common.utils import config_true_value, SWIFT_CONF_FILE
|
||||||
from swift.common.ring import Ring
|
from swift.common.ring import Ring
|
||||||
|
|
||||||
POLICY = 'X-Storage-Policy'
|
|
||||||
POLICY_INDEX = 'X-Backend-Storage-Policy-Index'
|
|
||||||
LEGACY_POLICY_NAME = 'Policy-0'
|
LEGACY_POLICY_NAME = 'Policy-0'
|
||||||
VALID_CHARS = '-' + string.letters + string.digits
|
VALID_CHARS = '-' + string.letters + string.digits
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ from swift.common.direct_client import (
|
|||||||
direct_head_container, direct_delete_container_object,
|
direct_head_container, direct_delete_container_object,
|
||||||
direct_put_container_object, ClientException)
|
direct_put_container_object, ClientException)
|
||||||
from swift.common.internal_client import InternalClient, UnexpectedResponse
|
from swift.common.internal_client import InternalClient, UnexpectedResponse
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
from swift.common.utils import get_logger, split_path, quorum_size, \
|
from swift.common.utils import get_logger, split_path, quorum_size, \
|
||||||
FileLikeIter, Timestamp, last_modified_date_to_timestamp, \
|
FileLikeIter, Timestamp, last_modified_date_to_timestamp, \
|
||||||
LRUCache
|
LRUCache
|
||||||
@ -100,7 +99,7 @@ def incorrect_policy_index(info, remote_info):
|
|||||||
def translate_container_headers_to_info(headers):
|
def translate_container_headers_to_info(headers):
|
||||||
default_timestamp = Timestamp(0).internal
|
default_timestamp = Timestamp(0).internal
|
||||||
return {
|
return {
|
||||||
'storage_policy_index': int(headers[POLICY_INDEX]),
|
'storage_policy_index': int(headers['X-Backend-Storage-Policy-Index']),
|
||||||
'put_timestamp': headers.get('x-backend-put-timestamp',
|
'put_timestamp': headers.get('x-backend-put-timestamp',
|
||||||
default_timestamp),
|
default_timestamp),
|
||||||
'delete_timestamp': headers.get('x-backend-delete-timestamp',
|
'delete_timestamp': headers.get('x-backend-delete-timestamp',
|
||||||
|
@ -37,7 +37,7 @@ from swift.common import constraints
|
|||||||
from swift.common.bufferedhttp import http_connect
|
from swift.common.bufferedhttp import http_connect
|
||||||
from swift.common.exceptions import ConnectionTimeout
|
from swift.common.exceptions import ConnectionTimeout
|
||||||
from swift.common.http import HTTP_NOT_FOUND, is_success
|
from swift.common.http import HTTP_NOT_FOUND, is_success
|
||||||
from swift.common.storage_policy import POLICIES, POLICY_INDEX
|
from swift.common.storage_policy import POLICIES
|
||||||
from swift.common.swob import HTTPAccepted, HTTPBadRequest, HTTPConflict, \
|
from swift.common.swob import HTTPAccepted, HTTPBadRequest, HTTPConflict, \
|
||||||
HTTPCreated, HTTPInternalServerError, HTTPNoContent, HTTPNotFound, \
|
HTTPCreated, HTTPInternalServerError, HTTPNoContent, HTTPNotFound, \
|
||||||
HTTPPreconditionFailed, HTTPMethodNotAllowed, Request, Response, \
|
HTTPPreconditionFailed, HTTPMethodNotAllowed, Request, Response, \
|
||||||
@ -57,7 +57,7 @@ def gen_resp_headers(info, is_deleted=False):
|
|||||||
info.get('delete_timestamp', 0)).internal,
|
info.get('delete_timestamp', 0)).internal,
|
||||||
'X-Backend-Status-Changed-At': Timestamp(
|
'X-Backend-Status-Changed-At': Timestamp(
|
||||||
info.get('status_changed_at', 0)).internal,
|
info.get('status_changed_at', 0)).internal,
|
||||||
POLICY_INDEX: info.get('storage_policy_index', 0),
|
'X-Backend-Storage-Policy-Index': info.get('storage_policy_index', 0),
|
||||||
}
|
}
|
||||||
if not is_deleted:
|
if not is_deleted:
|
||||||
# base container info on deleted containers is not exposed to client
|
# base container info on deleted containers is not exposed to client
|
||||||
@ -137,7 +137,7 @@ class ContainerController(object):
|
|||||||
:raises: HTTPBadRequest if the supplied index is bogus
|
:raises: HTTPBadRequest if the supplied index is bogus
|
||||||
"""
|
"""
|
||||||
|
|
||||||
policy_index = req.headers.get(POLICY_INDEX, None)
|
policy_index = req.headers.get('X-Backend-Storage-Policy-Index', None)
|
||||||
if policy_index is None:
|
if policy_index is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ class ContainerController(object):
|
|||||||
'x-object-count': info['object_count'],
|
'x-object-count': info['object_count'],
|
||||||
'x-bytes-used': info['bytes_used'],
|
'x-bytes-used': info['bytes_used'],
|
||||||
'x-trans-id': req.headers.get('x-trans-id', '-'),
|
'x-trans-id': req.headers.get('x-trans-id', '-'),
|
||||||
POLICY_INDEX: info['storage_policy_index'],
|
'X-Backend-Storage-Policy-Index': info['storage_policy_index'],
|
||||||
'user-agent': 'container-server %s' % os.getpid(),
|
'user-agent': 'container-server %s' % os.getpid(),
|
||||||
'referer': req.as_referer()})
|
'referer': req.as_referer()})
|
||||||
if req.headers.get('x-account-override-deleted', 'no').lower() == \
|
if req.headers.get('x-account-override-deleted', 'no').lower() == \
|
||||||
|
@ -35,7 +35,7 @@ from swift.common.utils import (
|
|||||||
whataremyips, Timestamp)
|
whataremyips, Timestamp)
|
||||||
from swift.common.daemon import Daemon
|
from swift.common.daemon import Daemon
|
||||||
from swift.common.http import HTTP_UNAUTHORIZED, HTTP_NOT_FOUND
|
from swift.common.http import HTTP_UNAUTHORIZED, HTTP_NOT_FOUND
|
||||||
from swift.common.storage_policy import POLICIES, POLICY_INDEX
|
from swift.common.storage_policy import POLICIES
|
||||||
|
|
||||||
|
|
||||||
class ContainerSync(Daemon):
|
class ContainerSync(Daemon):
|
||||||
@ -376,7 +376,8 @@ class ContainerSync(Daemon):
|
|||||||
looking_for_timestamp = Timestamp(row['created_at'])
|
looking_for_timestamp = Timestamp(row['created_at'])
|
||||||
timestamp = -1
|
timestamp = -1
|
||||||
headers = body = None
|
headers = body = None
|
||||||
headers_out = {POLICY_INDEX: str(info['storage_policy_index'])}
|
headers_out = {'X-Backend-Storage-Policy-Index':
|
||||||
|
str(info['storage_policy_index'])}
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
try:
|
try:
|
||||||
these_headers, this_body = direct_get_object(
|
these_headers, this_body = direct_get_object(
|
||||||
|
@ -33,7 +33,6 @@ from swift.common.utils import get_logger, config_true_value, ismount, \
|
|||||||
dump_recon_cache, quorum_size, Timestamp
|
dump_recon_cache, quorum_size, Timestamp
|
||||||
from swift.common.daemon import Daemon
|
from swift.common.daemon import Daemon
|
||||||
from swift.common.http import is_success, HTTP_INTERNAL_SERVER_ERROR
|
from swift.common.http import is_success, HTTP_INTERNAL_SERVER_ERROR
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
|
|
||||||
|
|
||||||
class ContainerUpdater(Daemon):
|
class ContainerUpdater(Daemon):
|
||||||
@ -278,7 +277,7 @@ class ContainerUpdater(Daemon):
|
|||||||
'X-Object-Count': count,
|
'X-Object-Count': count,
|
||||||
'X-Bytes-Used': bytes,
|
'X-Bytes-Used': bytes,
|
||||||
'X-Account-Override-Deleted': 'yes',
|
'X-Account-Override-Deleted': 'yes',
|
||||||
POLICY_INDEX: storage_policy_index,
|
'X-Backend-Storage-Policy-Index': storage_policy_index,
|
||||||
'user-agent': self.user_agent}
|
'user-agent': self.user_agent}
|
||||||
conn = http_connect(
|
conn = http_connect(
|
||||||
node['ip'], node['port'], node['device'], part,
|
node['ip'], node['port'], node['device'], part,
|
||||||
|
@ -37,7 +37,7 @@ from swift.common.http import HTTP_OK, HTTP_INSUFFICIENT_STORAGE
|
|||||||
from swift.obj import ssync_sender
|
from swift.obj import ssync_sender
|
||||||
from swift.obj.diskfile import (DiskFileManager, get_hashes, get_data_dir,
|
from swift.obj.diskfile import (DiskFileManager, get_hashes, get_data_dir,
|
||||||
get_tmp_dir)
|
get_tmp_dir)
|
||||||
from swift.common.storage_policy import POLICY_INDEX, POLICIES
|
from swift.common.storage_policy import POLICIES
|
||||||
|
|
||||||
|
|
||||||
hubs.use_hub(get_hub())
|
hubs.use_hub(get_hub())
|
||||||
@ -228,7 +228,7 @@ class ObjectReplicator(Daemon):
|
|||||||
if len(suff) == 3 and isdir(join(path, suff))]
|
if len(suff) == 3 and isdir(join(path, suff))]
|
||||||
self.replication_count += 1
|
self.replication_count += 1
|
||||||
self.logger.increment('partition.delete.count.%s' % (job['device'],))
|
self.logger.increment('partition.delete.count.%s' % (job['device'],))
|
||||||
self.headers[POLICY_INDEX] = job['policy_idx']
|
self.headers['X-Backend-Storage-Policy-Index'] = job['policy_idx']
|
||||||
begin = time.time()
|
begin = time.time()
|
||||||
try:
|
try:
|
||||||
responses = []
|
responses = []
|
||||||
@ -270,7 +270,7 @@ class ObjectReplicator(Daemon):
|
|||||||
"""
|
"""
|
||||||
self.replication_count += 1
|
self.replication_count += 1
|
||||||
self.logger.increment('partition.update.count.%s' % (job['device'],))
|
self.logger.increment('partition.update.count.%s' % (job['device'],))
|
||||||
self.headers[POLICY_INDEX] = job['policy_idx']
|
self.headers['X-Backend-Storage-Policy-Index'] = job['policy_idx']
|
||||||
begin = time.time()
|
begin = time.time()
|
||||||
try:
|
try:
|
||||||
hashed, local_hash = tpool_reraise(
|
hashed, local_hash = tpool_reraise(
|
||||||
|
@ -46,7 +46,6 @@ from swift.common.swob import HTTPAccepted, HTTPBadRequest, HTTPCreated, \
|
|||||||
HTTPInsufficientStorage, HTTPForbidden, HTTPException, HeaderKeyDict, \
|
HTTPInsufficientStorage, HTTPForbidden, HTTPException, HeaderKeyDict, \
|
||||||
HTTPConflict
|
HTTPConflict
|
||||||
from swift.obj.diskfile import DATAFILE_SYSTEM_META, DiskFileManager
|
from swift.obj.diskfile import DATAFILE_SYSTEM_META, DiskFileManager
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
|
|
||||||
|
|
||||||
class ObjectController(object):
|
class ObjectController(object):
|
||||||
@ -240,7 +239,7 @@ class ObjectController(object):
|
|||||||
|
|
||||||
headers_out['x-trans-id'] = headers_in.get('x-trans-id', '-')
|
headers_out['x-trans-id'] = headers_in.get('x-trans-id', '-')
|
||||||
headers_out['referer'] = request.as_referer()
|
headers_out['referer'] = request.as_referer()
|
||||||
headers_out[POLICY_INDEX] = policy_idx
|
headers_out['X-Backend-Storage-Policy-Index'] = policy_idx
|
||||||
for conthost, contdevice in updates:
|
for conthost, contdevice in updates:
|
||||||
self.async_update(op, account, container, obj, conthost,
|
self.async_update(op, account, container, obj, conthost,
|
||||||
contpartition, contdevice, headers_out,
|
contpartition, contdevice, headers_out,
|
||||||
@ -270,7 +269,8 @@ class ObjectController(object):
|
|||||||
hosts = contdevices = [None]
|
hosts = contdevices = [None]
|
||||||
headers_in = request.headers
|
headers_in = request.headers
|
||||||
headers_out = HeaderKeyDict({
|
headers_out = HeaderKeyDict({
|
||||||
POLICY_INDEX: 0, # system accounts are always Policy-0
|
# system accounts are always Policy-0
|
||||||
|
'X-Backend-Storage-Policy-Index': 0,
|
||||||
'x-timestamp': request.timestamp.internal,
|
'x-timestamp': request.timestamp.internal,
|
||||||
'x-trans-id': headers_in.get('x-trans-id', '-'),
|
'x-trans-id': headers_in.get('x-trans-id', '-'),
|
||||||
'referer': request.as_referer()})
|
'referer': request.as_referer()})
|
||||||
|
@ -25,8 +25,6 @@ from swift.common import http
|
|||||||
from swift.common import swob
|
from swift.common import swob
|
||||||
from swift.common import utils
|
from swift.common import utils
|
||||||
|
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
|
|
||||||
|
|
||||||
class Receiver(object):
|
class Receiver(object):
|
||||||
"""
|
"""
|
||||||
@ -170,7 +168,8 @@ class Receiver(object):
|
|||||||
self.request.environ['eventlet.minimum_write_chunk_size'] = 0
|
self.request.environ['eventlet.minimum_write_chunk_size'] = 0
|
||||||
self.device, self.partition = utils.split_path(
|
self.device, self.partition = utils.split_path(
|
||||||
urllib.unquote(self.request.path), 2, 2, False)
|
urllib.unquote(self.request.path), 2, 2, False)
|
||||||
self.policy_idx = int(self.request.headers.get(POLICY_INDEX, 0))
|
self.policy_idx = \
|
||||||
|
int(self.request.headers.get('X-Backend-Storage-Policy-Index', 0))
|
||||||
utils.validate_device_partition(self.device, self.partition)
|
utils.validate_device_partition(self.device, self.partition)
|
||||||
if self.app._diskfile_mgr.mount_check and \
|
if self.app._diskfile_mgr.mount_check and \
|
||||||
not constraints.check_mount(
|
not constraints.check_mount(
|
||||||
@ -354,7 +353,7 @@ class Receiver(object):
|
|||||||
subreq_iter())
|
subreq_iter())
|
||||||
else:
|
else:
|
||||||
raise Exception('Invalid subrequest method %s' % method)
|
raise Exception('Invalid subrequest method %s' % method)
|
||||||
subreq.headers[POLICY_INDEX] = self.policy_idx
|
subreq.headers['X-Backend-Storage-Policy-Index'] = self.policy_idx
|
||||||
subreq.headers['X-Backend-Replication'] = 'True'
|
subreq.headers['X-Backend-Replication'] = 'True'
|
||||||
if replication_headers:
|
if replication_headers:
|
||||||
subreq.headers['X-Backend-Replication-Headers'] = \
|
subreq.headers['X-Backend-Replication-Headers'] = \
|
||||||
|
@ -18,8 +18,6 @@ from swift.common import bufferedhttp
|
|||||||
from swift.common import exceptions
|
from swift.common import exceptions
|
||||||
from swift.common import http
|
from swift.common import http
|
||||||
|
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
|
|
||||||
|
|
||||||
class Sender(object):
|
class Sender(object):
|
||||||
"""
|
"""
|
||||||
@ -100,7 +98,8 @@ class Sender(object):
|
|||||||
self.connection.putrequest('REPLICATION', '/%s/%s' % (
|
self.connection.putrequest('REPLICATION', '/%s/%s' % (
|
||||||
self.node['device'], self.job['partition']))
|
self.node['device'], self.job['partition']))
|
||||||
self.connection.putheader('Transfer-Encoding', 'chunked')
|
self.connection.putheader('Transfer-Encoding', 'chunked')
|
||||||
self.connection.putheader(POLICY_INDEX, self.policy_idx)
|
self.connection.putheader('X-Backend-Storage-Policy-Index',
|
||||||
|
self.policy_idx)
|
||||||
self.connection.endheaders()
|
self.connection.endheaders()
|
||||||
with exceptions.MessageTimeout(
|
with exceptions.MessageTimeout(
|
||||||
self.daemon.node_timeout, 'connect receive'):
|
self.daemon.node_timeout, 'connect receive'):
|
||||||
|
@ -26,7 +26,6 @@ from eventlet import patcher, Timeout
|
|||||||
from swift.common.bufferedhttp import http_connect
|
from swift.common.bufferedhttp import http_connect
|
||||||
from swift.common.exceptions import ConnectionTimeout
|
from swift.common.exceptions import ConnectionTimeout
|
||||||
from swift.common.ring import Ring
|
from swift.common.ring import Ring
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
from swift.common.utils import get_logger, renamer, write_pickle, \
|
from swift.common.utils import get_logger, renamer, write_pickle, \
|
||||||
dump_recon_cache, config_true_value, ismount
|
dump_recon_cache, config_true_value, ismount
|
||||||
from swift.common.daemon import Daemon
|
from swift.common.daemon import Daemon
|
||||||
@ -222,7 +221,8 @@ class ObjectUpdater(Daemon):
|
|||||||
for node in nodes:
|
for node in nodes:
|
||||||
if node['id'] not in successes:
|
if node['id'] not in successes:
|
||||||
headers = update['headers'].copy()
|
headers = update['headers'].copy()
|
||||||
headers.setdefault(POLICY_INDEX, str(policy_idx))
|
headers.setdefault('X-Backend-Storage-Policy-Index',
|
||||||
|
str(policy_idx))
|
||||||
status = self.object_update(node, part, update['op'], obj,
|
status = self.object_update(node, part, update['op'], obj,
|
||||||
headers)
|
headers)
|
||||||
if not is_success(status) and status != HTTP_NOT_FOUND:
|
if not is_success(status) and status != HTTP_NOT_FOUND:
|
||||||
|
@ -50,7 +50,7 @@ from swift.common.swob import Request, Response, HeaderKeyDict, Range, \
|
|||||||
HTTPException, HTTPRequestedRangeNotSatisfiable
|
HTTPException, HTTPRequestedRangeNotSatisfiable
|
||||||
from swift.common.request_helpers import strip_sys_meta_prefix, \
|
from swift.common.request_helpers import strip_sys_meta_prefix, \
|
||||||
strip_user_meta_prefix, is_user_meta, is_sys_meta, is_sys_or_user_meta
|
strip_user_meta_prefix, is_user_meta, is_sys_meta, is_sys_or_user_meta
|
||||||
from swift.common.storage_policy import POLICY_INDEX, POLICY, POLICIES
|
from swift.common.storage_policy import POLICIES
|
||||||
|
|
||||||
|
|
||||||
def update_headers(response, headers):
|
def update_headers(response, headers):
|
||||||
@ -162,7 +162,8 @@ def headers_to_container_info(headers, status_int=HTTP_OK):
|
|||||||
'object_count': headers.get('x-container-object-count'),
|
'object_count': headers.get('x-container-object-count'),
|
||||||
'bytes': headers.get('x-container-bytes-used'),
|
'bytes': headers.get('x-container-bytes-used'),
|
||||||
'versions': headers.get('x-versions-location'),
|
'versions': headers.get('x-versions-location'),
|
||||||
'storage_policy': headers.get(POLICY_INDEX.lower(), '0'),
|
'storage_policy': headers.get('X-Backend-Storage-Policy-Index'.lower(),
|
||||||
|
'0'),
|
||||||
'cors': {
|
'cors': {
|
||||||
'allow_origin': meta.get('access-control-allow-origin'),
|
'allow_origin': meta.get('access-control-allow-origin'),
|
||||||
'expose_headers': meta.get('access-control-expose-headers'),
|
'expose_headers': meta.get('access-control-expose-headers'),
|
||||||
@ -1206,14 +1207,18 @@ class Controller(object):
|
|||||||
pass
|
pass
|
||||||
# if a backend policy index is present in resp headers, translate it
|
# if a backend policy index is present in resp headers, translate it
|
||||||
# here with the friendly policy name
|
# here with the friendly policy name
|
||||||
if POLICY_INDEX in res.headers and is_success(res.status_int):
|
if 'X-Backend-Storage-Policy-Index' in res.headers and \
|
||||||
policy = POLICIES.get_by_index(res.headers[POLICY_INDEX])
|
is_success(res.status_int):
|
||||||
|
policy = \
|
||||||
|
POLICIES.get_by_index(
|
||||||
|
res.headers['X-Backend-Storage-Policy-Index'])
|
||||||
if policy:
|
if policy:
|
||||||
res.headers[POLICY] = policy.name
|
res.headers['X-Storage-Policy'] = policy.name
|
||||||
else:
|
else:
|
||||||
self.app.logger.error(
|
self.app.logger.error(
|
||||||
'Could not translate %s (%r) from %r to policy',
|
'Could not translate %s (%r) from %r to policy',
|
||||||
POLICY_INDEX, res.headers[POLICY_INDEX], path)
|
'X-Backend-Storage-Policy-Index',
|
||||||
|
res.headers['X-Backend-Storage-Policy-Index'], path)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def is_origin_allowed(self, cors_info, origin):
|
def is_origin_allowed(self, cors_info, origin):
|
||||||
|
@ -23,7 +23,7 @@ from swift.common import constraints
|
|||||||
from swift.common.http import HTTP_ACCEPTED
|
from swift.common.http import HTTP_ACCEPTED
|
||||||
from swift.proxy.controllers.base import Controller, delay_denial, \
|
from swift.proxy.controllers.base import Controller, delay_denial, \
|
||||||
cors_validation, clear_info_cache
|
cors_validation, clear_info_cache
|
||||||
from swift.common.storage_policy import POLICIES, POLICY, POLICY_INDEX
|
from swift.common.storage_policy import POLICIES
|
||||||
from swift.common.swob import HTTPBadRequest, HTTPForbidden, \
|
from swift.common.swob import HTTPBadRequest, HTTPForbidden, \
|
||||||
HTTPNotFound
|
HTTPNotFound
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ class ContainerController(Controller):
|
|||||||
|
|
||||||
:param req: incoming request
|
:param req: incoming request
|
||||||
"""
|
"""
|
||||||
policy_name = req.headers.get(POLICY)
|
policy_name = req.headers.get('X-Storage-Policy')
|
||||||
if not policy_name:
|
if not policy_name:
|
||||||
return
|
return
|
||||||
policy = POLICIES.get_by_name(policy_name)
|
policy = POLICIES.get_by_name(policy_name)
|
||||||
@ -63,7 +63,7 @@ class ContainerController(Controller):
|
|||||||
raise HTTPBadRequest(request=req,
|
raise HTTPBadRequest(request=req,
|
||||||
content_type="text/plain",
|
content_type="text/plain",
|
||||||
body=("Invalid %s '%s'"
|
body=("Invalid %s '%s'"
|
||||||
% (POLICY, policy_name)))
|
% ('X-Storage-Policy', policy_name)))
|
||||||
if policy.is_deprecated:
|
if policy.is_deprecated:
|
||||||
body = 'Storage Policy %r is deprecated' % (policy.name)
|
body = 'Storage Policy %r is deprecated' % (policy.name)
|
||||||
raise HTTPBadRequest(request=req, body=body)
|
raise HTTPBadRequest(request=req, body=body)
|
||||||
@ -214,7 +214,7 @@ class ContainerController(Controller):
|
|||||||
additional['X-Backend-Storage-Policy-Default'] = \
|
additional['X-Backend-Storage-Policy-Default'] = \
|
||||||
int(POLICIES.default)
|
int(POLICIES.default)
|
||||||
else:
|
else:
|
||||||
additional[POLICY_INDEX] = str(policy_index)
|
additional['X-Backend-Storage-Policy-Index'] = str(policy_index)
|
||||||
headers = [self.generate_request_headers(req, transfer=True,
|
headers = [self.generate_request_headers(req, transfer=True,
|
||||||
additional=additional)
|
additional=additional)
|
||||||
for _junk in range(n_outgoing)]
|
for _junk in range(n_outgoing)]
|
||||||
|
@ -56,7 +56,6 @@ from swift.common.swob import HTTPAccepted, HTTPBadRequest, HTTPNotFound, \
|
|||||||
HTTPPreconditionFailed, HTTPRequestEntityTooLarge, HTTPRequestTimeout, \
|
HTTPPreconditionFailed, HTTPRequestEntityTooLarge, HTTPRequestTimeout, \
|
||||||
HTTPServerError, HTTPServiceUnavailable, Request, \
|
HTTPServerError, HTTPServiceUnavailable, Request, \
|
||||||
HTTPClientDisconnect, HTTPNotImplemented
|
HTTPClientDisconnect, HTTPNotImplemented
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
from swift.common.request_helpers import is_user_meta
|
from swift.common.request_helpers import is_user_meta
|
||||||
|
|
||||||
|
|
||||||
@ -197,10 +196,10 @@ class ObjectController(Controller):
|
|||||||
self.account_name, self.container_name, req)
|
self.account_name, self.container_name, req)
|
||||||
req.acl = container_info['read_acl']
|
req.acl = container_info['read_acl']
|
||||||
# pass the policy index to storage nodes via req header
|
# pass the policy index to storage nodes via req header
|
||||||
policy_index = req.headers.get(POLICY_INDEX,
|
policy_index = req.headers.get('X-Backend-Storage-Policy-Index',
|
||||||
container_info['storage_policy'])
|
container_info['storage_policy'])
|
||||||
obj_ring = self.app.get_object_ring(policy_index)
|
obj_ring = self.app.get_object_ring(policy_index)
|
||||||
req.headers[POLICY_INDEX] = policy_index
|
req.headers['X-Backend-Storage-Policy-Index'] = policy_index
|
||||||
if 'swift.authorize' in req.environ:
|
if 'swift.authorize' in req.environ:
|
||||||
aresp = req.environ['swift.authorize'](req)
|
aresp = req.environ['swift.authorize'](req)
|
||||||
if aresp:
|
if aresp:
|
||||||
@ -303,10 +302,10 @@ class ObjectController(Controller):
|
|||||||
else:
|
else:
|
||||||
delete_at_container = delete_at_part = delete_at_nodes = None
|
delete_at_container = delete_at_part = delete_at_nodes = None
|
||||||
# pass the policy index to storage nodes via req header
|
# pass the policy index to storage nodes via req header
|
||||||
policy_index = req.headers.get(POLICY_INDEX,
|
policy_index = req.headers.get('X-Backend-Storage-Policy-Index',
|
||||||
container_info['storage_policy'])
|
container_info['storage_policy'])
|
||||||
obj_ring = self.app.get_object_ring(policy_index)
|
obj_ring = self.app.get_object_ring(policy_index)
|
||||||
req.headers[POLICY_INDEX] = policy_index
|
req.headers['X-Backend-Storage-Policy-Index'] = policy_index
|
||||||
partition, nodes = obj_ring.get_nodes(
|
partition, nodes = obj_ring.get_nodes(
|
||||||
self.account_name, self.container_name, self.object_name)
|
self.account_name, self.container_name, self.object_name)
|
||||||
req.headers['X-Timestamp'] = Timestamp(time.time()).internal
|
req.headers['X-Timestamp'] = Timestamp(time.time()).internal
|
||||||
@ -458,11 +457,11 @@ class ObjectController(Controller):
|
|||||||
body='If-None-Match only supports *')
|
body='If-None-Match only supports *')
|
||||||
container_info = self.container_info(
|
container_info = self.container_info(
|
||||||
self.account_name, self.container_name, req)
|
self.account_name, self.container_name, req)
|
||||||
policy_index = req.headers.get(POLICY_INDEX,
|
policy_index = req.headers.get('X-Backend-Storage-Policy-Index',
|
||||||
container_info['storage_policy'])
|
container_info['storage_policy'])
|
||||||
obj_ring = self.app.get_object_ring(policy_index)
|
obj_ring = self.app.get_object_ring(policy_index)
|
||||||
# pass the policy index to storage nodes via req header
|
# pass the policy index to storage nodes via req header
|
||||||
req.headers[POLICY_INDEX] = policy_index
|
req.headers['X-Backend-Storage-Policy-Index'] = policy_index
|
||||||
container_partition = container_info['partition']
|
container_partition = container_info['partition']
|
||||||
containers = container_info['nodes']
|
containers = container_info['nodes']
|
||||||
req.acl = container_info['write_acl']
|
req.acl = container_info['write_acl']
|
||||||
@ -500,7 +499,8 @@ class ObjectController(Controller):
|
|||||||
(object_versions and not
|
(object_versions and not
|
||||||
req.environ.get('swift_versioned_copy')):
|
req.environ.get('swift_versioned_copy')):
|
||||||
# make sure proxy-server uses the right policy index
|
# make sure proxy-server uses the right policy index
|
||||||
_headers = {POLICY_INDEX: req.headers[POLICY_INDEX],
|
_headers = {'X-Backend-Storage-Policy-Index':
|
||||||
|
req.headers['X-Backend-Storage-Policy-Index'],
|
||||||
'X-Newest': 'True'}
|
'X-Newest': 'True'}
|
||||||
hreq = Request.blank(req.path_info, headers=_headers,
|
hreq = Request.blank(req.path_info, headers=_headers,
|
||||||
environ={'REQUEST_METHOD': 'HEAD'})
|
environ={'REQUEST_METHOD': 'HEAD'})
|
||||||
@ -586,7 +586,7 @@ class ObjectController(Controller):
|
|||||||
src_container_name, src_obj_name)
|
src_container_name, src_obj_name)
|
||||||
source_req = req.copy_get()
|
source_req = req.copy_get()
|
||||||
# make sure the source request uses it's container_info
|
# make sure the source request uses it's container_info
|
||||||
source_req.headers.pop(POLICY_INDEX, None)
|
source_req.headers.pop('X-Backend-Storage-Policy-Index', None)
|
||||||
source_req.path_info = source_header
|
source_req.path_info = source_header
|
||||||
source_req.headers['X-Newest'] = 'true'
|
source_req.headers['X-Newest'] = 'true'
|
||||||
orig_obj_name = self.object_name
|
orig_obj_name = self.object_name
|
||||||
@ -777,11 +777,11 @@ class ObjectController(Controller):
|
|||||||
container_info = self.container_info(
|
container_info = self.container_info(
|
||||||
self.account_name, self.container_name, req)
|
self.account_name, self.container_name, req)
|
||||||
# pass the policy index to storage nodes via req header
|
# pass the policy index to storage nodes via req header
|
||||||
policy_index = req.headers.get(POLICY_INDEX,
|
policy_index = req.headers.get('X-Backend-Storage-Policy-Index',
|
||||||
container_info['storage_policy'])
|
container_info['storage_policy'])
|
||||||
obj_ring = self.app.get_object_ring(policy_index)
|
obj_ring = self.app.get_object_ring(policy_index)
|
||||||
# pass the policy index to storage nodes via req header
|
# pass the policy index to storage nodes via req header
|
||||||
req.headers[POLICY_INDEX] = policy_index
|
req.headers['X-Backend-Storage-Policy-Index'] = policy_index
|
||||||
container_partition = container_info['partition']
|
container_partition = container_info['partition']
|
||||||
containers = container_info['nodes']
|
containers = container_info['nodes']
|
||||||
req.acl = container_info['write_acl']
|
req.acl = container_info['write_acl']
|
||||||
@ -838,7 +838,8 @@ class ObjectController(Controller):
|
|||||||
policy_idx = container_info['storage_policy']
|
policy_idx = container_info['storage_policy']
|
||||||
obj_ring = self.app.get_object_ring(policy_idx)
|
obj_ring = self.app.get_object_ring(policy_idx)
|
||||||
# pass the policy index to storage nodes via req header
|
# pass the policy index to storage nodes via req header
|
||||||
new_del_req.headers[POLICY_INDEX] = policy_idx
|
new_del_req.headers['X-Backend-Storage-Policy-Index'] = \
|
||||||
|
policy_idx
|
||||||
container_partition = container_info['partition']
|
container_partition = container_info['partition']
|
||||||
containers = container_info['nodes']
|
containers = container_info['nodes']
|
||||||
new_del_req.acl = container_info['write_acl']
|
new_del_req.acl = container_info['write_acl']
|
||||||
|
@ -28,8 +28,6 @@ import uuid
|
|||||||
import eventlet
|
import eventlet
|
||||||
from nose import SkipTest
|
from nose import SkipTest
|
||||||
|
|
||||||
from swift.common.storage_policy import POLICY
|
|
||||||
|
|
||||||
from test.functional import normalized_urls, load_constraint, cluster_info
|
from test.functional import normalized_urls, load_constraint, cluster_info
|
||||||
import test.functional as tf
|
import test.functional as tf
|
||||||
from test.functional.swift_test_client import Account, Connection, File, \
|
from test.functional.swift_test_client import Account, Connection, File, \
|
||||||
@ -2120,13 +2118,13 @@ class TestCrossPolicyObjectVersioningEnv(object):
|
|||||||
|
|
||||||
cls.versions_container = cls.account.container(prefix + "-versions")
|
cls.versions_container = cls.account.container(prefix + "-versions")
|
||||||
if not cls.versions_container.create(
|
if not cls.versions_container.create(
|
||||||
{POLICY: policy['name']}):
|
{'X-Storage-Policy': policy['name']}):
|
||||||
raise ResponseError(cls.conn.response)
|
raise ResponseError(cls.conn.response)
|
||||||
|
|
||||||
cls.container = cls.account.container(prefix + "-objs")
|
cls.container = cls.account.container(prefix + "-objs")
|
||||||
if not cls.container.create(
|
if not cls.container.create(
|
||||||
hdrs={'X-Versions-Location': cls.versions_container.name,
|
hdrs={'X-Versions-Location': cls.versions_container.name,
|
||||||
POLICY: version_policy['name']}):
|
'X-Storage-Policy': version_policy['name']}):
|
||||||
raise ResponseError(cls.conn.response)
|
raise ResponseError(cls.conn.response)
|
||||||
|
|
||||||
container_info = cls.container.info()
|
container_info = cls.container.info()
|
||||||
|
@ -27,7 +27,7 @@ from nose import SkipTest
|
|||||||
from swift.common.manager import Manager
|
from swift.common.manager import Manager
|
||||||
from swift.common.internal_client import InternalClient
|
from swift.common.internal_client import InternalClient
|
||||||
from swift.common import utils, direct_client, ring
|
from swift.common import utils, direct_client, ring
|
||||||
from swift.common.storage_policy import POLICIES, POLICY_INDEX
|
from swift.common.storage_policy import POLICIES
|
||||||
from swift.common.http import HTTP_NOT_FOUND
|
from swift.common.http import HTTP_NOT_FOUND
|
||||||
from test.probe.common import reset_environment, get_to_final_state
|
from test.probe.common import reset_environment, get_to_final_state
|
||||||
|
|
||||||
@ -203,8 +203,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase):
|
|||||||
metadata = direct_client.direct_head_container(
|
metadata = direct_client.direct_head_container(
|
||||||
node, container_part, self.account, self.container_name)
|
node, container_part, self.account, self.container_name)
|
||||||
head_responses.append((node, metadata))
|
head_responses.append((node, metadata))
|
||||||
found_policy_indexes = set(metadata[POLICY_INDEX] for
|
found_policy_indexes = \
|
||||||
node, metadata in head_responses)
|
set(metadata['X-Backend-Storage-Policy-Index'] for
|
||||||
|
node, metadata in head_responses)
|
||||||
self.assert_(len(found_policy_indexes) > 1,
|
self.assert_(len(found_policy_indexes) > 1,
|
||||||
'primary nodes did not disagree about policy index %r' %
|
'primary nodes did not disagree about policy index %r' %
|
||||||
head_responses)
|
head_responses)
|
||||||
@ -218,7 +219,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase):
|
|||||||
try:
|
try:
|
||||||
direct_client.direct_head_object(
|
direct_client.direct_head_object(
|
||||||
node, part, self.account, self.container_name,
|
node, part, self.account, self.container_name,
|
||||||
self.object_name, headers={POLICY_INDEX: policy_index})
|
self.object_name,
|
||||||
|
headers={'X-Backend-Storage-Policy-Index':
|
||||||
|
policy_index})
|
||||||
except direct_client.ClientException as err:
|
except direct_client.ClientException as err:
|
||||||
continue
|
continue
|
||||||
orig_policy_index = policy_index
|
orig_policy_index = policy_index
|
||||||
@ -237,8 +240,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase):
|
|||||||
metadata = direct_client.direct_head_container(
|
metadata = direct_client.direct_head_container(
|
||||||
node, container_part, self.account, self.container_name)
|
node, container_part, self.account, self.container_name)
|
||||||
head_responses.append((node, metadata))
|
head_responses.append((node, metadata))
|
||||||
found_policy_indexes = set(metadata[POLICY_INDEX] for
|
found_policy_indexes = \
|
||||||
node, metadata in head_responses)
|
set(metadata['X-Backend-Storage-Policy-Index'] for
|
||||||
|
node, metadata in head_responses)
|
||||||
self.assert_(len(found_policy_indexes) == 1,
|
self.assert_(len(found_policy_indexes) == 1,
|
||||||
'primary nodes disagree about policy index %r' %
|
'primary nodes disagree about policy index %r' %
|
||||||
head_responses)
|
head_responses)
|
||||||
@ -253,7 +257,7 @@ class TestContainerMergePolicyIndex(unittest.TestCase):
|
|||||||
direct_client.direct_head_object(
|
direct_client.direct_head_object(
|
||||||
node, part, self.account, self.container_name,
|
node, part, self.account, self.container_name,
|
||||||
self.object_name, headers={
|
self.object_name, headers={
|
||||||
POLICY_INDEX: orig_policy_index})
|
'X-Backend-Storage-Policy-Index': orig_policy_index})
|
||||||
except direct_client.ClientException as err:
|
except direct_client.ClientException as err:
|
||||||
if err.http_status == HTTP_NOT_FOUND:
|
if err.http_status == HTTP_NOT_FOUND:
|
||||||
continue
|
continue
|
||||||
@ -299,8 +303,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase):
|
|||||||
metadata = direct_client.direct_head_container(
|
metadata = direct_client.direct_head_container(
|
||||||
node, container_part, self.account, self.container_name)
|
node, container_part, self.account, self.container_name)
|
||||||
head_responses.append((node, metadata))
|
head_responses.append((node, metadata))
|
||||||
found_policy_indexes = set(metadata[POLICY_INDEX] for
|
found_policy_indexes = \
|
||||||
node, metadata in head_responses)
|
set(metadata['X-Backend-Storage-Policy-Index'] for
|
||||||
|
node, metadata in head_responses)
|
||||||
self.assert_(len(found_policy_indexes) > 1,
|
self.assert_(len(found_policy_indexes) > 1,
|
||||||
'primary nodes did not disagree about policy index %r' %
|
'primary nodes did not disagree about policy index %r' %
|
||||||
head_responses)
|
head_responses)
|
||||||
@ -314,7 +319,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase):
|
|||||||
try:
|
try:
|
||||||
direct_client.direct_head_object(
|
direct_client.direct_head_object(
|
||||||
node, part, self.account, self.container_name,
|
node, part, self.account, self.container_name,
|
||||||
self.object_name, headers={POLICY_INDEX: policy_index})
|
self.object_name,
|
||||||
|
headers={'X-Backend-Storage-Policy-Index':
|
||||||
|
policy_index})
|
||||||
except direct_client.ClientException as err:
|
except direct_client.ClientException as err:
|
||||||
if 'x-backend-timestamp' in err.http_headers:
|
if 'x-backend-timestamp' in err.http_headers:
|
||||||
ts_policy_index = policy_index
|
ts_policy_index = policy_index
|
||||||
@ -338,11 +345,13 @@ class TestContainerMergePolicyIndex(unittest.TestCase):
|
|||||||
metadata = direct_client.direct_head_container(
|
metadata = direct_client.direct_head_container(
|
||||||
node, container_part, self.account, self.container_name)
|
node, container_part, self.account, self.container_name)
|
||||||
head_responses.append((node, metadata))
|
head_responses.append((node, metadata))
|
||||||
new_found_policy_indexes = set(metadata[POLICY_INDEX] for node,
|
new_found_policy_indexes = \
|
||||||
metadata in head_responses)
|
set(metadata['X-Backend-Storage-Policy-Index'] for node,
|
||||||
|
metadata in head_responses)
|
||||||
self.assert_(len(new_found_policy_indexes) == 1,
|
self.assert_(len(new_found_policy_indexes) == 1,
|
||||||
'primary nodes disagree about policy index %r' %
|
'primary nodes disagree about policy index %r' %
|
||||||
dict((node['port'], metadata[POLICY_INDEX])
|
dict((node['port'],
|
||||||
|
metadata['X-Backend-Storage-Policy-Index'])
|
||||||
for node, metadata in head_responses))
|
for node, metadata in head_responses))
|
||||||
expected_policy_index = new_found_policy_indexes.pop()
|
expected_policy_index = new_found_policy_indexes.pop()
|
||||||
self.assertEqual(orig_policy_index, expected_policy_index)
|
self.assertEqual(orig_policy_index, expected_policy_index)
|
||||||
@ -355,7 +364,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase):
|
|||||||
try:
|
try:
|
||||||
direct_client.direct_head_object(
|
direct_client.direct_head_object(
|
||||||
node, part, self.account, self.container_name,
|
node, part, self.account, self.container_name,
|
||||||
self.object_name, headers={POLICY_INDEX: policy_index})
|
self.object_name,
|
||||||
|
headers={'X-Backend-Storage-Policy-Index':
|
||||||
|
policy_index})
|
||||||
except direct_client.ClientException as err:
|
except direct_client.ClientException as err:
|
||||||
if err.http_status == HTTP_NOT_FOUND:
|
if err.http_status == HTTP_NOT_FOUND:
|
||||||
continue
|
continue
|
||||||
@ -430,7 +441,7 @@ class TestContainerMergePolicyIndex(unittest.TestCase):
|
|||||||
'x-container-device': ','.join(n['device'] for n in
|
'x-container-device': ','.join(n['device'] for n in
|
||||||
self.container_ring.devs),
|
self.container_ring.devs),
|
||||||
'x-container-partition': container_part,
|
'x-container-partition': container_part,
|
||||||
POLICY_INDEX: wrong_policy.idx,
|
'X-Backend-Storage-Policy-Index': wrong_policy.idx,
|
||||||
'X-Static-Large-Object': 'True',
|
'X-Static-Large-Object': 'True',
|
||||||
}
|
}
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
|
@ -24,7 +24,6 @@ from uuid import uuid4
|
|||||||
from swiftclient import client
|
from swiftclient import client
|
||||||
|
|
||||||
from swift.common import direct_client
|
from swift.common import direct_client
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
from swift.obj.diskfile import get_data_dir
|
from swift.obj.diskfile import get_data_dir
|
||||||
from swift.common.exceptions import ClientException
|
from swift.common.exceptions import ClientException
|
||||||
from test.probe.common import kill_server, kill_servers, reset_environment,\
|
from test.probe.common import kill_server, kill_servers, reset_environment,\
|
||||||
@ -102,7 +101,7 @@ class TestEmptyDevice(TestCase):
|
|||||||
another_onode = self.object_ring.get_more_nodes(opart).next()
|
another_onode = self.object_ring.get_more_nodes(opart).next()
|
||||||
odata = direct_client.direct_get_object(
|
odata = direct_client.direct_get_object(
|
||||||
another_onode, opart, self.account, container, obj,
|
another_onode, opart, self.account, container, obj,
|
||||||
headers={POLICY_INDEX: self.policy.idx})[-1]
|
headers={'X-Backend-Storage-Policy-Index': self.policy.idx})[-1]
|
||||||
if odata != 'VERIFY':
|
if odata != 'VERIFY':
|
||||||
raise Exception('Direct object GET did not return VERIFY, instead '
|
raise Exception('Direct object GET did not return VERIFY, instead '
|
||||||
'it returned: %s' % repr(odata))
|
'it returned: %s' % repr(odata))
|
||||||
@ -134,7 +133,7 @@ class TestEmptyDevice(TestCase):
|
|||||||
try:
|
try:
|
||||||
direct_client.direct_get_object(
|
direct_client.direct_get_object(
|
||||||
onode, opart, self.account, container, obj, headers={
|
onode, opart, self.account, container, obj, headers={
|
||||||
POLICY_INDEX: self.policy.idx})
|
'X-Backend-Storage-Policy-Index': self.policy.idx})
|
||||||
except ClientException as err:
|
except ClientException as err:
|
||||||
exc = err
|
exc = err
|
||||||
self.assertEquals(exc.http_status, 404)
|
self.assertEquals(exc.http_status, 404)
|
||||||
@ -157,7 +156,7 @@ class TestEmptyDevice(TestCase):
|
|||||||
|
|
||||||
odata = direct_client.direct_get_object(
|
odata = direct_client.direct_get_object(
|
||||||
onode, opart, self.account, container, obj, headers={
|
onode, opart, self.account, container, obj, headers={
|
||||||
POLICY_INDEX: self.policy.idx})[-1]
|
'X-Backend-Storage-Policy-Index': self.policy.idx})[-1]
|
||||||
if odata != 'VERIFY':
|
if odata != 'VERIFY':
|
||||||
raise Exception('Direct object GET did not return VERIFY, instead '
|
raise Exception('Direct object GET did not return VERIFY, instead '
|
||||||
'it returned: %s' % repr(odata))
|
'it returned: %s' % repr(odata))
|
||||||
@ -165,7 +164,7 @@ class TestEmptyDevice(TestCase):
|
|||||||
try:
|
try:
|
||||||
direct_client.direct_get_object(
|
direct_client.direct_get_object(
|
||||||
another_onode, opart, self.account, container, obj, headers={
|
another_onode, opart, self.account, container, obj, headers={
|
||||||
POLICY_INDEX: self.policy.idx})
|
'X-Backend-Storage-Policy-Index': self.policy.idx})
|
||||||
except ClientException as err:
|
except ClientException as err:
|
||||||
exc = err
|
exc = err
|
||||||
self.assertEquals(exc.http_status, 404)
|
self.assertEquals(exc.http_status, 404)
|
||||||
|
@ -23,7 +23,6 @@ from uuid import uuid4
|
|||||||
from swiftclient import client
|
from swiftclient import client
|
||||||
|
|
||||||
from swift.common import direct_client
|
from swift.common import direct_client
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
from swift.common.exceptions import ClientException
|
from swift.common.exceptions import ClientException
|
||||||
from swift.common.utils import hash_path, readconf
|
from swift.common.utils import hash_path, readconf
|
||||||
from swift.obj.diskfile import write_metadata, read_metadata, get_data_dir
|
from swift.obj.diskfile import write_metadata, read_metadata, get_data_dir
|
||||||
@ -90,12 +89,12 @@ class TestObjectFailures(TestCase):
|
|||||||
|
|
||||||
odata = direct_client.direct_get_object(
|
odata = direct_client.direct_get_object(
|
||||||
onode, opart, self.account, container, obj, headers={
|
onode, opart, self.account, container, obj, headers={
|
||||||
POLICY_INDEX: self.policy.idx})[-1]
|
'X-Backend-Storage-Policy-Index': self.policy.idx})[-1]
|
||||||
self.assertEquals(odata, 'VERIFY')
|
self.assertEquals(odata, 'VERIFY')
|
||||||
try:
|
try:
|
||||||
direct_client.direct_get_object(
|
direct_client.direct_get_object(
|
||||||
onode, opart, self.account, container, obj, headers={
|
onode, opart, self.account, container, obj, headers={
|
||||||
POLICY_INDEX: self.policy.idx})
|
'X-Backend-Storage-Policy-Index': self.policy.idx})
|
||||||
raise Exception("Did not quarantine object")
|
raise Exception("Did not quarantine object")
|
||||||
except ClientException as err:
|
except ClientException as err:
|
||||||
self.assertEquals(err.http_status, 404)
|
self.assertEquals(err.http_status, 404)
|
||||||
@ -109,7 +108,7 @@ class TestObjectFailures(TestCase):
|
|||||||
metadata = read_metadata(data_file)
|
metadata = read_metadata(data_file)
|
||||||
metadata['ETag'] = 'badetag'
|
metadata['ETag'] = 'badetag'
|
||||||
write_metadata(data_file, metadata)
|
write_metadata(data_file, metadata)
|
||||||
base_headers = {POLICY_INDEX: self.policy.idx}
|
base_headers = {'X-Backend-Storage-Policy-Index': self.policy.idx}
|
||||||
for header, result in [({'Range': 'bytes=0-2'}, 'RAN'),
|
for header, result in [({'Range': 'bytes=0-2'}, 'RAN'),
|
||||||
({'Range': 'bytes=1-11'}, 'ANGE'),
|
({'Range': 'bytes=1-11'}, 'ANGE'),
|
||||||
({'Range': 'bytes=0-11'}, 'RANGE')]:
|
({'Range': 'bytes=0-11'}, 'RANGE')]:
|
||||||
@ -123,7 +122,7 @@ class TestObjectFailures(TestCase):
|
|||||||
try:
|
try:
|
||||||
direct_client.direct_get_object(
|
direct_client.direct_get_object(
|
||||||
onode, opart, self.account, container, obj, headers={
|
onode, opart, self.account, container, obj, headers={
|
||||||
POLICY_INDEX: self.policy.idx})
|
'X-Backend-Storage-Policy-Index': self.policy.idx})
|
||||||
raise Exception("Did not quarantine object")
|
raise Exception("Did not quarantine object")
|
||||||
except ClientException as err:
|
except ClientException as err:
|
||||||
self.assertEquals(err.http_status, 404)
|
self.assertEquals(err.http_status, 404)
|
||||||
@ -140,7 +139,8 @@ class TestObjectFailures(TestCase):
|
|||||||
try:
|
try:
|
||||||
direct_client.direct_get_object(
|
direct_client.direct_get_object(
|
||||||
onode, opart, self.account, container, obj, conn_timeout=1,
|
onode, opart, self.account, container, obj, conn_timeout=1,
|
||||||
response_timeout=1, headers={POLICY_INDEX: self.policy.idx})
|
response_timeout=1, headers={'X-Backend-Storage-Policy-Index':
|
||||||
|
self.policy.idx})
|
||||||
raise Exception("Did not quarantine object")
|
raise Exception("Did not quarantine object")
|
||||||
except ClientException as err:
|
except ClientException as err:
|
||||||
self.assertEquals(err.http_status, 404)
|
self.assertEquals(err.http_status, 404)
|
||||||
@ -157,7 +157,8 @@ class TestObjectFailures(TestCase):
|
|||||||
try:
|
try:
|
||||||
direct_client.direct_head_object(
|
direct_client.direct_head_object(
|
||||||
onode, opart, self.account, container, obj, conn_timeout=1,
|
onode, opart, self.account, container, obj, conn_timeout=1,
|
||||||
response_timeout=1, headers={POLICY_INDEX: self.policy.idx})
|
response_timeout=1, headers={'X-Backend-Storage-Policy-Index':
|
||||||
|
self.policy.idx})
|
||||||
raise Exception("Did not quarantine object")
|
raise Exception("Did not quarantine object")
|
||||||
except ClientException as err:
|
except ClientException as err:
|
||||||
self.assertEquals(err.http_status, 404)
|
self.assertEquals(err.http_status, 404)
|
||||||
@ -173,7 +174,7 @@ class TestObjectFailures(TestCase):
|
|||||||
write_metadata(fpointer, metadata)
|
write_metadata(fpointer, metadata)
|
||||||
try:
|
try:
|
||||||
headers = {'X-Object-Meta-1': 'One', 'X-Object-Meta-Two': 'Two',
|
headers = {'X-Object-Meta-1': 'One', 'X-Object-Meta-Two': 'Two',
|
||||||
POLICY_INDEX: self.policy.idx}
|
'X-Backend-Storage-Policy-Index': self.policy.idx}
|
||||||
direct_client.direct_post_object(
|
direct_client.direct_post_object(
|
||||||
onode, opart, self.account,
|
onode, opart, self.account,
|
||||||
container, obj,
|
container, obj,
|
||||||
|
@ -20,7 +20,6 @@ from uuid import uuid4
|
|||||||
from swiftclient import client
|
from swiftclient import client
|
||||||
|
|
||||||
from swift.common import direct_client
|
from swift.common import direct_client
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
from swift.common.exceptions import ClientException
|
from swift.common.exceptions import ClientException
|
||||||
from swift.common.manager import Manager
|
from swift.common.manager import Manager
|
||||||
from test.probe.common import kill_server, kill_servers, reset_environment, \
|
from test.probe.common import kill_server, kill_servers, reset_environment, \
|
||||||
@ -92,7 +91,7 @@ class TestObjectHandoff(TestCase):
|
|||||||
another_onode = self.object_ring.get_more_nodes(opart).next()
|
another_onode = self.object_ring.get_more_nodes(opart).next()
|
||||||
odata = direct_client.direct_get_object(
|
odata = direct_client.direct_get_object(
|
||||||
another_onode, opart, self.account, container, obj, headers={
|
another_onode, opart, self.account, container, obj, headers={
|
||||||
POLICY_INDEX: self.policy.idx})[-1]
|
'X-Backend-Storage-Policy-Index': self.policy.idx})[-1]
|
||||||
if odata != 'VERIFY':
|
if odata != 'VERIFY':
|
||||||
raise Exception('Direct object GET did not return VERIFY, instead '
|
raise Exception('Direct object GET did not return VERIFY, instead '
|
||||||
'it returned: %s' % repr(odata))
|
'it returned: %s' % repr(odata))
|
||||||
@ -113,7 +112,7 @@ class TestObjectHandoff(TestCase):
|
|||||||
try:
|
try:
|
||||||
direct_client.direct_get_object(
|
direct_client.direct_get_object(
|
||||||
onode, opart, self.account, container, obj, headers={
|
onode, opart, self.account, container, obj, headers={
|
||||||
POLICY_INDEX: self.policy.idx})
|
'X-Backend-Storage-Policy-Index': self.policy.idx})
|
||||||
except ClientException as err:
|
except ClientException as err:
|
||||||
exc = err
|
exc = err
|
||||||
self.assertEquals(exc.http_status, 404)
|
self.assertEquals(exc.http_status, 404)
|
||||||
@ -133,7 +132,7 @@ class TestObjectHandoff(TestCase):
|
|||||||
Manager(['object-replicator']).once(number=another_num)
|
Manager(['object-replicator']).once(number=another_num)
|
||||||
odata = direct_client.direct_get_object(
|
odata = direct_client.direct_get_object(
|
||||||
onode, opart, self.account, container, obj, headers={
|
onode, opart, self.account, container, obj, headers={
|
||||||
POLICY_INDEX: self.policy.idx})[-1]
|
'X-Backend-Storage-Policy-Index': self.policy.idx})[-1]
|
||||||
if odata != 'VERIFY':
|
if odata != 'VERIFY':
|
||||||
raise Exception('Direct object GET did not return VERIFY, instead '
|
raise Exception('Direct object GET did not return VERIFY, instead '
|
||||||
'it returned: %s' % repr(odata))
|
'it returned: %s' % repr(odata))
|
||||||
@ -141,7 +140,7 @@ class TestObjectHandoff(TestCase):
|
|||||||
try:
|
try:
|
||||||
direct_client.direct_get_object(
|
direct_client.direct_get_object(
|
||||||
another_onode, opart, self.account, container, obj, headers={
|
another_onode, opart, self.account, container, obj, headers={
|
||||||
POLICY_INDEX: self.policy.idx})
|
'X-Backend-Storage-Policy-Index': self.policy.idx})
|
||||||
except ClientException as err:
|
except ClientException as err:
|
||||||
exc = err
|
exc = err
|
||||||
self.assertEquals(exc.http_status, 404)
|
self.assertEquals(exc.http_status, 404)
|
||||||
@ -177,7 +176,7 @@ class TestObjectHandoff(TestCase):
|
|||||||
start_server(onode['port'], self.port2server, self.pids)
|
start_server(onode['port'], self.port2server, self.pids)
|
||||||
direct_client.direct_get_object(
|
direct_client.direct_get_object(
|
||||||
onode, opart, self.account, container, obj, headers={
|
onode, opart, self.account, container, obj, headers={
|
||||||
POLICY_INDEX: self.policy.idx})
|
'X-Backend-Storage-Policy-Index': self.policy.idx})
|
||||||
# Run the extra server last so it'll remove its extra partition
|
# Run the extra server last so it'll remove its extra partition
|
||||||
for node in onodes:
|
for node in onodes:
|
||||||
try:
|
try:
|
||||||
@ -192,7 +191,7 @@ class TestObjectHandoff(TestCase):
|
|||||||
try:
|
try:
|
||||||
direct_client.direct_get_object(
|
direct_client.direct_get_object(
|
||||||
another_onode, opart, self.account, container, obj, headers={
|
another_onode, opart, self.account, container, obj, headers={
|
||||||
POLICY_INDEX: self.policy.idx})
|
'X-Backend-Storage-Policy-Index': self.policy.idx})
|
||||||
except ClientException as err:
|
except ClientException as err:
|
||||||
exc = err
|
exc = err
|
||||||
self.assertEquals(exc.http_status, 404)
|
self.assertEquals(exc.http_status, 404)
|
||||||
|
@ -30,7 +30,7 @@ from swift.common.exceptions import ClientException
|
|||||||
from swift.common.utils import normalize_timestamp
|
from swift.common.utils import normalize_timestamp
|
||||||
|
|
||||||
from test import unit
|
from test import unit
|
||||||
from swift.common.storage_policy import StoragePolicy, POLICIES, POLICY_INDEX
|
from swift.common.storage_policy import StoragePolicy, POLICIES
|
||||||
|
|
||||||
|
|
||||||
class FakeLogger(object):
|
class FakeLogger(object):
|
||||||
@ -291,7 +291,7 @@ class TestReaper(unittest.TestCase):
|
|||||||
'X-Container-Host': host,
|
'X-Container-Host': host,
|
||||||
'X-Container-Partition': 'partition',
|
'X-Container-Partition': 'partition',
|
||||||
'X-Container-Device': device,
|
'X-Container-Device': device,
|
||||||
POLICY_INDEX: policy.idx
|
'X-Backend-Storage-Policy-Index': policy.idx
|
||||||
}
|
}
|
||||||
ring = r.get_object_ring(policy.idx)
|
ring = r.get_object_ring(policy.idx)
|
||||||
expected = call(ring.devs[i], 1, 'a', 'c', 'o',
|
expected = call(ring.devs[i], 1, 'a', 'c', 'o',
|
||||||
@ -322,7 +322,7 @@ class TestReaper(unittest.TestCase):
|
|||||||
direct_get_container=DEFAULT,
|
direct_get_container=DEFAULT,
|
||||||
direct_delete_object=DEFAULT,
|
direct_delete_object=DEFAULT,
|
||||||
direct_delete_container=DEFAULT) as mocks:
|
direct_delete_container=DEFAULT) as mocks:
|
||||||
headers = {POLICY_INDEX: policy.idx}
|
headers = {'X-Backend-Storage-Policy-Index': policy.idx}
|
||||||
obj_listing = [{'name': 'o'}]
|
obj_listing = [{'name': 'o'}]
|
||||||
|
|
||||||
def fake_get_container(*args, **kwargs):
|
def fake_get_container(*args, **kwargs):
|
||||||
@ -340,7 +340,8 @@ class TestReaper(unittest.TestCase):
|
|||||||
self.assertEqual(3, len(mock_calls))
|
self.assertEqual(3, len(mock_calls))
|
||||||
for call_args in mock_calls:
|
for call_args in mock_calls:
|
||||||
_args, kwargs = call_args
|
_args, kwargs = call_args
|
||||||
self.assertEqual(kwargs['headers'][POLICY_INDEX],
|
self.assertEqual(kwargs['headers']
|
||||||
|
['X-Backend-Storage-Policy-Index'],
|
||||||
policy.idx)
|
policy.idx)
|
||||||
|
|
||||||
self.assertEquals(mocks['direct_delete_container'].call_count, 3)
|
self.assertEquals(mocks['direct_delete_container'].call_count, 3)
|
||||||
|
@ -34,7 +34,7 @@ from swift.account.server import AccountController
|
|||||||
from swift.common.utils import normalize_timestamp, replication, public
|
from swift.common.utils import normalize_timestamp, replication, public
|
||||||
from swift.common.request_helpers import get_sys_meta_prefix
|
from swift.common.request_helpers import get_sys_meta_prefix
|
||||||
from test.unit import patch_policies
|
from test.unit import patch_policies
|
||||||
from swift.common.storage_policy import StoragePolicy, POLICIES, POLICY_INDEX
|
from swift.common.storage_policy import StoragePolicy, POLICIES
|
||||||
|
|
||||||
|
|
||||||
@patch_policies
|
@patch_policies
|
||||||
@ -1723,7 +1723,7 @@ class TestAccountController(unittest.TestCase):
|
|||||||
'X-Delete-Timestamp': '0',
|
'X-Delete-Timestamp': '0',
|
||||||
'X-Object-Count': '2',
|
'X-Object-Count': '2',
|
||||||
'X-Bytes-Used': '4',
|
'X-Bytes-Used': '4',
|
||||||
POLICY_INDEX: policy.idx,
|
'X-Backend-Storage-Policy-Index': policy.idx,
|
||||||
})
|
})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 201)
|
self.assertEqual(resp.status_int, 201)
|
||||||
@ -1780,7 +1780,7 @@ class TestAccountController(unittest.TestCase):
|
|||||||
'X-Delete-Timestamp': '0',
|
'X-Delete-Timestamp': '0',
|
||||||
'X-Object-Count': '2',
|
'X-Object-Count': '2',
|
||||||
'X-Bytes-Used': '4',
|
'X-Bytes-Used': '4',
|
||||||
POLICY_INDEX: policy.idx,
|
'X-Backend-Storage-Policy-Index': policy.idx,
|
||||||
})
|
})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 201)
|
self.assertEqual(resp.status_int, 201)
|
||||||
@ -1812,7 +1812,7 @@ class TestAccountController(unittest.TestCase):
|
|||||||
'X-Delete-Timestamp': '0',
|
'X-Delete-Timestamp': '0',
|
||||||
'X-Object-Count': count,
|
'X-Object-Count': count,
|
||||||
'X-Bytes-Used': count,
|
'X-Bytes-Used': count,
|
||||||
POLICY_INDEX: policy.idx,
|
'X-Backend-Storage-Policy-Index': policy.idx,
|
||||||
})
|
})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 201)
|
self.assertEqual(resp.status_int, 201)
|
||||||
|
@ -27,7 +27,7 @@ from swift.common import direct_client
|
|||||||
from swift.common.exceptions import ClientException
|
from swift.common.exceptions import ClientException
|
||||||
from swift.common.utils import json, Timestamp
|
from swift.common.utils import json, Timestamp
|
||||||
from swift.common.swob import HeaderKeyDict, RESPONSE_REASONS
|
from swift.common.swob import HeaderKeyDict, RESPONSE_REASONS
|
||||||
from swift.common.storage_policy import POLICY_INDEX, POLICIES
|
from swift.common.storage_policy import POLICIES
|
||||||
|
|
||||||
from test.unit import patch_policies
|
from test.unit import patch_policies
|
||||||
|
|
||||||
@ -134,9 +134,11 @@ class TestDirectClient(unittest.TestCase):
|
|||||||
for add_ts in (True, False):
|
for add_ts in (True, False):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
headers = direct_client.gen_headers(
|
headers = direct_client.gen_headers(
|
||||||
{POLICY_INDEX: policy.idx}, add_ts=add_ts)
|
{'X-Backend-Storage-Policy-Index': policy.idx},
|
||||||
|
add_ts=add_ts)
|
||||||
self.assertEqual(headers['user-agent'], stub_user_agent)
|
self.assertEqual(headers['user-agent'], stub_user_agent)
|
||||||
self.assertEqual(headers[POLICY_INDEX], str(policy.idx))
|
self.assertEqual(headers['X-Backend-Storage-Policy-Index'],
|
||||||
|
str(policy.idx))
|
||||||
expected_header_count = 2
|
expected_header_count = 2
|
||||||
if add_ts:
|
if add_ts:
|
||||||
expected_header_count += 1
|
expected_header_count += 1
|
||||||
|
@ -38,8 +38,7 @@ from swift.common import constraints
|
|||||||
from swift.common.utils import (Timestamp, mkdirs, public, replication,
|
from swift.common.utils import (Timestamp, mkdirs, public, replication,
|
||||||
lock_parent_directory, json)
|
lock_parent_directory, json)
|
||||||
from test.unit import fake_http_connect
|
from test.unit import fake_http_connect
|
||||||
from swift.common.storage_policy import (POLICY_INDEX, POLICIES,
|
from swift.common.storage_policy import (POLICIES, StoragePolicy)
|
||||||
StoragePolicy)
|
|
||||||
from swift.common.request_helpers import get_sys_meta_prefix
|
from swift.common.request_helpers import get_sys_meta_prefix
|
||||||
|
|
||||||
from test.unit import patch_policies
|
from test.unit import patch_policies
|
||||||
@ -87,7 +86,8 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank(req.path, method='HEAD')
|
req = Request.blank(req.path, method='HEAD')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(204, resp.status_int)
|
self.assertEqual(204, resp.status_int)
|
||||||
self.assertEqual(str(policy_index), resp.headers[POLICY_INDEX])
|
self.assertEqual(str(policy_index),
|
||||||
|
resp.headers['X-Backend-Storage-Policy-Index'])
|
||||||
|
|
||||||
def test_get_and_validate_policy_index(self):
|
def test_get_and_validate_policy_index(self):
|
||||||
# no policy is OK
|
# no policy is OK
|
||||||
@ -100,7 +100,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c_%s' % policy, method='PUT',
|
req = Request.blank('/sda1/p/a/c_%s' % policy, method='PUT',
|
||||||
headers={
|
headers={
|
||||||
'X-Timestamp': '0',
|
'X-Timestamp': '0',
|
||||||
POLICY_INDEX: policy
|
'X-Backend-Storage-Policy-Index': policy
|
||||||
})
|
})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(400, resp.status_int)
|
self.assertEqual(400, resp.status_int)
|
||||||
@ -111,7 +111,8 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c_%s' % policy.name, method='PUT',
|
req = Request.blank('/sda1/p/a/c_%s' % policy.name, method='PUT',
|
||||||
headers={
|
headers={
|
||||||
'X-Timestamp': '0',
|
'X-Timestamp': '0',
|
||||||
POLICY_INDEX: policy.idx,
|
'X-Backend-Storage-Policy-Index':
|
||||||
|
policy.idx,
|
||||||
})
|
})
|
||||||
self._check_put_container_storage_policy(req, policy.idx)
|
self._check_put_container_storage_policy(req, policy.idx)
|
||||||
|
|
||||||
@ -204,7 +205,8 @@ class TestContainerController(unittest.TestCase):
|
|||||||
Timestamp(start).normal)
|
Timestamp(start).normal)
|
||||||
|
|
||||||
# backend headers
|
# backend headers
|
||||||
self.assertEqual(int(response.headers[POLICY_INDEX]),
|
self.assertEqual(int(response.headers
|
||||||
|
['X-Backend-Storage-Policy-Index']),
|
||||||
int(POLICIES.default))
|
int(POLICIES.default))
|
||||||
self.assert_(
|
self.assert_(
|
||||||
Timestamp(response.headers['x-backend-timestamp']) >= start)
|
Timestamp(response.headers['x-backend-timestamp']) >= start)
|
||||||
@ -219,7 +221,8 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 404)
|
self.assertEqual(resp.status_int, 404)
|
||||||
self.assertEqual(int(resp.headers[POLICY_INDEX]), 0)
|
self.assertEqual(int(resp.headers['X-Backend-Storage-Policy-Index']),
|
||||||
|
0)
|
||||||
self.assertEqual(resp.headers['x-backend-timestamp'],
|
self.assertEqual(resp.headers['x-backend-timestamp'],
|
||||||
Timestamp(0).internal)
|
Timestamp(0).internal)
|
||||||
self.assertEqual(resp.headers['x-backend-put-timestamp'],
|
self.assertEqual(resp.headers['x-backend-put-timestamp'],
|
||||||
@ -252,7 +255,8 @@ class TestContainerController(unittest.TestCase):
|
|||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 404)
|
self.assertEqual(resp.status_int, 404)
|
||||||
# backend headers
|
# backend headers
|
||||||
self.assertEqual(int(resp.headers[POLICY_INDEX]),
|
self.assertEqual(int(resp.headers[
|
||||||
|
'X-Backend-Storage-Policy-Index']),
|
||||||
int(POLICIES.default))
|
int(POLICIES.default))
|
||||||
self.assert_(Timestamp(resp.headers['x-backend-timestamp']) >=
|
self.assert_(Timestamp(resp.headers['x-backend-timestamp']) >=
|
||||||
Timestamp(request_method_times['PUT']))
|
Timestamp(request_method_times['PUT']))
|
||||||
@ -363,14 +367,16 @@ class TestContainerController(unittest.TestCase):
|
|||||||
# Set metadata header
|
# Set metadata header
|
||||||
req = Request.blank('/sda1/p/a/c', method='PUT',
|
req = Request.blank('/sda1/p/a/c', method='PUT',
|
||||||
headers={'X-Timestamp': Timestamp(1).internal,
|
headers={'X-Timestamp': Timestamp(1).internal,
|
||||||
POLICY_INDEX: policy.idx})
|
'X-Backend-Storage-Policy-Index':
|
||||||
|
policy.idx})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.status_int, 201)
|
self.assertEquals(resp.status_int, 201)
|
||||||
|
|
||||||
# now make sure we read it back
|
# now make sure we read it back
|
||||||
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.headers.get(POLICY_INDEX), str(policy.idx))
|
self.assertEquals(resp.headers.get('X-Backend-Storage-Policy-Index'),
|
||||||
|
str(policy.idx))
|
||||||
|
|
||||||
def test_PUT_no_policy_specified(self):
|
def test_PUT_no_policy_specified(self):
|
||||||
# Set metadata header
|
# Set metadata header
|
||||||
@ -382,14 +388,14 @@ class TestContainerController(unittest.TestCase):
|
|||||||
# now make sure the default was used (pol 1)
|
# now make sure the default was used (pol 1)
|
||||||
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.headers.get(POLICY_INDEX),
|
self.assertEquals(resp.headers.get('X-Backend-Storage-Policy-Index'),
|
||||||
str(POLICIES.default.idx))
|
str(POLICIES.default.idx))
|
||||||
|
|
||||||
def test_PUT_bad_policy_specified(self):
|
def test_PUT_bad_policy_specified(self):
|
||||||
# Set metadata header
|
# Set metadata header
|
||||||
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'PUT'},
|
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'PUT'},
|
||||||
headers={'X-Timestamp': Timestamp(1).internal,
|
headers={'X-Timestamp': Timestamp(1).internal,
|
||||||
POLICY_INDEX: 'nada'})
|
'X-Backend-Storage-Policy-Index': 'nada'})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
# make sure we get bad response
|
# make sure we get bad response
|
||||||
self.assertEquals(resp.status_int, 400)
|
self.assertEquals(resp.status_int, 400)
|
||||||
@ -400,20 +406,21 @@ class TestContainerController(unittest.TestCase):
|
|||||||
# Set metadata header
|
# Set metadata header
|
||||||
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
||||||
'X-Timestamp': ts.next(),
|
'X-Timestamp': ts.next(),
|
||||||
POLICY_INDEX: policy.idx})
|
'X-Backend-Storage-Policy-Index': policy.idx})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.status_int, 201)
|
self.assertEquals(resp.status_int, 201)
|
||||||
req = Request.blank('/sda1/p/a/c')
|
req = Request.blank('/sda1/p/a/c')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.status_int, 204)
|
self.assertEquals(resp.status_int, 204)
|
||||||
# make sure we get the right index back
|
# make sure we get the right index back
|
||||||
self.assertEquals(resp.headers.get(POLICY_INDEX), str(policy.idx))
|
self.assertEquals(resp.headers.get('X-Backend-Storage-Policy-Index'),
|
||||||
|
str(policy.idx))
|
||||||
|
|
||||||
# now try to update w/o changing the policy
|
# now try to update w/o changing the policy
|
||||||
for method in ('POST', 'PUT'):
|
for method in ('POST', 'PUT'):
|
||||||
req = Request.blank('/sda1/p/a/c', method=method, headers={
|
req = Request.blank('/sda1/p/a/c', method=method, headers={
|
||||||
'X-Timestamp': ts.next(),
|
'X-Timestamp': ts.next(),
|
||||||
POLICY_INDEX: policy.idx
|
'X-Backend-Storage-Policy-Index': policy.idx
|
||||||
})
|
})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.status_int // 100, 2)
|
self.assertEquals(resp.status_int // 100, 2)
|
||||||
@ -421,7 +428,8 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.status_int, 204)
|
self.assertEquals(resp.status_int, 204)
|
||||||
self.assertEquals(resp.headers.get(POLICY_INDEX), str(policy.idx))
|
self.assertEquals(resp.headers.get('X-Backend-Storage-Policy-Index'),
|
||||||
|
str(policy.idx))
|
||||||
|
|
||||||
def test_PUT_bad_policy_change(self):
|
def test_PUT_bad_policy_change(self):
|
||||||
ts = (Timestamp(t).internal for t in itertools.count(time.time()))
|
ts = (Timestamp(t).internal for t in itertools.count(time.time()))
|
||||||
@ -429,21 +437,22 @@ class TestContainerController(unittest.TestCase):
|
|||||||
# Set metadata header
|
# Set metadata header
|
||||||
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
||||||
'X-Timestamp': ts.next(),
|
'X-Timestamp': ts.next(),
|
||||||
POLICY_INDEX: policy.idx})
|
'X-Backend-Storage-Policy-Index': policy.idx})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.status_int, 201)
|
self.assertEquals(resp.status_int, 201)
|
||||||
req = Request.blank('/sda1/p/a/c')
|
req = Request.blank('/sda1/p/a/c')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.status_int, 204)
|
self.assertEquals(resp.status_int, 204)
|
||||||
# make sure we get the right index back
|
# make sure we get the right index back
|
||||||
self.assertEquals(resp.headers.get(POLICY_INDEX), str(policy.idx))
|
self.assertEquals(resp.headers.get('X-Backend-Storage-Policy-Index'),
|
||||||
|
str(policy.idx))
|
||||||
|
|
||||||
other_policies = [p for p in POLICIES if p != policy]
|
other_policies = [p for p in POLICIES if p != policy]
|
||||||
for other_policy in other_policies:
|
for other_policy in other_policies:
|
||||||
# now try to change it and make sure we get a conflict
|
# now try to change it and make sure we get a conflict
|
||||||
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
||||||
'X-Timestamp': ts.next(),
|
'X-Timestamp': ts.next(),
|
||||||
POLICY_INDEX: other_policy.idx
|
'X-Backend-Storage-Policy-Index': other_policy.idx
|
||||||
})
|
})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.status_int, 409)
|
self.assertEquals(resp.status_int, 409)
|
||||||
@ -453,28 +462,30 @@ class TestContainerController(unittest.TestCase):
|
|||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.status_int, 204)
|
self.assertEquals(resp.status_int, 204)
|
||||||
# make sure we get the right index back
|
# make sure we get the right index back
|
||||||
self.assertEquals(resp.headers.get(POLICY_INDEX), str(policy.idx))
|
self.assertEquals(resp.headers.get('X-Backend-Storage-Policy-Index'),
|
||||||
|
str(policy.idx))
|
||||||
|
|
||||||
def test_POST_ignores_policy_change(self):
|
def test_POST_ignores_policy_change(self):
|
||||||
ts = (Timestamp(t).internal for t in itertools.count(time.time()))
|
ts = (Timestamp(t).internal for t in itertools.count(time.time()))
|
||||||
policy = random.choice(list(POLICIES))
|
policy = random.choice(list(POLICIES))
|
||||||
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
||||||
'X-Timestamp': ts.next(),
|
'X-Timestamp': ts.next(),
|
||||||
POLICY_INDEX: policy.idx})
|
'X-Backend-Storage-Policy-Index': policy.idx})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.status_int, 201)
|
self.assertEquals(resp.status_int, 201)
|
||||||
req = Request.blank('/sda1/p/a/c')
|
req = Request.blank('/sda1/p/a/c')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.status_int, 204)
|
self.assertEquals(resp.status_int, 204)
|
||||||
# make sure we get the right index back
|
# make sure we get the right index back
|
||||||
self.assertEquals(resp.headers.get(POLICY_INDEX), str(policy.idx))
|
self.assertEquals(resp.headers.get('X-Backend-Storage-Policy-Index'),
|
||||||
|
str(policy.idx))
|
||||||
|
|
||||||
other_policies = [p for p in POLICIES if p != policy]
|
other_policies = [p for p in POLICIES if p != policy]
|
||||||
for other_policy in other_policies:
|
for other_policy in other_policies:
|
||||||
# now try to change it and make sure we get a conflict
|
# now try to change it and make sure we get a conflict
|
||||||
req = Request.blank('/sda1/p/a/c', method='POST', headers={
|
req = Request.blank('/sda1/p/a/c', method='POST', headers={
|
||||||
'X-Timestamp': ts.next(),
|
'X-Timestamp': ts.next(),
|
||||||
POLICY_INDEX: other_policy.idx
|
'X-Backend-Storage-Policy-Index': other_policy.idx
|
||||||
})
|
})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
# valid request
|
# valid request
|
||||||
@ -485,7 +496,9 @@ class TestContainerController(unittest.TestCase):
|
|||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEquals(resp.status_int, 204)
|
self.assertEquals(resp.status_int, 204)
|
||||||
# make sure we get the right index back
|
# make sure we get the right index back
|
||||||
self.assertEquals(resp.headers.get(POLICY_INDEX), str(policy.idx))
|
self.assertEquals(resp.headers.get
|
||||||
|
('X-Backend-Storage-Policy-Index'),
|
||||||
|
str(policy.idx))
|
||||||
|
|
||||||
def test_PUT_no_policy_for_existing_default(self):
|
def test_PUT_no_policy_for_existing_default(self):
|
||||||
ts = (Timestamp(t).internal for t in
|
ts = (Timestamp(t).internal for t in
|
||||||
@ -501,7 +514,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 204)
|
self.assertEqual(resp.status_int, 204)
|
||||||
self.assertEqual(resp.headers[POLICY_INDEX],
|
self.assertEqual(resp.headers['X-Backend-Storage-Policy-Index'],
|
||||||
str(POLICIES.default.idx))
|
str(POLICIES.default.idx))
|
||||||
|
|
||||||
# put again without specifying the storage policy
|
# put again without specifying the storage policy
|
||||||
@ -515,7 +528,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 204)
|
self.assertEqual(resp.status_int, 204)
|
||||||
self.assertEqual(resp.headers[POLICY_INDEX],
|
self.assertEqual(resp.headers['X-Backend-Storage-Policy-Index'],
|
||||||
str(POLICIES.default.idx))
|
str(POLICIES.default.idx))
|
||||||
|
|
||||||
def test_PUT_proxy_default_no_policy_for_existing_default(self):
|
def test_PUT_proxy_default_no_policy_for_existing_default(self):
|
||||||
@ -537,7 +550,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 204)
|
self.assertEqual(resp.status_int, 204)
|
||||||
self.assertEqual(int(resp.headers[POLICY_INDEX]),
|
self.assertEqual(int(resp.headers['X-Backend-Storage-Policy-Index']),
|
||||||
int(proxy_default))
|
int(proxy_default))
|
||||||
|
|
||||||
# put again without proxy specifying the different default
|
# put again without proxy specifying the different default
|
||||||
@ -552,7 +565,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 204)
|
self.assertEqual(resp.status_int, 204)
|
||||||
self.assertEqual(int(resp.headers[POLICY_INDEX]),
|
self.assertEqual(int(resp.headers['X-Backend-Storage-Policy-Index']),
|
||||||
int(proxy_default))
|
int(proxy_default))
|
||||||
|
|
||||||
def test_PUT_no_policy_for_existing_non_default(self):
|
def test_PUT_no_policy_for_existing_non_default(self):
|
||||||
@ -561,7 +574,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
# create a container with the non-default storage policy
|
# create a container with the non-default storage policy
|
||||||
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
||||||
'X-Timestamp': ts.next(),
|
'X-Timestamp': ts.next(),
|
||||||
POLICY_INDEX: non_default_policy.idx,
|
'X-Backend-Storage-Policy-Index': non_default_policy.idx,
|
||||||
})
|
})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 201) # sanity check
|
self.assertEqual(resp.status_int, 201) # sanity check
|
||||||
@ -570,7 +583,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 204)
|
self.assertEqual(resp.status_int, 204)
|
||||||
self.assertEqual(resp.headers[POLICY_INDEX],
|
self.assertEqual(resp.headers['X-Backend-Storage-Policy-Index'],
|
||||||
str(non_default_policy.idx))
|
str(non_default_policy.idx))
|
||||||
|
|
||||||
# put again without specifiying the storage policy
|
# put again without specifiying the storage policy
|
||||||
@ -584,7 +597,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 204)
|
self.assertEqual(resp.status_int, 204)
|
||||||
self.assertEqual(resp.headers[POLICY_INDEX],
|
self.assertEqual(resp.headers['X-Backend-Storage-Policy-Index'],
|
||||||
str(non_default_policy.idx))
|
str(non_default_policy.idx))
|
||||||
|
|
||||||
def test_PUT_GET_metadata(self):
|
def test_PUT_GET_metadata(self):
|
||||||
@ -1244,7 +1257,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank(
|
req = Request.blank(
|
||||||
'/sda1/p/a/c', method='PUT',
|
'/sda1/p/a/c', method='PUT',
|
||||||
headers={'X-Timestamp': ts.next(),
|
headers={'X-Timestamp': ts.next(),
|
||||||
POLICY_INDEX: policy.idx})
|
'X-Backend-Storage-Policy-Index': policy.idx})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 201) # sanity check
|
self.assertEqual(resp.status_int, 201) # sanity check
|
||||||
|
|
||||||
@ -1261,14 +1274,14 @@ class TestContainerController(unittest.TestCase):
|
|||||||
# state, so changing the policy index is perfectly acceptable
|
# state, so changing the policy index is perfectly acceptable
|
||||||
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
||||||
'X-Timestamp': ts.next(),
|
'X-Timestamp': ts.next(),
|
||||||
POLICY_INDEX: other_policy.idx})
|
'X-Backend-Storage-Policy-Index': other_policy.idx})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 201) # sanity check
|
self.assertEqual(resp.status_int, 201) # sanity check
|
||||||
|
|
||||||
req = Request.blank(
|
req = Request.blank(
|
||||||
'/sda1/p/a/c', method='HEAD')
|
'/sda1/p/a/c', method='HEAD')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.headers[POLICY_INDEX],
|
self.assertEqual(resp.headers['X-Backend-Storage-Policy-Index'],
|
||||||
str(other_policy.idx))
|
str(other_policy.idx))
|
||||||
|
|
||||||
def test_change_to_default_storage_policy_via_DELETE_then_PUT(self):
|
def test_change_to_default_storage_policy_via_DELETE_then_PUT(self):
|
||||||
@ -1278,7 +1291,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
if not p.is_default])
|
if not p.is_default])
|
||||||
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
req = Request.blank('/sda1/p/a/c', method='PUT', headers={
|
||||||
'X-Timestamp': ts.next(),
|
'X-Timestamp': ts.next(),
|
||||||
POLICY_INDEX: non_default_policy.idx,
|
'X-Backend-Storage-Policy-Index': non_default_policy.idx,
|
||||||
})
|
})
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 201) # sanity check
|
self.assertEqual(resp.status_int, 201) # sanity check
|
||||||
@ -1299,7 +1312,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
|
|
||||||
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.headers[POLICY_INDEX],
|
self.assertEqual(resp.headers['X-Backend-Storage-Policy-Index'],
|
||||||
str(POLICIES.default.idx))
|
str(POLICIES.default.idx))
|
||||||
|
|
||||||
def test_DELETE_object(self):
|
def test_DELETE_object(self):
|
||||||
@ -1347,7 +1360,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
req = Request.blank('/sda1/p/a/c', method='HEAD')
|
||||||
resp = req.get_response(self.controller)
|
resp = req.get_response(self.controller)
|
||||||
self.assertEqual(resp.status_int, 204)
|
self.assertEqual(resp.status_int, 204)
|
||||||
self.assertEqual(int(resp.headers[POLICY_INDEX]),
|
self.assertEqual(int(resp.headers['X-Backend-Storage-Policy-Index']),
|
||||||
int(POLICIES.default))
|
int(POLICIES.default))
|
||||||
# create object
|
# create object
|
||||||
obj_timestamp = ts.next()
|
obj_timestamp = ts.next()
|
||||||
@ -2381,7 +2394,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
'x-delete-timestamp': '0',
|
'x-delete-timestamp': '0',
|
||||||
'x-object-count': 0,
|
'x-object-count': 0,
|
||||||
'x-put-timestamp': Timestamp(12345).internal,
|
'x-put-timestamp': Timestamp(12345).internal,
|
||||||
POLICY_INDEX: '%s' % POLICIES.default.idx,
|
'X-Backend-Storage-Policy-Index': '%s' % POLICIES.default.idx,
|
||||||
'referer': 'PUT http://localhost/sda1/p/a/c',
|
'referer': 'PUT http://localhost/sda1/p/a/c',
|
||||||
'user-agent': 'container-server %d' % os.getpid(),
|
'user-agent': 'container-server %d' % os.getpid(),
|
||||||
'x-trans-id': '-'})})
|
'x-trans-id': '-'})})
|
||||||
@ -2399,7 +2412,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
'x-delete-timestamp': '0',
|
'x-delete-timestamp': '0',
|
||||||
'x-object-count': 0,
|
'x-object-count': 0,
|
||||||
'x-put-timestamp': Timestamp(12345).internal,
|
'x-put-timestamp': Timestamp(12345).internal,
|
||||||
POLICY_INDEX: '%s' % POLICIES.default.idx,
|
'X-Backend-Storage-Policy-Index': '%s' % POLICIES.default.idx,
|
||||||
'referer': 'PUT http://localhost/sda1/p/a/c',
|
'referer': 'PUT http://localhost/sda1/p/a/c',
|
||||||
'user-agent': 'container-server %d' % os.getpid(),
|
'user-agent': 'container-server %d' % os.getpid(),
|
||||||
'x-trans-id': '-'})})
|
'x-trans-id': '-'})})
|
||||||
@ -2551,10 +2564,11 @@ class TestNonLegacyDefaultStoragePolicy(TestContainerController):
|
|||||||
|
|
||||||
def _update_object_put_headers(self, req):
|
def _update_object_put_headers(self, req):
|
||||||
"""
|
"""
|
||||||
Add policy index headers for containers created with default POLICY
|
Add policy index headers for containers created with default policy
|
||||||
- which in this TestCase is 1.
|
- which in this TestCase is 1.
|
||||||
"""
|
"""
|
||||||
req.headers[POLICY_INDEX] = str(POLICIES.default.idx)
|
req.headers['X-Backend-Storage-Policy-Index'] = \
|
||||||
|
str(POLICIES.default.idx)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -23,7 +23,7 @@ from test.unit import FakeLogger
|
|||||||
from swift.container import sync
|
from swift.container import sync
|
||||||
from swift.common import utils
|
from swift.common import utils
|
||||||
from swift.common.exceptions import ClientException
|
from swift.common.exceptions import ClientException
|
||||||
from swift.common.storage_policy import StoragePolicy, POLICY_INDEX
|
from swift.common.storage_policy import StoragePolicy
|
||||||
from test.unit import patch_policies
|
from test.unit import patch_policies
|
||||||
|
|
||||||
utils.HASH_PATH_SUFFIX = 'endcap'
|
utils.HASH_PATH_SUFFIX = 'endcap'
|
||||||
@ -789,7 +789,8 @@ class TestContainerSync(unittest.TestCase):
|
|||||||
|
|
||||||
def fake_direct_get_object(node, part, account, container, obj,
|
def fake_direct_get_object(node, part, account, container, obj,
|
||||||
headers, resp_chunk_size=1):
|
headers, resp_chunk_size=1):
|
||||||
self.assertEquals(headers[POLICY_INDEX], '0')
|
self.assertEquals(headers['X-Backend-Storage-Policy-Index'],
|
||||||
|
'0')
|
||||||
return ({'other-header': 'other header value',
|
return ({'other-header': 'other header value',
|
||||||
'etag': '"etagvalue"', 'x-timestamp': '1.2',
|
'etag': '"etagvalue"', 'x-timestamp': '1.2',
|
||||||
'content-type': 'text/plain; swift_bytes=123'},
|
'content-type': 'text/plain; swift_bytes=123'},
|
||||||
@ -807,7 +808,8 @@ class TestContainerSync(unittest.TestCase):
|
|||||||
|
|
||||||
def fake_direct_get_object(node, part, account, container, obj,
|
def fake_direct_get_object(node, part, account, container, obj,
|
||||||
headers, resp_chunk_size=1):
|
headers, resp_chunk_size=1):
|
||||||
self.assertEquals(headers[POLICY_INDEX], '0')
|
self.assertEquals(headers['X-Backend-Storage-Policy-Index'],
|
||||||
|
'0')
|
||||||
return ({'date': 'date value',
|
return ({'date': 'date value',
|
||||||
'last-modified': 'last modified value',
|
'last-modified': 'last modified value',
|
||||||
'x-timestamp': '1.2',
|
'x-timestamp': '1.2',
|
||||||
@ -833,7 +835,8 @@ class TestContainerSync(unittest.TestCase):
|
|||||||
|
|
||||||
def fake_direct_get_object(node, part, account, container, obj,
|
def fake_direct_get_object(node, part, account, container, obj,
|
||||||
headers, resp_chunk_size=1):
|
headers, resp_chunk_size=1):
|
||||||
self.assertEquals(headers[POLICY_INDEX], '0')
|
self.assertEquals(headers['X-Backend-Storage-Policy-Index'],
|
||||||
|
'0')
|
||||||
exc.append(Exception('test exception'))
|
exc.append(Exception('test exception'))
|
||||||
raise exc[-1]
|
raise exc[-1]
|
||||||
|
|
||||||
@ -854,7 +857,8 @@ class TestContainerSync(unittest.TestCase):
|
|||||||
|
|
||||||
def fake_direct_get_object(node, part, account, container, obj,
|
def fake_direct_get_object(node, part, account, container, obj,
|
||||||
headers, resp_chunk_size=1):
|
headers, resp_chunk_size=1):
|
||||||
self.assertEquals(headers[POLICY_INDEX], '0')
|
self.assertEquals(headers['X-Backend-Storage-Policy-Index'],
|
||||||
|
'0')
|
||||||
if len(exc) == 0:
|
if len(exc) == 0:
|
||||||
exc.append(Exception('test other exception'))
|
exc.append(Exception('test other exception'))
|
||||||
else:
|
else:
|
||||||
@ -878,7 +882,8 @@ class TestContainerSync(unittest.TestCase):
|
|||||||
|
|
||||||
def fake_direct_get_object(node, part, account, container, obj,
|
def fake_direct_get_object(node, part, account, container, obj,
|
||||||
headers, resp_chunk_size=1):
|
headers, resp_chunk_size=1):
|
||||||
self.assertEquals(headers[POLICY_INDEX], '0')
|
self.assertEquals(headers['X-Backend-Storage-Policy-Index'],
|
||||||
|
'0')
|
||||||
return ({'other-header': 'other header value',
|
return ({'other-header': 'other header value',
|
||||||
'x-timestamp': '1.2', 'etag': '"etagvalue"'},
|
'x-timestamp': '1.2', 'etag': '"etagvalue"'},
|
||||||
iter('contents'))
|
iter('contents'))
|
||||||
|
@ -31,7 +31,7 @@ from swift.common import utils
|
|||||||
from swift.common.utils import hash_path, mkdirs, normalize_timestamp
|
from swift.common.utils import hash_path, mkdirs, normalize_timestamp
|
||||||
from swift.common import ring
|
from swift.common import ring
|
||||||
from swift.obj import diskfile, replicator as object_replicator
|
from swift.obj import diskfile, replicator as object_replicator
|
||||||
from swift.common.storage_policy import StoragePolicy, POLICY_INDEX, POLICIES
|
from swift.common.storage_policy import StoragePolicy, POLICIES
|
||||||
|
|
||||||
|
|
||||||
def _ips():
|
def _ips():
|
||||||
@ -706,7 +706,7 @@ class TestObjectReplicator(unittest.TestCase):
|
|||||||
for job in jobs:
|
for job in jobs:
|
||||||
set_default(self)
|
set_default(self)
|
||||||
ring = self.replicator.get_object_ring(job['policy_idx'])
|
ring = self.replicator.get_object_ring(job['policy_idx'])
|
||||||
self.headers[POLICY_INDEX] = job['policy_idx']
|
self.headers['X-Backend-Storage-Policy-Index'] = job['policy_idx']
|
||||||
self.replicator.update(job)
|
self.replicator.update(job)
|
||||||
self.assertTrue(error in mock_logger.error.call_args[0][0])
|
self.assertTrue(error in mock_logger.error.call_args[0][0])
|
||||||
self.assertTrue(expect in mock_logger.exception.call_args[0][0])
|
self.assertTrue(expect in mock_logger.exception.call_args[0][0])
|
||||||
@ -792,7 +792,7 @@ class TestObjectReplicator(unittest.TestCase):
|
|||||||
set_default(self)
|
set_default(self)
|
||||||
# with only one set of headers make sure we speicy index 0 here
|
# with only one set of headers make sure we speicy index 0 here
|
||||||
# as otherwise it may be different from earlier tests
|
# as otherwise it may be different from earlier tests
|
||||||
self.headers[POLICY_INDEX] = 0
|
self.headers['X-Backend-Storage-Policy-Index'] = 0
|
||||||
self.replicator.update(repl_job)
|
self.replicator.update(repl_job)
|
||||||
reqs = []
|
reqs = []
|
||||||
for node in repl_job['nodes']:
|
for node in repl_job['nodes']:
|
||||||
|
@ -44,7 +44,7 @@ from swift.common.utils import hash_path, mkdirs, normalize_timestamp, \
|
|||||||
NullLogger, storage_directory, public, replication
|
NullLogger, storage_directory, public, replication
|
||||||
from swift.common import constraints
|
from swift.common import constraints
|
||||||
from swift.common.swob import Request, HeaderKeyDict
|
from swift.common.swob import Request, HeaderKeyDict
|
||||||
from swift.common.storage_policy import POLICY_INDEX, POLICIES
|
from swift.common.storage_policy import POLICIES
|
||||||
from swift.common.exceptions import DiskFileDeviceUnavailable
|
from swift.common.exceptions import DiskFileDeviceUnavailable
|
||||||
|
|
||||||
|
|
||||||
@ -2311,7 +2311,8 @@ class TestObjectController(unittest.TestCase):
|
|||||||
self.object_controller.async_update(
|
self.object_controller.async_update(
|
||||||
'PUT', 'a', 'c', 'o', '127.0.0.1:1234', 1, 'sdc1',
|
'PUT', 'a', 'c', 'o', '127.0.0.1:1234', 1, 'sdc1',
|
||||||
{'x-timestamp': '1', 'x-out': 'set',
|
{'x-timestamp': '1', 'x-out': 'set',
|
||||||
POLICY_INDEX: policy.idx}, 'sda1', policy.idx)
|
'X-Backend-Storage-Policy-Index': policy.idx}, 'sda1',
|
||||||
|
policy.idx)
|
||||||
finally:
|
finally:
|
||||||
object_server.http_connect = orig_http_connect
|
object_server.http_connect = orig_http_connect
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
@ -2319,7 +2320,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
['127.0.0.1', '1234', 'sdc1', 1, 'PUT', '/a/c/o', {
|
['127.0.0.1', '1234', 'sdc1', 1, 'PUT', '/a/c/o', {
|
||||||
'x-timestamp': '1', 'x-out': 'set',
|
'x-timestamp': '1', 'x-out': 'set',
|
||||||
'user-agent': 'obj-server %s' % os.getpid(),
|
'user-agent': 'obj-server %s' % os.getpid(),
|
||||||
POLICY_INDEX: policy.idx}])
|
'X-Backend-Storage-Policy-Index': policy.idx}])
|
||||||
|
|
||||||
@patch_policies([storage_policy.StoragePolicy(0, 'zero', True),
|
@patch_policies([storage_policy.StoragePolicy(0, 'zero', True),
|
||||||
storage_policy.StoragePolicy(1, 'one'),
|
storage_policy.StoragePolicy(1, 'one'),
|
||||||
@ -2363,7 +2364,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
headers={'X-Timestamp': '12345',
|
headers={'X-Timestamp': '12345',
|
||||||
'Content-Type': 'application/burrito',
|
'Content-Type': 'application/burrito',
|
||||||
'Content-Length': '0',
|
'Content-Length': '0',
|
||||||
POLICY_INDEX: policy.idx,
|
'X-Backend-Storage-Policy-Index': policy.idx,
|
||||||
'X-Container-Partition': '20',
|
'X-Container-Partition': '20',
|
||||||
'X-Container-Host': '1.2.3.4:5',
|
'X-Container-Host': '1.2.3.4:5',
|
||||||
'X-Container-Device': 'sdb1',
|
'X-Container-Device': 'sdb1',
|
||||||
@ -2396,10 +2397,10 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
|
'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
|
||||||
'x-size': '0',
|
'x-size': '0',
|
||||||
'x-timestamp': utils.Timestamp('12345').internal,
|
'x-timestamp': utils.Timestamp('12345').internal,
|
||||||
POLICY_INDEX: '37',
|
'X-Backend-Storage-Policy-Index': '37',
|
||||||
'referer': 'PUT http://localhost/sda1/p/a/c/o',
|
'referer': 'PUT http://localhost/sda1/p/a/c/o',
|
||||||
'user-agent': 'obj-server %d' % os.getpid(),
|
'user-agent': 'obj-server %d' % os.getpid(),
|
||||||
POLICY_INDEX: policy.idx,
|
'X-Backend-Storage-Policy-Index': policy.idx,
|
||||||
'x-trans-id': '-'})})
|
'x-trans-id': '-'})})
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
http_connect_args[1],
|
http_connect_args[1],
|
||||||
@ -2417,7 +2418,8 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'x-timestamp': utils.Timestamp('12345').internal,
|
'x-timestamp': utils.Timestamp('12345').internal,
|
||||||
'referer': 'PUT http://localhost/sda1/p/a/c/o',
|
'referer': 'PUT http://localhost/sda1/p/a/c/o',
|
||||||
'user-agent': 'obj-server %d' % os.getpid(),
|
'user-agent': 'obj-server %d' % os.getpid(),
|
||||||
POLICY_INDEX: 0, # system account storage policy is 0
|
# system account storage policy is 0
|
||||||
|
'X-Backend-Storage-Policy-Index': 0,
|
||||||
'x-trans-id': '-'})})
|
'x-trans-id': '-'})})
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
http_connect_args[2],
|
http_connect_args[2],
|
||||||
@ -2435,7 +2437,8 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'x-timestamp': utils.Timestamp('12345').internal,
|
'x-timestamp': utils.Timestamp('12345').internal,
|
||||||
'referer': 'PUT http://localhost/sda1/p/a/c/o',
|
'referer': 'PUT http://localhost/sda1/p/a/c/o',
|
||||||
'user-agent': 'obj-server %d' % os.getpid(),
|
'user-agent': 'obj-server %d' % os.getpid(),
|
||||||
POLICY_INDEX: 0, # system account storage policy is 0
|
# system account storage policy is 0
|
||||||
|
'X-Backend-Storage-Policy-Index': 0,
|
||||||
'x-trans-id': '-'})})
|
'x-trans-id': '-'})})
|
||||||
|
|
||||||
@patch_policies([storage_policy.StoragePolicy(0, 'zero', True),
|
@patch_policies([storage_policy.StoragePolicy(0, 'zero', True),
|
||||||
@ -2476,7 +2479,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
headers={'X-Timestamp': '12345',
|
headers={'X-Timestamp': '12345',
|
||||||
'Content-Type': 'application/burrito',
|
'Content-Type': 'application/burrito',
|
||||||
'Content-Length': '0',
|
'Content-Length': '0',
|
||||||
POLICY_INDEX: '26',
|
'X-Backend-Storage-Policy-Index': '26',
|
||||||
'X-Container-Partition': '20',
|
'X-Container-Partition': '20',
|
||||||
'X-Container-Host': '1.2.3.4:5, 6.7.8.9:10',
|
'X-Container-Host': '1.2.3.4:5, 6.7.8.9:10',
|
||||||
'X-Container-Device': 'sdb1, sdf1'})
|
'X-Container-Device': 'sdb1, sdf1'})
|
||||||
@ -2502,7 +2505,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
|
'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
|
||||||
'x-size': '0',
|
'x-size': '0',
|
||||||
'x-timestamp': utils.Timestamp('12345').internal,
|
'x-timestamp': utils.Timestamp('12345').internal,
|
||||||
POLICY_INDEX: '26',
|
'X-Backend-Storage-Policy-Index': '26',
|
||||||
'referer': 'PUT http://localhost/sda1/p/a/c/o',
|
'referer': 'PUT http://localhost/sda1/p/a/c/o',
|
||||||
'user-agent': 'obj-server %d' % os.getpid(),
|
'user-agent': 'obj-server %d' % os.getpid(),
|
||||||
'x-trans-id': '-'})})
|
'x-trans-id': '-'})})
|
||||||
@ -2520,7 +2523,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
|
'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
|
||||||
'x-size': '0',
|
'x-size': '0',
|
||||||
'x-timestamp': utils.Timestamp('12345').internal,
|
'x-timestamp': utils.Timestamp('12345').internal,
|
||||||
POLICY_INDEX: '26',
|
'X-Backend-Storage-Policy-Index': '26',
|
||||||
'referer': 'PUT http://localhost/sda1/p/a/c/o',
|
'referer': 'PUT http://localhost/sda1/p/a/c/o',
|
||||||
'user-agent': 'obj-server %d' % os.getpid(),
|
'user-agent': 'obj-server %d' % os.getpid(),
|
||||||
'x-trans-id': '-'})})
|
'x-trans-id': '-'})})
|
||||||
@ -2553,7 +2556,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'X-Delete-At-Partition': 'p',
|
'X-Delete-At-Partition': 'p',
|
||||||
'X-Delete-At-Host': '10.0.0.2:6002',
|
'X-Delete-At-Host': '10.0.0.2:6002',
|
||||||
'X-Delete-At-Device': 'sda1',
|
'X-Delete-At-Device': 'sda1',
|
||||||
POLICY_INDEX: int(policy),
|
'X-Backend-Storage-Policy-Index': int(policy),
|
||||||
})
|
})
|
||||||
with mocked_http_conn(
|
with mocked_http_conn(
|
||||||
500, 500, give_connect=capture_updates) as fake_conn:
|
500, 500, give_connect=capture_updates) as fake_conn:
|
||||||
@ -2571,7 +2574,8 @@ class TestObjectController(unittest.TestCase):
|
|||||||
(delete_at_container, delete_at_timestamp))
|
(delete_at_container, delete_at_timestamp))
|
||||||
expected = {
|
expected = {
|
||||||
'X-Timestamp': put_timestamp,
|
'X-Timestamp': put_timestamp,
|
||||||
POLICY_INDEX: 0, # system account is always 0
|
# system account storage policy is 0
|
||||||
|
'X-Backend-Storage-Policy-Index': 0,
|
||||||
}
|
}
|
||||||
for key, value in expected.items():
|
for key, value in expected.items():
|
||||||
self.assertEqual(headers[key], str(value))
|
self.assertEqual(headers[key], str(value))
|
||||||
@ -2583,7 +2587,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
self.assertEqual(path, '/sda1/p/a/c/o')
|
self.assertEqual(path, '/sda1/p/a/c/o')
|
||||||
expected = {
|
expected = {
|
||||||
'X-Timestamp': put_timestamp,
|
'X-Timestamp': put_timestamp,
|
||||||
POLICY_INDEX: int(policy),
|
'X-Backend-Storage-Policy-Index': int(policy),
|
||||||
}
|
}
|
||||||
for key, value in expected.items():
|
for key, value in expected.items():
|
||||||
self.assertEqual(headers[key], str(value))
|
self.assertEqual(headers[key], str(value))
|
||||||
@ -2598,10 +2602,12 @@ class TestObjectController(unittest.TestCase):
|
|||||||
data = pickle.load(open(async_file))
|
data = pickle.load(open(async_file))
|
||||||
if data['account'] == 'a':
|
if data['account'] == 'a':
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
int(data['headers'][POLICY_INDEX]), policy.idx)
|
int(data['headers']
|
||||||
|
['X-Backend-Storage-Policy-Index']), policy.idx)
|
||||||
elif data['account'] == '.expiring_objects':
|
elif data['account'] == '.expiring_objects':
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
int(data['headers'][POLICY_INDEX]), 0)
|
int(data['headers']
|
||||||
|
['X-Backend-Storage-Policy-Index']), 0)
|
||||||
else:
|
else:
|
||||||
self.fail('unexpected async pending data')
|
self.fail('unexpected async pending data')
|
||||||
self.assertEqual(2, len(found_files))
|
self.assertEqual(2, len(found_files))
|
||||||
@ -2621,7 +2627,8 @@ class TestObjectController(unittest.TestCase):
|
|||||||
self.object_controller.async_update(
|
self.object_controller.async_update(
|
||||||
'PUT', 'a', 'c', 'o', '127.0.0.1:1234', 1, 'sdc1',
|
'PUT', 'a', 'c', 'o', '127.0.0.1:1234', 1, 'sdc1',
|
||||||
{'x-timestamp': '1', 'x-out': 'set',
|
{'x-timestamp': '1', 'x-out': 'set',
|
||||||
POLICY_INDEX: policy.idx}, 'sda1', policy.idx)
|
'X-Backend-Storage-Policy-Index': policy.idx}, 'sda1',
|
||||||
|
policy.idx)
|
||||||
finally:
|
finally:
|
||||||
object_server.http_connect = orig_http_connect
|
object_server.http_connect = orig_http_connect
|
||||||
utils.HASH_PATH_PREFIX = _prefix
|
utils.HASH_PATH_PREFIX = _prefix
|
||||||
@ -2633,7 +2640,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
utils.Timestamp(1).internal))),
|
utils.Timestamp(1).internal))),
|
||||||
{'headers': {'x-timestamp': '1', 'x-out': 'set',
|
{'headers': {'x-timestamp': '1', 'x-out': 'set',
|
||||||
'user-agent': 'obj-server %s' % os.getpid(),
|
'user-agent': 'obj-server %s' % os.getpid(),
|
||||||
POLICY_INDEX: policy.idx},
|
'X-Backend-Storage-Policy-Index': policy.idx},
|
||||||
'account': 'a', 'container': 'c', 'obj': 'o', 'op': 'PUT'})
|
'account': 'a', 'container': 'c', 'obj': 'o', 'op': 'PUT'})
|
||||||
|
|
||||||
def test_async_update_saves_on_non_2xx(self):
|
def test_async_update_saves_on_non_2xx(self):
|
||||||
@ -2664,7 +2671,8 @@ class TestObjectController(unittest.TestCase):
|
|||||||
self.object_controller.async_update(
|
self.object_controller.async_update(
|
||||||
'PUT', 'a', 'c', 'o', '127.0.0.1:1234', 1, 'sdc1',
|
'PUT', 'a', 'c', 'o', '127.0.0.1:1234', 1, 'sdc1',
|
||||||
{'x-timestamp': '1', 'x-out': str(status),
|
{'x-timestamp': '1', 'x-out': str(status),
|
||||||
POLICY_INDEX: policy.idx}, 'sda1', policy.idx)
|
'X-Backend-Storage-Policy-Index': policy.idx}, 'sda1',
|
||||||
|
policy.idx)
|
||||||
async_dir = diskfile.get_async_dir(policy.idx)
|
async_dir = diskfile.get_async_dir(policy.idx)
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
pickle.load(open(os.path.join(
|
pickle.load(open(os.path.join(
|
||||||
@ -2673,7 +2681,8 @@ class TestObjectController(unittest.TestCase):
|
|||||||
utils.Timestamp(1).internal))),
|
utils.Timestamp(1).internal))),
|
||||||
{'headers': {'x-timestamp': '1', 'x-out': str(status),
|
{'headers': {'x-timestamp': '1', 'x-out': str(status),
|
||||||
'user-agent': 'obj-server %s' % os.getpid(),
|
'user-agent': 'obj-server %s' % os.getpid(),
|
||||||
POLICY_INDEX: policy.idx},
|
'X-Backend-Storage-Policy-Index':
|
||||||
|
policy.idx},
|
||||||
'account': 'a', 'container': 'c', 'obj': 'o',
|
'account': 'a', 'container': 'c', 'obj': 'o',
|
||||||
'op': 'PUT'})
|
'op': 'PUT'})
|
||||||
finally:
|
finally:
|
||||||
@ -2799,7 +2808,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
|
'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
|
||||||
'x-content-type': 'text/plain',
|
'x-content-type': 'text/plain',
|
||||||
'x-timestamp': utils.Timestamp(1).internal,
|
'x-timestamp': utils.Timestamp(1).internal,
|
||||||
POLICY_INDEX: '0', # default when not given
|
'X-Backend-Storage-Policy-Index': '0', # default when not given
|
||||||
'x-trans-id': '123',
|
'x-trans-id': '123',
|
||||||
'referer': 'PUT http://localhost/sda1/0/a/c/o'}))
|
'referer': 'PUT http://localhost/sda1/0/a/c/o'}))
|
||||||
|
|
||||||
@ -2900,7 +2909,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'DELETE', '.expiring_objects', '0000000000',
|
'DELETE', '.expiring_objects', '0000000000',
|
||||||
'0000000002-a/c/o', None, None, None,
|
'0000000002-a/c/o', None, None, None,
|
||||||
HeaderKeyDict({
|
HeaderKeyDict({
|
||||||
POLICY_INDEX: 0,
|
'X-Backend-Storage-Policy-Index': 0,
|
||||||
'x-timestamp': utils.Timestamp('1').internal,
|
'x-timestamp': utils.Timestamp('1').internal,
|
||||||
'x-trans-id': '123',
|
'x-trans-id': '123',
|
||||||
'referer': 'PUT http://localhost/v1/a/c/o'}),
|
'referer': 'PUT http://localhost/v1/a/c/o'}),
|
||||||
@ -2927,7 +2936,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'DELETE', '.expiring_objects', '0000000000', '0000000000-a/c/o',
|
'DELETE', '.expiring_objects', '0000000000', '0000000000-a/c/o',
|
||||||
None, None, None,
|
None, None, None,
|
||||||
HeaderKeyDict({
|
HeaderKeyDict({
|
||||||
POLICY_INDEX: 0,
|
'X-Backend-Storage-Policy-Index': 0,
|
||||||
'x-timestamp': utils.Timestamp('1').internal,
|
'x-timestamp': utils.Timestamp('1').internal,
|
||||||
'x-trans-id': '1234',
|
'x-trans-id': '1234',
|
||||||
'referer': 'PUT http://localhost/v1/a/c/o'}),
|
'referer': 'PUT http://localhost/v1/a/c/o'}),
|
||||||
@ -2954,7 +2963,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'DELETE', '.expiring_objects', '9999936000', '9999999999-a/c/o',
|
'DELETE', '.expiring_objects', '9999936000', '9999999999-a/c/o',
|
||||||
None, None, None,
|
None, None, None,
|
||||||
HeaderKeyDict({
|
HeaderKeyDict({
|
||||||
POLICY_INDEX: 0,
|
'X-Backend-Storage-Policy-Index': 0,
|
||||||
'x-timestamp': utils.Timestamp('1').internal,
|
'x-timestamp': utils.Timestamp('1').internal,
|
||||||
'x-trans-id': '1234',
|
'x-trans-id': '1234',
|
||||||
'referer': 'PUT http://localhost/v1/a/c/o'}),
|
'referer': 'PUT http://localhost/v1/a/c/o'}),
|
||||||
@ -2986,7 +2995,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'PUT', '.expiring_objects', '0000000000', '0000000002-a/c/o',
|
'PUT', '.expiring_objects', '0000000000', '0000000002-a/c/o',
|
||||||
'127.0.0.1:1234',
|
'127.0.0.1:1234',
|
||||||
'3', 'sdc1', HeaderKeyDict({
|
'3', 'sdc1', HeaderKeyDict({
|
||||||
POLICY_INDEX: 0,
|
'X-Backend-Storage-Policy-Index': 0,
|
||||||
'x-size': '0',
|
'x-size': '0',
|
||||||
'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
|
'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
|
||||||
'x-content-type': 'text/plain',
|
'x-content-type': 'text/plain',
|
||||||
@ -3040,7 +3049,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'DELETE', '.expiring_objects', '0000000000',
|
'DELETE', '.expiring_objects', '0000000000',
|
||||||
'0000000002-a/c/o', None, None,
|
'0000000002-a/c/o', None, None,
|
||||||
None, HeaderKeyDict({
|
None, HeaderKeyDict({
|
||||||
POLICY_INDEX: 0,
|
'X-Backend-Storage-Policy-Index': 0,
|
||||||
'x-timestamp': utils.Timestamp('1').internal,
|
'x-timestamp': utils.Timestamp('1').internal,
|
||||||
'x-trans-id': '1234',
|
'x-trans-id': '1234',
|
||||||
'referer': 'DELETE http://localhost/v1/a/c/o'}),
|
'referer': 'DELETE http://localhost/v1/a/c/o'}),
|
||||||
@ -4065,7 +4074,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'Content-Type': 'application/x-test',
|
'Content-Type': 'application/x-test',
|
||||||
'Foo': 'fooheader',
|
'Foo': 'fooheader',
|
||||||
'Baz': 'bazheader',
|
'Baz': 'bazheader',
|
||||||
POLICY_INDEX: 1,
|
'X-Backend-Storage-Policy-Index': 1,
|
||||||
'X-Object-Meta-1': 'One',
|
'X-Object-Meta-1': 'One',
|
||||||
'X-Object-Meta-Two': 'Two'})
|
'X-Object-Meta-Two': 'Two'})
|
||||||
req.body = 'VERIFY'
|
req.body = 'VERIFY'
|
||||||
|
@ -27,7 +27,6 @@ from swift.common import constraints
|
|||||||
from swift.common import exceptions
|
from swift.common import exceptions
|
||||||
from swift.common import swob
|
from swift.common import swob
|
||||||
from swift.common import utils
|
from swift.common import utils
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
from swift.obj import diskfile
|
from swift.obj import diskfile
|
||||||
from swift.obj import server
|
from swift.obj import server
|
||||||
from swift.obj import ssync_receiver
|
from swift.obj import ssync_receiver
|
||||||
@ -1066,7 +1065,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
'Content-Encoding': 'gzip',
|
'Content-Encoding': 'gzip',
|
||||||
'Specialty-Header': 'value',
|
'Specialty-Header': 'value',
|
||||||
'Host': 'localhost:80',
|
'Host': 'localhost:80',
|
||||||
POLICY_INDEX: '0',
|
'X-Backend-Storage-Policy-Index': '0',
|
||||||
'X-Backend-Replication': 'True',
|
'X-Backend-Replication': 'True',
|
||||||
'X-Backend-Replication-Headers': (
|
'X-Backend-Replication-Headers': (
|
||||||
'content-length x-timestamp x-object-meta-test1 '
|
'content-length x-timestamp x-object-meta-test1 '
|
||||||
@ -1117,7 +1116,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
'Content-Encoding': 'gzip',
|
'Content-Encoding': 'gzip',
|
||||||
'Specialty-Header': 'value',
|
'Specialty-Header': 'value',
|
||||||
'Host': 'localhost:80',
|
'Host': 'localhost:80',
|
||||||
POLICY_INDEX: '1',
|
'X-Backend-Storage-Policy-Index': '1',
|
||||||
'X-Backend-Replication': 'True',
|
'X-Backend-Replication': 'True',
|
||||||
'X-Backend-Replication-Headers': (
|
'X-Backend-Replication-Headers': (
|
||||||
'content-length x-timestamp x-object-meta-test1 '
|
'content-length x-timestamp x-object-meta-test1 '
|
||||||
@ -1155,7 +1154,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
self.assertEqual(req.headers, {
|
self.assertEqual(req.headers, {
|
||||||
'X-Timestamp': '1364456113.76334',
|
'X-Timestamp': '1364456113.76334',
|
||||||
'Host': 'localhost:80',
|
'Host': 'localhost:80',
|
||||||
POLICY_INDEX: '0',
|
'X-Backend-Storage-Policy-Index': '0',
|
||||||
'X-Backend-Replication': 'True',
|
'X-Backend-Replication': 'True',
|
||||||
'X-Backend-Replication-Headers': 'x-timestamp'})
|
'X-Backend-Replication-Headers': 'x-timestamp'})
|
||||||
|
|
||||||
@ -1256,7 +1255,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
'Content-Encoding': 'gzip',
|
'Content-Encoding': 'gzip',
|
||||||
'Specialty-Header': 'value',
|
'Specialty-Header': 'value',
|
||||||
'Host': 'localhost:80',
|
'Host': 'localhost:80',
|
||||||
POLICY_INDEX: '0',
|
'X-Backend-Storage-Policy-Index': '0',
|
||||||
'X-Backend-Replication': 'True',
|
'X-Backend-Replication': 'True',
|
||||||
'X-Backend-Replication-Headers': (
|
'X-Backend-Replication-Headers': (
|
||||||
'content-length x-timestamp x-object-meta-test1 '
|
'content-length x-timestamp x-object-meta-test1 '
|
||||||
@ -1268,7 +1267,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
self.assertEqual(req.headers, {
|
self.assertEqual(req.headers, {
|
||||||
'X-Timestamp': '1364456113.00002',
|
'X-Timestamp': '1364456113.00002',
|
||||||
'Host': 'localhost:80',
|
'Host': 'localhost:80',
|
||||||
POLICY_INDEX: '0',
|
'X-Backend-Storage-Policy-Index': '0',
|
||||||
'X-Backend-Replication': 'True',
|
'X-Backend-Replication': 'True',
|
||||||
'X-Backend-Replication-Headers': 'x-timestamp'})
|
'X-Backend-Replication-Headers': 'x-timestamp'})
|
||||||
req = _requests.pop(0)
|
req = _requests.pop(0)
|
||||||
@ -1279,7 +1278,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
'Content-Length': '3',
|
'Content-Length': '3',
|
||||||
'X-Timestamp': '1364456113.00003',
|
'X-Timestamp': '1364456113.00003',
|
||||||
'Host': 'localhost:80',
|
'Host': 'localhost:80',
|
||||||
POLICY_INDEX: '0',
|
'X-Backend-Storage-Policy-Index': '0',
|
||||||
'X-Backend-Replication': 'True',
|
'X-Backend-Replication': 'True',
|
||||||
'X-Backend-Replication-Headers': (
|
'X-Backend-Replication-Headers': (
|
||||||
'content-length x-timestamp')})
|
'content-length x-timestamp')})
|
||||||
@ -1292,7 +1291,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
'Content-Length': '4',
|
'Content-Length': '4',
|
||||||
'X-Timestamp': '1364456113.00004',
|
'X-Timestamp': '1364456113.00004',
|
||||||
'Host': 'localhost:80',
|
'Host': 'localhost:80',
|
||||||
POLICY_INDEX: '0',
|
'X-Backend-Storage-Policy-Index': '0',
|
||||||
'X-Backend-Replication': 'True',
|
'X-Backend-Replication': 'True',
|
||||||
'X-Backend-Replication-Headers': (
|
'X-Backend-Replication-Headers': (
|
||||||
'content-length x-timestamp')})
|
'content-length x-timestamp')})
|
||||||
@ -1303,7 +1302,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
self.assertEqual(req.headers, {
|
self.assertEqual(req.headers, {
|
||||||
'X-Timestamp': '1364456113.00005',
|
'X-Timestamp': '1364456113.00005',
|
||||||
'Host': 'localhost:80',
|
'Host': 'localhost:80',
|
||||||
POLICY_INDEX: '0',
|
'X-Backend-Storage-Policy-Index': '0',
|
||||||
'X-Backend-Replication': 'True',
|
'X-Backend-Replication': 'True',
|
||||||
'X-Backend-Replication-Headers': 'x-timestamp'})
|
'X-Backend-Replication-Headers': 'x-timestamp'})
|
||||||
req = _requests.pop(0)
|
req = _requests.pop(0)
|
||||||
@ -1312,7 +1311,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
self.assertEqual(req.headers, {
|
self.assertEqual(req.headers, {
|
||||||
'X-Timestamp': '1364456113.00006',
|
'X-Timestamp': '1364456113.00006',
|
||||||
'Host': 'localhost:80',
|
'Host': 'localhost:80',
|
||||||
POLICY_INDEX: '0',
|
'X-Backend-Storage-Policy-Index': '0',
|
||||||
'X-Backend-Replication': 'True',
|
'X-Backend-Replication': 'True',
|
||||||
'X-Backend-Replication-Headers': 'x-timestamp'})
|
'X-Backend-Replication-Headers': 'x-timestamp'})
|
||||||
self.assertEqual(_requests, [])
|
self.assertEqual(_requests, [])
|
||||||
@ -1376,7 +1375,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
'Content-Length': '3',
|
'Content-Length': '3',
|
||||||
'X-Timestamp': '1364456113.00001',
|
'X-Timestamp': '1364456113.00001',
|
||||||
'Host': 'localhost:80',
|
'Host': 'localhost:80',
|
||||||
POLICY_INDEX: '0',
|
'X-Backend-Storage-Policy-Index': '0',
|
||||||
'X-Backend-Replication': 'True',
|
'X-Backend-Replication': 'True',
|
||||||
'X-Backend-Replication-Headers': (
|
'X-Backend-Replication-Headers': (
|
||||||
'content-length x-timestamp')})
|
'content-length x-timestamp')})
|
||||||
@ -1388,7 +1387,7 @@ class TestReceiver(unittest.TestCase):
|
|||||||
'Content-Length': '1',
|
'Content-Length': '1',
|
||||||
'X-Timestamp': '1364456113.00002',
|
'X-Timestamp': '1364456113.00002',
|
||||||
'Host': 'localhost:80',
|
'Host': 'localhost:80',
|
||||||
POLICY_INDEX: '0',
|
'X-Backend-Storage-Policy-Index': '0',
|
||||||
'X-Backend-Replication': 'True',
|
'X-Backend-Replication': 'True',
|
||||||
'X-Backend-Replication-Headers': (
|
'X-Backend-Replication-Headers': (
|
||||||
'content-length x-timestamp')})
|
'content-length x-timestamp')})
|
||||||
|
@ -26,7 +26,6 @@ import mock
|
|||||||
|
|
||||||
from swift.common import exceptions, utils
|
from swift.common import exceptions, utils
|
||||||
from swift.obj import ssync_sender, diskfile
|
from swift.obj import ssync_sender, diskfile
|
||||||
from swift.common.storage_policy import POLICY_INDEX
|
|
||||||
|
|
||||||
from test.unit import DebugLogger, patch_policies
|
from test.unit import DebugLogger, patch_policies
|
||||||
|
|
||||||
@ -228,7 +227,7 @@ class TestSender(unittest.TestCase):
|
|||||||
],
|
],
|
||||||
'putheader': [
|
'putheader': [
|
||||||
mock.call('Transfer-Encoding', 'chunked'),
|
mock.call('Transfer-Encoding', 'chunked'),
|
||||||
mock.call(POLICY_INDEX, 1),
|
mock.call('X-Backend-Storage-Policy-Index', 1),
|
||||||
],
|
],
|
||||||
'endheaders': [mock.call()],
|
'endheaders': [mock.call()],
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ from swift.common.utils import hash_path, normalize_timestamp, mkdirs, \
|
|||||||
write_pickle
|
write_pickle
|
||||||
from swift.common import swob
|
from swift.common import swob
|
||||||
from test.unit import debug_logger, patch_policies, mocked_http_conn
|
from test.unit import debug_logger, patch_policies, mocked_http_conn
|
||||||
from swift.common.storage_policy import StoragePolicy, POLICIES, POLICY_INDEX
|
from swift.common.storage_policy import StoragePolicy, POLICIES
|
||||||
|
|
||||||
|
|
||||||
_mocked_policies = [StoragePolicy(0, 'zero', False),
|
_mocked_policies = [StoragePolicy(0, 'zero', False),
|
||||||
@ -288,7 +288,8 @@ class TestObjectUpdater(unittest.TestCase):
|
|||||||
line.split(':')[1].strip()
|
line.split(':')[1].strip()
|
||||||
line = inc.readline()
|
line = inc.readline()
|
||||||
self.assertTrue('x-container-timestamp' in headers)
|
self.assertTrue('x-container-timestamp' in headers)
|
||||||
self.assertTrue(POLICY_INDEX in headers)
|
self.assertTrue('X-Backend-Storage-Policy-Index' in
|
||||||
|
headers)
|
||||||
except BaseException as err:
|
except BaseException as err:
|
||||||
return err
|
return err
|
||||||
return None
|
return None
|
||||||
@ -392,7 +393,8 @@ class TestObjectUpdater(unittest.TestCase):
|
|||||||
for request_args, request_kwargs in request_log:
|
for request_args, request_kwargs in request_log:
|
||||||
ip, part, method, path, headers, qs, ssl = request_args
|
ip, part, method, path, headers, qs, ssl = request_args
|
||||||
self.assertEqual(method, op)
|
self.assertEqual(method, op)
|
||||||
self.assertEqual(headers[POLICY_INDEX], str(policy.idx))
|
self.assertEqual(headers['X-Backend-Storage-Policy-Index'],
|
||||||
|
str(policy.idx))
|
||||||
self.assertEqual(daemon.logger.get_increment_counts(),
|
self.assertEqual(daemon.logger.get_increment_counts(),
|
||||||
{'successes': 1, 'unlinks': 1,
|
{'successes': 1, 'unlinks': 1,
|
||||||
'async_pendings': 1})
|
'async_pendings': 1})
|
||||||
@ -420,7 +422,7 @@ class TestObjectUpdater(unittest.TestCase):
|
|||||||
'x-content-type': 'text/plain',
|
'x-content-type': 'text/plain',
|
||||||
'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
|
'x-etag': 'd41d8cd98f00b204e9800998ecf8427e',
|
||||||
'x-timestamp': ts.next(),
|
'x-timestamp': ts.next(),
|
||||||
POLICY_INDEX: policy.idx,
|
'X-Backend-Storage-Policy-Index': policy.idx,
|
||||||
})
|
})
|
||||||
data = {'op': op, 'account': account, 'container': container,
|
data = {'op': op, 'account': account, 'container': container,
|
||||||
'obj': obj, 'headers': headers_out}
|
'obj': obj, 'headers': headers_out}
|
||||||
@ -444,7 +446,8 @@ class TestObjectUpdater(unittest.TestCase):
|
|||||||
for request_args, request_kwargs in request_log:
|
for request_args, request_kwargs in request_log:
|
||||||
ip, part, method, path, headers, qs, ssl = request_args
|
ip, part, method, path, headers, qs, ssl = request_args
|
||||||
self.assertEqual(method, 'PUT')
|
self.assertEqual(method, 'PUT')
|
||||||
self.assertEqual(headers[POLICY_INDEX], str(policy.idx))
|
self.assertEqual(headers['X-Backend-Storage-Policy-Index'],
|
||||||
|
str(policy.idx))
|
||||||
self.assertEqual(daemon.logger.get_increment_counts(),
|
self.assertEqual(daemon.logger.get_increment_counts(),
|
||||||
{'successes': 1, 'unlinks': 1, 'async_pendings': 1})
|
{'successes': 1, 'unlinks': 1, 'async_pendings': 1})
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ from swift.common.swob import Request, Response, HTTPUnauthorized, \
|
|||||||
HTTPException
|
HTTPException
|
||||||
from swift.common import storage_policy
|
from swift.common import storage_policy
|
||||||
from swift.common.storage_policy import StoragePolicy, \
|
from swift.common.storage_policy import StoragePolicy, \
|
||||||
StoragePolicyCollection, POLICIES, POLICY, POLICY_INDEX
|
StoragePolicyCollection, POLICIES
|
||||||
from swift.common.request_helpers import get_sys_meta_prefix
|
from swift.common.request_helpers import get_sys_meta_prefix
|
||||||
|
|
||||||
# mocks
|
# mocks
|
||||||
@ -1729,7 +1729,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'X-Container-Device': device,
|
'X-Container-Device': device,
|
||||||
'Referer': 'POST http://localhost/v1/a/c/o',
|
'Referer': 'POST http://localhost/v1/a/c/o',
|
||||||
'X-Object-Meta-Color': 'Blue',
|
'X-Object-Meta-Color': 'Blue',
|
||||||
POLICY_INDEX: '1'
|
'X-Backend-Storage-Policy-Index': '1'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
check_request(request, **expectations)
|
check_request(request, **expectations)
|
||||||
@ -1739,7 +1739,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
backend_requests = []
|
backend_requests = []
|
||||||
req = Request.blank('/v1/a/c/o', {}, method='POST',
|
req = Request.blank('/v1/a/c/o', {}, method='POST',
|
||||||
headers={'X-Object-Meta-Color': 'Blue',
|
headers={'X-Object-Meta-Color': 'Blue',
|
||||||
POLICY_INDEX: 0})
|
'X-Backend-Storage-Policy-Index': 0})
|
||||||
with mocked_http_conn(
|
with mocked_http_conn(
|
||||||
200, 200, 202, 202, 202,
|
200, 200, 202, 202, 202,
|
||||||
headers=resp_headers, give_connect=capture_requests
|
headers=resp_headers, give_connect=capture_requests
|
||||||
@ -1754,7 +1754,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'path': '/1/a/c/o', # ignore device bit
|
'path': '/1/a/c/o', # ignore device bit
|
||||||
'headers': {
|
'headers': {
|
||||||
'X-Object-Meta-Color': 'Blue',
|
'X-Object-Meta-Color': 'Blue',
|
||||||
POLICY_INDEX: '0',
|
'X-Backend-Storage-Policy-Index': '0',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_request(request, **expectations)
|
check_request(request, **expectations)
|
||||||
@ -1765,7 +1765,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
backend_requests = []
|
backend_requests = []
|
||||||
req = Request.blank('/v1/a/c/o', {}, method='POST',
|
req = Request.blank('/v1/a/c/o', {}, method='POST',
|
||||||
headers={'X-Object-Meta-Color': 'Blue',
|
headers={'X-Object-Meta-Color': 'Blue',
|
||||||
POLICY_INDEX: 0})
|
'X-Backend-Storage-Policy-Index': 0})
|
||||||
with mocked_http_conn(
|
with mocked_http_conn(
|
||||||
200, 200, 200, 200, 200, 201, 201, 201,
|
200, 200, 200, 200, 200, 201, 201, 201,
|
||||||
headers=resp_headers, give_connect=capture_requests
|
headers=resp_headers, give_connect=capture_requests
|
||||||
@ -1774,8 +1774,8 @@ class TestObjectController(unittest.TestCase):
|
|||||||
self.assertRaises(StopIteration, fake_conn.code_iter.next)
|
self.assertRaises(StopIteration, fake_conn.code_iter.next)
|
||||||
self.assertEqual(resp.status_int, 202)
|
self.assertEqual(resp.status_int, 202)
|
||||||
self.assertEqual(len(backend_requests), 8)
|
self.assertEqual(len(backend_requests), 8)
|
||||||
policy0 = {POLICY_INDEX: '0'}
|
policy0 = {'X-Backend-Storage-Policy-Index': '0'}
|
||||||
policy1 = {POLICY_INDEX: '1'}
|
policy1 = {'X-Backend-Storage-Policy-Index': '1'}
|
||||||
expected = [
|
expected = [
|
||||||
# account info
|
# account info
|
||||||
{'method': 'HEAD', 'path': '/1/a'},
|
{'method': 'HEAD', 'path': '/1/a'},
|
||||||
@ -4234,8 +4234,10 @@ class TestObjectController(unittest.TestCase):
|
|||||||
headers=None, query_string=None):
|
headers=None, query_string=None):
|
||||||
if method == "HEAD":
|
if method == "HEAD":
|
||||||
self.assertEquals(path, '/a/c/o.jpg')
|
self.assertEquals(path, '/a/c/o.jpg')
|
||||||
self.assertNotEquals(None, headers[POLICY_INDEX])
|
self.assertNotEquals(None,
|
||||||
self.assertEquals(1, int(headers[POLICY_INDEX]))
|
headers['X-Backend-Storage-Policy-Index'])
|
||||||
|
self.assertEquals(1, int(headers
|
||||||
|
['X-Backend-Storage-Policy-Index']))
|
||||||
|
|
||||||
def fake_container_info(account, container, req):
|
def fake_container_info(account, container, req):
|
||||||
return {'status': 200, 'sync_key': None, 'storage_policy': '1',
|
return {'status': 200, 'sync_key': None, 'storage_policy': '1',
|
||||||
@ -4333,7 +4335,8 @@ class TestObjectController(unittest.TestCase):
|
|||||||
expected_storage_policy = 0
|
expected_storage_policy = 0
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
storage_policy_index = int(headers[POLICY_INDEX])
|
storage_policy_index = \
|
||||||
|
int(headers['X-Backend-Storage-Policy-Index'])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
expected_storage_policy, storage_policy_index,
|
expected_storage_policy, storage_policy_index,
|
||||||
'Unexpected %s request for %s '
|
'Unexpected %s request for %s '
|
||||||
@ -4829,7 +4832,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
for name, index in expected.items():
|
for name, index in expected.items():
|
||||||
req = Request.blank('/a/c', headers={'Content-Length': '0',
|
req = Request.blank('/a/c', headers={'Content-Length': '0',
|
||||||
'Content-Type': 'text/plain',
|
'Content-Type': 'text/plain',
|
||||||
POLICY: name})
|
'X-Storage-Policy': name})
|
||||||
self.assertEqual(controller._convert_policy_to_index(req), index)
|
self.assertEqual(controller._convert_policy_to_index(req), index)
|
||||||
# default test
|
# default test
|
||||||
req = Request.blank('/a/c', headers={'Content-Length': '0',
|
req = Request.blank('/a/c', headers={'Content-Length': '0',
|
||||||
@ -4837,13 +4840,14 @@ class TestContainerController(unittest.TestCase):
|
|||||||
self.assertEqual(controller._convert_policy_to_index(req), None)
|
self.assertEqual(controller._convert_policy_to_index(req), None)
|
||||||
# negative test
|
# negative test
|
||||||
req = Request.blank('/a/c', headers={'Content-Length': '0',
|
req = Request.blank('/a/c', headers={'Content-Length': '0',
|
||||||
'Content-Type': 'text/plain', POLICY: 'nada'})
|
'Content-Type': 'text/plain',
|
||||||
|
'X-Storage-Policy': 'nada'})
|
||||||
self.assertRaises(HTTPException, controller._convert_policy_to_index,
|
self.assertRaises(HTTPException, controller._convert_policy_to_index,
|
||||||
req)
|
req)
|
||||||
# storage policy two is deprecated
|
# storage policy two is deprecated
|
||||||
req = Request.blank('/a/c', headers={'Content-Length': '0',
|
req = Request.blank('/a/c', headers={'Content-Length': '0',
|
||||||
'Content-Type': 'text/plain',
|
'Content-Type': 'text/plain',
|
||||||
POLICY: 'two'})
|
'X-Storage-Policy': 'two'})
|
||||||
self.assertRaises(HTTPException, controller._convert_policy_to_index,
|
self.assertRaises(HTTPException, controller._convert_policy_to_index,
|
||||||
req)
|
req)
|
||||||
|
|
||||||
@ -4852,33 +4856,34 @@ class TestContainerController(unittest.TestCase):
|
|||||||
req = Request.blank('/v1/a/c')
|
req = Request.blank('/v1/a/c')
|
||||||
with mocked_http_conn(
|
with mocked_http_conn(
|
||||||
200, 200,
|
200, 200,
|
||||||
headers={POLICY_INDEX: int(policy)},
|
headers={'X-Backend-Storage-Policy-Index': int(policy)},
|
||||||
) as fake_conn:
|
) as fake_conn:
|
||||||
resp = req.get_response(self.app)
|
resp = req.get_response(self.app)
|
||||||
self.assertRaises(StopIteration, fake_conn.code_iter.next)
|
self.assertRaises(StopIteration, fake_conn.code_iter.next)
|
||||||
self.assertEqual(resp.status_int, 200)
|
self.assertEqual(resp.status_int, 200)
|
||||||
self.assertEqual(resp.headers[POLICY], policy.name)
|
self.assertEqual(resp.headers['X-Storage-Policy'], policy.name)
|
||||||
|
|
||||||
def test_no_convert_index_to_name_when_container_not_found(self):
|
def test_no_convert_index_to_name_when_container_not_found(self):
|
||||||
policy = random.choice(list(POLICIES))
|
policy = random.choice(list(POLICIES))
|
||||||
req = Request.blank('/v1/a/c')
|
req = Request.blank('/v1/a/c')
|
||||||
with mocked_http_conn(
|
with mocked_http_conn(
|
||||||
200, 404, 404, 404,
|
200, 404, 404, 404,
|
||||||
headers={POLICY_INDEX: int(policy)}) as fake_conn:
|
headers={'X-Backend-Storage-Policy-Index':
|
||||||
|
int(policy)}) as fake_conn:
|
||||||
resp = req.get_response(self.app)
|
resp = req.get_response(self.app)
|
||||||
self.assertRaises(StopIteration, fake_conn.code_iter.next)
|
self.assertRaises(StopIteration, fake_conn.code_iter.next)
|
||||||
self.assertEqual(resp.status_int, 404)
|
self.assertEqual(resp.status_int, 404)
|
||||||
self.assertEqual(resp.headers[POLICY], None)
|
self.assertEqual(resp.headers['X-Storage-Policy'], None)
|
||||||
|
|
||||||
def test_error_convert_index_to_name(self):
|
def test_error_convert_index_to_name(self):
|
||||||
req = Request.blank('/v1/a/c')
|
req = Request.blank('/v1/a/c')
|
||||||
with mocked_http_conn(
|
with mocked_http_conn(
|
||||||
200, 200,
|
200, 200,
|
||||||
headers={POLICY_INDEX: '-1'}) as fake_conn:
|
headers={'X-Backend-Storage-Policy-Index': '-1'}) as fake_conn:
|
||||||
resp = req.get_response(self.app)
|
resp = req.get_response(self.app)
|
||||||
self.assertRaises(StopIteration, fake_conn.code_iter.next)
|
self.assertRaises(StopIteration, fake_conn.code_iter.next)
|
||||||
self.assertEqual(resp.status_int, 200)
|
self.assertEqual(resp.status_int, 200)
|
||||||
self.assertEqual(resp.headers[POLICY], None)
|
self.assertEqual(resp.headers['X-Storage-Policy'], None)
|
||||||
error_lines = self.app.logger.get_lines_for_level('error')
|
error_lines = self.app.logger.get_lines_for_level('error')
|
||||||
self.assertEqual(2, len(error_lines))
|
self.assertEqual(2, len(error_lines))
|
||||||
for msg in error_lines:
|
for msg in error_lines:
|
||||||
@ -5010,7 +5015,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
headers={'Content-Length': 0})
|
headers={'Content-Length': 0})
|
||||||
if requested_policy:
|
if requested_policy:
|
||||||
expected_policy = requested_policy
|
expected_policy = requested_policy
|
||||||
req.headers[POLICY] = policy.name
|
req.headers['X-Storage-Policy'] = policy.name
|
||||||
else:
|
else:
|
||||||
expected_policy = POLICIES.default
|
expected_policy = POLICIES.default
|
||||||
res = req.get_response(self.app)
|
res = req.get_response(self.app)
|
||||||
@ -5028,15 +5033,18 @@ class TestContainerController(unittest.TestCase):
|
|||||||
len(backend_requests))
|
len(backend_requests))
|
||||||
for headers in backend_requests:
|
for headers in backend_requests:
|
||||||
if not requested_policy:
|
if not requested_policy:
|
||||||
self.assertFalse(POLICY_INDEX in headers)
|
self.assertFalse('X-Backend-Storage-Policy-Index' in
|
||||||
|
headers)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'X-Backend-Storage-Policy-Default' in headers)
|
'X-Backend-Storage-Policy-Default' in headers)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
int(expected_policy),
|
int(expected_policy),
|
||||||
int(headers['X-Backend-Storage-Policy-Default']))
|
int(headers['X-Backend-Storage-Policy-Default']))
|
||||||
else:
|
else:
|
||||||
self.assertTrue(POLICY_INDEX in headers)
|
self.assertTrue('X-Backend-Storage-Policy-Index' in
|
||||||
self.assertEqual(int(headers[POLICY_INDEX]),
|
headers)
|
||||||
|
self.assertEqual(int(headers
|
||||||
|
['X-Backend-Storage-Policy-Index']),
|
||||||
policy.idx)
|
policy.idx)
|
||||||
# make sure all mocked responses are consumed
|
# make sure all mocked responses are consumed
|
||||||
self.assertRaises(StopIteration, mock_conn.code_iter.next)
|
self.assertRaises(StopIteration, mock_conn.code_iter.next)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user