From c44ce398eacbd95331fb8990390a662cf4ce8f24 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Mon, 3 Sep 2012 21:44:36 +0100 Subject: Allow admins to de-allocate any floating IPs Fix bug 1045508 Change-Id: Ie5be3748c16a592209934cc85777f534e84842bc --- nova/network/manager.py | 3 +++ nova/tests/network/test_manager.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/nova/network/manager.py b/nova/network/manager.py index f2af017df..d908b7a4c 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -388,6 +388,9 @@ class FloatingIP(object): def _floating_ip_owned_by_project(self, context, floating_ip): """Raises if floating ip does not belong to project""" + if context.is_admin: + return + if floating_ip['project_id'] != context.project_id: if floating_ip['project_id'] is None: LOG.warn(_('Address |%(address)s| is not allocated'), diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py index bfe8d7a3b..31b600b16 100644 --- a/nova/tests/network/test_manager.py +++ b/nova/tests/network/test_manager.py @@ -581,6 +581,19 @@ class VlanNetworkTestCase(test.TestCase): 'project_id': ctxt.project_id} self.network._floating_ip_owned_by_project(ctxt, floating_ip) + ctxt = context.RequestContext(None, None, + is_admin=True) + + # does not raise (ctxt is admin) + floating_ip = {'address': '10.0.0.1', + 'project_id': None} + self.network._floating_ip_owned_by_project(ctxt, floating_ip) + + # does not raise (ctxt is admin) + floating_ip = {'address': '10.0.0.1', + 'project_id': 'testproject'} + self.network._floating_ip_owned_by_project(ctxt, floating_ip) + def test_allocate_floating_ip(self): ctxt = context.RequestContext('testuser', 'testproject', is_admin=False) -- cgit