Use right most occurrence object dir in diskfile.extract_policy
I like using the rightmost one more; it's basically /operator-defined/mountpoint/objects/part/suffix/hash/ts.data, so I don't see any opportunity for other things named "objects" to creep in on the right of the real objects-N dir; but I could see some admin using /srv/object-storage/ or something -- Torgomatic The Wise Change-Id: I0a63a3e02df091a5ee2e110a345183012e357a2f
This commit is contained in:
parent
3d9b2d077a
commit
83025ff38d
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user