Add API check for server_groups.create
The policies field has been replaced with the policy field since Nova API version 2.64[1] This commit adds a check to make sure the correct field is used. [1]https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#id59 Change-Id: I06d3211937d822c26070b7f8ad757c365dcbb1bb Story: #2007822 Task: #40101
This commit is contained in:
parent
8b7a2c8d59
commit
51a1ea65f4
openstackclient
@ -17,6 +17,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from novaclient import api_versions
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
@ -67,9 +68,13 @@ class CreateServerGroup(command.ShowOne):
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.compute
|
||||
info = {}
|
||||
|
||||
policy_arg = {'policies': [parsed_args.policy]}
|
||||
if compute_client.api_version >= api_versions.APIVersion("2.64"):
|
||||
policy_arg = {'policy': parsed_args.policy}
|
||||
server_group = compute_client.server_groups.create(
|
||||
name=parsed_args.name,
|
||||
policies=[parsed_args.policy])
|
||||
name=parsed_args.name, **policy_arg)
|
||||
|
||||
info.update(server_group._info)
|
||||
|
||||
columns = _get_columns(info)
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from novaclient import api_versions
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
|
||||
@ -80,6 +81,28 @@ class TestServerGroupCreate(TestServerGroup):
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
def test_server_group_create_v264(self):
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.64')
|
||||
|
||||
arglist = [
|
||||
'--policy', 'soft-anti-affinity',
|
||||
'affinity_group',
|
||||
]
|
||||
verifylist = [
|
||||
('policy', 'soft-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,
|
||||
policy=parsed_args.policy,
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
|
||||
class TestServerGroupDelete(TestServerGroup):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user