Fix is_valid_cidr raises TypeError

is_valid_cidr raises TypeError if invalid addr type is passed.
Caught TypeError to return False if addr type is other than
expected.

Change-Id: I2bb6070e96eb07a47aab12eeef2840ca4f6abc1e
Closes-Bug: #1584599
This commit is contained in:
Abhishek Kekane 2016-05-23 12:10:37 +05:30
parent 6cf8386cc7
commit 388a15e6c0
2 changed files with 2 additions and 1 deletions

View File

@ -123,7 +123,7 @@ def is_valid_cidr(address):
try:
# Validate the correct CIDR Address
netaddr.IPNetwork(address)
except netaddr.AddrFormatError:
except (TypeError, netaddr.AddrFormatError):
return False
# Prior validation partially verify /xx part

View File

@ -190,6 +190,7 @@ class NetworkUtilsTest(test_base.BaseTestCase):
self.assertFalse(netutils.is_valid_cidr('10.0.0.1'))
self.assertFalse(netutils.is_valid_cidr('10.0.0.1/33'))
self.assertFalse(netutils.is_valid_cidr(10))
def test_valid_port(self):
valid_inputs = [1, '1', 2, '3', '5', 8, 13, 21,