Router flavor_id can be a name

Change-Id: I72fc21a1adb4790a2a51e9b37744ee1ee3d01f32
Partial-Bug: #2020823
This commit is contained in:
elajkat 2023-12-05 14:01:36 +01:00
parent 25f2e22429
commit 2e7ba5e3dd
3 changed files with 42 additions and 3 deletions

View File

@ -13,6 +13,7 @@
"""Router action implementations""" """Router action implementations"""
import argparse
import collections import collections
import copy import copy
import json import json
@ -198,6 +199,8 @@ def _get_external_gateway_attrs(client_manager, parsed_args):
def _get_attrs(client_manager, parsed_args): def _get_attrs(client_manager, parsed_args):
attrs = {} attrs = {}
n_client = client_manager.network
if parsed_args.name is not None: if parsed_args.name is not None:
attrs['name'] = parsed_args.name attrs['name'] = parsed_args.name
if parsed_args.enable: if parsed_args.enable:
@ -229,7 +232,8 @@ def _get_attrs(client_manager, parsed_args):
# "router set" command doesn't support setting flavor_id. # "router set" command doesn't support setting flavor_id.
if 'flavor_id' in parsed_args and parsed_args.flavor_id is not None: if 'flavor_id' in parsed_args and parsed_args.flavor_id is not None:
attrs['flavor_id'] = parsed_args.flavor_id flavor = n_client.find_flavor(parsed_args.flavor_id)
attrs['flavor_id'] = flavor.id
for attr in ('enable_default_route_bfd', 'enable_default_route_ecmp'): for attr in ('enable_default_route_bfd', 'enable_default_route_ecmp'):
value = getattr(parsed_args, attr, None) value = getattr(parsed_args, attr, None)
@ -560,10 +564,15 @@ class CreateRouter(command.ShowOne, common.NeutronCommandWithExtraArgs):
action='store_false', action='store_false',
help=_("Disable IPv6 NDP proxy on external gateway"), help=_("Disable IPv6 NDP proxy on external gateway"),
) )
parser.add_argument(
'--flavor',
metavar='<flavor-id>',
help=_("Associate the router to a flavor (by name or ID"),
)
parser.add_argument( parser.add_argument(
'--flavor-id', '--flavor-id',
metavar='<flavor-id>', metavar='<flavor-id>',
help=_("Associate the router to a flavor by ID"), help=argparse.SUPPRESS,
) )
_parser_add_bfd_ecmp_arguments(parser) _parser_add_bfd_ecmp_arguments(parser)

View File

@ -384,13 +384,15 @@ class TestCreateRouter(TestRouter):
def test_create_with_no_tag(self): def test_create_with_no_tag(self):
self._test_create_with_tag(add_tags=False) self._test_create_with_tag(add_tags=False)
def test_create_with_flavor_id(self): def test_create_with_flavor_id_or_name(self):
_flavor = network_fakes.create_one_network_flavor() _flavor = network_fakes.create_one_network_flavor()
self.network_client.find_flavor = mock.Mock(return_value=_flavor)
arglist = [ arglist = [
self.new_router.name, self.new_router.name,
'--flavor-id', '--flavor-id',
_flavor.id, _flavor.id,
] ]
arglist_with_name = [self.new_router.name, '--flavor-id', _flavor.name]
verifylist = [ verifylist = [
('name', self.new_router.name), ('name', self.new_router.name),
('enable', True), ('enable', True),
@ -410,6 +412,28 @@ class TestCreateRouter(TestRouter):
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertCountEqual(self.data, data) self.assertCountEqual(self.data, data)
self.network_client.create_router.reset_mock()
verifylist_w_name = [
('name', self.new_router.name),
('enable', True),
('distributed', False),
('ha', False),
('flavor_id', _flavor.name),
]
parsed_args_w_name = self.check_parser(
self.cmd, arglist_with_name, verifylist_w_name
)
columns, data = self.cmd.take_action(parsed_args_w_name)
self.network_client.create_router.assert_called_once_with(
**{
'admin_state_up': True,
'name': self.new_router.name,
'flavor_id': _flavor.id,
}
)
self.assertEqual(self.columns, columns)
self.assertCountEqual(self.data, data)
def test_create_with_enable_default_route_bfd(self): def test_create_with_enable_default_route_bfd(self):
self.network_client.find_extension = mock.Mock( self.network_client.find_extension = mock.Mock(
return_value=network_fakes.create_one_extension( return_value=network_fakes.create_one_extension(

View File

@ -0,0 +1,6 @@
---
fixes:
- |
The ``router create --flavor-id`` parameter has been deprecated
in favour of the ``--flavor`` parameter, which accepts both
flavor names and flavor IDs.