Fix listing checkpoints by plan error with FS bank
When listing checkpoints by plan with using FS bank, it will fail with 'could not be found' error. The reason is, in the bank, checkpoints by plan are stored as "<bank_path>/karbor/indices/by-plan/<plan_id>/<project_id> /<date>/<checkpoint>", but the file bank plugin only list the <date> level, not include the checkpoint level. This patch will fix it. Closes-Bug: #1802815 Change-Id: I8c1356269277647490925e0181e2cd1dfca1fa4e
This commit is contained in:
parent
cf9b1c491e
commit
fd17f48547
|
@ -121,16 +121,11 @@ class FileSystemBankPlugin(BankPlugin):
|
|||
LOG.debug(_("Path is not a directory. name: %s"), obj_file_path)
|
||||
return ()
|
||||
try:
|
||||
if os.path.isdir(obj_file_path):
|
||||
return os.listdir(obj_file_path)
|
||||
else:
|
||||
base_dir = os.path.dirname(obj_file_path)
|
||||
base_name = os.path.basename(obj_file_path)
|
||||
return (
|
||||
base_dir + '/' + obj_file
|
||||
for obj_file in os.listdir(base_dir)
|
||||
if obj_file.startswith(base_name)
|
||||
)
|
||||
file_list = []
|
||||
for root, sub_dirs, files in os.walk(obj_file_path):
|
||||
for file_path in files:
|
||||
file_list.append(os.path.join(root, file_path))
|
||||
return file_list
|
||||
except OSError:
|
||||
LOG.exception(_("List the object failed. path: %s"), obj_file_path)
|
||||
raise
|
||||
|
@ -186,6 +181,7 @@ class FileSystemBankPlugin(BankPlugin):
|
|||
LOG.error("List objects failed. err: %s", err)
|
||||
raise exception.BankListObjectsFailed(reason=err)
|
||||
else:
|
||||
if prefix is not None:
|
||||
file_lists = [(prefix + file_name) for file_name in file_lists]
|
||||
container_path_length = len(self.object_container_path)
|
||||
file_lists = [(
|
||||
file_name[container_path_length:]) for file_name in file_lists]
|
||||
return file_lists[-limit:] if limit is not None else file_lists
|
||||
|
|
|
@ -59,6 +59,16 @@ class FileSystemBankPluginTest(base.TestCase):
|
|||
self.assertIn('/list/key-1', objects)
|
||||
self.assertIn('/list/key-2', objects)
|
||||
|
||||
def test_list_objects_with_contain_sub_dir(self):
|
||||
self.fs_bank_plugin.update_object("/list/key-1", "value-1")
|
||||
self.fs_bank_plugin.update_object("/list/sub/key-2", "value-2")
|
||||
self.fs_bank_plugin.update_object("/list/sub/key-3", "value-3")
|
||||
objects = self.fs_bank_plugin.list_objects(prefix="/list/")
|
||||
self.assertEqual(3, len(objects))
|
||||
self.assertIn("/list/key-1", objects)
|
||||
self.assertIn("/list/sub/key-2", objects)
|
||||
self.assertIn("/list/sub/key-3", objects)
|
||||
|
||||
def test_update_object(self):
|
||||
self.fs_bank_plugin.update_object("/key-1", "value-1")
|
||||
self.fs_bank_plugin.update_object("/key-1", "value-2")
|
||||
|
|
Loading…
Reference in New Issue