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:
openstackclient
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from novaclient import api_versions
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import exceptions
|
from osc_lib import exceptions
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
@ -67,9 +68,13 @@ class CreateServerGroup(command.ShowOne):
|
|||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
info = {}
|
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(
|
server_group = compute_client.server_groups.create(
|
||||||
name=parsed_args.name,
|
name=parsed_args.name, **policy_arg)
|
||||||
policies=[parsed_args.policy])
|
|
||||||
info.update(server_group._info)
|
info.update(server_group._info)
|
||||||
|
|
||||||
columns = _get_columns(info)
|
columns = _get_columns(info)
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
|
from novaclient import api_versions
|
||||||
from osc_lib import exceptions
|
from osc_lib import exceptions
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
|
|
||||||
@ -80,6 +81,28 @@ 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_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):
|
class TestServerGroupDelete(TestServerGroup):
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user