Skip to content

Commit f686d3a

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Fix inconsistent usages for network resources"
2 parents b1a3b0a + f2dfdd4 commit f686d3a

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

nova/network/floating_ips.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ def allocate_floating_ip(self, context, project_id, auto_assigned=False,
214214
# called into from other places
215215
try:
216216
if use_quota:
217-
reservations = QUOTAS.reserve(context, floating_ips=1)
217+
reservations = QUOTAS.reserve(context, floating_ips=1,
218+
project_id=project_id)
218219
except exception.OverQuota:
219220
LOG.warn(_("Quota exceeded for %s, tried to allocate "
220221
"floating IP"), context.project_id)
@@ -229,11 +230,12 @@ def allocate_floating_ip(self, context, project_id, auto_assigned=False,
229230

230231
# Commit the reservations
231232
if use_quota:
232-
QUOTAS.commit(context, reservations)
233+
QUOTAS.commit(context, reservations, project_id=project_id)
233234
except Exception:
234235
with excutils.save_and_reraise_exception():
235236
if use_quota:
236-
QUOTAS.rollback(context, reservations)
237+
QUOTAS.rollback(context, reservations,
238+
project_id=project_id)
237239

238240
return floating_ip
239241

@@ -263,10 +265,13 @@ def deallocate_floating_ip(self, context, address,
263265
floating_ip=floating_ip['address'])
264266
self.notifier.info(context, 'network.floating_ip.deallocate', payload)
265267

268+
project_id = floating_ip['project_id']
266269
# Get reservations...
267270
try:
268271
if use_quota:
269-
reservations = QUOTAS.reserve(context, floating_ips=-1)
272+
reservations = QUOTAS.reserve(context,
273+
project_id=project_id,
274+
floating_ips=-1)
270275
else:
271276
reservations = None
272277
except Exception:
@@ -278,7 +283,7 @@ def deallocate_floating_ip(self, context, address,
278283

279284
# Commit the reservations
280285
if reservations:
281-
QUOTAS.commit(context, reservations)
286+
QUOTAS.commit(context, reservations, project_id=project_id)
282287

283288
@rpc_common.client_exceptions(exception.FloatingIpNotFoundForAddress)
284289
def associate_floating_ip(self, context, floating_address, fixed_address,

nova/network/manager.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,16 @@ def deallocate_fixed_ip(self, context, address, host=None, teardown=True):
880880
instance_uuid = fixed_ip_ref['instance_uuid']
881881
vif_id = fixed_ip_ref['virtual_interface_id']
882882

883+
# NOTE(vish) This db query could be removed if we pass az and name
884+
# (or the whole instance object).
885+
instance = self.db.instance_get_by_uuid(
886+
context.elevated(read_deleted='yes'),
887+
instance_uuid)
888+
project_id = instance.project_id
883889
try:
884-
reservations = self.quotas.reserve(context, fixed_ips=-1)
890+
reservations = self.quotas.reserve(context,
891+
project_id=project_id,
892+
fixed_ips=-1)
885893
except Exception:
886894
reservations = None
887895
LOG.exception(_("Failed to update usages deallocating "
@@ -890,12 +898,6 @@ def deallocate_fixed_ip(self, context, address, host=None, teardown=True):
890898
self._do_trigger_security_group_members_refresh_for_instance(
891899
instance_uuid)
892900

893-
# NOTE(vish) This db query could be removed if we pass az and name
894-
# (or the whole instance object).
895-
instance = self.db.instance_get_by_uuid(
896-
context.elevated(read_deleted='yes'),
897-
instance_uuid)
898-
899901
if self._validate_instance_zone_for_dns_domain(context, instance):
900902
for n in self.instance_dns_manager.get_entries_by_address(address,
901903
self.instance_dns_domain):
@@ -951,7 +953,7 @@ def deallocate_fixed_ip(self, context, address, host=None, teardown=True):
951953

952954
# Commit the reservations
953955
if reservations:
954-
self.quotas.commit(context, reservations)
956+
self.quotas.commit(context, reservations, project_id=project_id)
955957

956958
def lease_fixed_ip(self, context, address):
957959
"""Called by dhcp-bridge when ip is leased."""

0 commit comments

Comments
 (0)