summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiaopengju <jiaopengju@cmss.chinamobile.com>2018-11-12 12:43:29 +0800
committerjiaopengju <jiaopengju@cmss.chinamobile.com>2018-11-12 12:48:25 +0800
commitfd17f48547553dbef3d36a79cb3670b61cdeb817 (patch)
treedd4547bcb899d2017dae5fead96bf5ce57ab8cb8
parentcf9b1c491e3fbac4ae64debba735718e9952d80a (diff)
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
Notes
Notes (review): Code-Review+2: Jiao Pengju <jiaopengju@cmss.chinamobile.com> Workflow+1: Jiao Pengju <jiaopengju@cmss.chinamobile.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 12 Nov 2018 06:04:25 +0000 Reviewed-on: https://review.openstack.org/617224 Project: openstack/karbor Branch: refs/heads/master
-rw-r--r--karbor/services/protection/bank_plugins/file_system_bank_plugin.py20
-rw-r--r--karbor/tests/unit/protection/test_file_system_bank_plugin.py10
2 files changed, 18 insertions, 12 deletions
diff --git a/karbor/services/protection/bank_plugins/file_system_bank_plugin.py b/karbor/services/protection/bank_plugins/file_system_bank_plugin.py
index 381f919..9fe0815 100644
--- a/karbor/services/protection/bank_plugins/file_system_bank_plugin.py
+++ b/karbor/services/protection/bank_plugins/file_system_bank_plugin.py
@@ -121,16 +121,11 @@ class FileSystemBankPlugin(BankPlugin):
121 LOG.debug(_("Path is not a directory. name: %s"), obj_file_path) 121 LOG.debug(_("Path is not a directory. name: %s"), obj_file_path)
122 return () 122 return ()
123 try: 123 try:
124 if os.path.isdir(obj_file_path): 124 file_list = []
125 return os.listdir(obj_file_path) 125 for root, sub_dirs, files in os.walk(obj_file_path):
126 else: 126 for file_path in files:
127 base_dir = os.path.dirname(obj_file_path) 127 file_list.append(os.path.join(root, file_path))
128 base_name = os.path.basename(obj_file_path) 128 return file_list
129 return (
130 base_dir + '/' + obj_file
131 for obj_file in os.listdir(base_dir)
132 if obj_file.startswith(base_name)
133 )
134 except OSError: 129 except OSError:
135 LOG.exception(_("List the object failed. path: %s"), obj_file_path) 130 LOG.exception(_("List the object failed. path: %s"), obj_file_path)
136 raise 131 raise
@@ -186,6 +181,7 @@ class FileSystemBankPlugin(BankPlugin):
186 LOG.error("List objects failed. err: %s", err) 181 LOG.error("List objects failed. err: %s", err)
187 raise exception.BankListObjectsFailed(reason=err) 182 raise exception.BankListObjectsFailed(reason=err)
188 else: 183 else:
189 if prefix is not None: 184 container_path_length = len(self.object_container_path)
190 file_lists = [(prefix + file_name) for file_name in file_lists] 185 file_lists = [(
186 file_name[container_path_length:]) for file_name in file_lists]
191 return file_lists[-limit:] if limit is not None else file_lists 187 return file_lists[-limit:] if limit is not None else file_lists
diff --git a/karbor/tests/unit/protection/test_file_system_bank_plugin.py b/karbor/tests/unit/protection/test_file_system_bank_plugin.py
index a708906..f07c76a 100644
--- a/karbor/tests/unit/protection/test_file_system_bank_plugin.py
+++ b/karbor/tests/unit/protection/test_file_system_bank_plugin.py
@@ -59,6 +59,16 @@ class FileSystemBankPluginTest(base.TestCase):
59 self.assertIn('/list/key-1', objects) 59 self.assertIn('/list/key-1', objects)
60 self.assertIn('/list/key-2', objects) 60 self.assertIn('/list/key-2', objects)
61 61
62 def test_list_objects_with_contain_sub_dir(self):
63 self.fs_bank_plugin.update_object("/list/key-1", "value-1")
64 self.fs_bank_plugin.update_object("/list/sub/key-2", "value-2")
65 self.fs_bank_plugin.update_object("/list/sub/key-3", "value-3")
66 objects = self.fs_bank_plugin.list_objects(prefix="/list/")
67 self.assertEqual(3, len(objects))
68 self.assertIn("/list/key-1", objects)
69 self.assertIn("/list/sub/key-2", objects)
70 self.assertIn("/list/sub/key-3", objects)
71
62 def test_update_object(self): 72 def test_update_object(self):
63 self.fs_bank_plugin.update_object("/key-1", "value-1") 73 self.fs_bank_plugin.update_object("/key-1", "value-1")
64 self.fs_bank_plugin.update_object("/key-1", "value-2") 74 self.fs_bank_plugin.update_object("/key-1", "value-2")