From: Gary Kotton Date: Thu, 10 Dec 2015 12:23:55 +0000 (-0800) Subject: API: _validate_ip_address should not raise an exception X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=981b7e4cb4f6752568059c03ef3722a1c828e2e7;p=openstack-build%2Fneutron-build.git API: _validate_ip_address should not raise an exception 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 --- diff --git a/neutron/api/v2/attributes.py b/neutron/api/v2/attributes.py index 00a827e92..e7b5ce592 100644 --- a/neutron/api/v2/attributes.py +++ b/neutron/api/v2/attributes.py @@ -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):