Browse Source

Replace db function get_session by get_writer_session

get_session was deprectaed on Ocata and removed in Queens [1].
So replace get_session by get_writer_session.

[1] https://review.openstack.org/#/c/529143

Change-Id: I669eaa5c02c21c253ac95666fe75b15f2da0c9d0
Swaminathan Vasudevan 1 year ago
parent
commit
f999f3446e

+ 9
- 9
networking_vsphere/db/ovsvapp_db.py View File

@@ -56,7 +56,7 @@ def _generate_vcenter_cluster_allocations(session, vcenter, cluster):
56 56
 def _initialize_lvids_for_cluster(port_info):
57 57
     vcenter = port_info['vcenter_id']
58 58
     cluster = port_info['cluster_id']
59
-    session = db_api.get_session()
59
+    session = db_api.get_writer_session()
60 60
     with session.begin(subtransactions=True):
61 61
         try:
62 62
             (session.query(models.ClusterVNIAllocations).
@@ -126,7 +126,7 @@ def _try_to_obtain_local_vlan(session, port_info, assign):
126 126
 
127 127
 def get_local_vlan(port_info, assign=True):
128 128
     lvid = None
129
-    session = db_api.get_session()
129
+    session = db_api.get_writer_session()
130 130
     res_keys = ['vcenter_id', 'cluster_id', 'network_id']
131 131
     res = dict((k, port_info[k]) for k in res_keys)
132 132
     with session.begin(subtransactions=True):
@@ -170,7 +170,7 @@ def get_local_vlan(port_info, assign=True):
170 170
 
171 171
 def check_to_reclaim_local_vlan(port_info):
172 172
     lvid = -1
173
-    session = db_api.get_session()
173
+    session = db_api.get_writer_session()
174 174
     with session.begin(subtransactions=True):
175 175
         res_keys = ['vcenter_id', 'cluster_id', 'network_id']
176 176
         res = dict((k, port_info[k]) for k in res_keys)
@@ -201,7 +201,7 @@ def check_to_reclaim_local_vlan(port_info):
201 201
 
202 202
 
203 203
 def release_local_vlan(net_info):
204
-    session = db_api.get_session()
204
+    session = db_api.get_writer_session()
205 205
     with session.begin(subtransactions=True):
206 206
         res_keys = ['vcenter_id', 'cluster_id', 'network_id']
207 207
         res = dict((k, net_info[k]) for k in res_keys)
@@ -231,7 +231,7 @@ def release_local_vlan(net_info):
231 231
 
232 232
 
233 233
 def get_stale_local_vlans_for_network(network_id):
234
-    session = db_api.get_session()
234
+    session = db_api.get_writer_session()
235 235
     vcenter_clusters = None
236 236
     with session.begin(subtransactions=True):
237 237
         try:
@@ -256,7 +256,7 @@ def get_stale_local_vlans_for_network(network_id):
256 256
 
257 257
 
258 258
 def update_and_get_cluster_lock(vcenter_id, cluster_id):
259
-    session = db_api.get_session()
259
+    session = db_api.get_writer_session()
260 260
     with session.begin(subtransactions=True):
261 261
         try:
262 262
             query = session.query(models.OVSvAppClusters)
@@ -294,7 +294,7 @@ def update_and_get_cluster_lock(vcenter_id, cluster_id):
294 294
 
295 295
 
296 296
 def release_cluster_lock(vcenter_id, cluster_id):
297
-    session = db_api.get_session()
297
+    session = db_api.get_writer_session()
298 298
     with session.begin(subtransactions=True):
299 299
         try:
300 300
             query = session.query(models.OVSvAppClusters)
@@ -309,7 +309,7 @@ def release_cluster_lock(vcenter_id, cluster_id):
309 309
 
310 310
 
311 311
 def reset_cluster_threshold(vcenter_id, cluster_id):
312
-    session = db_api.get_session()
312
+    session = db_api.get_writer_session()
313 313
     with session.begin(subtransactions=True):
314 314
         try:
315 315
             query = session.query(models.OVSvAppClusters)
@@ -330,7 +330,7 @@ def reset_cluster_threshold(vcenter_id, cluster_id):
330 330
 
331 331
 
332 332
 def set_cluster_threshold(vcenter_id, cluster_id):
333
-    session = db_api.get_session()
333
+    session = db_api.get_writer_session()
334 334
     with session.begin(subtransactions=True):
335 335
         try:
336 336
             query = session.query(models.OVSvAppClusters)

+ 1
- 1
networking_vsphere/tests/unit/extensions/test_ovsvapp_mitigated_cluster_resource.py View File

@@ -38,7 +38,7 @@ class OVSvAppMitigatedClusterDBTestCase(testlib_api.SqlTestCase):
38 38
 
39 39
     def _create_ovsvapp_mitigated_cluster(self, ovsvapp_mitigated_cluster):
40 40
         """Create mitigated_cluster helper method."""
41
-        session = db_api.get_session()
41
+        session = db_api.get_writer_session()
42 42
         db_entry_dict = ovsvapp_mitigated_cluster['ovsvapp_mitigated_cluster']
43 43
         db_entry = {'vcenter_id': db_entry_dict['vcenter_id'],
44 44
                     'cluster_id': db_entry_dict['cluster_id'],

+ 1
- 1
networking_vsphere/tests/unit/ml2/test_dvs_mechanism_driver.py View File

@@ -45,7 +45,7 @@ class VMwareDVSMechanismDriverTestCase(base.BaseTestCase):
45 45
         self.dvs_notifier = mock.Mock()
46 46
         self.driver.network_map = {'physnet1': mock.Mock()}
47 47
 
48
-    @mock.patch('neutron.db.api.get_session')
48
+    @mock.patch('neutron.db.api.get_writer_session')
49 49
     @mock.patch('networking_vsphere.utils.dvs_util.'
50 50
                 'create_network_map_from_config', return_value='network_map')
51 51
     def test_initialize(self, create_network_map_from_config, get_session):

+ 1
- 1
networking_vsphere/utils/db.py View File

@@ -21,7 +21,7 @@ from networking_vsphere.common import constants
21 21
 
22 22
 def get_agent_by_host(agent_host):
23 23
     """Return a L2 agent on the host."""
24
-    session = db_api.get_session()
24
+    session = db_api.get_writer_session()
25 25
     with session.begin(subtransactions=True):
26 26
         query = session.query(agents_db.Agent)
27 27
         agent = query.filter(

Loading…
Cancel
Save