summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Tran <jtran@attinteractive.com>2011-07-19 13:49:05 -0700
committerJohn Tran <jtran@attinteractive.com>2011-07-19 13:49:05 -0700
commitecb68bf77565cb01ec0ea4d28c7f1315e10b21c4 (patch)
treeb5248658dc4b9ce6792bcd2af8fe118bf13daf87
parentcf25ab33cb7d6b5e233a767ad96b3c45b1387b5e (diff)
downloadnova-ecb68bf77565cb01ec0ea4d28c7f1315e10b21c4.tar.gz
nova-ecb68bf77565cb01ec0ea4d28c7f1315e10b21c4.tar.xz
nova-ecb68bf77565cb01ec0ea4d28c7f1315e10b21c4.zip
network api release_floating_ip method checks if an instance associated to the floating prior to releasing. added test
-rw-r--r--nova/network/api.py3
-rw-r--r--nova/tests/test_cloud.py29
2 files changed, 32 insertions, 0 deletions
diff --git a/nova/network/api.py b/nova/network/api.py
index 70b1099f0..f03081be4 100644
--- a/nova/network/api.py
+++ b/nova/network/api.py
@@ -61,6 +61,9 @@ class API(base.Base):
affect_auto_assigned=False):
"""Removes floating ip with address from a project."""
floating_ip = self.db.floating_ip_get_by_address(context, address)
+ if floating_ip['fixed_ip']:
+ raise exception.ApiError(_('Floating ip is in use. '
+ 'Disassociate it before releasing.'))
if not affect_auto_assigned and floating_ip.get('auto_assigned'):
return
# NOTE(vish): We don't know which network host should get the ip
diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py
index d71a03aff..557e3f89b 100644
--- a/nova/tests/test_cloud.py
+++ b/nova/tests/test_cloud.py
@@ -15,6 +15,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
+import mox
from base64 import b64decode
from M2Crypto import BIO
@@ -131,6 +132,34 @@ class CloudTestCase(test.TestCase):
allocate,
self.context)
+ def test_release_address(self):
+ address = "10.10.10.10"
+ allocate = self.cloud.allocate_address
+ db.floating_ip_create(self.context,
+ {'address': address,
+ 'host': self.network.host})
+ result = self.cloud.release_address(self.context, address)
+ self.assertEqual(result['releaseResponse'], ['Address released.'])
+
+ def test_release_address_still_associated(self):
+ address = "10.10.10.10"
+ fixed_ip = {'instance': {'id': 1}}
+ floating_ip = {'id': 0,
+ 'address': address,
+ 'fixed_ip_id': 0,
+ 'fixed_ip': fixed_ip,
+ 'project_id': None,
+ 'auto_assigned': False}
+ from nova import network
+ network_api = network.api.API()
+ self.mox.StubOutWithMock(network_api.db, 'floating_ip_get_by_address')
+ network_api.db.floating_ip_get_by_address(mox.IgnoreArg(),
+ mox.IgnoreArg()).AndReturn(floating_ip)
+ self.mox.ReplayAll()
+ release = self.cloud.release_address
+ # ApiError: Floating ip is in use. Disassociate it before releasing.
+ self.assertRaises(exception.ApiError, release, self.context, address)
+
@test.skip_test("Skipping this pending future merge")
def test_associate_disassociate_address(self):
"""Verifies associate runs cleanly without raising an exception"""