Merge lp:~jtran/nova/lp761827 into lp:~hudson-openstack/nova/trunk

Proposed by John Tran
Status: Merged
Approved by: Brian Waldon
Approved revision: 1284
Merged at revision: 1286
Proposed branch: lp:~jtran/nova/lp761827
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 67 lines (+32/-0)
2 files modified
nova/network/api.py (+3/-0)
nova/tests/test_cloud.py (+29/-0)
To merge this branch: bzr merge lp:~jtran/nova/lp761827
Reviewer Review Type Date Requested Status
Jason Kölker (community) Approve
Brian Waldon (community) Approve
Brian Lamar (community) Approve
Review via email: mp+68465@code.launchpad.net

Commit message

network api release_floating_ip method will now check to see if an instance is associated to it, prior to releasing.

Description of the change

network api release_floating_ip method will now check to see if an instance is associated to it, prior to releasing.

To post a comment you must log in.
lp:~jtran/nova/lp761827 updated
1284. By John Tran

move import network to the top

Revision history for this message
Brian Lamar (blamar) wrote :

Seems like a good straight-forward fix to me.

review: Approve
Revision history for this message
Brian Waldon (bcwaldon) wrote :

Looks good, John.

review: Approve
Revision history for this message
Jason Kölker (jason-koelker) wrote :

Is Bueno.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/network/api.py'
2--- nova/network/api.py 2011-07-07 16:45:00 +0000
3+++ nova/network/api.py 2011-07-19 21:16:44 +0000
4@@ -61,6 +61,9 @@
5 affect_auto_assigned=False):
6 """Removes floating ip with address from a project."""
7 floating_ip = self.db.floating_ip_get_by_address(context, address)
8+ if floating_ip['fixed_ip']:
9+ raise exception.ApiError(_('Floating ip is in use. '
10+ 'Disassociate it before releasing.'))
11 if not affect_auto_assigned and floating_ip.get('auto_assigned'):
12 return
13 # NOTE(vish): We don't know which network host should get the ip
14
15=== modified file 'nova/tests/test_cloud.py'
16--- nova/tests/test_cloud.py 2011-07-18 23:42:02 +0000
17+++ nova/tests/test_cloud.py 2011-07-19 21:16:44 +0000
18@@ -15,6 +15,7 @@
19 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
20 # License for the specific language governing permissions and limitations
21 # under the License.
22+import mox
23
24 from base64 import b64decode
25 from M2Crypto import BIO
26@@ -29,6 +30,7 @@
27 from nova import exception
28 from nova import flags
29 from nova import log as logging
30+from nova import network
31 from nova import rpc
32 from nova import test
33 from nova import utils
34@@ -132,6 +134,33 @@
35 allocate,
36 self.context)
37
38+ def test_release_address(self):
39+ address = "10.10.10.10"
40+ allocate = self.cloud.allocate_address
41+ db.floating_ip_create(self.context,
42+ {'address': address,
43+ 'host': self.network.host})
44+ result = self.cloud.release_address(self.context, address)
45+ self.assertEqual(result['releaseResponse'], ['Address released.'])
46+
47+ def test_release_address_still_associated(self):
48+ address = "10.10.10.10"
49+ fixed_ip = {'instance': {'id': 1}}
50+ floating_ip = {'id': 0,
51+ 'address': address,
52+ 'fixed_ip_id': 0,
53+ 'fixed_ip': fixed_ip,
54+ 'project_id': None,
55+ 'auto_assigned': False}
56+ network_api = network.api.API()
57+ self.mox.StubOutWithMock(network_api.db, 'floating_ip_get_by_address')
58+ network_api.db.floating_ip_get_by_address(mox.IgnoreArg(),
59+ mox.IgnoreArg()).AndReturn(floating_ip)
60+ self.mox.ReplayAll()
61+ release = self.cloud.release_address
62+ # ApiError: Floating ip is in use. Disassociate it before releasing.
63+ self.assertRaises(exception.ApiError, release, self.context, address)
64+
65 @test.skip_test("Skipping this pending future merge")
66 def test_associate_disassociate_address(self):
67 """Verifies associate runs cleanly without raising an exception"""