Browse Source

OSP-224: Cleanup for NSAPI context header

patch 3: also remove test_req_context_header_present

---

Intially the context header was intended for 2 purposes:

1. Update tenant name
2. Provide debug information to BCF

However, long ago, we changed to use tenant_name for identification and stops supporting renaming, so 1 is unessesary.

Note: we will support renaming with the next uuid change, but it will be using different approach and this context can not only be used for the purpose, but also causes intended behaviors to block it.

For 2, there might be some miscommunications among different devs as we have never been logging the information on BCF side.

Considering no one found this before, means that nobody uses this for debug, it is a waste of resource to generate the context for every REST call.

For above two reasons, we are removing related logics completely.

Change-Id: I8b536526b7515ac5587e3dcd52afaa660e462348
(cherry picked from commit 3cd793b9fd)
Weifan Fu 7 months ago
parent
commit
f6bb4b4c51

+ 10
- 10
networking_bigswitch/plugins/bigswitch/l3_router_plugin.py View File

@@ -51,7 +51,7 @@ from networking_bigswitch.plugins.bigswitch import servermanager
51 51
 from networking_bigswitch.plugins.bigswitch.utils import Util
52 52
 
53 53
 LOG = logging.getLogger(__name__)
54
-put_context_in_serverpool = cplugin.put_context_in_serverpool
54
+add_debug_log = cplugin.add_debug_log
55 55
 BCF_CAPABILITY_L3_PLUGIN_MISS_MATCH = (
56 56
     "BCF does not have floatingip capability, should not "
57 57
     "deploy BSN l3 router plugin")
@@ -208,7 +208,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
208 208
                 self.servers.rest_create_tenantpolicy(
209 209
                     tenantpolicy_dict['tenant_id'], tenantpolicy_dict)
210 210
 
211
-    @put_context_in_serverpool
211
+    @add_debug_log
212 212
     @log_helper.log_method_call
213 213
     def create_router(self, context, router):
214 214
         self._warn_on_state_status(router['router'])
@@ -235,7 +235,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
235 235
         finally:
236 236
             self.txn_cache.remove_transaction(bsn_transaction_id)
237 237
 
238
-    @put_context_in_serverpool
238
+    @add_debug_log
239 239
     @log_helper.log_method_call
240 240
     def update_router(self, context, router_id, router):
241 241
         self._warn_on_state_status(router['router'])
@@ -280,7 +280,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
280 280
                 super(L3RestProxy, self).remove_default_policy(context,
281 281
                                                                tenant_id)
282 282
 
283
-    @put_context_in_serverpool
283
+    @add_debug_log
284 284
     @log_helper.log_method_call
285 285
     def delete_router(self, context, router_id):
286 286
         with db.context_manager.reader.using(context):
@@ -339,7 +339,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
339 339
         directory.get_plugin().update_port(context, port['id'],
340 340
                                            {'port': {'status': 'ACTIVE'}})
341 341
 
342
-    @put_context_in_serverpool
342
+    @add_debug_log
343 343
     @log_helper.log_method_call
344 344
     def add_router_interface(self, context, router_id, interface_info):
345 345
         bsn_transaction_id = uuidutils.generate_uuid()
@@ -364,7 +364,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
364 364
         finally:
365 365
             self.txn_cache.remove_transaction(bsn_transaction_id)
366 366
 
367
-    @put_context_in_serverpool
367
+    @add_debug_log
368 368
     @log_helper.log_method_call
369 369
     def remove_router_interface(self, context, router_id, interface_info):
370 370
         # Validate args
@@ -408,7 +408,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
408 408
         res['floating_port_id'] = floatingip['floating_port_id']
409 409
         return self._fields(res, fields)
410 410
 
411
-    @put_context_in_serverpool
411
+    @add_debug_log
412 412
     @log_helper.log_method_call
413 413
     def create_floatingip(self, context, floatingip):
414 414
         with db.context_manager.writer.using(context):
@@ -438,7 +438,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
438 438
             # return created floating IP
439 439
             return new_fl_ip
440 440
 
441
-    @put_context_in_serverpool
441
+    @add_debug_log
442 442
     @log_helper.log_method_call
443 443
     def update_floatingip(self, context, id, floatingip):
444 444
         with db.context_manager.writer.using(context):
@@ -462,7 +462,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
462 462
                 self._send_floatingip_update(context)
463 463
             return new_fl_ip
464 464
 
465
-    @put_context_in_serverpool
465
+    @add_debug_log
466 466
     @log_helper.log_method_call
467 467
     def delete_floatingip(self, context, id):
468 468
         with db.context_manager.writer.using(context):
@@ -479,7 +479,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
479 479
                 LOG.error(BCF_CAPABILITY_L3_PLUGIN_MISS_MATCH)
480 480
                 self._send_floatingip_update(context)
481 481
 
482
-    @put_context_in_serverpool
482
+    @add_debug_log
483 483
     @log_helper.log_method_call
484 484
     def disassociate_floatingips(self, context, port_id, do_notify=True):
485 485
         router_ids = super(L3RestProxy, self).disassociate_floatingips(

+ 11
- 12
networking_bigswitch/plugins/bigswitch/plugin.py View File

@@ -920,13 +920,12 @@ class NeutronRestProxyV2Base(db_base_plugin_v2.NeutronDbPluginV2,
920 920
             raise lib_exceptions.PortNotFound(port_id=port_id)
921 921
 
922 922
 
923
-def put_context_in_serverpool(f):
923
+def add_debug_log(f):
924 924
     @functools.wraps(f)
925 925
     def wrapper(self, context, *args, **kwargs):
926 926
         # core plugin: context is top level object
927
-        # ml2: keeps context in _plugin_context
927
+        # Do not need context in header anymore
928 928
         LOG.debug("Function: %(fname)s called", {'fname': f.__name__})
929
-        self.servers.set_context(getattr(context, '_plugin_context', context))
930 929
         return f(self, context, *args, **kwargs)
931 930
     return wrapper
932 931
 
@@ -982,7 +981,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
982 981
         LOG.debug("NeutronRestProxyV2: initialization done")
983 982
 
984 983
     @db.context_manager.writer
985
-    @put_context_in_serverpool
984
+    @add_debug_log
986 985
     def create_network(self, context, network):
987 986
         """Create a network.
988 987
 
@@ -1024,7 +1023,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1024 1023
         return new_net
1025 1024
 
1026 1025
     @db.context_manager.writer
1027
-    @put_context_in_serverpool
1026
+    @add_debug_log
1028 1027
     def update_network(self, context, net_id, network):
1029 1028
         """Updates the properties of a particular Virtual Network.
1030 1029
 
@@ -1059,7 +1058,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1059 1058
         return new_net
1060 1059
 
1061 1060
     @db.context_manager.writer
1062
-    @put_context_in_serverpool
1061
+    @add_debug_log
1063 1062
     def delete_network(self, context, net_id):
1064 1063
         """Delete a network.
1065 1064
 
@@ -1081,7 +1080,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1081 1080
         self._send_delete_network(orig_net, context)
1082 1081
         return ret_val
1083 1082
 
1084
-    @put_context_in_serverpool
1083
+    @add_debug_log
1085 1084
     def create_port(self, context, port):
1086 1085
         """Create a port.
1087 1086
 
@@ -1173,7 +1172,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1173 1172
                 self._extend_port_dict_binding(context, port)
1174 1173
         return [self._fields(port, fields) for port in ports]
1175 1174
 
1176
-    @put_context_in_serverpool
1175
+    @add_debug_log
1177 1176
     def update_port(self, context, port_id, port):
1178 1177
         """Update values of a port.
1179 1178
 
@@ -1252,7 +1251,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1252 1251
 
1253 1252
     # NOTE(kevinbenton): workaround for eventlet/mysql deadlock
1254 1253
     @runtime.synchronized('bsn-port-barrier')
1255
-    @put_context_in_serverpool
1254
+    @add_debug_log
1256 1255
     def delete_port(self, context, port_id, l3_port_check=True):
1257 1256
         """Delete a port.
1258 1257
 
@@ -1283,7 +1282,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1283 1282
             # now that we've left db transaction, we are safe to notify
1284 1283
             self.l3_plugin.notify_routers_updated(context, router_ids)
1285 1284
 
1286
-    @put_context_in_serverpool
1285
+    @add_debug_log
1287 1286
     def create_subnet(self, context, subnet):
1288 1287
         self._warn_on_state_status(subnet['subnet'])
1289 1288
 
@@ -1298,7 +1297,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1298 1297
             self._send_update_network(orig_net, context)
1299 1298
         return new_subnet
1300 1299
 
1301
-    @put_context_in_serverpool
1300
+    @add_debug_log
1302 1301
     def update_subnet(self, context, id, subnet):
1303 1302
         self._warn_on_state_status(subnet['subnet'])
1304 1303
 
@@ -1313,7 +1312,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1313 1312
             self._send_update_network(orig_net, context)
1314 1313
             return new_subnet
1315 1314
 
1316
-    @put_context_in_serverpool
1315
+    @add_debug_log
1317 1316
     def delete_subnet(self, context, id):
1318 1317
         orig_subnet = super(NeutronRestProxyV2, self).get_subnet(context, id)
1319 1318
         net_id = orig_subnet['network_id']

+ 0
- 31
networking_bigswitch/plugins/bigswitch/servermanager.py View File

@@ -32,7 +32,6 @@ import re
32 32
 import socket
33 33
 import ssl
34 34
 import time
35
-import weakref
36 35
 
37 36
 from neutron_lib import exceptions
38 37
 
@@ -88,7 +87,6 @@ FAILURE_CODES = [0, 301, 302, 303, 400, 401, 403, 404, 500, 501, 502, 503,
88 87
 BASE_URI = '/networkService/v2.0'
89 88
 ORCHESTRATION_SERVICE_ID = 'Neutron v2.0'
90 89
 HASH_MATCH_HEADER = 'X-BSN-BVS-HASH-MATCH'
91
-REQ_CONTEXT_HEADER = 'X-REQ-CONTEXT'
92 90
 SERVICE_TENANT = 'VRRP_Service'
93 91
 KS_AUTH_GROUP_NAME = 'keystone_authtoken'
94 92
 KS_AUTH_DOMAIN_DEFAULT = 'default'
@@ -448,7 +446,6 @@ class ServerPool(object):
448 446
 
449 447
         self.base_uri = base_uri
450 448
         self.name = name
451
-        self.contexts = {}
452 449
         # Cache for Openstack projects
453 450
         # The cache is maintained in a separate thread and sync'ed with
454 451
         # Keystone periodically.
@@ -497,23 +494,6 @@ class ServerPool(object):
497 494
             self._keystone_sync,
498 495
             cfg.CONF.RESTPROXY.keystone_sync_interval)
499 496
 
500
-    def set_context(self, context):
501
-        # this context needs to be local to the greenthread
502
-        # so concurrent requests don't use the wrong context.
503
-        # Use a weakref so the context is garbage collected
504
-        # after the plugin is done with it.
505
-        ref = weakref.ref(context)
506
-        self.contexts[eventlet.corolocal.get_ident()] = ref
507
-
508
-    def get_context_ref(self):
509
-        # Try to get the context cached for this thread. If one
510
-        # doesn't exist or if it's been garbage collected, this will
511
-        # just return None.
512
-        try:
513
-            return self.contexts[eventlet.corolocal.get_ident()]()
514
-        except KeyError:
515
-            return None
516
-
517 497
     def get_capabilities(self):
518 498
         # lookup on first try
519 499
         try:
@@ -657,17 +637,6 @@ class ServerPool(object):
657 637
 
658 638
     def rest_call(self, action, resource, data, headers, ignore_codes,
659 639
                   timeout=False):
660
-        context = self.get_context_ref()
661
-        if context:
662
-            # include the requesting context information if available
663
-            cdict = context.to_dict()
664
-            # remove the auth token so it's not present in debug logs on the
665
-            # backend controller
666
-            cdict.pop('auth_token', None)
667
-            if ('tenant_name' in cdict and cdict['tenant_name']):
668
-                cdict['tenant_name'] = Util.format_resource_name(
669
-                    cdict['tenant_name'])
670
-            headers[REQ_CONTEXT_HEADER] = jsonutils.dumps(cdict)
671 640
         good_first = sorted(self.servers, key=lambda x: x.failed)
672 641
         first_response = None
673 642
         for active_server in good_first:

+ 15
- 15
networking_bigswitch/plugins/ml2/drivers/mech_bigswitch/driver.py View File

@@ -48,7 +48,7 @@ ROUTER_GATEWAY_PORT_OWNER = 'network:router_gateway'
48 48
 OVS_AGENT_INI_FILEPATH = '/etc/neutron/plugins/ml2/openvswitch_agent.ini'
49 49
 RH_NET_CONF_PATH = "/etc/os-net-config/config.json"
50 50
 LOG = log.getLogger(__name__)
51
-put_context_in_serverpool = plugin.put_context_in_serverpool
51
+add_debug_log = plugin.add_debug_log
52 52
 
53 53
 # time in seconds to maintain existence of vswitch response
54 54
 CACHE_VSWITCH_TIME = 60
@@ -261,7 +261,7 @@ class BigSwitchMechanismDriver(plugin.NeutronRestProxyV2Base,
261 261
         else:
262 262
             LOG.debug("Else events: %s payload: %s", (event_type, payload))
263 263
 
264
-    @put_context_in_serverpool
264
+    @add_debug_log
265 265
     def security_groups_rule_updated(self, context, **kwargs):
266 266
         # this will get called whenever a security group rule updated message
267 267
         # goes onto the RPC bus
@@ -270,37 +270,37 @@ class BigSwitchMechanismDriver(plugin.NeutronRestProxyV2Base,
270 270
             for sg_id in kwargs.get('security_groups'):
271 271
                 self.bsn_create_security_group(sg_id, context=context)
272 272
 
273
-    @put_context_in_serverpool
273
+    @add_debug_log
274 274
     def security_groups_member_updated(self, context, **kwargs):
275 275
         pass
276 276
 
277
-    @put_context_in_serverpool
277
+    @add_debug_log
278 278
     def security_groups_provider_updated(self, context, **kwargs):
279 279
         pass
280 280
 
281
-    @put_context_in_serverpool
281
+    @add_debug_log
282 282
     def create_network_postcommit(self, context):
283 283
         # create network on the network controller
284 284
         self._send_create_network(context.current)
285 285
 
286
-    @put_context_in_serverpool
286
+    @add_debug_log
287 287
     def update_network_precommit(self, context):
288 288
         self._verify_network_precommit(context)
289 289
 
290
-    @put_context_in_serverpool
290
+    @add_debug_log
291 291
     def update_network_postcommit(self, context):
292 292
         # update network on the network controller
293 293
         self._send_update_network(context.current)
294 294
 
295
-    @put_context_in_serverpool
295
+    @add_debug_log
296 296
     def update_subnet_postcommit(self, context):
297 297
         self._trigger_network_update_from_subnet_transaction(context)
298 298
 
299
-    @put_context_in_serverpool
299
+    @add_debug_log
300 300
     def create_subnet_postcommit(self, context):
301 301
         self._trigger_network_update_from_subnet_transaction(context)
302 302
 
303
-    @put_context_in_serverpool
303
+    @add_debug_log
304 304
     def delete_subnet_postcommit(self, context):
305 305
         self._trigger_network_update_from_subnet_transaction(context)
306 306
 
@@ -309,12 +309,12 @@ class BigSwitchMechanismDriver(plugin.NeutronRestProxyV2Base,
309 309
             ctx.get_admin_context(), context.current['network_id'])
310 310
         self._send_update_network(net)
311 311
 
312
-    @put_context_in_serverpool
312
+    @add_debug_log
313 313
     def delete_network_postcommit(self, context):
314 314
         # delete network on the network controller
315 315
         self._send_delete_network(context.current)
316 316
 
317
-    @put_context_in_serverpool
317
+    @add_debug_log
318 318
     def create_port_postcommit(self, context):
319 319
         if not self._is_port_supported(context.current):
320 320
             LOG.debug("Ignoring unsupported vnic type")
@@ -348,7 +348,7 @@ class BigSwitchMechanismDriver(plugin.NeutronRestProxyV2Base,
348 348
             self.async_port_create(port["network"]["tenant_id"],
349 349
                                    port["network"]["id"], port)
350 350
 
351
-    @put_context_in_serverpool
351
+    @add_debug_log
352 352
     def update_port_postcommit(self, context):
353 353
         if not self._is_port_supported(context.current):
354 354
             LOG.debug("Ignoring unsupported vnic type")
@@ -396,7 +396,7 @@ class BigSwitchMechanismDriver(plugin.NeutronRestProxyV2Base,
396 396
                             triggered_by_tenant=port["network"]["tenant_id"]
397 397
                         )
398 398
 
399
-    @put_context_in_serverpool
399
+    @add_debug_log
400 400
     def delete_port_postcommit(self, context):
401 401
         if not self._is_port_supported(context.current):
402 402
             LOG.debug("Ignoring unsupported vnic type")
@@ -434,7 +434,7 @@ class BigSwitchMechanismDriver(plugin.NeutronRestProxyV2Base,
434 434
                        portbindings.OVS_HYBRID_PLUG: True}
435 435
         context.set_binding(segment[api.ID], vif_type, vif_details)
436 436
 
437
-    @put_context_in_serverpool
437
+    @add_debug_log
438 438
     def bind_port(self, context):
439 439
         """Marks ports as bound.
440 440
 

+ 0
- 19
networking_bigswitch/tests/unit/bigswitch/test_servermanager.py View File

@@ -19,14 +19,12 @@ import time
19 19
 import mock
20 20
 from oslo_config import cfg
21 21
 from oslo_db import exception as db_exc
22
-from oslo_serialization import jsonutils
23 22
 from oslo_utils import importutils
24 23
 
25 24
 from networking_bigswitch.plugins.bigswitch.db import consistency_db
26 25
 from networking_bigswitch.plugins.bigswitch import servermanager
27 26
 from networking_bigswitch.tests.unit.bigswitch \
28 27
     import test_restproxy_plugin as test_rp
29
-from neutron_lib import context
30 28
 from neutron_lib.plugins import directory
31 29
 
32 30
 SERVERMANAGER = 'networking_bigswitch.plugins.bigswitch.servermanager'
@@ -181,23 +179,6 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
181 179
         self.assertIn('EXTRA-HEADER', callheaders)
182 180
         self.assertEqual(callheaders['EXTRA-HEADER'], 'HI')
183 181
 
184
-    def test_req_context_header(self):
185
-        sp = directory.get_plugin().servers
186
-        ncontext = context.Context('uid', 'tid')
187
-        sp.set_context(ncontext)
188
-        with mock.patch(HTTPCON) as conmock:
189
-            rv = conmock.return_value
190
-            rv.getresponse.return_value.getheader.return_value = 'HASHHEADER'
191
-            sp.rest_action('GET', '/')
192
-        callheaders = rv.request.mock_calls[0][1][3]
193
-        self.assertIn(servermanager.REQ_CONTEXT_HEADER, callheaders)
194
-        ctxdct = ncontext.to_dict()
195
-        # auth token is not included
196
-        ctxdct.pop('auth_token')
197
-        self.assertEqual(
198
-            ctxdct, jsonutils.loads(
199
-                callheaders[servermanager.REQ_CONTEXT_HEADER]))
200
-
201 182
     def test_capabilities_retrieval(self):
202 183
         sp = servermanager.ServerPool()
203 184
         with mock.patch(HTTPCON) as conmock:

+ 0
- 12
networking_bigswitch/tests/unit/ml2/drivers/test_bigswitch_mech.py View File

@@ -373,15 +373,3 @@ class TestBigSwitchMechDriverPortsV2(test_db_base_plugin_v2.TestPortsV2,
373 373
             create_body = rmock.mock_calls[-1][1][2]
374 374
             self.assertIsNotNone(create_body['bound_segment'])
375 375
             self.assertEqual(create_body[portbindings.HOST_ID], ext_id)
376
-
377
-    def test_req_context_header_present(self):
378
-        # with\
379
-        #     mock.patch(SERVER_MANAGER + '.ServerProxy.rest_call') as \
380
-        #             mock_rest,\
381
-        #     self.port(**{'device_id': 'devid',
382
-        #                  'binding:host_id': 'host'}):
383
-        #
384
-        #     headers = mock_rest.mock_calls[0][1][3]
385
-        #     self.assertIn('X-REQ-CONTEXT', headers)
386
-        # TODO(wolverineav) fix intermittent test failure
387
-        pass

Loading…
Cancel
Save