Add policy support to objects

Objects now have a storage policy index associated with them as well;
this is determined by their filesystem path. Like before, objects in
policy 0 are in /srv/node/$disk/objects; this provides compatibility
on upgrade. (Recall that policy 0 is given to all existing data when a
cluster is upgraded.) Objects in policy 1 are in
/srv/node/$disk/objects-1, objects in policy 2 are in
/srv/node/$disk/objects-2, and so on.

Containers now have a storage policy index associated with them,
stored in the container_stat table. This index is only at container
creation time, and cannot be changed without deleting and recreating
the container. This is because a container's policy index applies to
all its objects, so changing a container's policy index would require
moving large amounts of object data around.  Thus, if it is desired to
change the policy for data in a container, the supported method would
be to create a new container with the desired policy and move the data
over.

This commit does not address replicators, auditors, or updaters except
where method signatures changed. They'll still work if your cluster
has only one storage policy, though.

Change-Id: I459f3ed97df516cb0c9294477c28729c30f48e09

Conflicts:
	test/unit/obj/test_server.py
	test/unit/proxy/controllers/test_obj.py

fixup simple proxy obj controller test

Change-Id: I65751f7a21c374c4936edf920c3ede4338df560f
Add Storage Policy Support to list_endpoints

This patch makes list_endpoints policy aware so that the object is
looked up in the right ring and its actual locations returned to the
client.

Change-Id: Ic33f54d806e85c969f65e6feab8ab45b16648975
Add storage policy support to object updates

The object server will now send its storage policy index to the
container server synchronously and asynchronously (via async_pending).

Each storage policy gets its own async_pending directory under
/srv/node/$disk/objects-$N, so there's no need to change the on-disk
pickle format; the policy index comes from the async_pending's
filename. This avoids any hassle on upgrade. (Recall that policy 0's
objects live in /srv/node/$disk/objects, not objects-0.)

Also clean up a couple little things in the object updater. Now it
won't abort processing when it encounters a file (not directory) named
"async_pending-\d+", and it won't process updates in a directory that
does not correspond to a storage policy.

That is, if you have policies 1, 2, and 3, but there's a directory on
your disk named "async_pending-5", the updater will now skip over that
entirely. It won't even bother doing directory listings at all. This
is a good idea, believe it or not, because there's nothing good that
the container server can do with an update from some unknown storage
policy. It can't update the listing, it can't move the object if it's
misplaced... all it can do is ignore the request, so it's better to
just not send it in the first place. Plus, if this is due to a
misconfiguration on one storage node, then the updates will get
processed once the configuration is fixed.

Change-Id: I07c730bebaee068f75024fa9c2fa9e11e295d9bd
Add Storage Policy Support to the Auditor

This patch makes the object auditor policy-aware, so it'll audit
objects in any storage policy.

Change-Id: I94e3a7937d9814b9ecef6ca35371e245a43513d3
Add storage policy support for the Replicator

This makes it so that objects stored in all policies get replicated
properly. This is only for rsync replication, not ssync.

Change-Id: Ifdb4624841f35953ba80189e669d3ef15d5563fd
Add Storage Policy Support to ssync

This patch makes ssync policy aware so that clusters using storage
policies and ssync replication will replicate objects in all policies.

Change-Id: I64879077676d764c6330e03734fc6665bb26f552
Put X-Timestamp in object 404 responses

This way the container reconciler can tell (sometimes) that an object
was deleted at a certain time.

Change-Id: Idaba3255f4109e5150d6c457f913c600fd8923eb
Allow overriding of storage policy index.

This is something the reconciler will need so that it can GET from one
policy, PUT in another, and then DELETE from the first one again.

Change-Id: Icd32332e330a967f634f96f29670671270eb074e
Add Storage Policy Support to Account HEAD

This change updates the account HEAD handler to report out per
policy object and byte usage for the account.  Cumulative values
are still reported and policy names are used in the report
out (unless request is sent to an account server directly in
which case policy indexes are used for easier accounting).

Below is an example of the relevant HEAD response for a cluster
with 3 policies and just a few small objects:

   X-Account-Container-Count: 3
   X-Account-Object-Count: 3
   X-Account-Bytes-Used: 21
   X-Storage-Policy-Bronze-Object-Count: 1
   X-Storage-Policy-Bronze-Bytes-Used: 7
   X-Storage-Policy-Silver-Object-Count: 1
   X-Storage-Policy-Silver-Bytes-Used: 7
   X-Storage-Policy-Gold-Object-Count: 1
   X-Storage-Policy-Gold-Bytes-Used: 7

Change-Id: I5ec251f9a8014dd89764340de927d09466c72221
Implements: blueprint storage-policies
Move Storage Policy validation from parser to class

Currently we validate Storage Policy conflicts while parsing
swift.conf in parse_storage_policies. This let's us get away
with unnatural things in tests like patch_policies with two
policies that have the same name.

Additionally this change makes the rules a bit easier to
identify and assure coverage.

Change-Id: I6cd48e5a3b3658e106ecd20df0b04fd804c028a4
Implements: blueprint storage-policies
Fix issue with account broker and pre-SPI databases

Set a DEFAULT storage_policy_index for existing container rows during
migration.

Copy existing object_count and bytes_used in policy_stat table during
migration.

Change-Id: I6b3f591bad455dcd072056c28fc5a37c3f618e40
Implements: blueprint storage-policies
Fixes versioning function tests with non-zero default policy

In each PUT, proxy-server will do HEAD request for container sync
and checking the object versions. This patch makes proxy-server
knows the non-zero default policy when HEADing

Change-Id: I29c5715a9dbc11d9f2ca9ccdfa7655beadf354f8
Minor refactor of storage policy helper functions

Pulled from a larger pending review where it became clear that
we didn't need to keep adding get_data_dir(index) type routines
so this patch makes a generic function in the policy module that
constructs strings given a base and a policy index then others
can use it directly or as a partial (as is done with get_data_dir()
for example)

Change-Id: Ia3bed58f4b8d52f44b8ab3e8fad8014231c19c50
Implements: blueprint storage-policies
Quick fix to Storage Policy Support for List Endpoints

The path being sent to get_container_info didn't include the ver
so downstream path parsers were off by one on interpretting
parms.  get_info is mocked in unit tests so not caught there,
found while doing an example for the docs.  The version doesn't
matter in this case, just need a placeholder so the downstream
functions get the parms correct.

Also added policy support for custom endpoint names which was
missing before and tightened up unit test coverage for both
functional issues addressed here.

Change-Id: I56d4b0f4f321a4c72b11ec44d868a194d02ea3a3
Implements: blueprint storage-policies
Add Storage Policy Support to Container Sync

Have container sync get its object ring from POLICIES now,
update tests to use policy index from container_info and pass
that along for use in ring selection.

Change-Id: If57d3b0ff8c395f21c81fda76458bc34fcb23257
Implements: blueprint storage-policies
Add Storage Policy Support to Recon Middleware

Recon middleware returns object ring file MD5 sums; this patch
updates it to include other object files that may be present
because of Storage Policies.  Also adds unit test coverage for
the MD5 reporting function which previously had none.

The recon script will now check all rings the server responds with
match the on-disk md5's regardless of server-type; including any
storage policy object rings.

Note the small change to the ring save method, needed to
stimulate the right code paths in 2.6 and 2.7 versions of
gzip to enable testing of ring MD5 sums.

Change-Id: I01efd2999d6d9c57ee8693ac3a6236ace17c5566
Implements: blueprint storage-policies

Conflicts:
	swift/cli/recon.py
	test/unit/cli/test_recon.py
Adding functional tests for Storage Policy

Change-Id: If17bc7b9737558d3b9a54eeb6ff3e6b51463f002

Conflicts:
	test/functional/__init__.py
Fix X-Backend-Storage-Policy-Index requests

The reconciler needs to make PUT/GET requests to specific Storage Policies
despite the cached value of the container_info.

The existing implementation was pulling the request header after it had
already selected the ring and was placing objects on the wrong devices.

Change-Id: I2f92b9ddc1179e0223bcb33fc4cfead50db0ae78
Fix recursive Policy patching

When using test.unit.patch_policies on a TestCase that subclasses a patched
TestCase the mock policies would be unwound too early.  This change allows you
to subclass a TestCase decorated with patch_policies and get the parent
classes effective POLICIES.

Change-Id: I1b5baefe1ae4281e3be8a5f772994aff4065f981
Cleanup container update headers in obj server tests

The object server tests for container backed headers were doing a match
expectation against the backend HeaderKeyDict using a real dict so in tests
the keys were needlessly case sensitive.  This change updates the tests so
they perform correct assertions with case insensitive header keys and removes
some needless string manipulation in the obj server added to satisfy the
overly picky unittests.

There's also a drive by fix to update some backend http mocks for container
update tests that we're not fully exercising their their request fakes.
Because the object server container update code is resilient to to all manor
of failure from backend requests the general intent of the tests was
unaffected but this change cleans up some confusing logging in the debug
logger output.

Change-Id: Iea5ed128b62fd2dc17f55cd8076b711e6087dd26