From a5a9f04c342c85904ccd7419ad95721fdaf7d3f7 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Fri, 16 Jul 2010 12:00:15 -0500 Subject: [PATCH] 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/tests/network_unittest.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/nova/tests/network_unittest.py b/nova/tests/network_unittest.py index dd1966ff..441a7809 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)