Use new enginefacade for quota and provisioning blocks
Use reader and writer for db operations. Partially-Implements blueprint: enginefacade-switch Change-Id: I3adaec4cae814c1feb88aa646b99823de9c0eb9e
This commit is contained in:
parent
9364f58ec5
commit
9195c66cbf
@ -486,7 +486,7 @@ class Controller(object):
|
||||
def notify(create_result):
|
||||
# Ensure usage trackers for all resources affected by this API
|
||||
# operation are marked as dirty
|
||||
with request.context.session.begin():
|
||||
with db_api.context_manager.writer.using(request.context):
|
||||
# Commit the reservation(s)
|
||||
for reservation in reservations:
|
||||
quota.QUOTAS.commit_reservation(
|
||||
|
@ -85,7 +85,7 @@ def set_quota_usage(context, resource, tenant_id,
|
||||
:param delta: Specifies whether in_use is an absolute number
|
||||
or a delta (default to False)
|
||||
"""
|
||||
with db_api.autonested_transaction(context.session):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
usage_data = quota_obj.QuotaUsage.get_object(
|
||||
context, resource=resource, project_id=tenant_id)
|
||||
if not usage_data:
|
||||
|
@ -168,7 +168,7 @@ class DbQuotaDriver(object):
|
||||
# locks should be ok to use when support for sending "hotspot" writes
|
||||
# to a single node will be available.
|
||||
requested_resources = deltas.keys()
|
||||
with db_api.autonested_transaction(context.session):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
# get_tenant_quotes needs in input a dictionary mapping resource
|
||||
# name to BaseResosurce instances so that the default quota can be
|
||||
# retrieved
|
||||
|
@ -19,6 +19,7 @@ from oslo_log import log as logging
|
||||
from pecan import hooks
|
||||
|
||||
from neutron.common import exceptions
|
||||
from neutron.db import api as db_api
|
||||
from neutron import manager
|
||||
from neutron import quota
|
||||
from neutron.quota import resource_registry
|
||||
@ -66,7 +67,7 @@ class QuotaEnforcementHook(hooks.PecanHook):
|
||||
if not reservations:
|
||||
return
|
||||
neutron_context = state.request.context.get('neutron_context')
|
||||
with neutron_context.session.begin():
|
||||
with db_api.context_manager.writer.using(neutron_context):
|
||||
# Commit the reservation(s)
|
||||
for reservation in reservations:
|
||||
quota.QUOTAS.commit_reservation(
|
||||
|
@ -177,7 +177,7 @@ class TrackedResource(BaseResource):
|
||||
def mark_dirty(self, context):
|
||||
if not self._dirty_tenants:
|
||||
return
|
||||
with db_api.autonested_transaction(context.session):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
# It is not necessary to protect this operation with a lock.
|
||||
# Indeed when this method is called the request has been processed
|
||||
# and therefore all resources created or deleted.
|
||||
|
@ -15,6 +15,7 @@ from oslo_log import log
|
||||
import six
|
||||
|
||||
from neutron._i18n import _, _LI, _LW
|
||||
from neutron.db import api as db_api
|
||||
from neutron.quota import resource
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
@ -71,7 +72,7 @@ def set_resources_dirty(context):
|
||||
return
|
||||
|
||||
for res in get_all_resources().values():
|
||||
with context.session.begin(subtransactions=True):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
if is_tracked(res.name) and res.dirty:
|
||||
res.mark_dirty(context)
|
||||
|
||||
|
@ -18,6 +18,7 @@ import testtools
|
||||
|
||||
from neutron.callbacks import registry
|
||||
from neutron.callbacks import resources
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import models_v2
|
||||
from neutron.db import provisioning_blocks as pb
|
||||
from neutron.tests.unit import testlib_api
|
||||
@ -37,7 +38,7 @@ class TestStatusBarriers(testlib_api.SqlTestCase):
|
||||
pb.PROVISIONING_COMPLETE)
|
||||
|
||||
def _make_net(self):
|
||||
with self.ctx.session.begin():
|
||||
with db_api.context_manager.writer.using(self.ctx):
|
||||
net = models_v2.Network(name='net_net', status='ACTIVE',
|
||||
tenant_id='1', admin_state_up=True)
|
||||
self.ctx.session.add(net)
|
||||
@ -45,7 +46,7 @@ class TestStatusBarriers(testlib_api.SqlTestCase):
|
||||
|
||||
def _make_port(self):
|
||||
net = self._make_net()
|
||||
with self.ctx.session.begin():
|
||||
with db_api.context_manager.writer.using(self.ctx):
|
||||
port = models_v2.Port(network_id=net.id, mac_address='1',
|
||||
tenant_id='1', admin_state_up=True,
|
||||
status='DOWN', device_id='2',
|
||||
|
Loading…
x
Reference in New Issue
Block a user