Browse Source

Add project id support for checkpoints filter

Change-Id: I93ab8a3a503045fb8a7612cf47bbfa014ac00fd2
jiaopengju 5 months ago
parent
commit
b6342feeb6

+ 7
- 1
karbor/services/protection/manager.py View File

@@ -384,7 +384,13 @@ class ProtectionManager(manager.Manager):
384 384
 
385 385
         sort_dir = None if sort_dirs is None else sort_dirs[0]
386 386
         provider = self.provider_registry.show_provider(provider_id)
387
-        project_id = context.project_id
387
+
388
+        if filters.get('project_id', None) and all_tenants:
389
+            project_id = filters.get('project_id')
390
+            all_tenants = False
391
+        else:
392
+            project_id = context.project_id
393
+
388 394
         checkpoint_ids = provider.list_checkpoints(
389 395
             project_id, provider_id, limit=limit, marker=marker,
390 396
             plan_id=plan_id, start_date=start_date, end_date=end_date,

+ 40
- 0
karbor/tests/unit/protection/test_manager.py View File

@@ -146,6 +146,46 @@ class ProtectionServiceTest(base.TestCase):
146 146
                           None,
147 147
                           fakes.fake_protection_plan())
148 148
 
149
+    @mock.patch.object(provider.ProviderRegistry, 'show_provider')
150
+    def test_list_checkpoints(self, mock_provider):
151
+        fake_provider = fakes.FakeProvider()
152
+        fake_provider.list_checkpoints = mock.MagicMock()
153
+        mock_provider.return_value = fake_provider
154
+        context = mock.MagicMock(project_id='fake_project_id')
155
+        self.pro_manager.list_checkpoints(context, 'provider1', filters={},
156
+                                          all_tenants=False)
157
+        fake_provider.list_checkpoints.assert_called_once_with(
158
+            'fake_project_id', 'provider1', limit=None, marker=None,
159
+            plan_id=None, start_date=None, end_date=None,
160
+            sort_dir=None, context=context, all_tenants=False)
161
+
162
+    @mock.patch.object(provider.ProviderRegistry, 'show_provider')
163
+    def test_list_checkpoints_with_all_tenants(self, mock_provider):
164
+        fake_provider = fakes.FakeProvider()
165
+        fake_provider.list_checkpoints = mock.MagicMock()
166
+        mock_provider.return_value = fake_provider
167
+        context = mock.MagicMock(project_id='fake_project_id')
168
+        self.pro_manager.list_checkpoints(context, 'provider1', filters={},
169
+                                          all_tenants=True)
170
+        fake_provider.list_checkpoints.assert_called_once_with(
171
+            'fake_project_id', 'provider1', limit=None, marker=None,
172
+            plan_id=None, start_date=None, end_date=None,
173
+            sort_dir=None, context=context, all_tenants=True)
174
+
175
+    @mock.patch.object(provider.ProviderRegistry, 'show_provider')
176
+    def test_list_checkpoints_with_all_tenants_and_filter_by_project_id(
177
+            self, mock_provider):
178
+        fake_provider = fakes.FakeProvider()
179
+        fake_provider.list_checkpoints = mock.MagicMock()
180
+        mock_provider.return_value = fake_provider
181
+        context = mock.MagicMock(project_id='fake_project_id')
182
+        self.pro_manager.list_checkpoints(context, 'provider1', filters={
183
+            'project_id': 'fake_project_id1'}, all_tenants=True)
184
+        fake_provider.list_checkpoints.assert_called_once_with(
185
+            'fake_project_id1', 'provider1', limit=None, marker=None,
186
+            plan_id=None, start_date=None, end_date=None,
187
+            sort_dir=None, context=context, all_tenants=False)
188
+
149 189
     @mock.patch.object(provider.ProviderRegistry, 'show_provider')
150 190
     def test_show_checkpoint(self, mock_provider):
151 191
         mock_provider.return_value = fakes.FakeProvider()

Loading…
Cancel
Save