Merge "Add option to filter for projects when listing volume backups"
This commit is contained in:
@@ -17,6 +17,7 @@ from openstack.block_storage.v3 import backup as _backup
|
|||||||
from openstack.block_storage.v3 import snapshot as _snapshot
|
from openstack.block_storage.v3 import snapshot as _snapshot
|
||||||
from openstack.block_storage.v3 import volume as _volume
|
from openstack.block_storage.v3 import volume as _volume
|
||||||
from openstack import exceptions as sdk_exceptions
|
from openstack import exceptions as sdk_exceptions
|
||||||
|
from openstack.identity.v3 import project as _project
|
||||||
from openstack.test import fakes as sdk_fakes
|
from openstack.test import fakes as sdk_fakes
|
||||||
from osc_lib import exceptions
|
from osc_lib import exceptions
|
||||||
|
|
||||||
@@ -381,6 +382,7 @@ class TestBackupList(volume_fakes.TestVolume):
|
|||||||
("marker", None),
|
("marker", None),
|
||||||
("limit", None),
|
("limit", None),
|
||||||
('all_projects', False),
|
('all_projects', False),
|
||||||
|
("project", None),
|
||||||
]
|
]
|
||||||
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
@@ -395,11 +397,14 @@ class TestBackupList(volume_fakes.TestVolume):
|
|||||||
all_tenants=False,
|
all_tenants=False,
|
||||||
marker=None,
|
marker=None,
|
||||||
limit=None,
|
limit=None,
|
||||||
|
project_id=None,
|
||||||
)
|
)
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertCountEqual(self.data, list(data))
|
self.assertCountEqual(self.data, list(data))
|
||||||
|
|
||||||
def test_backup_list_with_options(self):
|
def test_backup_list_with_options(self):
|
||||||
|
project = sdk_fakes.generate_fake_resource(_project.Project)
|
||||||
|
self.identity_sdk_client.find_project.return_value = project
|
||||||
arglist = [
|
arglist = [
|
||||||
"--long",
|
"--long",
|
||||||
"--name",
|
"--name",
|
||||||
@@ -413,6 +418,8 @@ class TestBackupList(volume_fakes.TestVolume):
|
|||||||
"--all-projects",
|
"--all-projects",
|
||||||
"--limit",
|
"--limit",
|
||||||
"3",
|
"3",
|
||||||
|
"--project",
|
||||||
|
project.id,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
("long", True),
|
("long", True),
|
||||||
@@ -422,6 +429,7 @@ class TestBackupList(volume_fakes.TestVolume):
|
|||||||
("marker", self.backups[0].id),
|
("marker", self.backups[0].id),
|
||||||
('all_projects', True),
|
('all_projects', True),
|
||||||
("limit", 3),
|
("limit", 3),
|
||||||
|
("project", project.id),
|
||||||
]
|
]
|
||||||
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
@@ -440,6 +448,7 @@ class TestBackupList(volume_fakes.TestVolume):
|
|||||||
all_tenants=True,
|
all_tenants=True,
|
||||||
marker=self.backups[0].id,
|
marker=self.backups[0].id,
|
||||||
limit=3,
|
limit=3,
|
||||||
|
project_id=project.id,
|
||||||
)
|
)
|
||||||
self.assertEqual(self.columns_long, columns)
|
self.assertEqual(self.columns_long, columns)
|
||||||
self.assertCountEqual(self.data_long, list(data))
|
self.assertCountEqual(self.data_long, list(data))
|
||||||
|
|||||||
@@ -236,6 +236,11 @@ class ListVolumeBackup(command.Lister):
|
|||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super().get_parser(prog_name)
|
parser = super().get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'--project',
|
||||||
|
metavar='<project>',
|
||||||
|
help=_('Filter results by project (name or ID) (admin only)'),
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--long",
|
"--long",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
@@ -296,6 +301,7 @@ class ListVolumeBackup(command.Lister):
|
|||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
volume_client = self.app.client_manager.sdk_connection.volume
|
volume_client = self.app.client_manager.sdk_connection.volume
|
||||||
|
identity_client = self.app.client_manager.sdk_connection.identity
|
||||||
|
|
||||||
columns: tuple[str, ...] = (
|
columns: tuple[str, ...] = (
|
||||||
'id',
|
'id',
|
||||||
@@ -332,6 +338,14 @@ class ListVolumeBackup(command.Lister):
|
|||||||
VolumeIdColumn, volume_cache=volume_cache
|
VolumeIdColumn, volume_cache=volume_cache
|
||||||
)
|
)
|
||||||
|
|
||||||
|
all_tenants = parsed_args.all_projects
|
||||||
|
project_id = None
|
||||||
|
if parsed_args.project:
|
||||||
|
all_tenants = True
|
||||||
|
project_id = identity_client.find_project(
|
||||||
|
parsed_args.project, ignore_missing=False
|
||||||
|
).id
|
||||||
|
|
||||||
filter_volume_id = None
|
filter_volume_id = None
|
||||||
if parsed_args.volume:
|
if parsed_args.volume:
|
||||||
try:
|
try:
|
||||||
@@ -360,9 +374,10 @@ class ListVolumeBackup(command.Lister):
|
|||||||
name=parsed_args.name,
|
name=parsed_args.name,
|
||||||
status=parsed_args.status,
|
status=parsed_args.status,
|
||||||
volume_id=filter_volume_id,
|
volume_id=filter_volume_id,
|
||||||
all_tenants=parsed_args.all_projects,
|
all_tenants=all_tenants,
|
||||||
marker=marker_backup_id,
|
marker=marker_backup_id,
|
||||||
limit=parsed_args.limit,
|
limit=parsed_args.limit,
|
||||||
|
project_id=project_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add ``--project`` option to ``volume backup list`` command,
|
||||||
|
to allow filtering for projects when listing volume backups.
|
||||||
Reference in New Issue
Block a user