summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Tran <jtran@attinteractive.com>2011-07-20 16:41:10 +0000
committerTarmac <>2011-07-20 16:41:10 +0000
commitf926ae2a0fcf115beae78b8edfbf4ddee1d646be (patch)
treed2be1a0c2b7ed8ce437e996b69b62d30c8f7bb46
parentb76d31cf6be76f9ece78d2377c0cbad0cb10c584 (diff)
parent1d4a789ed370fe0cc00c292f89b96b0ffaf115ff (diff)
downloadnova-f926ae2a0fcf115beae78b8edfbf4ddee1d646be.tar.gz
nova-f926ae2a0fcf115beae78b8edfbf4ddee1d646be.tar.xz
nova-f926ae2a0fcf115beae78b8edfbf4ddee1d646be.zip
network api release_floating_ip method will now check to see if an instance is associated to it, prior to releasing.
-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 a0d50b287..8cdc73a66 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
@@ -29,6 +30,7 @@ from nova import db
from nova import exception
from nova import flags
from nova import log as logging
+from nova import network
from nova import rpc
from nova import test
from nova import utils
@@ -132,6 +134,33 @@ 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}
+ 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"""