|
81 | 81 | 'port: %(port_id)s.')
|
82 | 82 |
|
83 | 83 |
|
| 84 | +# TODO(froyo): Move this exception to neutron-lib as soon as possible, and when |
| 85 | +# a new release is created and pointed to in the requirements remove this code. |
| 86 | +class FipAssociated(n_exc.InUse): |
| 87 | + message = _('Unable to complete the operation on port "%(port_id)s" ' |
| 88 | + 'because the port still has an associated floating IP.') |
| 89 | + |
| 90 | + |
84 | 91 | @registry.has_registry_receivers
|
85 | 92 | class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
86 | 93 | base_services.WorkerBase,
|
@@ -1766,12 +1773,27 @@ def disassociate_floatingips(self, context, port_id, do_notify=True):
|
1766 | 1773 | @return: set of router-ids that require notification updates
|
1767 | 1774 | """
|
1768 | 1775 | with db_api.CONTEXT_WRITER.using(context):
|
| 1776 | + # NOTE(froyo): Context is elevated to confirm the presence of at |
| 1777 | + # least one FIP associated to the port_id. Additional checks |
| 1778 | + # regarding the tenant's grants will be carried out in following |
| 1779 | + # lines. |
1769 | 1780 | if not l3_obj.FloatingIP.objects_exist(
|
1770 |
| - context, fixed_port_id=port_id): |
| 1781 | + context.elevated(), fixed_port_id=port_id): |
1771 | 1782 | return []
|
1772 | 1783 |
|
1773 | 1784 | floating_ip_objs = l3_obj.FloatingIP.get_objects(
|
1774 | 1785 | context, fixed_port_id=port_id)
|
| 1786 | + |
| 1787 | + # NOTE(froyo): To ensure that a FIP assigned by an admin user |
| 1788 | + # cannot be disassociated by a tenant user, we raise exception to |
| 1789 | + # generate a 409 Conflict response message that prompts the tenant |
| 1790 | + # user to contact an admin, rather than a 500 error message. |
| 1791 | + if not context.is_admin: |
| 1792 | + floating_ip_objs_admin = l3_obj.FloatingIP.get_objects( |
| 1793 | + context.elevated(), fixed_port_id=port_id) |
| 1794 | + if floating_ip_objs_admin != floating_ip_objs: |
| 1795 | + raise FipAssociated(port_id=port_id) |
| 1796 | + |
1775 | 1797 | router_ids = {fip.router_id for fip in floating_ip_objs}
|
1776 | 1798 | old_fips = {fip.id: self._make_floatingip_dict(fip)
|
1777 | 1799 | for fip in floating_ip_objs}
|
|
0 commit comments