]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
BigSwitch: Fix error for server config check
authorKevin Benton <blak111@gmail.com>
Fri, 7 Mar 2014 18:26:47 +0000 (10:26 -0800)
committerKevin Benton <blak111@gmail.com>
Fri, 7 Mar 2014 18:28:53 +0000 (10:28 -0800)
Raises config error when a port is incorrectly
configured for a server instead of getting a
ValueError when python tries to convert it to
an integer.

Closes-Bug: #1289132
Change-Id: Ifec0bec5640a4a57859f2673c46c610f1d21c36c

neutron/plugins/bigswitch/servermanager.py
neutron/tests/unit/bigswitch/test_servermanager.py [new file with mode: 0644]

index 5f2714176efda19b41ba5a8885a8dd96cc33add4..a886849fe5709063c1e2edb60493dbf13616dbf4 100644 (file)
@@ -253,8 +253,9 @@ class ServerPool(object):
         servers = [s if len(s.rsplit(':', 1)) == 2
                    else "%s:%d" % (s, default_port)
                    for s in servers]
-        if any((len(spl) != 2)for spl in [sp.rsplit(':', 1)
-                                          for sp in servers]):
+        if any((len(spl) != 2 or not spl[1].isdigit())
+               for spl in [sp.rsplit(':', 1)
+                           for sp in servers]):
             raise cfg.Error(_('Servers must be defined as <ip>:<port>. '
                               'Configuration was %s') % servers)
         self.servers = [
diff --git a/neutron/tests/unit/bigswitch/test_servermanager.py b/neutron/tests/unit/bigswitch/test_servermanager.py
new file mode 100644 (file)
index 0000000..f313141
--- /dev/null
@@ -0,0 +1,31 @@
+# Copyright 2014 Big Switch Networks, Inc.  All rights reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+#
+# @author: Kevin Benton, kevin.benton@bigswitch.com
+#
+from oslo.config import cfg
+
+from neutron.plugins.bigswitch import servermanager
+from neutron.tests.unit.bigswitch import test_restproxy_plugin as test_rp
+
+
+class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
+
+    def test_no_servers(self):
+        cfg.CONF.set_override('servers', [], 'RESTPROXY')
+        self.assertRaises(cfg.Error, servermanager.ServerPool)
+
+    def test_malformed_servers(self):
+        cfg.CONF.set_override('servers', ['a:b:c'], 'RESTPROXY')
+        self.assertRaises(cfg.Error, servermanager.ServerPool)