Fix unbalanced rings after initial creation.

Sometimes you'd make a ring that should have a good balance (~= 1),
but it would come out with a poor balance (>= 90). Rebalancing a
couple times would fix it, but it shouldn't be necessary to do that.

This was due to a bug in the ring builder's rebalance() method where,
when placing a replica for a partition, it would pick *one of* the
tiers with the lowest number of replicas, but the choice was made
without regard to parts_wanted.  Now rebalancing pays attention to the
drives' parts_wanted attributes, so the tier with the emptiest drive
gets the replica.

(Also fixed a typo in a completely unrelated comment.)

Change-Id: I1821f15170f0ed212b0ad7c81b97031540ab4460
Made the signature of HeaderKeyDict.__init__ match dict's

Change-Id: I75dc6228bc39de44f58d7ae9beb8ca3bf24b100f
Refactor finalize_put as an object method

Change-Id: Iec3f53c564505c29739bb5531a71a0a101f64193
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Rename DiskFile.writer to create

Change-Id: I3af71c64dd4c61e665fe128a0b5241fd87ba71e0
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Add a delete() method to DiskFile

In preparation for making the DiskFile class an abstraction layer for
the backend to all the object server REST API services, we add a
simple delete method which encapsulates the required behavior.

Change-Id: I539ad53c297e4c572e2f93c2524188fb89b2db40
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Perform fewer stat calls when doing auditing of objects

Each `isdir` or `exists` call performs a stat, but that info is already
available from the exception if it doesn't exist in `listdir`.

Change-Id: I831494e3dbc8fda62ab29431471566bdb8dc6d27
Remove reference to 'file' built-in

Change-Id: Ie79e8ede393e92824fd906df1ff1933193c00943
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Merge "Remove reference to 'file' built-in"
Merge "Refactor finalize_put as an object method"
Provide a method for retrieving on-disk metadata

We hide the internal dictionary for the metadata providing a method to
retrieve it to abstract away the implementation details of how
DiskFile object provides and maintains that metadata.

This is in anticipation of the DiskFile API refactoring.

Change-Id: I1c0dc01a4680bd435512405e2d31fba24421720a
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Do not use locals() for string formatting (H501)

Fixes a warning triggered by Hacking 0.7.x or newer. There
is no need to use a positional string formatting here, since
this is not going to be localized.

Change-Id: Ie38d620aecb0b48cd113af45cc9ca0d61f8f8ff1
Use Python 3.x compatible except construct

except x,y: was deprected and is removed in Python 3.x.
Use "except x as y:" instead which works in any Python
version >= 2.6.

Change-Id: I7008c74b807340f3457d3a0c8bd0b83f23169d14
Move string expansion outside localisation (H702)

String expansion should be done outside localisation call (_()),
otherwise there will never be a matching string found in the
catalogue.

Also enable gating on this Hacking check (H702).

Change-Id: Ie7c89fbfb52629e75d5e68e9afda8bcf50bf4cdd
Merge "Made the signature of HeaderKeyDict.__init__ match dict's"
Don't stat the path in ``unlink_older_than``

``listdir`` already handles the ENOENT and returns an empty list in
that case.

Change-Id: I597d7ffa9979f668a856519062839505d26129f2
Fixed a suite that was over-indented

Change-Id: I3d05b29e57b77c3751d9f5ff694085bd082e8eb1
Merge "Do not use locals() for string formatting (H501)"
Merge "Use Python 3.x compatible except construct"
Merge "Move string expansion outside localisation (H702)"
Merge "Fix unbalanced rings after initial creation."