]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
API: _validate_ip_address should not raise an exception
authorGary Kotton <gkotton@vmware.com>
Thu, 10 Dec 2015 12:23:55 +0000 (04:23 -0800)
committerGary Kotton <gkotton@vmware.com>
Fri, 11 Dec 2015 17:19:25 +0000 (09:19 -0800)
The _validate* methods should return an error message and
not raise an exception.

Commit 2794bb89d664355ae1194a0b1f8346c1538caef8 raised an
exception instead of returning a message with the invalid data.

TrivialFix

Change-Id: Id3cc44a4ed248415f19c73beec2b24fd295110c8

neutron/api/v2/attributes.py

index 00a827e92983cc0bc37ec9081c2b19d42a2e910b..e7b5ce592a9f46cece72da34222ea511d2cb879d 100644 (file)
@@ -204,6 +204,7 @@ def _validate_mac_address_or_none(data, valid_values=None):
 
 
 def _validate_ip_address(data, valid_values=None):
+    msg = None
     try:
         netaddr.IPAddress(_validate_no_whitespace(data))
         # The followings are quick checks for IPv6 (has ':') and
@@ -220,11 +221,12 @@ def _validate_ip_address(data, valid_values=None):
         #   IPAddress('199.28.113.199')
         #   >>>
         if ':' not in data and data.count('.') != 3:
-            raise ValueError()
+            msg = _("'%s' is not a valid IP address") % data
     except Exception:
         msg = _("'%s' is not a valid IP address") % data
+    if msg:
         LOG.debug(msg)
-        return msg
+    return msg
 
 
 def _validate_ip_pools(data, valid_values=None):