Floating_ip create /31,32 shouldn't silent error
Fixes bug 1017682 the netaddr.IPNetwork.iter_hosts method doesn't return any IPs when /32 or /31 and should throw an exception instead of silent error Change-Id: Id8875b6016a4dbb40b29d2f7687e6c35491e0129
This commit is contained in:
@@ -343,7 +343,13 @@ class FloatingIpCommands(object):
|
||||
try:
|
||||
return [netaddr.IPAddress(addresses)]
|
||||
except ValueError:
|
||||
return netaddr.IPNetwork(addresses).iter_hosts()
|
||||
net = netaddr.IPNetwork(addresses)
|
||||
if net.size < 4:
|
||||
reason = _("/%s should be specified as single address(es) "
|
||||
"not in cidr format") % net.prefixlen
|
||||
raise exception.InvalidInput(reason=reason)
|
||||
else:
|
||||
return net.iter_hosts()
|
||||
|
||||
@args('--ip_range', dest="ip_range", metavar='<range>', help='IP range')
|
||||
@args('--pool', dest="pool", metavar='<pool>', help='Optional pool')
|
||||
|
@@ -22,6 +22,7 @@ import sys
|
||||
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import test
|
||||
from nova.tests.db import fakes as db_fakes
|
||||
|
||||
@@ -66,6 +67,40 @@ class FixedIpCommandsTestCase(test.TestCase):
|
||||
'55.55.55.55')
|
||||
|
||||
|
||||
class FloatingIpCommandsTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(FloatingIpCommandsTestCase, self).setUp()
|
||||
db_fakes.stub_out_db_network_api(self.stubs)
|
||||
self.commands = nova_manage.FloatingIpCommands()
|
||||
|
||||
def test_address_to_hosts(self):
|
||||
def assert_loop(result, expected):
|
||||
for ip in result:
|
||||
self.assertTrue(str(ip) in expected)
|
||||
|
||||
address_to_hosts = self.commands.address_to_hosts
|
||||
# /32 and /31
|
||||
self.assertRaises(exception.InvalidInput, address_to_hosts,
|
||||
'192.168.100.1/32')
|
||||
self.assertRaises(exception.InvalidInput, address_to_hosts,
|
||||
'192.168.100.1/31')
|
||||
# /30
|
||||
expected = ["192.168.100.%s" % i for i in range(1, 3)]
|
||||
result = address_to_hosts('192.168.100.0/30')
|
||||
self.assertTrue(len(list(result)) == 2)
|
||||
assert_loop(result, expected)
|
||||
# /29
|
||||
expected = ["192.168.100.%s" % i for i in range(1, 7)]
|
||||
result = address_to_hosts('192.168.100.0/29')
|
||||
self.assertTrue(len(list(result)) == 6)
|
||||
assert_loop(result, expected)
|
||||
# /28
|
||||
expected = ["192.168.100.%s" % i for i in range(1, 15)]
|
||||
result = address_to_hosts('192.168.100.0/28')
|
||||
self.assertTrue(len(list(result)) == 14)
|
||||
assert_loop(result, expected)
|
||||
|
||||
|
||||
class NetworkCommandsTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(NetworkCommandsTestCase, self).setUp()
|
||||
|
Reference in New Issue
Block a user