From 680446f0acd8aa7820974d32b5b4093a6d4e7a10 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Fri, 16 Jul 2010 12:00:15 -0500 Subject: Adds a fix to the idempotency of the test_too_many_addresses test case by adding a simple property to the BaseNetwork class and calculating the number of available IPs by asking the network class to tell the test how many static and preallocated IP addresses are in use before entering the loop to "blow up" the address allocation... --- nova/compute/network.py | 7 ++++++- nova/tests/network_unittest.py | 29 +++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/nova/compute/network.py b/nova/compute/network.py index 8592d7af7..2b271d0ca 100644 --- a/nova/compute/network.py +++ b/nova/compute/network.py @@ -164,6 +164,7 @@ class Vlan(datastore.BasicModel): class BaseNetwork(datastore.BasicModel): override_type = 'network' + NUM_STATIC_IPS = 3 # Network, Gateway, and CloudPipe @property def identifier(self): @@ -239,11 +240,15 @@ class BaseNetwork(datastore.BasicModel): def available(self): # the .2 address is always CloudPipe # and the top are for vpn clients - for idx in range(3, len(self.network)-(1 + FLAGS.cnt_vpn_clients)): + for idx in range(self.num_static_ips, len(self.network)-(1 + FLAGS.cnt_vpn_clients)): address = str(self.network[idx]) if not address in self.hosts.keys(): yield str(address) + @property + def num_static_ips(self): + return BaseNetwork.NUM_STATIC_IPS + def allocate_ip(self, user_id, project_id, mac): for address in self.available: logging.debug("Allocating IP %s to %s" % (address, project_id)) diff --git a/nova/tests/network_unittest.py b/nova/tests/network_unittest.py index dd1966ffa..441a78097 100644 --- a/nova/tests/network_unittest.py +++ b/nova/tests/network_unittest.py @@ -150,21 +150,42 @@ class NetworkTestCase(test.TrialTestCase): def test_too_many_addresses(self): """ - Network size is 32, there are 5 addresses reserved for VPN. - So we should get 23 usable addresses + Here, we test that a proper NoMoreAddresses exception is raised. + + However, the number of available IP addresses depends on the test + environment's setup. + + Network size is 32. + + There are FLAGS.cnt_vpn_clients addresses reserved for VPN (NUM_RESERVED_VPN_IPS) + + And there are NUM_CONST_IPS that are always reserved by Nova for the necessary + services (API, CloudPipe, etc) + + So we should get 32 - (NUM_STATIC_IPS + + NUM_PREALLOCATED_IPS + + NUM_RESERVED_VPN_IPS) + usable addresses """ net = network.get_project_network("project0", "default") + + # Determine expected number of available IP addresses + num_static_ips = net.num_static_ips + num_preallocated_ips = len(net.hosts.keys()) + num_reserved_vpn_ips = flags.FLAGS.cnt_vpn_clients + num_available_ips = 32 - (num_static_ips + num_preallocated_ips + num_reserved_vpn_ips) + hostname = "toomany-hosts" macs = {} addresses = {} - for i in range(0, 22): + for i in range(0, (num_available_ips - 1)): macs[i] = utils.generate_mac() addresses[i] = network.allocate_ip("netuser", "project0", macs[i]) self.dnsmasq.issue_ip(macs[i], addresses[i], hostname, net.bridge_name) self.assertRaises(NoMoreAddresses, network.allocate_ip, "netuser", "project0", utils.generate_mac()) - for i in range(0, 22): + for i in range(0, (num_available_ips - 1)): rv = network.deallocate_ip(addresses[i]) self.dnsmasq.release_ip(macs[i], addresses[i], hostname, net.bridge_name) -- cgit From a5668a0e8ebc96d01ec7a26229079ccda6032e75 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Fri, 16 Jul 2010 12:41:13 -0500 Subject: Quick fix to variable names for consistency in documentation... --- nova/tests/network_unittest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/network_unittest.py b/nova/tests/network_unittest.py index 441a78097..3cfba2cf9 100644 --- a/nova/tests/network_unittest.py +++ b/nova/tests/network_unittest.py @@ -159,8 +159,8 @@ class NetworkTestCase(test.TrialTestCase): There are FLAGS.cnt_vpn_clients addresses reserved for VPN (NUM_RESERVED_VPN_IPS) - And there are NUM_CONST_IPS that are always reserved by Nova for the necessary - services (API, CloudPipe, etc) + And there are NUM_STATIC_IPS that are always reserved by Nova for the necessary + services (gateway, CloudPipe, etc) So we should get 32 - (NUM_STATIC_IPS + NUM_PREALLOCATED_IPS + -- cgit From c39b3add4b3db1c027c32ea0f145c3d3ab3f4d1c Mon Sep 17 00:00:00 2001 From: "jaypipes@gmail.com" <> Date: Mon, 19 Jul 2010 09:50:22 -0500 Subject: Hmm, serves me right for not understanding the request, eh? :) Now too_many_addresses test case is idempotent in regards to running in isolation and uses self.flags.network_size instead of the magic number 32. --- nova/tests/network_unittest.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/nova/tests/network_unittest.py b/nova/tests/network_unittest.py index 3cfba2cf9..4a9f9b8ab 100644 --- a/nova/tests/network_unittest.py +++ b/nova/tests/network_unittest.py @@ -155,16 +155,16 @@ class NetworkTestCase(test.TrialTestCase): However, the number of available IP addresses depends on the test environment's setup. - Network size is 32. + Network size is set in test fixture's setUp method. - There are FLAGS.cnt_vpn_clients addresses reserved for VPN (NUM_RESERVED_VPN_IPS) + There are FLAGS.cnt_vpn_clients addresses reserved for VPN (NUM_RESERVED_VPN_IPS) - And there are NUM_STATIC_IPS that are always reserved by Nova for the necessary - services (gateway, CloudPipe, etc) + And there are NUM_STATIC_IPS that are always reserved by Nova for the necessary + services (gateway, CloudPipe, etc) - So we should get 32 - (NUM_STATIC_IPS + - NUM_PREALLOCATED_IPS + - NUM_RESERVED_VPN_IPS) + So we should get flags.network_size - (NUM_STATIC_IPS + + NUM_PREALLOCATED_IPS + + NUM_RESERVED_VPN_IPS) usable addresses """ net = network.get_project_network("project0", "default") @@ -173,7 +173,7 @@ class NetworkTestCase(test.TrialTestCase): num_static_ips = net.num_static_ips num_preallocated_ips = len(net.hosts.keys()) num_reserved_vpn_ips = flags.FLAGS.cnt_vpn_clients - num_available_ips = 32 - (num_static_ips + num_preallocated_ips + num_reserved_vpn_ips) + num_available_ips = flags.FLAGS.network_size - (num_static_ips + num_preallocated_ips + num_reserved_vpn_ips) hostname = "toomany-hosts" macs = {} -- cgit