summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSandy Walsh <sandy.walsh@rackspace.com>2011-07-07 06:25:03 -0700
committerSandy Walsh <sandy.walsh@rackspace.com>2011-07-07 06:25:03 -0700
commitd24a8689dceaae1145d0cc0aa12e60bfdabbe2b2 (patch)
treedd02373c921be22456319cdae3629d96f8e0a9ac
parentbd297ae3bc779853cf82f05d0d4da60305416a99 (diff)
downloadnova-d24a8689dceaae1145d0cc0aa12e60bfdabbe2b2.tar.gz
nova-d24a8689dceaae1145d0cc0aa12e60bfdabbe2b2.tar.xz
nova-d24a8689dceaae1145d0cc0aa12e60bfdabbe2b2.zip
unit tests
-rw-r--r--nova/compute/api.py3
-rw-r--r--nova/network/manager.py4
-rw-r--r--nova/tests/test_network.py33
3 files changed, 37 insertions, 3 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index e4992bbfa..8507c5871 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -890,7 +890,8 @@ class API(base.Base):
"""Add fixed_ip from specified network to given instance."""
self._cast_compute_message('add_fixed_ip_to_instance', context,
instance_id, network_id)
-
+
+
@scheduler_api.reroute_compute("remove_fixed_ip")
def remove_fixed_ip(self, context, instance_id, address):
"""Remove fixed_ip from specified network to given instance."""
diff --git a/nova/network/manager.py b/nova/network/manager.py
index 4b9fb98f4..ea946a1f4 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -486,10 +486,10 @@ class NetworkManager(manager.SchedulerDependentManager):
"""Removes a fixed ip from an instance from specified network."""
addresses = self.db.fixed_ip_get_by_instance(context, instance_id)
for addr in addresses:
- if addr == address:
+ if addr['address'] == address:
self.deallocate_fixed_ip(context, address)
return
- raise exception.NoSuchAddress(address=address)
+ raise exception.FixedIpNotFound(id=address)
def allocate_fixed_ip(self, context, instance_id, network, **kwargs):
diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py
index 6d5166019..d5cab47cf 100644
--- a/nova/tests/test_network.py
+++ b/nova/tests/test_network.py
@@ -16,6 +16,7 @@
# under the License.
from nova import db
+from nova import exception
from nova import flags
from nova import log as logging
from nova import test
@@ -238,3 +239,35 @@ class VlanNetworkTestCase(test.TestCase):
self.assertRaises(ValueError, self.network.create_networks, None,
num_networks=100, vlan_start=1,
cidr='192.168.0.1/24', network_size=100)
+
+
+class CommonNetworkTestCase(test.TestCase):
+
+ class FakeNetworkManager(network_manager.NetworkManager):
+ """This NetworkManager doesn't call the base class so we can bypass all
+ inherited service cruft and just perform unit tests.
+ """
+
+ class FakeDB:
+ def fixed_ip_get_by_instance(self, context, instance_id):
+ return [dict(address='10.0.0.0'), dict(address='10.0.0.1'),
+ dict(address='10.0.0.2')]
+
+ def __init__(self):
+ self.db = self.FakeDB()
+ self.deallocate_called = None
+
+ def deallocate_fixed_ip(self, context, address):
+ self.deallocate_called = address
+
+ def test_remove_fixed_ip_from_instance(self):
+ manager = self.FakeNetworkManager()
+ manager.remove_fixed_ip_from_instance(None, 99, '10.0.0.1')
+
+ self.assertEquals(manager.deallocate_called, '10.0.0.1')
+
+ def test_remove_fixed_ip_from_instance_bad_input(self):
+ manager = self.FakeNetworkManager()
+ self.assertRaises(exception.FixedIpNotFound,
+ manager.remove_fixed_ip_from_instance,
+ None, 99, 'bad input')