summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohammed Naser <mnaser@vexxhost.com>2012-05-25 03:50:25 +0000
committerMohammed Naser <mnaser@vexxhost.com>2012-05-25 21:29:50 +0000
commit4e65a33276895432121e2d4e8efd323956d73529 (patch)
tree330e32a2e0a2d0b6d7edb5a0080cc8a1433234a9
parenta75486d6240cd9291face18108326eafd6273acd (diff)
downloadnova-4e65a33276895432121e2d4e8efd323956d73529.tar.gz
nova-4e65a33276895432121e2d4e8efd323956d73529.tar.xz
nova-4e65a33276895432121e2d4e8efd323956d73529.zip
Allow adding fixed IPs by network UUID
Fixes LP Bug #1004280 Change-Id: I832b21091803d8da511ded96d14000602016e984
-rw-r--r--nova/network/manager.py7
-rw-r--r--nova/tests/network/test_manager.py35
2 files changed, 39 insertions, 3 deletions
diff --git a/nova/network/manager.py b/nova/network/manager.py
index ac77ebaf7..0da16a2b5 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -1177,8 +1177,11 @@ class NetworkManager(manager.SchedulerDependentManager):
@wrap_check_policy
def add_fixed_ip_to_instance(self, context, instance_id, host, network_id):
"""Adds a fixed ip to an instance from specified network."""
- networks = [self._get_network_by_id(context, network_id)]
- self._allocate_fixed_ips(context, instance_id, host, networks)
+ if utils.is_uuid_like(network_id):
+ network = self.get_network(context, network_id)
+ else:
+ network = self._get_network_by_id(context, network_id)
+ self._allocate_fixed_ips(context, instance_id, host, [network])
@wrap_check_policy
def remove_fixed_ip_from_instance(self, context, instance_id, host,
diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py
index f6931a876..3d2a09ccd 100644
--- a/nova/tests/network/test_manager.py
+++ b/nova/tests/network/test_manager.py
@@ -268,7 +268,7 @@ class FlatNetworkTestCase(test.TestCase):
self.network.validate_networks(self.context, requested_networks)
- def test_add_fixed_ip_instance_without_vpn_requested_networks(self):
+ def test_add_fixed_ip_instance_using_id_without_vpn(self):
self.mox.StubOutWithMock(db, 'network_get')
self.mox.StubOutWithMock(db, 'network_update')
self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
@@ -301,6 +301,39 @@ class FlatNetworkTestCase(test.TestCase):
self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
networks[0]['id'])
+ def test_add_fixed_ip_instance_using_uuid_without_vpn(self):
+ self.mox.StubOutWithMock(db, 'network_get_by_uuid')
+ self.mox.StubOutWithMock(db, 'network_update')
+ self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
+ self.mox.StubOutWithMock(db, 'instance_get')
+ self.mox.StubOutWithMock(db,
+ 'virtual_interface_get_by_instance_and_network')
+ self.mox.StubOutWithMock(db, 'fixed_ip_update')
+
+ db.fixed_ip_update(mox.IgnoreArg(),
+ mox.IgnoreArg(),
+ mox.IgnoreArg())
+ db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
+ mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
+
+ db.instance_get(mox.IgnoreArg(),
+ mox.IgnoreArg()).AndReturn({'security_groups':
+ [{'id': 0}]})
+ db.instance_get(self.context,
+ 1).AndReturn({'display_name': HOST,
+ 'uuid': 'test-00001'})
+ db.instance_get(mox.IgnoreArg(),
+ mox.IgnoreArg()).AndReturn({'availability_zone': ''})
+ db.fixed_ip_associate_pool(mox.IgnoreArg(),
+ mox.IgnoreArg(),
+ mox.IgnoreArg()).AndReturn('192.168.0.101')
+ db.network_get_by_uuid(mox.IgnoreArg(),
+ mox.IgnoreArg()).AndReturn(networks[0])
+ db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
+ self.mox.ReplayAll()
+ self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
+ networks[0]['uuid'])
+
def test_mini_dns_driver(self):
zone1 = "example.org"
zone2 = "example.com"