summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiaopengju <jiaopengju@cmss.chinamobile.com>2018-11-21 17:58:49 +0800
committerjiaopengju <jiaopengju@cmss.chinamobile.com>2018-11-21 17:58:49 +0800
commitb6342feeb6b8f7f8984f10962c3286416100ade8 (patch)
treee7e125ca3a99321ac994def2b1fc1d1ce27fd952
parentabab99c0eb57ceef1c9701000c16c0616fba3e2b (diff)
Add project id support for checkpoints filter
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: Thu, 22 Nov 2018 02:59:10 +0000 Reviewed-on: https://review.openstack.org/619188 Project: openstack/karbor Branch: refs/heads/master
-rw-r--r--karbor/services/protection/manager.py8
-rw-r--r--karbor/tests/unit/protection/test_manager.py40
2 files changed, 47 insertions, 1 deletions
diff --git a/karbor/services/protection/manager.py b/karbor/services/protection/manager.py
index 59aafcf..c3db38c 100644
--- a/karbor/services/protection/manager.py
+++ b/karbor/services/protection/manager.py
@@ -384,7 +384,13 @@ class ProtectionManager(manager.Manager):
384 384
385 sort_dir = None if sort_dirs is None else sort_dirs[0] 385 sort_dir = None if sort_dirs is None else sort_dirs[0]
386 provider = self.provider_registry.show_provider(provider_id) 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 checkpoint_ids = provider.list_checkpoints( 394 checkpoint_ids = provider.list_checkpoints(
389 project_id, provider_id, limit=limit, marker=marker, 395 project_id, provider_id, limit=limit, marker=marker,
390 plan_id=plan_id, start_date=start_date, end_date=end_date, 396 plan_id=plan_id, start_date=start_date, end_date=end_date,
diff --git a/karbor/tests/unit/protection/test_manager.py b/karbor/tests/unit/protection/test_manager.py
index ab23da3..7528f02 100644
--- a/karbor/tests/unit/protection/test_manager.py
+++ b/karbor/tests/unit/protection/test_manager.py
@@ -147,6 +147,46 @@ class ProtectionServiceTest(base.TestCase):
147 fakes.fake_protection_plan()) 147 fakes.fake_protection_plan())
148 148
149 @mock.patch.object(provider.ProviderRegistry, 'show_provider') 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
189 @mock.patch.object(provider.ProviderRegistry, 'show_provider')
150 def test_show_checkpoint(self, mock_provider): 190 def test_show_checkpoint(self, mock_provider):
151 mock_provider.return_value = fakes.FakeProvider() 191 mock_provider.return_value = fakes.FakeProvider()
152 context = mock.MagicMock(project_id='fake_project_id') 192 context = mock.MagicMock(project_id='fake_project_id')