Merge "compute: Improve 'server migration list' options"
This commit is contained in:
commit
6905e97565
@ -2369,21 +2369,21 @@ class ListMigration(command.Lister):
|
||||
parser.add_argument(
|
||||
'--project',
|
||||
metavar='<project>',
|
||||
dest='project_id',
|
||||
help=_(
|
||||
"Filter migrations by project (ID) "
|
||||
"Filter migrations by project (name or ID) "
|
||||
"(supported with --os-compute-api-version 2.80 or above)"
|
||||
),
|
||||
)
|
||||
identity_common.add_project_domain_option_to_parser(parser)
|
||||
parser.add_argument(
|
||||
'--user',
|
||||
metavar='<user>',
|
||||
dest='user_id',
|
||||
help=_(
|
||||
"Filter migrations by user (ID) "
|
||||
"Filter migrations by user (name or ID) "
|
||||
"(supported with --os-compute-api-version 2.80 or above)"
|
||||
),
|
||||
)
|
||||
identity_common.add_user_domain_option_to_parser(parser)
|
||||
return parser
|
||||
|
||||
def print_migrations(self, parsed_args, compute_client, migrations):
|
||||
@ -2402,9 +2402,9 @@ class ListMigration(command.Lister):
|
||||
columns.insert(len(columns) - 2, "Type")
|
||||
|
||||
if compute_client.api_version >= api_versions.APIVersion("2.80"):
|
||||
if parsed_args.project_id:
|
||||
if parsed_args.project:
|
||||
columns.insert(len(columns) - 2, "Project")
|
||||
if parsed_args.user_id:
|
||||
if parsed_args.user:
|
||||
columns.insert(len(columns) - 2, "User")
|
||||
|
||||
return (
|
||||
@ -2414,6 +2414,7 @@ class ListMigration(command.Lister):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.compute
|
||||
identity_client = self.app.client_manager.identity
|
||||
|
||||
search_opts = {
|
||||
'host': parsed_args.host,
|
||||
@ -2469,23 +2470,33 @@ class ListMigration(command.Lister):
|
||||
raise exceptions.CommandError(msg)
|
||||
search_opts['changes_before'] = parsed_args.changes_before
|
||||
|
||||
if parsed_args.project_id:
|
||||
if parsed_args.project:
|
||||
if compute_client.api_version < api_versions.APIVersion('2.80'):
|
||||
msg = _(
|
||||
'--os-compute-api-version 2.80 or greater is required to '
|
||||
'support the --project option'
|
||||
)
|
||||
raise exceptions.CommandError(msg)
|
||||
search_opts['project_id'] = parsed_args.project_id
|
||||
|
||||
if parsed_args.user_id:
|
||||
search_opts['project_id'] = identity_common.find_project(
|
||||
identity_client,
|
||||
parsed_args.project,
|
||||
parsed_args.project_domain,
|
||||
).id
|
||||
|
||||
if parsed_args.user:
|
||||
if compute_client.api_version < api_versions.APIVersion('2.80'):
|
||||
msg = _(
|
||||
'--os-compute-api-version 2.80 or greater is required to '
|
||||
'support the --user option'
|
||||
)
|
||||
raise exceptions.CommandError(msg)
|
||||
search_opts['user_id'] = parsed_args.user_id
|
||||
|
||||
search_opts['user_id'] = identity_common.find_user(
|
||||
identity_client,
|
||||
parsed_args.user,
|
||||
parsed_args.user_domain,
|
||||
).id
|
||||
|
||||
migrations = compute_client.migrations.list(**search_opts)
|
||||
|
||||
|
@ -28,6 +28,7 @@ from osc_lib import utils as common_utils
|
||||
|
||||
from openstackclient.compute.v2 import server
|
||||
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
|
||||
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
|
||||
from openstackclient.tests.unit.image.v2 import fakes as image_fakes
|
||||
from openstackclient.tests.unit.network.v2 import fakes as network_fakes
|
||||
from openstackclient.tests.unit import utils
|
||||
@ -4548,9 +4549,21 @@ class TestListMigrationV280(TestListMigration):
|
||||
'Old Flavor', 'New Flavor', 'Type', 'Created At', 'Updated At'
|
||||
]
|
||||
|
||||
project = identity_fakes.FakeProject.create_one_project()
|
||||
user = identity_fakes.FakeUser.create_one_user()
|
||||
|
||||
def setUp(self):
|
||||
super(TestListMigrationV280, self).setUp()
|
||||
|
||||
self.projects_mock = self.app.client_manager.identity.projects
|
||||
self.projects_mock.reset_mock()
|
||||
|
||||
self.users_mock = self.app.client_manager.identity.users
|
||||
self.users_mock.reset_mock()
|
||||
|
||||
self.projects_mock.get.return_value = self.project
|
||||
self.users_mock.get.return_value = self.user
|
||||
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.80')
|
||||
|
||||
@ -4561,7 +4574,7 @@ class TestListMigrationV280(TestListMigration):
|
||||
'--marker', 'test_kp',
|
||||
'--changes-since', '2019-08-07T08:03:25Z',
|
||||
'--changes-before', '2019-08-09T08:03:25Z',
|
||||
'--project', '0c2accde-644a-45fa-8c10-e76debc7fbc3'
|
||||
'--project', self.project.id
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
@ -4569,7 +4582,7 @@ class TestListMigrationV280(TestListMigration):
|
||||
('marker', 'test_kp'),
|
||||
('changes_since', '2019-08-07T08:03:25Z'),
|
||||
('changes_before', '2019-08-09T08:03:25Z'),
|
||||
('project_id', '0c2accde-644a-45fa-8c10-e76debc7fbc3')
|
||||
('project', self.project.id)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
@ -4580,7 +4593,7 @@ class TestListMigrationV280(TestListMigration):
|
||||
'limit': 1,
|
||||
'marker': 'test_kp',
|
||||
'host': None,
|
||||
'project_id': '0c2accde-644a-45fa-8c10-e76debc7fbc3',
|
||||
'project_id': self.project.id,
|
||||
'changes_since': '2019-08-07T08:03:25Z',
|
||||
'changes_before': "2019-08-09T08:03:25Z",
|
||||
}
|
||||
@ -4605,7 +4618,7 @@ class TestListMigrationV280(TestListMigration):
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
('changes_before', '2019-08-09T08:03:25Z'),
|
||||
('project_id', '0c2accde-644a-45fa-8c10-e76debc7fbc3')
|
||||
('project', '0c2accde-644a-45fa-8c10-e76debc7fbc3')
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
@ -4623,7 +4636,7 @@ class TestListMigrationV280(TestListMigration):
|
||||
'--marker', 'test_kp',
|
||||
'--changes-since', '2019-08-07T08:03:25Z',
|
||||
'--changes-before', '2019-08-09T08:03:25Z',
|
||||
'--user', 'dd214878-ca12-40fb-b035-fa7d2c1e86d6'
|
||||
'--user', self.user.id,
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
@ -4631,7 +4644,7 @@ class TestListMigrationV280(TestListMigration):
|
||||
('marker', 'test_kp'),
|
||||
('changes_since', '2019-08-07T08:03:25Z'),
|
||||
('changes_before', '2019-08-09T08:03:25Z'),
|
||||
('user_id', 'dd214878-ca12-40fb-b035-fa7d2c1e86d6')
|
||||
('user', self.user.id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
@ -4642,7 +4655,7 @@ class TestListMigrationV280(TestListMigration):
|
||||
'limit': 1,
|
||||
'marker': 'test_kp',
|
||||
'host': None,
|
||||
'user_id': 'dd214878-ca12-40fb-b035-fa7d2c1e86d6',
|
||||
'user_id': self.user.id,
|
||||
'changes_since': '2019-08-07T08:03:25Z',
|
||||
'changes_before': "2019-08-09T08:03:25Z",
|
||||
}
|
||||
@ -4662,12 +4675,12 @@ class TestListMigrationV280(TestListMigration):
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--changes-before', '2019-08-09T08:03:25Z',
|
||||
'--user', 'dd214878-ca12-40fb-b035-fa7d2c1e86d6'
|
||||
'--user', self.user.id,
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
('changes_before', '2019-08-09T08:03:25Z'),
|
||||
('user_id', 'dd214878-ca12-40fb-b035-fa7d2c1e86d6')
|
||||
('user', self.user.id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
@ -4684,16 +4697,16 @@ class TestListMigrationV280(TestListMigration):
|
||||
'--limit', '1',
|
||||
'--changes-since', '2019-08-07T08:03:25Z',
|
||||
'--changes-before', '2019-08-09T08:03:25Z',
|
||||
'--project', '0c2accde-644a-45fa-8c10-e76debc7fbc3',
|
||||
'--user', 'dd214878-ca12-40fb-b035-fa7d2c1e86d6'
|
||||
'--project', self.project.id,
|
||||
'--user', self.user.id,
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
('limit', 1),
|
||||
('changes_since', '2019-08-07T08:03:25Z'),
|
||||
('changes_before', '2019-08-09T08:03:25Z'),
|
||||
('project_id', '0c2accde-644a-45fa-8c10-e76debc7fbc3'),
|
||||
('user_id', 'dd214878-ca12-40fb-b035-fa7d2c1e86d6')
|
||||
('project', self.project.id),
|
||||
('user', self.user.id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
@ -4703,8 +4716,8 @@ class TestListMigrationV280(TestListMigration):
|
||||
'status': 'migrating',
|
||||
'limit': 1,
|
||||
'host': None,
|
||||
'project_id': '0c2accde-644a-45fa-8c10-e76debc7fbc3',
|
||||
'user_id': 'dd214878-ca12-40fb-b035-fa7d2c1e86d6',
|
||||
'project_id': self.project.id,
|
||||
'user_id': self.user.id,
|
||||
'changes_since': '2019-08-07T08:03:25Z',
|
||||
'changes_before': "2019-08-09T08:03:25Z",
|
||||
}
|
||||
@ -4727,14 +4740,14 @@ class TestListMigrationV280(TestListMigration):
|
||||
arglist = [
|
||||
'--status', 'migrating',
|
||||
'--changes-before', '2019-08-09T08:03:25Z',
|
||||
'--project', '0c2accde-644a-45fa-8c10-e76debc7fbc3',
|
||||
'--user', 'dd214878-ca12-40fb-b035-fa7d2c1e86d6'
|
||||
'--project', self.project.id,
|
||||
'--user', self.user.id,
|
||||
]
|
||||
verifylist = [
|
||||
('status', 'migrating'),
|
||||
('changes_before', '2019-08-09T08:03:25Z'),
|
||||
('project_id', '0c2accde-644a-45fa-8c10-e76debc7fbc3'),
|
||||
('user_id', 'dd214878-ca12-40fb-b035-fa7d2c1e86d6')
|
||||
('project', self.project.id),
|
||||
('user', self.user.id)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
ex = self.assertRaises(
|
||||
|
Loading…
x
Reference in New Issue
Block a user