summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Griffith <john.griffith@solidfire.com>2012-03-07 17:45:12 -0700
committerJohn Griffith <john.griffith@solidfire.com>2012-03-12 14:00:18 -0600
commitc63c42146704fdf19f2f163ade62033313e27dc9 (patch)
treea5b0c57050e27c7851a8c02f2a6516a80e6a8e81
parentb057ab60a39eb8dfa6604d6f207625c29df6cd70 (diff)
downloadnova-c63c42146704fdf19f2f163ade62033313e27dc9.tar.gz
nova-c63c42146704fdf19f2f163ade62033313e27dc9.tar.xz
nova-c63c42146704fdf19f2f163ade62033313e27dc9.zip
Update floating auto assignment to use the model
* addresses bug 928819 * previously submitted changes (#change,4236) * unit tests added that don't use fakes for everything * added testAssert to check assignment process * added call to deallocate as well Change-Id: I46503e6e88031a6e1ab3ac76163402091168c6b0
-rw-r--r--nova/api/openstack/common.py3
-rw-r--r--nova/network/manager.py6
-rw-r--r--nova/tests/network/test_manager.py40
3 files changed, 44 insertions, 5 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
index 3fefa6718..719a74bb9 100644
--- a/nova/api/openstack/common.py
+++ b/nova/api/openstack/common.py
@@ -288,7 +288,7 @@ def dict_to_query_str(params):
def get_networks_for_instance_from_nw_info(nw_info):
networks = {}
-
+ LOG.debug(_('Converting nw_info: %s') % nw_info)
for vif in nw_info:
ips = vif.fixed_ips()
floaters = vif.floating_ips()
@@ -298,6 +298,7 @@ def get_networks_for_instance_from_nw_info(nw_info):
networks[label]['ips'].extend(ips)
networks[label]['floating_ips'].extend(floaters)
+ LOG.debug(_('Converted networks: %s') % networks)
return networks
diff --git a/nova/network/manager.py b/nova/network/manager.py
index 41ddf57c5..e80396bdd 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -320,10 +320,8 @@ class FloatingIP(object):
self.db.floating_ip_set_auto_assigned(context, floating_address)
# get the first fixed address belonging to the instance
- for nw, info in nw_info:
- if info.get('ips'):
- fixed_address = info['ips'][0]['ip']
- break
+ fixed_ips = nw_info.fixed_ips()
+ fixed_address = fixed_ips[0]['address']
# associate the floating ip to fixed_ip
self.associate_floating_ip(context,
diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py
index 2e50587f9..589aab067 100644
--- a/nova/tests/network/test_manager.py
+++ b/nova/tests/network/test_manager.py
@@ -1268,6 +1268,46 @@ class TestFloatingIPManager(network_manager.FloatingIP,
"""Dummy manager that implements FloatingIP"""
+class AllocateTestCase(test.TestCase):
+ def test_allocate_for_instance(self):
+ address = "10.10.10.10"
+ self.flags(auto_assign_floating_ip=True)
+ self.compute = self.start_service('compute')
+ self.network = self.start_service('network')
+
+ self.user_id = 'fake'
+ self.project_id = 'fake'
+ self.context = context.RequestContext(self.user_id,
+ self.project_id,
+ is_admin=True)
+
+ db.floating_ip_create(self.context,
+ {'address': address,
+ 'pool': 'nova'})
+ inst = db.instance_create(self.context, {'host': self.compute.host,
+ 'instance_type_id': 1})
+ networks = db.network_get_all(self.context)
+ for network in networks:
+ db.network_update(self.context, network['id'],
+ {'host': self.network.host})
+ project_id = self.context.project_id
+ nw_info = self.network.allocate_for_instance(self.context,
+ instance_id=inst['id'],
+ instance_uuid='',
+ host=inst['host'],
+ vpn=None,
+ rxtx_factor=3,
+ project_id=project_id)
+ self.assertEquals(1, len(nw_info))
+ fixed_ip = nw_info.fixed_ips()[0]['address']
+ self.assertTrue(utils.is_valid_ipv4(fixed_ip))
+ self.network.deallocate_for_instance(self.context,
+ instance_id=inst['id'],
+ fixed_ips=fixed_ip,
+ host=self.network.host,
+ project_id=project_id)
+
+
class FloatingIPTestCase(test.TestCase):
"""Tests nova.network.manager.FloatingIP"""
def setUp(self):