Merge "Use right most occurrence object dir in diskfile.extract_policy"

This commit is contained in:
Jenkins 2015-07-27 21:26:16 +00:00 committed by Gerrit Code Review
commit 3691c08e98
3 changed files with 4 additions and 10 deletions

View File

@ -366,12 +366,7 @@ def print_obj(datafile, check_etag=True, swift_dir='/etc/swift',
# try to extract policy index from datafile disk path
fullpath = os.path.abspath(datafile)
try:
# obj_path should be device-relative path of an object
obj_path = fullpath[fullpath.rindex('objects'):]
except ValueError:
obj_path = fullpath
policy_index = int(extract_policy(obj_path) or POLICIES.legacy)
policy_index = int(extract_policy(fullpath) or POLICIES.legacy)
try:
if policy_index:

View File

@ -175,11 +175,11 @@ def extract_policy(obj_path):
objects-5/179/485dc017205a81df3af616d917c90179/1401811134.873649.data
:param obj_path: device-relative path of an object
:param obj_path: device-relative path of an object, or the full path
:returns: a :class:`~swift.common.storage_policy.BaseStoragePolicy` or None
"""
try:
obj_portion = obj_path[obj_path.index(DATADIR_BASE):]
obj_portion = obj_path[obj_path.rindex(DATADIR_BASE):]
obj_dirname = obj_portion[:obj_portion.index('/')]
except Exception:
return None

View File

@ -399,9 +399,8 @@ class TestPrintObjFullMeta(TestCliInfoBase):
os.chdir(hash_dir)
with mock.patch('sys.stdout', out):
print_obj(file_name, swift_dir=self.testdir)
finally:
os.chdir(cwd)
except OSError: # Failure case of os.chdir
self.fail("Unexpected exception raised")
self.assertTrue('X-Backend-Storage-Policy-Index: 1' in out.getvalue())
def test_print_obj_meta_and_ts_files(self):