From e5890b172817937ca883f6bcac42dfa85d8511d5 Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Wed, 18 Nov 2015 10:21:55 -0800 Subject: [PATCH] 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 --- vmware_nsx/common/config.py | 9 +++++---- vmware_nsx/plugins/nsx_v/plugin.py | 11 +---------- vmware_nsx/tests/unit/nsx_v/test_plugin.py | 12 ------------ 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/vmware_nsx/common/config.py b/vmware_nsx/common/config.py index 8989b41bb1..478e289757 100644 --- a/vmware_nsx/common/config.py +++ b/vmware_nsx/common/config.py @@ -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 diff --git a/vmware_nsx/plugins/nsx_v/plugin.py b/vmware_nsx/plugins/nsx_v/plugin.py index 88864ba0ae..5426db3046 100644 --- a/vmware_nsx/plugins/nsx_v/plugin.py +++ b/vmware_nsx/plugins/nsx_v/plugin.py @@ -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'] diff --git a/vmware_nsx/tests/unit/nsx_v/test_plugin.py b/vmware_nsx/tests/unit/nsx_v/test_plugin.py index b2760578e9..0696a49d2e 100644 --- a/vmware_nsx/tests/unit/nsx_v/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v/test_plugin.py @@ -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