Merge "Use right most occurrence object dir in diskfile.extract_policy"
This commit is contained in:
commit
3691c08e98
@ -366,12 +366,7 @@ def print_obj(datafile, check_etag=True, swift_dir='/etc/swift',
|
|||||||
|
|
||||||
# try to extract policy index from datafile disk path
|
# try to extract policy index from datafile disk path
|
||||||
fullpath = os.path.abspath(datafile)
|
fullpath = os.path.abspath(datafile)
|
||||||
try:
|
policy_index = int(extract_policy(fullpath) or POLICIES.legacy)
|
||||||
# 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)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if policy_index:
|
if policy_index:
|
||||||
|
@ -175,11 +175,11 @@ def extract_policy(obj_path):
|
|||||||
|
|
||||||
objects-5/179/485dc017205a81df3af616d917c90179/1401811134.873649.data
|
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
|
:returns: a :class:`~swift.common.storage_policy.BaseStoragePolicy` or None
|
||||||
"""
|
"""
|
||||||
try:
|
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('/')]
|
obj_dirname = obj_portion[:obj_portion.index('/')]
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
@ -399,9 +399,8 @@ class TestPrintObjFullMeta(TestCliInfoBase):
|
|||||||
os.chdir(hash_dir)
|
os.chdir(hash_dir)
|
||||||
with mock.patch('sys.stdout', out):
|
with mock.patch('sys.stdout', out):
|
||||||
print_obj(file_name, swift_dir=self.testdir)
|
print_obj(file_name, swift_dir=self.testdir)
|
||||||
|
finally:
|
||||||
os.chdir(cwd)
|
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())
|
self.assertTrue('X-Backend-Storage-Policy-Index: 1' in out.getvalue())
|
||||||
|
|
||||||
def test_print_obj_meta_and_ts_files(self):
|
def test_print_obj_meta_and_ts_files(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user