Skip to content

Commit 492a184

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add option to filter for projects when listing volume backups"
2 parents b0763f9 + 305e037 commit 492a184

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

openstackclient/tests/unit/volume/v3/test_volume_backup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from openstack.block_storage.v3 import snapshot as _snapshot
1818
from openstack.block_storage.v3 import volume as _volume
1919
from openstack import exceptions as sdk_exceptions
20+
from openstack.identity.v3 import project as _project
2021
from openstack.test import fakes as sdk_fakes
2122
from osc_lib import exceptions
2223

@@ -381,6 +382,7 @@ def test_backup_list_without_options(self):
381382
("marker", None),
382383
("limit", None),
383384
('all_projects', False),
385+
("project", None),
384386
]
385387

386388
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -395,11 +397,14 @@ def test_backup_list_without_options(self):
395397
all_tenants=False,
396398
marker=None,
397399
limit=None,
400+
project_id=None,
398401
)
399402
self.assertEqual(self.columns, columns)
400403
self.assertCountEqual(self.data, list(data))
401404

402405
def test_backup_list_with_options(self):
406+
project = sdk_fakes.generate_fake_resource(_project.Project)
407+
self.identity_sdk_client.find_project.return_value = project
403408
arglist = [
404409
"--long",
405410
"--name",
@@ -413,6 +418,8 @@ def test_backup_list_with_options(self):
413418
"--all-projects",
414419
"--limit",
415420
"3",
421+
"--project",
422+
project.id,
416423
]
417424
verifylist = [
418425
("long", True),
@@ -422,6 +429,7 @@ def test_backup_list_with_options(self):
422429
("marker", self.backups[0].id),
423430
('all_projects', True),
424431
("limit", 3),
432+
("project", project.id),
425433
]
426434

427435
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -440,6 +448,7 @@ def test_backup_list_with_options(self):
440448
all_tenants=True,
441449
marker=self.backups[0].id,
442450
limit=3,
451+
project_id=project.id,
443452
)
444453
self.assertEqual(self.columns_long, columns)
445454
self.assertCountEqual(self.data_long, list(data))

openstackclient/volume/v3/volume_backup.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ class ListVolumeBackup(command.Lister):
236236

237237
def get_parser(self, prog_name):
238238
parser = super().get_parser(prog_name)
239+
parser.add_argument(
240+
'--project',
241+
metavar='<project>',
242+
help=_('Filter results by project (name or ID) (admin only)'),
243+
)
239244
parser.add_argument(
240245
"--long",
241246
action="store_true",
@@ -296,6 +301,7 @@ def get_parser(self, prog_name):
296301

297302
def take_action(self, parsed_args):
298303
volume_client = self.app.client_manager.sdk_connection.volume
304+
identity_client = self.app.client_manager.sdk_connection.identity
299305

300306
columns: tuple[str, ...] = (
301307
'id',
@@ -332,6 +338,14 @@ def take_action(self, parsed_args):
332338
VolumeIdColumn, volume_cache=volume_cache
333339
)
334340

341+
all_tenants = parsed_args.all_projects
342+
project_id = None
343+
if parsed_args.project:
344+
all_tenants = True
345+
project_id = identity_client.find_project(
346+
parsed_args.project, ignore_missing=False
347+
).id
348+
335349
filter_volume_id = None
336350
if parsed_args.volume:
337351
try:
@@ -360,9 +374,10 @@ def take_action(self, parsed_args):
360374
name=parsed_args.name,
361375
status=parsed_args.status,
362376
volume_id=filter_volume_id,
363-
all_tenants=parsed_args.all_projects,
377+
all_tenants=all_tenants,
364378
marker=marker_backup_id,
365379
limit=parsed_args.limit,
380+
project_id=project_id,
366381
)
367382

368383
return (
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add ``--project`` option to ``volume backup list`` command,
5+
to allow filtering for projects when listing volume backups.

0 commit comments

Comments
 (0)