Skip to content

Commit

Permalink
Use is_valid_cidr and is_valid_ipv6_cidr from oslo_utils
Browse files Browse the repository at this point in the history
Use is_valid_cidr and is_valid_ipv6_cidr from oslo_utils instead of
having own method in the repo.
https://github.com/openstack/oslo.utils/blob/master/oslo_utils/netutils.py#L116
https://github.com/openstack/oslo.utils/blob/master/oslo_utils/netutils.py#L142

TrivialFix

Change-Id: Ie8791606be1c62944323fd9ffe392c7f74bf9424
  • Loading branch information
abhishekkekane committed Jan 31, 2017
1 parent 4762d63 commit 506b3d7
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 44 deletions.
2 changes: 1 addition & 1 deletion nova/db/sqlalchemy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def load_dialect_impl(self, dialect):
def process_bind_param(self, value, dialect):
"""Process/Formats the value before insert it into the db."""
# NOTE(sdague): normalize all the inserts
if utils.is_valid_ipv6_cidr(value):
if netutils.is_valid_ipv6_cidr(value):
return utils.get_shortened_ipv6_cidr(value)
return value

Expand Down
2 changes: 1 addition & 1 deletion nova/network/security_group/security_group_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
# under the License.

from oslo_utils import encodeutils
from oslo_utils import netutils as utils
from six.moves import urllib

from nova import exception
from nova.i18n import _
from nova.objects import security_group as security_group_obj
from nova import utils


class SecurityGroupBase(object):
Expand Down
11 changes: 0 additions & 11 deletions nova/tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,6 @@ def test_xhtml_escape(self):
self.assertEqual('&lt;', utils.xhtml_escape('<'))
self.assertEqual('&lt;foo&gt;', utils.xhtml_escape('<foo>'))

def test_is_valid_ipv6_cidr(self):
self.assertTrue(utils.is_valid_ipv6_cidr("2600::/64"))
self.assertTrue(utils.is_valid_ipv6_cidr(
"abcd:ef01:2345:6789:abcd:ef01:192.168.254.254/48"))
self.assertTrue(utils.is_valid_ipv6_cidr(
"0000:0000:0000:0000:0000:0000:0000:0001/32"))
self.assertTrue(utils.is_valid_ipv6_cidr(
"0000:0000:0000:0000:0000:0000:0000:0001"))
self.assertFalse(utils.is_valid_ipv6_cidr("foo"))
self.assertFalse(utils.is_valid_ipv6_cidr("127.0.0.1"))

def test_get_shortened_ipv6(self):
self.assertEqual("abcd:ef01:2345:6789:abcd:ef01:c0a8:fefe",
utils.get_shortened_ipv6(
Expand Down
31 changes: 0 additions & 31 deletions nova/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,6 @@ def parse_server_string(server_str):
return ('', '')


def is_valid_ipv6_cidr(address):
try:
netaddr.IPNetwork(address, version=6).cidr
return True
except (TypeError, netaddr.AddrFormatError):
return False


def get_shortened_ipv6(address):
addr = netaddr.IPAddress(address, version=6)
return str(addr.ipv6())
Expand All @@ -555,29 +547,6 @@ def get_shortened_ipv6_cidr(address):
return str(net.cidr)


def is_valid_cidr(address):
"""Check if address is valid
The provided address can be a IPv6 or a IPv4
CIDR address.
"""
try:
# Validate the correct CIDR Address
netaddr.IPNetwork(address)
except netaddr.AddrFormatError:
return False

# Prior validation partially verify /xx part
# Verify it here
ip_segment = address.split('/')

if (len(ip_segment) <= 1 or
ip_segment[1] == ''):
return False

return True


def get_ip_version(network):
"""Returns the IP version of a network (IPv4 or IPv6).
Expand Down

0 comments on commit 506b3d7

Please sign in to comment.