Replace db get_session with get_reader/writer_session
The db/api get_session is deprecated. We should use get_reader_session or get_writer_session instead. Change-Id: I5f04bd0cfd43ae5b9c31b9ece3cf77fcef56cd3f
This commit is contained in:
parent
7deb5eb8c3
commit
20c55bcac4
@ -44,7 +44,7 @@ def _apply_filters_to_query(query, model, filters, like_filters=None):
|
||||
|
||||
|
||||
def get_network_bindings(session, network_id):
|
||||
session = session or db.get_session()
|
||||
session = session or db.get_reader_session()
|
||||
return (session.query(nsx_models.TzNetworkBinding).
|
||||
filter_by(network_id=network_id).
|
||||
all())
|
||||
@ -52,7 +52,7 @@ def get_network_bindings(session, network_id):
|
||||
|
||||
def get_network_bindings_by_vlanid_and_physical_net(session, vlan_id,
|
||||
phy_uuid):
|
||||
session = session or db.get_session()
|
||||
session = session or db.get_reader_session()
|
||||
return (session.query(nsx_models.TzNetworkBinding).
|
||||
filter_by(vlan_id=vlan_id, phy_uuid=phy_uuid).
|
||||
all())
|
||||
|
@ -102,7 +102,7 @@ def get_nsxv_router_bindings_by_edge(session, edge_id):
|
||||
@warn_on_binding_status_error
|
||||
def get_nsxv_router_bindings(session, filters=None,
|
||||
like_filters=None):
|
||||
session = db.get_session()
|
||||
session = db.get_reader_session()
|
||||
query = session.query(nsxv_models.NsxvRouterBinding)
|
||||
return nsx_db._apply_filters_to_query(query, nsxv_models.NsxvRouterBinding,
|
||||
filters, like_filters).all()
|
||||
@ -505,7 +505,7 @@ def get_nsx_vnic_id(session, neutron_id):
|
||||
|
||||
|
||||
def get_network_bindings(session, network_id):
|
||||
session = session or db.get_session()
|
||||
session = session or db.get_reader_session()
|
||||
return (session.query(nsxv_models.NsxvTzNetworkBinding).
|
||||
filter_by(network_id=network_id).
|
||||
all())
|
||||
@ -513,7 +513,7 @@ def get_network_bindings(session, network_id):
|
||||
|
||||
def get_network_bindings_by_vlanid_and_physical_net(session, vlan_id,
|
||||
phy_uuid):
|
||||
session = session or db.get_session()
|
||||
session = session or db.get_reader_session()
|
||||
return (session.query(nsxv_models.NsxvTzNetworkBinding).
|
||||
filter_by(vlan_id=vlan_id, phy_uuid=phy_uuid).
|
||||
all())
|
||||
@ -533,7 +533,7 @@ def add_network_binding(session, network_id, binding_type, phy_uuid, vlan_id):
|
||||
|
||||
|
||||
def get_network_bindings_by_vlanid(session, vlan_id):
|
||||
session = session or db.get_session()
|
||||
session = session or db.get_reader_session()
|
||||
return (session.query(nsxv_models.NsxvTzNetworkBinding).
|
||||
filter_by(vlan_id=vlan_id).
|
||||
all())
|
||||
@ -616,7 +616,7 @@ def get_spoofguard_policy_id(session, network_id):
|
||||
|
||||
def get_nsxv_spoofguard_policy_network_mappings(session, filters=None,
|
||||
like_filters=None):
|
||||
session = db.get_session()
|
||||
session = db.get_reader_session()
|
||||
query = session.query(nsxv_models.NsxvSpoofGuardPolicyNetworkMapping)
|
||||
return nsx_db._apply_filters_to_query(
|
||||
query, nsxv_models.NsxvSpoofGuardPolicyNetworkMapping,
|
||||
|
@ -383,20 +383,22 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
return self.conn.consume_in_threads()
|
||||
|
||||
def _ext_extend_network_dict(self, result, netdb):
|
||||
session = db_api.get_session()
|
||||
with session.begin(subtransactions=True):
|
||||
self._extension_manager.extend_network_dict(session, netdb, result)
|
||||
ctx = n_context.get_admin_context()
|
||||
with db_api.context_manager.writer.using(ctx):
|
||||
self._extension_manager.extend_network_dict(
|
||||
ctx.session, netdb, result)
|
||||
|
||||
def _ext_extend_port_dict(self, result, portdb):
|
||||
session = db_api.get_session()
|
||||
with session.begin(subtransactions=True):
|
||||
self._extension_manager.extend_port_dict(session, portdb, result)
|
||||
ctx = n_context.get_admin_context()
|
||||
with db_api.context_manager.writer.using(ctx):
|
||||
self._extension_manager.extend_port_dict(
|
||||
ctx.session, portdb, result)
|
||||
|
||||
def _ext_extend_subnet_dict(self, result, subnetdb):
|
||||
session = db_api.get_session()
|
||||
with session.begin(subtransactions=True):
|
||||
ctx = n_context.get_admin_context()
|
||||
with db_api.context_manager.writer.using(ctx):
|
||||
self._extension_manager.extend_subnet_dict(
|
||||
session, subnetdb, result)
|
||||
ctx.session, subnetdb, result)
|
||||
|
||||
def _create_security_group_container(self):
|
||||
name = "OpenStack Security Group container"
|
||||
|
@ -588,20 +588,22 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
return self.conn.consume_in_threads()
|
||||
|
||||
def _ext_extend_network_dict(self, result, netdb):
|
||||
session = db_api.get_session()
|
||||
with session.begin(subtransactions=True):
|
||||
self._extension_manager.extend_network_dict(session, netdb, result)
|
||||
ctx = q_context.get_admin_context()
|
||||
with db_api.context_manager.writer.using(ctx):
|
||||
self._extension_manager.extend_network_dict(
|
||||
ctx.session, netdb, result)
|
||||
|
||||
def _ext_extend_port_dict(self, result, portdb):
|
||||
session = db_api.get_session()
|
||||
with session.begin(subtransactions=True):
|
||||
self._extension_manager.extend_port_dict(session, portdb, result)
|
||||
ctx = q_context.get_admin_context()
|
||||
with db_api.context_manager.writer.using(ctx):
|
||||
self._extension_manager.extend_port_dict(
|
||||
ctx.session, portdb, result)
|
||||
|
||||
def _ext_extend_subnet_dict(self, result, subnetdb):
|
||||
session = db_api.get_session()
|
||||
with session.begin(subtransactions=True):
|
||||
ctx = q_context.get_admin_context()
|
||||
with db_api.context_manager.writer.using(ctx):
|
||||
self._extension_manager.extend_subnet_dict(
|
||||
session, subnetdb, result)
|
||||
ctx.session, subnetdb, result)
|
||||
|
||||
def _validate_provider_create(self, context, network_data):
|
||||
is_provider_net = any(
|
||||
|
@ -126,7 +126,7 @@ class DhcpMtuDBTestCase(test_db.NeutronDbPluginV2TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(DhcpMtuDBTestCase, self).setUp()
|
||||
self.session = db.get_session()
|
||||
self.session = db.get_writer_session()
|
||||
|
||||
def test_get_nsxv_subnet_ext_attributes_no_dhcp_mtu(self):
|
||||
with self.subnet() as sub:
|
||||
|
@ -85,7 +85,7 @@ class DnsSearchDomainDBTestCase(test_db.NeutronDbPluginV2TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(DnsSearchDomainDBTestCase, self).setUp()
|
||||
self.session = db.get_session()
|
||||
self.session = db.get_writer_session()
|
||||
|
||||
def test_get_nsxv_subnet_ext_attributes_no_dns_search_domain(self):
|
||||
with self.subnet() as sub:
|
||||
|
@ -583,7 +583,7 @@ class NetworkGatewayDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
|
||||
# Nothing to do here - just let the gateway go
|
||||
gw_id = gw[self.gw_resource]['id']
|
||||
# Verify nothing left on db
|
||||
session = db_api.get_session()
|
||||
session = db_api.get_reader_session()
|
||||
dev_query = session.query(
|
||||
nsx_models.NetworkGatewayDevice).filter(
|
||||
nsx_models.NetworkGatewayDevice.id == device_id)
|
||||
@ -909,7 +909,7 @@ class NetworkGatewayDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
|
||||
# Nothing to do here - just note the device id
|
||||
dev_id = dev[self.dev_resource]['id']
|
||||
# Verify nothing left on db
|
||||
session = db_api.get_session()
|
||||
session = db_api.get_reader_session()
|
||||
dev_query = session.query(nsx_models.NetworkGatewayDevice)
|
||||
dev_query.filter(nsx_models.NetworkGatewayDevice.id == dev_id)
|
||||
self.assertIsNone(dev_query.first())
|
||||
|
@ -68,7 +68,7 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
# The nsxlib and db calls are mocked, therefore the cluster
|
||||
# and the neutron_port_id parameters can be set to None
|
||||
ls_uuid, lp_uuid = nsx_utils.get_nsx_switch_and_port_id(
|
||||
db_api.get_session(), None, None)
|
||||
db_api.get_reader_session(), None, None)
|
||||
self.assertEqual(exp_ls_uuid, ls_uuid)
|
||||
self.assertEqual(exp_lp_uuid, lp_uuid)
|
||||
|
||||
@ -76,7 +76,7 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
# The nsxlib and db calls are mocked, therefore the cluster
|
||||
# and the neutron_router_id parameters can be set to None
|
||||
ls_uuids = nsx_utils.get_nsx_switch_ids(
|
||||
db_api.get_session(), None, None)
|
||||
db_api.get_reader_session(), None, None)
|
||||
for ls_uuid in ls_uuids or []:
|
||||
self.assertIn(ls_uuid, exp_ls_uuids)
|
||||
exp_ls_uuids.remove(ls_uuid)
|
||||
@ -84,7 +84,8 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
|
||||
def _verify_get_nsx_router_id(self, exp_lr_uuid):
|
||||
neutron_router_id = uuidutils.generate_uuid()
|
||||
lr_uuid = nsx_utils.get_nsx_router_id(db_api.get_session(), None,
|
||||
lr_uuid = nsx_utils.get_nsx_router_id(db_api.get_reader_session(),
|
||||
None,
|
||||
neutron_router_id)
|
||||
self.assertEqual(exp_lr_uuid, lr_uuid)
|
||||
|
||||
@ -280,7 +281,7 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
||||
# The nsxlib and db calls are mocked, therefore the cluster
|
||||
# and the neutron_id parameters can be set to None
|
||||
sec_prof_uuid = nsx_utils.get_nsx_security_group_id(
|
||||
db_api.get_session(), None, None)
|
||||
db_api.get_reader_session(), None, None)
|
||||
self.assertEqual(exp_sec_prof_uuid, sec_prof_uuid)
|
||||
|
||||
def test_get_nsx_sec_profile_id_from_db_mappings(self):
|
||||
|
Loading…
Reference in New Issue
Block a user