Validate 'server group create --policy' option
We were documenting that some of these policies were only supported with specific microversions, however, we weren't actually enforcing that, leading to a poor user experience. Correct this. Change-Id: Ic3c555226a220efd9b0f27edffccf6c4c95c2747 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
375fe31525
commit
ab0b1fe885
@ -56,12 +56,18 @@ class CreateServerGroup(command.ShowOne):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--policy',
|
'--policy',
|
||||||
metavar='<policy>',
|
metavar='<policy>',
|
||||||
|
choices=[
|
||||||
|
'affinity',
|
||||||
|
'anti-affinity',
|
||||||
|
'soft-affinity',
|
||||||
|
'soft-anti-affinity',
|
||||||
|
],
|
||||||
default='affinity',
|
default='affinity',
|
||||||
help=_("Add a policy to <name> "
|
help=_(
|
||||||
"('affinity' or 'anti-affinity', "
|
"Add a policy to <name> "
|
||||||
"defaults to 'affinity'). Specify --os-compute-api-version "
|
"Specify --os-compute-api-version 2.15 or higher for the "
|
||||||
"2.15 or higher for the 'soft-affinity' or "
|
"'soft-affinity' or 'soft-anti-affinity' policy."
|
||||||
"'soft-anti-affinity' policy.")
|
)
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@ -69,9 +75,18 @@ class CreateServerGroup(command.ShowOne):
|
|||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
info = {}
|
info = {}
|
||||||
|
|
||||||
|
if parsed_args.policy in ('soft-affinity', 'soft-anti-affinity'):
|
||||||
|
if compute_client.api_version < api_versions.APIVersion('2.15'):
|
||||||
|
msg = _(
|
||||||
|
'--os-compute-api-version 2.15 or greater is required to '
|
||||||
|
'support the %s policy'
|
||||||
|
)
|
||||||
|
raise exceptions.CommandError(msg % parsed_args.policy)
|
||||||
|
|
||||||
policy_arg = {'policies': [parsed_args.policy]}
|
policy_arg = {'policies': [parsed_args.policy]}
|
||||||
if compute_client.api_version >= api_versions.APIVersion("2.64"):
|
if compute_client.api_version >= api_versions.APIVersion("2.64"):
|
||||||
policy_arg = {'policy': parsed_args.policy}
|
policy_arg = {'policy': parsed_args.policy}
|
||||||
|
|
||||||
server_group = compute_client.server_groups.create(
|
server_group = compute_client.server_groups.create(
|
||||||
name=parsed_args.name, **policy_arg)
|
name=parsed_args.name, **policy_arg)
|
||||||
|
|
||||||
|
@ -90,6 +90,28 @@ class TestServerGroupCreate(TestServerGroup):
|
|||||||
self.cmd = server_group.CreateServerGroup(self.app, None)
|
self.cmd = server_group.CreateServerGroup(self.app, None)
|
||||||
|
|
||||||
def test_server_group_create(self):
|
def test_server_group_create(self):
|
||||||
|
arglist = [
|
||||||
|
'--policy', 'anti-affinity',
|
||||||
|
'affinity_group',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('policy', 'anti-affinity'),
|
||||||
|
('name', 'affinity_group'),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
self.server_groups_mock.create.assert_called_once_with(
|
||||||
|
name=parsed_args.name,
|
||||||
|
policies=[parsed_args.policy],
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(self.data, data)
|
||||||
|
|
||||||
|
def test_server_group_create_with_soft_policies(self):
|
||||||
|
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||||
|
'2.15')
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
'--policy', 'soft-anti-affinity',
|
'--policy', 'soft-anti-affinity',
|
||||||
'affinity_group',
|
'affinity_group',
|
||||||
@ -108,6 +130,27 @@ class TestServerGroupCreate(TestServerGroup):
|
|||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.data, data)
|
self.assertEqual(self.data, data)
|
||||||
|
|
||||||
|
def test_server_group_create_with_soft_policies_pre_v215(self):
|
||||||
|
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||||
|
'2.14')
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--policy', 'soft-anti-affinity',
|
||||||
|
'affinity_group',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('policy', 'soft-anti-affinity'),
|
||||||
|
('name', 'affinity_group'),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
ex = self.assertRaises(
|
||||||
|
exceptions.CommandError,
|
||||||
|
self.cmd.take_action,
|
||||||
|
parsed_args)
|
||||||
|
self.assertIn(
|
||||||
|
'--os-compute-api-version 2.15 or greater is required',
|
||||||
|
str(ex))
|
||||||
|
|
||||||
def test_server_group_create_v264(self):
|
def test_server_group_create_v264(self):
|
||||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||||
'2.64')
|
'2.64')
|
||||||
|
Loading…
Reference in New Issue
Block a user