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...
This commit is contained in:
Jay Pipes
2010-07-16 12:00:15 -05:00
parent 2f44115977
commit a5a9f04c34

View File

@@ -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)