Use choices for exclusive_router_appliance_size

The exclusive_router_appliance_size config option is a StrOpt
that accepts only valid choices.  The oslo.config module permits
using a choices parameter to avoid the need to do runtime checking
of options.

Change-Id: I281fbe626b5f48f3cd63bf90b70b057f088b1dcc
This commit is contained in:
Eric Brown 2015-11-18 10:21:55 -08:00
parent 402c3bb90a
commit e5890b1728
3 changed files with 6 additions and 26 deletions

View File

@ -18,6 +18,7 @@ from oslo_config import cfg
from neutron.i18n import _LW
from vmware_nsx.common import exceptions as nsx_exc
from vmware_nsx.extensions import routersize
LOG = logging.getLogger(__name__)
@ -327,11 +328,11 @@ nsxv_opts = [
help=_("Enable HA for NSX Edges")),
cfg.StrOpt('exclusive_router_appliance_size',
default="compact",
choices=routersize.VALID_EDGE_SIZES,
help=_("Edge appliance size to be used for creating exclusive "
"router. Valid values: ['compact', 'large', 'xlarge', "
"'quadlarge']. This edge_appliance_size will be picked "
"up if --router-size parameter is not specified while "
"doing neutron router-create")),
"router. This edge_appliance_size will be picked up if "
"--router-size parameter is not specified while doing "
"neutron router-create")),
]
# Register the configuration options

View File

@ -1403,16 +1403,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
raise n_exc.BadRequest(resource="router", msg=msg)
else:
if r.get('router_type') == nsxv_constants.EXCLUSIVE:
appliance_size = cfg.CONF.nsxv.exclusive_router_appliance_size
if appliance_size not in VALID_EDGE_SIZES:
msg = (_("Invalid edge size specified in nsx.ini file. "
"Specified value: %(specified)s; "
"Valid values: %(valid)s") %
{'specified': appliance_size,
'valid': VALID_EDGE_SIZES})
raise n_exc.BadRequest(resource="router", msg=msg)
else:
r[ROUTER_SIZE] = appliance_size
r[ROUTER_SIZE] = cfg.CONF.nsxv.exclusive_router_appliance_size
def create_router(self, context, router, allow_metadata=True):
r = router['router']

View File

@ -1961,18 +1961,6 @@ class TestExclusiveRouterTestCase(L3NatTest, L3NatTestCaseBase,
router = self.deserialize(self.fmt, res)
self.assertEqual('xlarge', router['router']['router_size'])
def test_router_create_fails_when_bad_edge_size_specified(self):
data = {'router': {
'tenant_id': 'whatever',
'name': 'test_router',
'router_type': 'exclusive'}}
cfg.CONF.set_override('exclusive_router_appliance_size',
'foobar', group='nsxv')
router_req = self.new_create_request('routers', data, self.fmt)
res = router_req.get_response(self.ext_api)
router = self.deserialize(self.fmt, res)
self.assertEqual("BadRequest", router['NeutronError']['type'])
def test_router_add_gateway_invalid_network_returns_404(self):
# NOTE(salv-orlando): This unit test has been overriden
# as the nsx plugin support the ext_gw_mode extension