summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhishek Kekane <abhishek.kekane@nttdata.com>2016-05-23 12:10:37 +0530
committerAbhishek Kekane <abhishek.kekane@nttdata.com>2016-05-23 12:17:07 +0530
commit388a15e6c0ea8d3ac83daef2794c0ab4c53a97d1 (patch)
tree196ba7ef8c9a460e7a0309d1d65b54ab6a8a2a82
parent6cf8386cc7278a98f9ba9260d7ea61e519e93975 (diff)
downloadoslo-utils-388a15e6c0ea8d3ac83daef2794c0ab4c53a97d1.tar.gz
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
-rw-r--r--oslo_utils/netutils.py2
-rw-r--r--oslo_utils/tests/test_netutils.py1
2 files changed, 2 insertions, 1 deletions
diff --git a/oslo_utils/netutils.py b/oslo_utils/netutils.py
index ebef117..0ad02fd 100644
--- a/oslo_utils/netutils.py
+++ b/oslo_utils/netutils.py
@@ -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
diff --git a/oslo_utils/tests/test_netutils.py b/oslo_utils/tests/test_netutils.py
index d80f6b7..9b15d61 100644
--- a/oslo_utils/tests/test_netutils.py
+++ b/oslo_utils/tests/test_netutils.py
@@ -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,