summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjaypipes@gmail.com <>2010-07-21 02:57:31 +0000
committerTarmac <>2010-07-21 02:57:31 +0000
commitd44943d84db793937185b044ecb72c52522cfe72 (patch)
tree2d0c0bf0ac3b8fbb6f5a1f9fd8ad793a4c8a901e
parentc771ef02cdbae6a9f409a1ec9fb8aed965f13639 (diff)
parentc39b3add4b3db1c027c32ea0f145c3d3ab3f4d1c (diff)
downloadnova-d44943d84db793937185b044ecb72c52522cfe72.tar.gz
nova-d44943d84db793937185b044ecb72c52522cfe72.tar.xz
nova-d44943d84db793937185b044ecb72c52522cfe72.zip
update the logic for calculating network sizes
-rw-r--r--nova/compute/network.py7
-rw-r--r--nova/tests/network_unittest.py29
2 files changed, 31 insertions, 5 deletions
diff --git a/nova/compute/network.py b/nova/compute/network.py
index bdb8a22f9..43011f696 100644
--- a/nova/compute/network.py
+++ b/nova/compute/network.py
@@ -162,6 +162,7 @@ class Vlan(datastore.BasicModel):
class BaseNetwork(datastore.BasicModel):
override_type = 'network'
+ NUM_STATIC_IPS = 3 # Network, Gateway, and CloudPipe
@property
def identifier(self):
@@ -237,11 +238,15 @@ class BaseNetwork(datastore.BasicModel):
def available(self):
# the .2 address is always CloudPipe
# and the top <n> 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 444063d0f..f3a5868d1 100644
--- a/nova/tests/network_unittest.py
+++ b/nova/tests/network_unittest.py
@@ -147,21 +147,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 set in test fixture's setUp method.
+
+ 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)
+
+ 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")
+
+ # 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 = flags.FLAGS.network_size - (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)