netaddr<=0.7.10 raises ValueError instead of AddrFormatError

This patch is based on Aarons work for the Bug#1308675.
It ensures that ValueError is also caught in addition to
AddrFormatError as in netaddr>=0.7.11 AddrFormatError is raised and
in netaddr<=0.7.10 ValueError is raised.

Change-Id: I71cfe82e57290552fb22637ad929747a6fa22460
Closes-bug: #1308675
This commit is contained in:
sridhargaddam 2014-04-18 21:01:48 +05:30
parent dadcbeefaa
commit 7305ace9f3
2 changed files with 2 additions and 2 deletions

View File

@ -30,7 +30,7 @@ def get_ipv6_addr_by_EUI64(prefix, mac):
eui64 = int(netaddr.EUI(mac).eui64()) eui64 = int(netaddr.EUI(mac).eui64())
prefix = netaddr.IPNetwork(prefix) prefix = netaddr.IPNetwork(prefix)
return netaddr.IPAddress(prefix.first + eui64 ^ (1 << 57)) return netaddr.IPAddress(prefix.first + eui64 ^ (1 << 57))
except netaddr.AddrFormatError: except (ValueError, netaddr.AddrFormatError):
raise TypeError(_('Bad prefix or mac format for generating IPv6 ' raise TypeError(_('Bad prefix or mac format for generating IPv6 '
'address by EUI-64: %(prefix)s, %(mac)s:') 'address by EUI-64: %(prefix)s, %(mac)s:')
% {'prefix': prefix, 'mac': mac}) % {'prefix': prefix, 'mac': mac})

View File

@ -321,7 +321,7 @@ class Client(object):
ip = netaddr.IPNetwork(subnet['cidr']) ip = netaddr.IPNetwork(subnet['cidr'])
netmask = str(ip.netmask) netmask = str(ip.netmask)
network_address = str(ip.network) network_address = str(ip.network)
except netaddr.AddrFormatError: except (ValueError, netaddr.AddrFormatError):
msg = _("Invalid input for CIDR") msg = _("Invalid input for CIDR")
raise n_exc.InvalidInput(error_message=msg) raise n_exc.InvalidInput(error_message=msg)
else: else: