From 873c52e608d46e4c34035a8dd3476e604fe2248e Mon Sep 17 00:00:00 2001 From: Paul Luse Date: Mon, 23 Jun 2014 12:52:50 -0700 Subject: [PATCH] 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 --- swift/account/reaper.py | 6 +- swift/account/server.py | 4 +- swift/cli/info.py | 8 +- swift/common/request_helpers.py | 3 +- swift/common/storage_policy.py | 2 - swift/container/reconciler.py | 3 +- swift/container/server.py | 8 +- swift/container/sync.py | 5 +- swift/container/updater.py | 3 +- swift/obj/replicator.py | 6 +- swift/obj/server.py | 6 +- swift/obj/ssync_receiver.py | 7 +- swift/obj/ssync_sender.py | 5 +- swift/obj/updater.py | 4 +- swift/proxy/controllers/base.py | 17 ++-- swift/proxy/controllers/container.py | 8 +- swift/proxy/controllers/obj.py | 25 ++--- test/functional/tests.py | 6 +- .../test_container_merge_policy_index.py | 41 +++++--- test/probe/test_empty_device_handoff.py | 9 +- test/probe/test_object_failures.py | 17 ++-- test/probe/test_object_handoff.py | 13 ++- test/unit/account/test_reaper.py | 9 +- test/unit/account/test_server.py | 8 +- test/unit/common/test_direct_client.py | 8 +- test/unit/container/test_server.py | 96 +++++++++++-------- test/unit/container/test_sync.py | 17 ++-- test/unit/obj/test_replicator.py | 6 +- test/unit/obj/test_server.py | 63 ++++++------ test/unit/obj/test_ssync_receiver.py | 23 +++-- test/unit/obj/test_ssync_sender.py | 3 +- test/unit/obj/test_updater.py | 13 ++- test/unit/proxy/test_server.py | 54 ++++++----- 33 files changed, 278 insertions(+), 228 deletions(-) diff --git a/swift/account/reaper.py b/swift/account/reaper.py index 2f0bb0f8d7..0891d6fc59 100644 --- a/swift/account/reaper.py +++ b/swift/account/reaper.py @@ -31,7 +31,7 @@ from swift.common.ring import Ring from swift.common.utils import get_logger, whataremyips, ismount, \ config_true_value, Timestamp 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): @@ -352,7 +352,7 @@ class AccountReaper(Daemon): if not objects: break try: - policy_index = headers.get(POLICY_INDEX, 0) + policy_index = headers.get('X-Backend-Storage-Policy-Index', 0) for obj in objects: if isinstance(obj['name'], unicode): obj['name'] = obj['name'].encode('utf8') @@ -442,7 +442,7 @@ class AccountReaper(Daemon): headers={'X-Container-Host': '%(ip)s:%(port)s' % cnode, 'X-Container-Partition': str(container_partition), 'X-Container-Device': cnode['device'], - POLICY_INDEX: policy_index}) + 'X-Backend-Storage-Policy-Index': policy_index}) successes += 1 self.stats_return_codes[2] = \ self.stats_return_codes.get(2, 0) + 1 diff --git a/swift/account/server.py b/swift/account/server.py index 58dfd607ad..3bdf37f156 100644 --- a/swift/account/server.py +++ b/swift/account/server.py @@ -38,7 +38,6 @@ from swift.common.swob import HTTPAccepted, HTTPBadRequest, \ HTTPPreconditionFailed, HTTPConflict, Request, \ HTTPInsufficientStorage, HTTPException from swift.common.request_helpers import is_sys_or_user_meta -from swift.common.storage_policy import POLICY_INDEX class AccountController(object): @@ -110,7 +109,8 @@ class AccountController(object): else: timestamp = valid_timestamp(req) 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: pending_timeout = 3 broker = self._get_account_broker(drive, part, account, diff --git a/swift/cli/info.py b/swift/cli/info.py index 7d1557c08e..cffb93eed5 100644 --- a/swift/cli/info.py +++ b/swift/cli/info.py @@ -25,7 +25,7 @@ from swift.account.backend import AccountBroker, DATADIR as ABDATADIR from swift.container.backend import ContainerBroker, DATADIR as CBDATADIR from swift.obj.diskfile import get_data_dir, read_metadata, DATADIR_BASE, \ extract_policy_index -from swift.common.storage_policy import POLICIES, POLICY_INDEX +from swift.common.storage_policy import POLICIES 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, urllib.quote(target)) 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 for node in handoff_nodes: cmd = 'curl -I -XHEAD "http://%s:%s/%s/%s/%s"' \ % (node['ip'], node['port'], node['device'], part, urllib.quote(target)) 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]' print cmd diff --git a/swift/common/request_helpers.py b/swift/common/request_helpers.py index 3e3db57080..c7677c11ed 100644 --- a/swift/common/request_helpers.py +++ b/swift/common/request_helpers.py @@ -30,7 +30,6 @@ from swift.common.exceptions import ListingIterError, SegmentError from swift.common.http import is_success, HTTP_SERVICE_UNAVAILABLE from swift.common.swob import HTTPBadRequest, HTTPNotAcceptable 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 @@ -91,7 +90,7 @@ def get_name_and_placement(request, minsegs=1, maxsegs=None, storage_policy_index appended on the end :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) results = split_and_validate_path(request, minsegs=minsegs, maxsegs=maxsegs, diff --git a/swift/common/storage_policy.py b/swift/common/storage_policy.py index 0c0c0eee2c..4cd95a5d9e 100644 --- a/swift/common/storage_policy.py +++ b/swift/common/storage_policy.py @@ -18,8 +18,6 @@ import string from swift.common.utils import config_true_value, SWIFT_CONF_FILE from swift.common.ring import Ring -POLICY = 'X-Storage-Policy' -POLICY_INDEX = 'X-Backend-Storage-Policy-Index' LEGACY_POLICY_NAME = 'Policy-0' VALID_CHARS = '-' + string.letters + string.digits diff --git a/swift/container/reconciler.py b/swift/container/reconciler.py index 7bde84147b..f1ba782db4 100644 --- a/swift/container/reconciler.py +++ b/swift/container/reconciler.py @@ -25,7 +25,6 @@ from swift.common.direct_client import ( direct_head_container, direct_delete_container_object, direct_put_container_object, ClientException) 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, \ FileLikeIter, Timestamp, last_modified_date_to_timestamp, \ LRUCache @@ -100,7 +99,7 @@ def incorrect_policy_index(info, remote_info): def translate_container_headers_to_info(headers): default_timestamp = Timestamp(0).internal 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', default_timestamp), 'delete_timestamp': headers.get('x-backend-delete-timestamp', diff --git a/swift/container/server.py b/swift/container/server.py index 74c0bb2821..76b7771ac4 100644 --- a/swift/container/server.py +++ b/swift/container/server.py @@ -37,7 +37,7 @@ from swift.common import constraints from swift.common.bufferedhttp import http_connect from swift.common.exceptions import ConnectionTimeout 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, \ HTTPCreated, HTTPInternalServerError, HTTPNoContent, HTTPNotFound, \ HTTPPreconditionFailed, HTTPMethodNotAllowed, Request, Response, \ @@ -57,7 +57,7 @@ def gen_resp_headers(info, is_deleted=False): info.get('delete_timestamp', 0)).internal, 'X-Backend-Status-Changed-At': Timestamp( 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: # 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 """ - policy_index = req.headers.get(POLICY_INDEX, None) + policy_index = req.headers.get('X-Backend-Storage-Policy-Index', None) if policy_index is None: return None @@ -202,7 +202,7 @@ class ContainerController(object): 'x-object-count': info['object_count'], 'x-bytes-used': info['bytes_used'], '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(), 'referer': req.as_referer()}) if req.headers.get('x-account-override-deleted', 'no').lower() == \ diff --git a/swift/container/sync.py b/swift/container/sync.py index b5fb5e203a..27cd0d04f3 100644 --- a/swift/container/sync.py +++ b/swift/container/sync.py @@ -35,7 +35,7 @@ from swift.common.utils import ( whataremyips, Timestamp) from swift.common.daemon import Daemon 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): @@ -376,7 +376,8 @@ class ContainerSync(Daemon): looking_for_timestamp = Timestamp(row['created_at']) timestamp = -1 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: try: these_headers, this_body = direct_get_object( diff --git a/swift/container/updater.py b/swift/container/updater.py index 4097f136b6..418883a130 100644 --- a/swift/container/updater.py +++ b/swift/container/updater.py @@ -33,7 +33,6 @@ from swift.common.utils import get_logger, config_true_value, ismount, \ dump_recon_cache, quorum_size, Timestamp from swift.common.daemon import Daemon from swift.common.http import is_success, HTTP_INTERNAL_SERVER_ERROR -from swift.common.storage_policy import POLICY_INDEX class ContainerUpdater(Daemon): @@ -278,7 +277,7 @@ class ContainerUpdater(Daemon): 'X-Object-Count': count, 'X-Bytes-Used': bytes, 'X-Account-Override-Deleted': 'yes', - POLICY_INDEX: storage_policy_index, + 'X-Backend-Storage-Policy-Index': storage_policy_index, 'user-agent': self.user_agent} conn = http_connect( node['ip'], node['port'], node['device'], part, diff --git a/swift/obj/replicator.py b/swift/obj/replicator.py index ca94c9f710..fdc5378252 100644 --- a/swift/obj/replicator.py +++ b/swift/obj/replicator.py @@ -37,7 +37,7 @@ from swift.common.http import HTTP_OK, HTTP_INSUFFICIENT_STORAGE from swift.obj import ssync_sender from swift.obj.diskfile import (DiskFileManager, get_hashes, get_data_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()) @@ -228,7 +228,7 @@ class ObjectReplicator(Daemon): if len(suff) == 3 and isdir(join(path, suff))] self.replication_count += 1 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() try: responses = [] @@ -270,7 +270,7 @@ class ObjectReplicator(Daemon): """ self.replication_count += 1 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() try: hashed, local_hash = tpool_reraise( diff --git a/swift/obj/server.py b/swift/obj/server.py index d7b4ef292d..55c29aa284 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -46,7 +46,6 @@ from swift.common.swob import HTTPAccepted, HTTPBadRequest, HTTPCreated, \ HTTPInsufficientStorage, HTTPForbidden, HTTPException, HeaderKeyDict, \ HTTPConflict from swift.obj.diskfile import DATAFILE_SYSTEM_META, DiskFileManager -from swift.common.storage_policy import POLICY_INDEX class ObjectController(object): @@ -240,7 +239,7 @@ class ObjectController(object): headers_out['x-trans-id'] = headers_in.get('x-trans-id', '-') 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: self.async_update(op, account, container, obj, conthost, contpartition, contdevice, headers_out, @@ -270,7 +269,8 @@ class ObjectController(object): hosts = contdevices = [None] headers_in = request.headers 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-trans-id': headers_in.get('x-trans-id', '-'), 'referer': request.as_referer()}) diff --git a/swift/obj/ssync_receiver.py b/swift/obj/ssync_receiver.py index 24b417739c..248715d006 100644 --- a/swift/obj/ssync_receiver.py +++ b/swift/obj/ssync_receiver.py @@ -25,8 +25,6 @@ from swift.common import http from swift.common import swob from swift.common import utils -from swift.common.storage_policy import POLICY_INDEX - class Receiver(object): """ @@ -170,7 +168,8 @@ class Receiver(object): self.request.environ['eventlet.minimum_write_chunk_size'] = 0 self.device, self.partition = utils.split_path( 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) if self.app._diskfile_mgr.mount_check and \ not constraints.check_mount( @@ -354,7 +353,7 @@ class Receiver(object): subreq_iter()) else: 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' if replication_headers: subreq.headers['X-Backend-Replication-Headers'] = \ diff --git a/swift/obj/ssync_sender.py b/swift/obj/ssync_sender.py index b671bd3f30..e4a5910bc5 100644 --- a/swift/obj/ssync_sender.py +++ b/swift/obj/ssync_sender.py @@ -18,8 +18,6 @@ from swift.common import bufferedhttp from swift.common import exceptions from swift.common import http -from swift.common.storage_policy import POLICY_INDEX - class Sender(object): """ @@ -100,7 +98,8 @@ class Sender(object): self.connection.putrequest('REPLICATION', '/%s/%s' % ( self.node['device'], self.job['partition'])) 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() with exceptions.MessageTimeout( self.daemon.node_timeout, 'connect receive'): diff --git a/swift/obj/updater.py b/swift/obj/updater.py index 95f4357ec3..6a9e7a1a4c 100644 --- a/swift/obj/updater.py +++ b/swift/obj/updater.py @@ -26,7 +26,6 @@ from eventlet import patcher, Timeout from swift.common.bufferedhttp import http_connect from swift.common.exceptions import ConnectionTimeout from swift.common.ring import Ring -from swift.common.storage_policy import POLICY_INDEX from swift.common.utils import get_logger, renamer, write_pickle, \ dump_recon_cache, config_true_value, ismount from swift.common.daemon import Daemon @@ -222,7 +221,8 @@ class ObjectUpdater(Daemon): for node in nodes: if node['id'] not in successes: 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, headers) if not is_success(status) and status != HTTP_NOT_FOUND: diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py index 5d65e3c783..e1b2bdf42b 100644 --- a/swift/proxy/controllers/base.py +++ b/swift/proxy/controllers/base.py @@ -50,7 +50,7 @@ from swift.common.swob import Request, Response, HeaderKeyDict, Range, \ HTTPException, HTTPRequestedRangeNotSatisfiable 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 -from swift.common.storage_policy import POLICY_INDEX, POLICY, POLICIES +from swift.common.storage_policy import POLICIES 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'), 'bytes': headers.get('x-container-bytes-used'), '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': { 'allow_origin': meta.get('access-control-allow-origin'), 'expose_headers': meta.get('access-control-expose-headers'), @@ -1206,14 +1207,18 @@ class Controller(object): pass # if a backend policy index is present in resp headers, translate it # here with the friendly policy name - if POLICY_INDEX in res.headers and is_success(res.status_int): - policy = POLICIES.get_by_index(res.headers[POLICY_INDEX]) + if 'X-Backend-Storage-Policy-Index' in res.headers and \ + is_success(res.status_int): + policy = \ + POLICIES.get_by_index( + res.headers['X-Backend-Storage-Policy-Index']) if policy: - res.headers[POLICY] = policy.name + res.headers['X-Storage-Policy'] = policy.name else: self.app.logger.error( '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 def is_origin_allowed(self, cors_info, origin): diff --git a/swift/proxy/controllers/container.py b/swift/proxy/controllers/container.py index 5920561525..b61dd26320 100644 --- a/swift/proxy/controllers/container.py +++ b/swift/proxy/controllers/container.py @@ -23,7 +23,7 @@ from swift.common import constraints from swift.common.http import HTTP_ACCEPTED from swift.proxy.controllers.base import Controller, delay_denial, \ 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, \ HTTPNotFound @@ -55,7 +55,7 @@ class ContainerController(Controller): :param req: incoming request """ - policy_name = req.headers.get(POLICY) + policy_name = req.headers.get('X-Storage-Policy') if not policy_name: return policy = POLICIES.get_by_name(policy_name) @@ -63,7 +63,7 @@ class ContainerController(Controller): raise HTTPBadRequest(request=req, content_type="text/plain", body=("Invalid %s '%s'" - % (POLICY, policy_name))) + % ('X-Storage-Policy', policy_name))) if policy.is_deprecated: body = 'Storage Policy %r is deprecated' % (policy.name) raise HTTPBadRequest(request=req, body=body) @@ -214,7 +214,7 @@ class ContainerController(Controller): additional['X-Backend-Storage-Policy-Default'] = \ int(POLICIES.default) else: - additional[POLICY_INDEX] = str(policy_index) + additional['X-Backend-Storage-Policy-Index'] = str(policy_index) headers = [self.generate_request_headers(req, transfer=True, additional=additional) for _junk in range(n_outgoing)] diff --git a/swift/proxy/controllers/obj.py b/swift/proxy/controllers/obj.py index 63162f50ad..a6fafbbe17 100644 --- a/swift/proxy/controllers/obj.py +++ b/swift/proxy/controllers/obj.py @@ -56,7 +56,6 @@ from swift.common.swob import HTTPAccepted, HTTPBadRequest, HTTPNotFound, \ HTTPPreconditionFailed, HTTPRequestEntityTooLarge, HTTPRequestTimeout, \ HTTPServerError, HTTPServiceUnavailable, Request, \ HTTPClientDisconnect, HTTPNotImplemented -from swift.common.storage_policy import POLICY_INDEX from swift.common.request_helpers import is_user_meta @@ -197,10 +196,10 @@ class ObjectController(Controller): self.account_name, self.container_name, req) req.acl = container_info['read_acl'] # 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']) 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: aresp = req.environ['swift.authorize'](req) if aresp: @@ -303,10 +302,10 @@ class ObjectController(Controller): else: delete_at_container = delete_at_part = delete_at_nodes = None # 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']) 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( self.account_name, self.container_name, self.object_name) req.headers['X-Timestamp'] = Timestamp(time.time()).internal @@ -458,11 +457,11 @@ class ObjectController(Controller): body='If-None-Match only supports *') container_info = self.container_info( 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']) obj_ring = self.app.get_object_ring(policy_index) # 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'] containers = container_info['nodes'] req.acl = container_info['write_acl'] @@ -500,7 +499,8 @@ class ObjectController(Controller): (object_versions and not req.environ.get('swift_versioned_copy')): # 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'} hreq = Request.blank(req.path_info, headers=_headers, environ={'REQUEST_METHOD': 'HEAD'}) @@ -586,7 +586,7 @@ class ObjectController(Controller): src_container_name, src_obj_name) source_req = req.copy_get() # 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.headers['X-Newest'] = 'true' orig_obj_name = self.object_name @@ -777,11 +777,11 @@ class ObjectController(Controller): container_info = self.container_info( self.account_name, self.container_name, req) # 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']) obj_ring = self.app.get_object_ring(policy_index) # 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'] containers = container_info['nodes'] req.acl = container_info['write_acl'] @@ -838,7 +838,8 @@ class ObjectController(Controller): policy_idx = container_info['storage_policy'] obj_ring = self.app.get_object_ring(policy_idx) # 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'] containers = container_info['nodes'] new_del_req.acl = container_info['write_acl'] diff --git a/test/functional/tests.py b/test/functional/tests.py index c4e300f468..399200b92e 100644 --- a/test/functional/tests.py +++ b/test/functional/tests.py @@ -28,8 +28,6 @@ import uuid import eventlet from nose import SkipTest -from swift.common.storage_policy import POLICY - from test.functional import normalized_urls, load_constraint, cluster_info import test.functional as tf 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") if not cls.versions_container.create( - {POLICY: policy['name']}): + {'X-Storage-Policy': policy['name']}): raise ResponseError(cls.conn.response) cls.container = cls.account.container(prefix + "-objs") if not cls.container.create( hdrs={'X-Versions-Location': cls.versions_container.name, - POLICY: version_policy['name']}): + 'X-Storage-Policy': version_policy['name']}): raise ResponseError(cls.conn.response) container_info = cls.container.info() diff --git a/test/probe/test_container_merge_policy_index.py b/test/probe/test_container_merge_policy_index.py index 1090a2452a..7f49971d58 100644 --- a/test/probe/test_container_merge_policy_index.py +++ b/test/probe/test_container_merge_policy_index.py @@ -27,7 +27,7 @@ from nose import SkipTest from swift.common.manager import Manager from swift.common.internal_client import InternalClient 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 test.probe.common import reset_environment, get_to_final_state @@ -203,8 +203,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase): metadata = direct_client.direct_head_container( node, container_part, self.account, self.container_name) head_responses.append((node, metadata)) - found_policy_indexes = set(metadata[POLICY_INDEX] for - node, metadata in head_responses) + found_policy_indexes = \ + set(metadata['X-Backend-Storage-Policy-Index'] for + node, metadata in head_responses) self.assert_(len(found_policy_indexes) > 1, 'primary nodes did not disagree about policy index %r' % head_responses) @@ -218,7 +219,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase): try: direct_client.direct_head_object( 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: continue orig_policy_index = policy_index @@ -237,8 +240,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase): metadata = direct_client.direct_head_container( node, container_part, self.account, self.container_name) head_responses.append((node, metadata)) - found_policy_indexes = set(metadata[POLICY_INDEX] for - node, metadata in head_responses) + found_policy_indexes = \ + set(metadata['X-Backend-Storage-Policy-Index'] for + node, metadata in head_responses) self.assert_(len(found_policy_indexes) == 1, 'primary nodes disagree about policy index %r' % head_responses) @@ -253,7 +257,7 @@ class TestContainerMergePolicyIndex(unittest.TestCase): direct_client.direct_head_object( node, part, self.account, self.container_name, self.object_name, headers={ - POLICY_INDEX: orig_policy_index}) + 'X-Backend-Storage-Policy-Index': orig_policy_index}) except direct_client.ClientException as err: if err.http_status == HTTP_NOT_FOUND: continue @@ -299,8 +303,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase): metadata = direct_client.direct_head_container( node, container_part, self.account, self.container_name) head_responses.append((node, metadata)) - found_policy_indexes = set(metadata[POLICY_INDEX] for - node, metadata in head_responses) + found_policy_indexes = \ + set(metadata['X-Backend-Storage-Policy-Index'] for + node, metadata in head_responses) self.assert_(len(found_policy_indexes) > 1, 'primary nodes did not disagree about policy index %r' % head_responses) @@ -314,7 +319,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase): try: direct_client.direct_head_object( 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: if 'x-backend-timestamp' in err.http_headers: ts_policy_index = policy_index @@ -338,11 +345,13 @@ class TestContainerMergePolicyIndex(unittest.TestCase): metadata = direct_client.direct_head_container( node, container_part, self.account, self.container_name) head_responses.append((node, metadata)) - new_found_policy_indexes = set(metadata[POLICY_INDEX] for node, - metadata in head_responses) + new_found_policy_indexes = \ + set(metadata['X-Backend-Storage-Policy-Index'] for node, + metadata in head_responses) self.assert_(len(new_found_policy_indexes) == 1, '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)) expected_policy_index = new_found_policy_indexes.pop() self.assertEqual(orig_policy_index, expected_policy_index) @@ -355,7 +364,9 @@ class TestContainerMergePolicyIndex(unittest.TestCase): try: direct_client.direct_head_object( 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: if err.http_status == HTTP_NOT_FOUND: continue @@ -430,7 +441,7 @@ class TestContainerMergePolicyIndex(unittest.TestCase): 'x-container-device': ','.join(n['device'] for n in self.container_ring.devs), 'x-container-partition': container_part, - POLICY_INDEX: wrong_policy.idx, + 'X-Backend-Storage-Policy-Index': wrong_policy.idx, 'X-Static-Large-Object': 'True', } for node in nodes: diff --git a/test/probe/test_empty_device_handoff.py b/test/probe/test_empty_device_handoff.py index f154d1ad48..48641120e5 100755 --- a/test/probe/test_empty_device_handoff.py +++ b/test/probe/test_empty_device_handoff.py @@ -24,7 +24,6 @@ from uuid import uuid4 from swiftclient import 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.common.exceptions import ClientException 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() odata = direct_client.direct_get_object( 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': raise Exception('Direct object GET did not return VERIFY, instead ' 'it returned: %s' % repr(odata)) @@ -134,7 +133,7 @@ class TestEmptyDevice(TestCase): try: direct_client.direct_get_object( onode, opart, self.account, container, obj, headers={ - POLICY_INDEX: self.policy.idx}) + 'X-Backend-Storage-Policy-Index': self.policy.idx}) except ClientException as err: exc = err self.assertEquals(exc.http_status, 404) @@ -157,7 +156,7 @@ class TestEmptyDevice(TestCase): odata = direct_client.direct_get_object( 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': raise Exception('Direct object GET did not return VERIFY, instead ' 'it returned: %s' % repr(odata)) @@ -165,7 +164,7 @@ class TestEmptyDevice(TestCase): try: direct_client.direct_get_object( 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: exc = err self.assertEquals(exc.http_status, 404) diff --git a/test/probe/test_object_failures.py b/test/probe/test_object_failures.py index 1ea0fc25eb..204b38ccc2 100755 --- a/test/probe/test_object_failures.py +++ b/test/probe/test_object_failures.py @@ -23,7 +23,6 @@ from uuid import uuid4 from swiftclient import client from swift.common import direct_client -from swift.common.storage_policy import POLICY_INDEX from swift.common.exceptions import ClientException from swift.common.utils import hash_path, readconf 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( 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') try: direct_client.direct_get_object( 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") except ClientException as err: self.assertEquals(err.http_status, 404) @@ -109,7 +108,7 @@ class TestObjectFailures(TestCase): metadata = read_metadata(data_file) metadata['ETag'] = 'badetag' 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'), ({'Range': 'bytes=1-11'}, 'ANGE'), ({'Range': 'bytes=0-11'}, 'RANGE')]: @@ -123,7 +122,7 @@ class TestObjectFailures(TestCase): try: direct_client.direct_get_object( 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") except ClientException as err: self.assertEquals(err.http_status, 404) @@ -140,7 +139,8 @@ class TestObjectFailures(TestCase): try: direct_client.direct_get_object( 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") except ClientException as err: self.assertEquals(err.http_status, 404) @@ -157,7 +157,8 @@ class TestObjectFailures(TestCase): try: direct_client.direct_head_object( 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") except ClientException as err: self.assertEquals(err.http_status, 404) @@ -173,7 +174,7 @@ class TestObjectFailures(TestCase): write_metadata(fpointer, metadata) try: 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( onode, opart, self.account, container, obj, diff --git a/test/probe/test_object_handoff.py b/test/probe/test_object_handoff.py index 12ade94e1a..8fe8d7ffe8 100755 --- a/test/probe/test_object_handoff.py +++ b/test/probe/test_object_handoff.py @@ -20,7 +20,6 @@ from uuid import uuid4 from swiftclient import client from swift.common import direct_client -from swift.common.storage_policy import POLICY_INDEX from swift.common.exceptions import ClientException from swift.common.manager import Manager 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() odata = direct_client.direct_get_object( 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': raise Exception('Direct object GET did not return VERIFY, instead ' 'it returned: %s' % repr(odata)) @@ -113,7 +112,7 @@ class TestObjectHandoff(TestCase): try: direct_client.direct_get_object( onode, opart, self.account, container, obj, headers={ - POLICY_INDEX: self.policy.idx}) + 'X-Backend-Storage-Policy-Index': self.policy.idx}) except ClientException as err: exc = err self.assertEquals(exc.http_status, 404) @@ -133,7 +132,7 @@ class TestObjectHandoff(TestCase): Manager(['object-replicator']).once(number=another_num) odata = direct_client.direct_get_object( 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': raise Exception('Direct object GET did not return VERIFY, instead ' 'it returned: %s' % repr(odata)) @@ -141,7 +140,7 @@ class TestObjectHandoff(TestCase): try: direct_client.direct_get_object( 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: exc = err self.assertEquals(exc.http_status, 404) @@ -177,7 +176,7 @@ class TestObjectHandoff(TestCase): start_server(onode['port'], self.port2server, self.pids) direct_client.direct_get_object( 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 for node in onodes: try: @@ -192,7 +191,7 @@ class TestObjectHandoff(TestCase): try: direct_client.direct_get_object( 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: exc = err self.assertEquals(exc.http_status, 404) diff --git a/test/unit/account/test_reaper.py b/test/unit/account/test_reaper.py index d0a73ebca8..d9bd6eb1b6 100644 --- a/test/unit/account/test_reaper.py +++ b/test/unit/account/test_reaper.py @@ -30,7 +30,7 @@ from swift.common.exceptions import ClientException from swift.common.utils import normalize_timestamp 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): @@ -291,7 +291,7 @@ class TestReaper(unittest.TestCase): 'X-Container-Host': host, 'X-Container-Partition': 'partition', 'X-Container-Device': device, - POLICY_INDEX: policy.idx + 'X-Backend-Storage-Policy-Index': policy.idx } ring = r.get_object_ring(policy.idx) expected = call(ring.devs[i], 1, 'a', 'c', 'o', @@ -322,7 +322,7 @@ class TestReaper(unittest.TestCase): direct_get_container=DEFAULT, direct_delete_object=DEFAULT, direct_delete_container=DEFAULT) as mocks: - headers = {POLICY_INDEX: policy.idx} + headers = {'X-Backend-Storage-Policy-Index': policy.idx} obj_listing = [{'name': 'o'}] def fake_get_container(*args, **kwargs): @@ -340,7 +340,8 @@ class TestReaper(unittest.TestCase): self.assertEqual(3, len(mock_calls)) for call_args in mock_calls: _args, kwargs = call_args - self.assertEqual(kwargs['headers'][POLICY_INDEX], + self.assertEqual(kwargs['headers'] + ['X-Backend-Storage-Policy-Index'], policy.idx) self.assertEquals(mocks['direct_delete_container'].call_count, 3) diff --git a/test/unit/account/test_server.py b/test/unit/account/test_server.py index 0eca828998..26c63ebdc9 100644 --- a/test/unit/account/test_server.py +++ b/test/unit/account/test_server.py @@ -34,7 +34,7 @@ from swift.account.server import AccountController from swift.common.utils import normalize_timestamp, replication, public from swift.common.request_helpers import get_sys_meta_prefix 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 @@ -1723,7 +1723,7 @@ class TestAccountController(unittest.TestCase): 'X-Delete-Timestamp': '0', 'X-Object-Count': '2', 'X-Bytes-Used': '4', - POLICY_INDEX: policy.idx, + 'X-Backend-Storage-Policy-Index': policy.idx, }) resp = req.get_response(self.controller) self.assertEqual(resp.status_int, 201) @@ -1780,7 +1780,7 @@ class TestAccountController(unittest.TestCase): 'X-Delete-Timestamp': '0', 'X-Object-Count': '2', 'X-Bytes-Used': '4', - POLICY_INDEX: policy.idx, + 'X-Backend-Storage-Policy-Index': policy.idx, }) resp = req.get_response(self.controller) self.assertEqual(resp.status_int, 201) @@ -1812,7 +1812,7 @@ class TestAccountController(unittest.TestCase): 'X-Delete-Timestamp': '0', 'X-Object-Count': count, 'X-Bytes-Used': count, - POLICY_INDEX: policy.idx, + 'X-Backend-Storage-Policy-Index': policy.idx, }) resp = req.get_response(self.controller) self.assertEqual(resp.status_int, 201) diff --git a/test/unit/common/test_direct_client.py b/test/unit/common/test_direct_client.py index 90b6c1754f..535bc991d8 100644 --- a/test/unit/common/test_direct_client.py +++ b/test/unit/common/test_direct_client.py @@ -27,7 +27,7 @@ from swift.common import direct_client from swift.common.exceptions import ClientException from swift.common.utils import json, Timestamp 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 @@ -134,9 +134,11 @@ class TestDirectClient(unittest.TestCase): for add_ts in (True, False): now = time.time() 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[POLICY_INDEX], str(policy.idx)) + self.assertEqual(headers['X-Backend-Storage-Policy-Index'], + str(policy.idx)) expected_header_count = 2 if add_ts: expected_header_count += 1 diff --git a/test/unit/container/test_server.py b/test/unit/container/test_server.py index 757ce5ac97..7a9b7b7859 100644 --- a/test/unit/container/test_server.py +++ b/test/unit/container/test_server.py @@ -38,8 +38,7 @@ from swift.common import constraints from swift.common.utils import (Timestamp, mkdirs, public, replication, lock_parent_directory, json) from test.unit import fake_http_connect -from swift.common.storage_policy import (POLICY_INDEX, POLICIES, - StoragePolicy) +from swift.common.storage_policy import (POLICIES, StoragePolicy) from swift.common.request_helpers import get_sys_meta_prefix from test.unit import patch_policies @@ -87,7 +86,8 @@ class TestContainerController(unittest.TestCase): req = Request.blank(req.path, method='HEAD') resp = req.get_response(self.controller) 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): # no policy is OK @@ -100,7 +100,7 @@ class TestContainerController(unittest.TestCase): req = Request.blank('/sda1/p/a/c_%s' % policy, method='PUT', headers={ 'X-Timestamp': '0', - POLICY_INDEX: policy + 'X-Backend-Storage-Policy-Index': policy }) resp = req.get_response(self.controller) 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', headers={ 'X-Timestamp': '0', - POLICY_INDEX: policy.idx, + 'X-Backend-Storage-Policy-Index': + policy.idx, }) self._check_put_container_storage_policy(req, policy.idx) @@ -204,7 +205,8 @@ class TestContainerController(unittest.TestCase): Timestamp(start).normal) # backend headers - self.assertEqual(int(response.headers[POLICY_INDEX]), + self.assertEqual(int(response.headers + ['X-Backend-Storage-Policy-Index']), int(POLICIES.default)) self.assert_( Timestamp(response.headers['x-backend-timestamp']) >= start) @@ -219,7 +221,8 @@ class TestContainerController(unittest.TestCase): req = Request.blank('/sda1/p/a/c', method='HEAD') resp = req.get_response(self.controller) 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'], Timestamp(0).internal) self.assertEqual(resp.headers['x-backend-put-timestamp'], @@ -252,7 +255,8 @@ class TestContainerController(unittest.TestCase): resp = req.get_response(self.controller) self.assertEqual(resp.status_int, 404) # backend headers - self.assertEqual(int(resp.headers[POLICY_INDEX]), + self.assertEqual(int(resp.headers[ + 'X-Backend-Storage-Policy-Index']), int(POLICIES.default)) self.assert_(Timestamp(resp.headers['x-backend-timestamp']) >= Timestamp(request_method_times['PUT'])) @@ -363,14 +367,16 @@ class TestContainerController(unittest.TestCase): # Set metadata header req = Request.blank('/sda1/p/a/c', method='PUT', headers={'X-Timestamp': Timestamp(1).internal, - POLICY_INDEX: policy.idx}) + 'X-Backend-Storage-Policy-Index': + policy.idx}) resp = req.get_response(self.controller) self.assertEquals(resp.status_int, 201) # now make sure we read it back req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'}) 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): # Set metadata header @@ -382,14 +388,14 @@ class TestContainerController(unittest.TestCase): # now make sure the default was used (pol 1) req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'}) 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)) def test_PUT_bad_policy_specified(self): # Set metadata header req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'PUT'}, headers={'X-Timestamp': Timestamp(1).internal, - POLICY_INDEX: 'nada'}) + 'X-Backend-Storage-Policy-Index': 'nada'}) resp = req.get_response(self.controller) # make sure we get bad response self.assertEquals(resp.status_int, 400) @@ -400,20 +406,21 @@ class TestContainerController(unittest.TestCase): # Set metadata header req = Request.blank('/sda1/p/a/c', method='PUT', headers={ 'X-Timestamp': ts.next(), - POLICY_INDEX: policy.idx}) + 'X-Backend-Storage-Policy-Index': policy.idx}) resp = req.get_response(self.controller) self.assertEquals(resp.status_int, 201) req = Request.blank('/sda1/p/a/c') resp = req.get_response(self.controller) self.assertEquals(resp.status_int, 204) # 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 for method in ('POST', 'PUT'): req = Request.blank('/sda1/p/a/c', method=method, headers={ 'X-Timestamp': ts.next(), - POLICY_INDEX: policy.idx + 'X-Backend-Storage-Policy-Index': policy.idx }) resp = req.get_response(self.controller) 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'}) resp = req.get_response(self.controller) 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): ts = (Timestamp(t).internal for t in itertools.count(time.time())) @@ -429,21 +437,22 @@ class TestContainerController(unittest.TestCase): # Set metadata header req = Request.blank('/sda1/p/a/c', method='PUT', headers={ 'X-Timestamp': ts.next(), - POLICY_INDEX: policy.idx}) + 'X-Backend-Storage-Policy-Index': policy.idx}) resp = req.get_response(self.controller) self.assertEquals(resp.status_int, 201) req = Request.blank('/sda1/p/a/c') resp = req.get_response(self.controller) self.assertEquals(resp.status_int, 204) # 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] for other_policy in other_policies: # now try to change it and make sure we get a conflict req = Request.blank('/sda1/p/a/c', method='PUT', headers={ 'X-Timestamp': ts.next(), - POLICY_INDEX: other_policy.idx + 'X-Backend-Storage-Policy-Index': other_policy.idx }) resp = req.get_response(self.controller) self.assertEquals(resp.status_int, 409) @@ -453,28 +462,30 @@ class TestContainerController(unittest.TestCase): resp = req.get_response(self.controller) self.assertEquals(resp.status_int, 204) # 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): ts = (Timestamp(t).internal for t in itertools.count(time.time())) policy = random.choice(list(POLICIES)) req = Request.blank('/sda1/p/a/c', method='PUT', headers={ 'X-Timestamp': ts.next(), - POLICY_INDEX: policy.idx}) + 'X-Backend-Storage-Policy-Index': policy.idx}) resp = req.get_response(self.controller) self.assertEquals(resp.status_int, 201) req = Request.blank('/sda1/p/a/c') resp = req.get_response(self.controller) self.assertEquals(resp.status_int, 204) # 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] for other_policy in other_policies: # now try to change it and make sure we get a conflict req = Request.blank('/sda1/p/a/c', method='POST', headers={ 'X-Timestamp': ts.next(), - POLICY_INDEX: other_policy.idx + 'X-Backend-Storage-Policy-Index': other_policy.idx }) resp = req.get_response(self.controller) # valid request @@ -485,7 +496,9 @@ class TestContainerController(unittest.TestCase): resp = req.get_response(self.controller) self.assertEquals(resp.status_int, 204) # 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): ts = (Timestamp(t).internal for t in @@ -501,7 +514,7 @@ class TestContainerController(unittest.TestCase): req = Request.blank('/sda1/p/a/c', method='HEAD') resp = req.get_response(self.controller) 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)) # put again without specifying the storage policy @@ -515,7 +528,7 @@ class TestContainerController(unittest.TestCase): req = Request.blank('/sda1/p/a/c', method='HEAD') resp = req.get_response(self.controller) 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)) 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') resp = req.get_response(self.controller) 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)) # 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') resp = req.get_response(self.controller) 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)) 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 req = Request.blank('/sda1/p/a/c', method='PUT', headers={ '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) 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') resp = req.get_response(self.controller) 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)) # put again without specifiying the storage policy @@ -584,7 +597,7 @@ class TestContainerController(unittest.TestCase): req = Request.blank('/sda1/p/a/c', method='HEAD') resp = req.get_response(self.controller) 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)) def test_PUT_GET_metadata(self): @@ -1244,7 +1257,7 @@ class TestContainerController(unittest.TestCase): req = Request.blank( '/sda1/p/a/c', method='PUT', headers={'X-Timestamp': ts.next(), - POLICY_INDEX: policy.idx}) + 'X-Backend-Storage-Policy-Index': policy.idx}) resp = req.get_response(self.controller) 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 req = Request.blank('/sda1/p/a/c', method='PUT', headers={ 'X-Timestamp': ts.next(), - POLICY_INDEX: other_policy.idx}) + 'X-Backend-Storage-Policy-Index': other_policy.idx}) resp = req.get_response(self.controller) self.assertEqual(resp.status_int, 201) # sanity check req = Request.blank( '/sda1/p/a/c', method='HEAD') 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)) 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]) req = Request.blank('/sda1/p/a/c', method='PUT', headers={ '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) 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') 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)) def test_DELETE_object(self): @@ -1347,7 +1360,7 @@ class TestContainerController(unittest.TestCase): req = Request.blank('/sda1/p/a/c', method='HEAD') resp = req.get_response(self.controller) 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)) # create object obj_timestamp = ts.next() @@ -2381,7 +2394,7 @@ class TestContainerController(unittest.TestCase): 'x-delete-timestamp': '0', 'x-object-count': 0, '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', 'user-agent': 'container-server %d' % os.getpid(), 'x-trans-id': '-'})}) @@ -2399,7 +2412,7 @@ class TestContainerController(unittest.TestCase): 'x-delete-timestamp': '0', 'x-object-count': 0, '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', 'user-agent': 'container-server %d' % os.getpid(), 'x-trans-id': '-'})}) @@ -2551,10 +2564,11 @@ class TestNonLegacyDefaultStoragePolicy(TestContainerController): 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. """ - req.headers[POLICY_INDEX] = str(POLICIES.default.idx) + req.headers['X-Backend-Storage-Policy-Index'] = \ + str(POLICIES.default.idx) if __name__ == '__main__': diff --git a/test/unit/container/test_sync.py b/test/unit/container/test_sync.py index 0800937282..645c7935c3 100644 --- a/test/unit/container/test_sync.py +++ b/test/unit/container/test_sync.py @@ -23,7 +23,7 @@ from test.unit import FakeLogger from swift.container import sync from swift.common import utils 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 utils.HASH_PATH_SUFFIX = 'endcap' @@ -789,7 +789,8 @@ class TestContainerSync(unittest.TestCase): def fake_direct_get_object(node, part, account, container, obj, 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', 'etag': '"etagvalue"', 'x-timestamp': '1.2', '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, headers, resp_chunk_size=1): - self.assertEquals(headers[POLICY_INDEX], '0') + self.assertEquals(headers['X-Backend-Storage-Policy-Index'], + '0') return ({'date': 'date value', 'last-modified': 'last modified value', 'x-timestamp': '1.2', @@ -833,7 +835,8 @@ class TestContainerSync(unittest.TestCase): def fake_direct_get_object(node, part, account, container, obj, 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')) raise exc[-1] @@ -854,7 +857,8 @@ class TestContainerSync(unittest.TestCase): def fake_direct_get_object(node, part, account, container, obj, headers, resp_chunk_size=1): - self.assertEquals(headers[POLICY_INDEX], '0') + self.assertEquals(headers['X-Backend-Storage-Policy-Index'], + '0') if len(exc) == 0: exc.append(Exception('test other exception')) else: @@ -878,7 +882,8 @@ class TestContainerSync(unittest.TestCase): def fake_direct_get_object(node, part, account, container, obj, 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', 'x-timestamp': '1.2', 'etag': '"etagvalue"'}, iter('contents')) diff --git a/test/unit/obj/test_replicator.py b/test/unit/obj/test_replicator.py index 9a21bbf6c0..2b49f20167 100644 --- a/test/unit/obj/test_replicator.py +++ b/test/unit/obj/test_replicator.py @@ -31,7 +31,7 @@ from swift.common import utils from swift.common.utils import hash_path, mkdirs, normalize_timestamp from swift.common import ring 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(): @@ -706,7 +706,7 @@ class TestObjectReplicator(unittest.TestCase): for job in jobs: set_default(self) 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.assertTrue(error in mock_logger.error.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) # with only one set of headers make sure we speicy index 0 here # 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) reqs = [] for node in repl_job['nodes']: diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index a293ae99cf..67c24dd743 100755 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -44,7 +44,7 @@ from swift.common.utils import hash_path, mkdirs, normalize_timestamp, \ NullLogger, storage_directory, public, replication from swift.common import constraints 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 @@ -2311,7 +2311,8 @@ class TestObjectController(unittest.TestCase): self.object_controller.async_update( 'PUT', 'a', 'c', 'o', '127.0.0.1:1234', 1, 'sdc1', {'x-timestamp': '1', 'x-out': 'set', - POLICY_INDEX: policy.idx}, 'sda1', policy.idx) + 'X-Backend-Storage-Policy-Index': policy.idx}, 'sda1', + policy.idx) finally: object_server.http_connect = orig_http_connect self.assertEquals( @@ -2319,7 +2320,7 @@ class TestObjectController(unittest.TestCase): ['127.0.0.1', '1234', 'sdc1', 1, 'PUT', '/a/c/o', { 'x-timestamp': '1', 'x-out': 'set', '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), storage_policy.StoragePolicy(1, 'one'), @@ -2363,7 +2364,7 @@ class TestObjectController(unittest.TestCase): headers={'X-Timestamp': '12345', 'Content-Type': 'application/burrito', 'Content-Length': '0', - POLICY_INDEX: policy.idx, + 'X-Backend-Storage-Policy-Index': policy.idx, 'X-Container-Partition': '20', 'X-Container-Host': '1.2.3.4:5', 'X-Container-Device': 'sdb1', @@ -2396,10 +2397,10 @@ class TestObjectController(unittest.TestCase): 'x-etag': 'd41d8cd98f00b204e9800998ecf8427e', 'x-size': '0', 'x-timestamp': utils.Timestamp('12345').internal, - POLICY_INDEX: '37', + 'X-Backend-Storage-Policy-Index': '37', 'referer': 'PUT http://localhost/sda1/p/a/c/o', 'user-agent': 'obj-server %d' % os.getpid(), - POLICY_INDEX: policy.idx, + 'X-Backend-Storage-Policy-Index': policy.idx, 'x-trans-id': '-'})}) self.assertEquals( http_connect_args[1], @@ -2417,7 +2418,8 @@ class TestObjectController(unittest.TestCase): 'x-timestamp': utils.Timestamp('12345').internal, 'referer': 'PUT http://localhost/sda1/p/a/c/o', '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': '-'})}) self.assertEquals( http_connect_args[2], @@ -2435,7 +2437,8 @@ class TestObjectController(unittest.TestCase): 'x-timestamp': utils.Timestamp('12345').internal, 'referer': 'PUT http://localhost/sda1/p/a/c/o', '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': '-'})}) @patch_policies([storage_policy.StoragePolicy(0, 'zero', True), @@ -2476,7 +2479,7 @@ class TestObjectController(unittest.TestCase): headers={'X-Timestamp': '12345', 'Content-Type': 'application/burrito', 'Content-Length': '0', - POLICY_INDEX: '26', + 'X-Backend-Storage-Policy-Index': '26', 'X-Container-Partition': '20', 'X-Container-Host': '1.2.3.4:5, 6.7.8.9:10', 'X-Container-Device': 'sdb1, sdf1'}) @@ -2502,7 +2505,7 @@ class TestObjectController(unittest.TestCase): 'x-etag': 'd41d8cd98f00b204e9800998ecf8427e', 'x-size': '0', 'x-timestamp': utils.Timestamp('12345').internal, - POLICY_INDEX: '26', + 'X-Backend-Storage-Policy-Index': '26', 'referer': 'PUT http://localhost/sda1/p/a/c/o', 'user-agent': 'obj-server %d' % os.getpid(), 'x-trans-id': '-'})}) @@ -2520,7 +2523,7 @@ class TestObjectController(unittest.TestCase): 'x-etag': 'd41d8cd98f00b204e9800998ecf8427e', 'x-size': '0', 'x-timestamp': utils.Timestamp('12345').internal, - POLICY_INDEX: '26', + 'X-Backend-Storage-Policy-Index': '26', 'referer': 'PUT http://localhost/sda1/p/a/c/o', 'user-agent': 'obj-server %d' % os.getpid(), 'x-trans-id': '-'})}) @@ -2553,7 +2556,7 @@ class TestObjectController(unittest.TestCase): 'X-Delete-At-Partition': 'p', 'X-Delete-At-Host': '10.0.0.2:6002', 'X-Delete-At-Device': 'sda1', - POLICY_INDEX: int(policy), + 'X-Backend-Storage-Policy-Index': int(policy), }) with mocked_http_conn( 500, 500, give_connect=capture_updates) as fake_conn: @@ -2571,7 +2574,8 @@ class TestObjectController(unittest.TestCase): (delete_at_container, delete_at_timestamp)) expected = { '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(): self.assertEqual(headers[key], str(value)) @@ -2583,7 +2587,7 @@ class TestObjectController(unittest.TestCase): self.assertEqual(path, '/sda1/p/a/c/o') expected = { 'X-Timestamp': put_timestamp, - POLICY_INDEX: int(policy), + 'X-Backend-Storage-Policy-Index': int(policy), } for key, value in expected.items(): self.assertEqual(headers[key], str(value)) @@ -2598,10 +2602,12 @@ class TestObjectController(unittest.TestCase): data = pickle.load(open(async_file)) if data['account'] == 'a': self.assertEquals( - int(data['headers'][POLICY_INDEX]), policy.idx) + int(data['headers'] + ['X-Backend-Storage-Policy-Index']), policy.idx) elif data['account'] == '.expiring_objects': self.assertEquals( - int(data['headers'][POLICY_INDEX]), 0) + int(data['headers'] + ['X-Backend-Storage-Policy-Index']), 0) else: self.fail('unexpected async pending data') self.assertEqual(2, len(found_files)) @@ -2621,7 +2627,8 @@ class TestObjectController(unittest.TestCase): self.object_controller.async_update( 'PUT', 'a', 'c', 'o', '127.0.0.1:1234', 1, 'sdc1', {'x-timestamp': '1', 'x-out': 'set', - POLICY_INDEX: policy.idx}, 'sda1', policy.idx) + 'X-Backend-Storage-Policy-Index': policy.idx}, 'sda1', + policy.idx) finally: object_server.http_connect = orig_http_connect utils.HASH_PATH_PREFIX = _prefix @@ -2633,7 +2640,7 @@ class TestObjectController(unittest.TestCase): utils.Timestamp(1).internal))), {'headers': {'x-timestamp': '1', 'x-out': 'set', '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'}) def test_async_update_saves_on_non_2xx(self): @@ -2664,7 +2671,8 @@ class TestObjectController(unittest.TestCase): self.object_controller.async_update( 'PUT', 'a', 'c', 'o', '127.0.0.1:1234', 1, 'sdc1', {'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) self.assertEquals( pickle.load(open(os.path.join( @@ -2673,7 +2681,8 @@ class TestObjectController(unittest.TestCase): utils.Timestamp(1).internal))), {'headers': {'x-timestamp': '1', 'x-out': str(status), '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'}) finally: @@ -2799,7 +2808,7 @@ class TestObjectController(unittest.TestCase): 'x-etag': 'd41d8cd98f00b204e9800998ecf8427e', 'x-content-type': 'text/plain', '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', 'referer': 'PUT http://localhost/sda1/0/a/c/o'})) @@ -2900,7 +2909,7 @@ class TestObjectController(unittest.TestCase): 'DELETE', '.expiring_objects', '0000000000', '0000000002-a/c/o', None, None, None, HeaderKeyDict({ - POLICY_INDEX: 0, + 'X-Backend-Storage-Policy-Index': 0, 'x-timestamp': utils.Timestamp('1').internal, 'x-trans-id': '123', 'referer': 'PUT http://localhost/v1/a/c/o'}), @@ -2927,7 +2936,7 @@ class TestObjectController(unittest.TestCase): 'DELETE', '.expiring_objects', '0000000000', '0000000000-a/c/o', None, None, None, HeaderKeyDict({ - POLICY_INDEX: 0, + 'X-Backend-Storage-Policy-Index': 0, 'x-timestamp': utils.Timestamp('1').internal, 'x-trans-id': '1234', 'referer': 'PUT http://localhost/v1/a/c/o'}), @@ -2954,7 +2963,7 @@ class TestObjectController(unittest.TestCase): 'DELETE', '.expiring_objects', '9999936000', '9999999999-a/c/o', None, None, None, HeaderKeyDict({ - POLICY_INDEX: 0, + 'X-Backend-Storage-Policy-Index': 0, 'x-timestamp': utils.Timestamp('1').internal, 'x-trans-id': '1234', 'referer': 'PUT http://localhost/v1/a/c/o'}), @@ -2986,7 +2995,7 @@ class TestObjectController(unittest.TestCase): 'PUT', '.expiring_objects', '0000000000', '0000000002-a/c/o', '127.0.0.1:1234', '3', 'sdc1', HeaderKeyDict({ - POLICY_INDEX: 0, + 'X-Backend-Storage-Policy-Index': 0, 'x-size': '0', 'x-etag': 'd41d8cd98f00b204e9800998ecf8427e', 'x-content-type': 'text/plain', @@ -3040,7 +3049,7 @@ class TestObjectController(unittest.TestCase): 'DELETE', '.expiring_objects', '0000000000', '0000000002-a/c/o', None, None, None, HeaderKeyDict({ - POLICY_INDEX: 0, + 'X-Backend-Storage-Policy-Index': 0, 'x-timestamp': utils.Timestamp('1').internal, 'x-trans-id': '1234', 'referer': 'DELETE http://localhost/v1/a/c/o'}), @@ -4065,7 +4074,7 @@ class TestObjectController(unittest.TestCase): 'Content-Type': 'application/x-test', 'Foo': 'fooheader', 'Baz': 'bazheader', - POLICY_INDEX: 1, + 'X-Backend-Storage-Policy-Index': 1, 'X-Object-Meta-1': 'One', 'X-Object-Meta-Two': 'Two'}) req.body = 'VERIFY' diff --git a/test/unit/obj/test_ssync_receiver.py b/test/unit/obj/test_ssync_receiver.py index 5d21cbe1d6..9af76185b1 100644 --- a/test/unit/obj/test_ssync_receiver.py +++ b/test/unit/obj/test_ssync_receiver.py @@ -27,7 +27,6 @@ from swift.common import constraints from swift.common import exceptions from swift.common import swob from swift.common import utils -from swift.common.storage_policy import POLICY_INDEX from swift.obj import diskfile from swift.obj import server from swift.obj import ssync_receiver @@ -1066,7 +1065,7 @@ class TestReceiver(unittest.TestCase): 'Content-Encoding': 'gzip', 'Specialty-Header': 'value', 'Host': 'localhost:80', - POLICY_INDEX: '0', + 'X-Backend-Storage-Policy-Index': '0', 'X-Backend-Replication': 'True', 'X-Backend-Replication-Headers': ( 'content-length x-timestamp x-object-meta-test1 ' @@ -1117,7 +1116,7 @@ class TestReceiver(unittest.TestCase): 'Content-Encoding': 'gzip', 'Specialty-Header': 'value', 'Host': 'localhost:80', - POLICY_INDEX: '1', + 'X-Backend-Storage-Policy-Index': '1', 'X-Backend-Replication': 'True', 'X-Backend-Replication-Headers': ( 'content-length x-timestamp x-object-meta-test1 ' @@ -1155,7 +1154,7 @@ class TestReceiver(unittest.TestCase): self.assertEqual(req.headers, { 'X-Timestamp': '1364456113.76334', 'Host': 'localhost:80', - POLICY_INDEX: '0', + 'X-Backend-Storage-Policy-Index': '0', 'X-Backend-Replication': 'True', 'X-Backend-Replication-Headers': 'x-timestamp'}) @@ -1256,7 +1255,7 @@ class TestReceiver(unittest.TestCase): 'Content-Encoding': 'gzip', 'Specialty-Header': 'value', 'Host': 'localhost:80', - POLICY_INDEX: '0', + 'X-Backend-Storage-Policy-Index': '0', 'X-Backend-Replication': 'True', 'X-Backend-Replication-Headers': ( 'content-length x-timestamp x-object-meta-test1 ' @@ -1268,7 +1267,7 @@ class TestReceiver(unittest.TestCase): self.assertEqual(req.headers, { 'X-Timestamp': '1364456113.00002', 'Host': 'localhost:80', - POLICY_INDEX: '0', + 'X-Backend-Storage-Policy-Index': '0', 'X-Backend-Replication': 'True', 'X-Backend-Replication-Headers': 'x-timestamp'}) req = _requests.pop(0) @@ -1279,7 +1278,7 @@ class TestReceiver(unittest.TestCase): 'Content-Length': '3', 'X-Timestamp': '1364456113.00003', 'Host': 'localhost:80', - POLICY_INDEX: '0', + 'X-Backend-Storage-Policy-Index': '0', 'X-Backend-Replication': 'True', 'X-Backend-Replication-Headers': ( 'content-length x-timestamp')}) @@ -1292,7 +1291,7 @@ class TestReceiver(unittest.TestCase): 'Content-Length': '4', 'X-Timestamp': '1364456113.00004', 'Host': 'localhost:80', - POLICY_INDEX: '0', + 'X-Backend-Storage-Policy-Index': '0', 'X-Backend-Replication': 'True', 'X-Backend-Replication-Headers': ( 'content-length x-timestamp')}) @@ -1303,7 +1302,7 @@ class TestReceiver(unittest.TestCase): self.assertEqual(req.headers, { 'X-Timestamp': '1364456113.00005', 'Host': 'localhost:80', - POLICY_INDEX: '0', + 'X-Backend-Storage-Policy-Index': '0', 'X-Backend-Replication': 'True', 'X-Backend-Replication-Headers': 'x-timestamp'}) req = _requests.pop(0) @@ -1312,7 +1311,7 @@ class TestReceiver(unittest.TestCase): self.assertEqual(req.headers, { 'X-Timestamp': '1364456113.00006', 'Host': 'localhost:80', - POLICY_INDEX: '0', + 'X-Backend-Storage-Policy-Index': '0', 'X-Backend-Replication': 'True', 'X-Backend-Replication-Headers': 'x-timestamp'}) self.assertEqual(_requests, []) @@ -1376,7 +1375,7 @@ class TestReceiver(unittest.TestCase): 'Content-Length': '3', 'X-Timestamp': '1364456113.00001', 'Host': 'localhost:80', - POLICY_INDEX: '0', + 'X-Backend-Storage-Policy-Index': '0', 'X-Backend-Replication': 'True', 'X-Backend-Replication-Headers': ( 'content-length x-timestamp')}) @@ -1388,7 +1387,7 @@ class TestReceiver(unittest.TestCase): 'Content-Length': '1', 'X-Timestamp': '1364456113.00002', 'Host': 'localhost:80', - POLICY_INDEX: '0', + 'X-Backend-Storage-Policy-Index': '0', 'X-Backend-Replication': 'True', 'X-Backend-Replication-Headers': ( 'content-length x-timestamp')}) diff --git a/test/unit/obj/test_ssync_sender.py b/test/unit/obj/test_ssync_sender.py index 1a7b222d6b..34394a8df0 100644 --- a/test/unit/obj/test_ssync_sender.py +++ b/test/unit/obj/test_ssync_sender.py @@ -26,7 +26,6 @@ import mock from swift.common import exceptions, utils from swift.obj import ssync_sender, diskfile -from swift.common.storage_policy import POLICY_INDEX from test.unit import DebugLogger, patch_policies @@ -228,7 +227,7 @@ class TestSender(unittest.TestCase): ], 'putheader': [ mock.call('Transfer-Encoding', 'chunked'), - mock.call(POLICY_INDEX, 1), + mock.call('X-Backend-Storage-Policy-Index', 1), ], 'endheaders': [mock.call()], } diff --git a/test/unit/obj/test_updater.py b/test/unit/obj/test_updater.py index 12e3cf803f..e059bf04e3 100644 --- a/test/unit/obj/test_updater.py +++ b/test/unit/obj/test_updater.py @@ -37,7 +37,7 @@ from swift.common.utils import hash_path, normalize_timestamp, mkdirs, \ write_pickle from swift.common import swob 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), @@ -288,7 +288,8 @@ class TestObjectUpdater(unittest.TestCase): line.split(':')[1].strip() line = inc.readline() 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: return err return None @@ -392,7 +393,8 @@ class TestObjectUpdater(unittest.TestCase): for request_args, request_kwargs in request_log: ip, part, method, path, headers, qs, ssl = request_args 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(), {'successes': 1, 'unlinks': 1, 'async_pendings': 1}) @@ -420,7 +422,7 @@ class TestObjectUpdater(unittest.TestCase): 'x-content-type': 'text/plain', 'x-etag': 'd41d8cd98f00b204e9800998ecf8427e', 'x-timestamp': ts.next(), - POLICY_INDEX: policy.idx, + 'X-Backend-Storage-Policy-Index': policy.idx, }) data = {'op': op, 'account': account, 'container': container, 'obj': obj, 'headers': headers_out} @@ -444,7 +446,8 @@ class TestObjectUpdater(unittest.TestCase): for request_args, request_kwargs in request_log: ip, part, method, path, headers, qs, ssl = request_args 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(), {'successes': 1, 'unlinks': 1, 'async_pendings': 1}) diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index bd554e7c9e..c488a65a19 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -59,7 +59,7 @@ from swift.common.swob import Request, Response, HTTPUnauthorized, \ HTTPException from swift.common import storage_policy from swift.common.storage_policy import StoragePolicy, \ - StoragePolicyCollection, POLICIES, POLICY, POLICY_INDEX + StoragePolicyCollection, POLICIES from swift.common.request_helpers import get_sys_meta_prefix # mocks @@ -1729,7 +1729,7 @@ class TestObjectController(unittest.TestCase): 'X-Container-Device': device, 'Referer': 'POST http://localhost/v1/a/c/o', 'X-Object-Meta-Color': 'Blue', - POLICY_INDEX: '1' + 'X-Backend-Storage-Policy-Index': '1' }, } check_request(request, **expectations) @@ -1739,7 +1739,7 @@ class TestObjectController(unittest.TestCase): backend_requests = [] req = Request.blank('/v1/a/c/o', {}, method='POST', headers={'X-Object-Meta-Color': 'Blue', - POLICY_INDEX: 0}) + 'X-Backend-Storage-Policy-Index': 0}) with mocked_http_conn( 200, 200, 202, 202, 202, headers=resp_headers, give_connect=capture_requests @@ -1754,7 +1754,7 @@ class TestObjectController(unittest.TestCase): 'path': '/1/a/c/o', # ignore device bit 'headers': { 'X-Object-Meta-Color': 'Blue', - POLICY_INDEX: '0', + 'X-Backend-Storage-Policy-Index': '0', } } check_request(request, **expectations) @@ -1765,7 +1765,7 @@ class TestObjectController(unittest.TestCase): backend_requests = [] req = Request.blank('/v1/a/c/o', {}, method='POST', headers={'X-Object-Meta-Color': 'Blue', - POLICY_INDEX: 0}) + 'X-Backend-Storage-Policy-Index': 0}) with mocked_http_conn( 200, 200, 200, 200, 200, 201, 201, 201, headers=resp_headers, give_connect=capture_requests @@ -1774,8 +1774,8 @@ class TestObjectController(unittest.TestCase): self.assertRaises(StopIteration, fake_conn.code_iter.next) self.assertEqual(resp.status_int, 202) self.assertEqual(len(backend_requests), 8) - policy0 = {POLICY_INDEX: '0'} - policy1 = {POLICY_INDEX: '1'} + policy0 = {'X-Backend-Storage-Policy-Index': '0'} + policy1 = {'X-Backend-Storage-Policy-Index': '1'} expected = [ # account info {'method': 'HEAD', 'path': '/1/a'}, @@ -4234,8 +4234,10 @@ class TestObjectController(unittest.TestCase): headers=None, query_string=None): if method == "HEAD": self.assertEquals(path, '/a/c/o.jpg') - self.assertNotEquals(None, headers[POLICY_INDEX]) - self.assertEquals(1, int(headers[POLICY_INDEX])) + self.assertNotEquals(None, + headers['X-Backend-Storage-Policy-Index']) + self.assertEquals(1, int(headers + ['X-Backend-Storage-Policy-Index'])) def fake_container_info(account, container, req): return {'status': 200, 'sync_key': None, 'storage_policy': '1', @@ -4333,7 +4335,8 @@ class TestObjectController(unittest.TestCase): expected_storage_policy = 0 else: continue - storage_policy_index = int(headers[POLICY_INDEX]) + storage_policy_index = \ + int(headers['X-Backend-Storage-Policy-Index']) self.assertEqual( expected_storage_policy, storage_policy_index, 'Unexpected %s request for %s ' @@ -4829,7 +4832,7 @@ class TestContainerController(unittest.TestCase): for name, index in expected.items(): req = Request.blank('/a/c', headers={'Content-Length': '0', 'Content-Type': 'text/plain', - POLICY: name}) + 'X-Storage-Policy': name}) self.assertEqual(controller._convert_policy_to_index(req), index) # default test 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) # negative test 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, req) # storage policy two is deprecated req = Request.blank('/a/c', headers={'Content-Length': '0', 'Content-Type': 'text/plain', - POLICY: 'two'}) + 'X-Storage-Policy': 'two'}) self.assertRaises(HTTPException, controller._convert_policy_to_index, req) @@ -4852,33 +4856,34 @@ class TestContainerController(unittest.TestCase): req = Request.blank('/v1/a/c') with mocked_http_conn( 200, 200, - headers={POLICY_INDEX: int(policy)}, + headers={'X-Backend-Storage-Policy-Index': int(policy)}, ) as fake_conn: resp = req.get_response(self.app) self.assertRaises(StopIteration, fake_conn.code_iter.next) 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): policy = random.choice(list(POLICIES)) req = Request.blank('/v1/a/c') with mocked_http_conn( 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) self.assertRaises(StopIteration, fake_conn.code_iter.next) 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): req = Request.blank('/v1/a/c') with mocked_http_conn( 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) self.assertRaises(StopIteration, fake_conn.code_iter.next) 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') self.assertEqual(2, len(error_lines)) for msg in error_lines: @@ -5010,7 +5015,7 @@ class TestContainerController(unittest.TestCase): headers={'Content-Length': 0}) if requested_policy: expected_policy = requested_policy - req.headers[POLICY] = policy.name + req.headers['X-Storage-Policy'] = policy.name else: expected_policy = POLICIES.default res = req.get_response(self.app) @@ -5028,15 +5033,18 @@ class TestContainerController(unittest.TestCase): len(backend_requests)) for headers in backend_requests: if not requested_policy: - self.assertFalse(POLICY_INDEX in headers) + self.assertFalse('X-Backend-Storage-Policy-Index' in + headers) self.assertTrue( 'X-Backend-Storage-Policy-Default' in headers) self.assertEqual( int(expected_policy), int(headers['X-Backend-Storage-Policy-Default'])) else: - self.assertTrue(POLICY_INDEX in headers) - self.assertEqual(int(headers[POLICY_INDEX]), + self.assertTrue('X-Backend-Storage-Policy-Index' in + headers) + self.assertEqual(int(headers + ['X-Backend-Storage-Policy-Index']), policy.idx) # make sure all mocked responses are consumed self.assertRaises(StopIteration, mock_conn.code_iter.next)