diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-07-12 21:39:01 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-07-12 21:39:01 +0000 |
commit | 849c2e92ac294e4a847430170fdf83842539c05d (patch) | |
tree | 8bc15ec36ea45a6d688d54911978c20566716d01 | |
parent | 4d0ffe3c7c2ec14af4d199294e13a3eb5ac97dd6 (diff) | |
parent | 1684c95568a3cf98458f154a4ea3508dd475e763 (diff) | |
download | nova-849c2e92ac294e4a847430170fdf83842539c05d.tar.gz nova-849c2e92ac294e4a847430170fdf83842539c05d.tar.xz nova-849c2e92ac294e4a847430170fdf83842539c05d.zip |
Merge "Floating_ip create /31,32 shouldn't silent error"
-rwxr-xr-x | bin/nova-manage | 8 | ||||
-rw-r--r-- | nova/tests/test_nova_manage.py | 35 |
2 files changed, 42 insertions, 1 deletions
diff --git a/bin/nova-manage b/bin/nova-manage index e31971579..22f670442 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -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') diff --git a/nova/tests/test_nova_manage.py b/nova/tests/test_nova_manage.py index 7e0d8cfe9..9e8322763 100644 --- a/nova/tests/test_nova_manage.py +++ b/nova/tests/test_nova_manage.py @@ -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() |