Skip to content

Commit b61c14f

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Use Adapter global_request_id kwarg"
2 parents cea01e5 + 8068bb3 commit b61c14f

File tree

6 files changed

+70
-81
lines changed

6 files changed

+70
-81
lines changed

lower-constraints.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jsonpath-rw==1.4.0
4444
jsonpath-rw-ext==1.1.3
4545
jsonpointer==2.0
4646
jsonschema==2.6.0
47-
keystoneauth1==3.9.0
47+
keystoneauth1==3.15.0
4848
keystonemiddleware==4.20.0
4949
kombu==4.1.0
5050
linecache2==1.0.0

nova/network/neutronv2/api.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from neutronclient.common import exceptions as neutron_client_exc
2323
from neutronclient.v2_0 import client as clientv20
2424
from oslo_log import log as logging
25-
from oslo_middleware import request_id
2625
from oslo_utils import excutils
2726
from oslo_utils import strutils
2827
from oslo_utils import uuidutils
@@ -1328,7 +1327,7 @@ def _create_port_binding(context, client, port_id, data):
13281327
"""
13291328
return client.post(
13301329
'/v2.0/ports/%s/bindings' % port_id, json=data, raise_exc=False,
1331-
headers={request_id.INBOUND_HEADER: context.global_id})
1330+
global_request_id=context.global_id)
13321331

13331332
def delete_port_binding(self, context, port_id, host):
13341333
"""Delete the port binding for the given port ID and host
@@ -1371,7 +1370,7 @@ def _delete_port_binding(context, client, port_id, host):
13711370
"""
13721371
return client.delete(
13731372
'/v2.0/ports/%s/bindings/%s' % (port_id, host), raise_exc=False,
1374-
headers={request_id.INBOUND_HEADER: context.global_id})
1373+
global_request_id=context.global_id)
13751374

13761375
def activate_port_binding(self, context, port_id, host):
13771376
"""Activates an inactive port binding.
@@ -1393,7 +1392,7 @@ def activate_port_binding(self, context, port_id, host):
13931392
resp = client.put(
13941393
'/v2.0/ports/%s/bindings/%s/activate' % (port_id, host),
13951394
raise_exc=False,
1396-
headers={request_id.INBOUND_HEADER: context.global_id})
1395+
global_request_id=context.global_id)
13971396
if resp:
13981397
LOG.debug('Activated binding for port %s and host %s.',
13991398
port_id, host)
@@ -2701,8 +2700,7 @@ def migrate_instance_start(self, context, instance, migration):
27012700
# port and destination host.
27022701
resp = client.get(
27032702
'/v2.0/ports/%s/bindings/%s' % (vif['id'], dest_host),
2704-
raise_exc=False,
2705-
headers={request_id.INBOUND_HEADER: context.global_id})
2703+
raise_exc=False, global_request_id=context.global_id)
27062704
if resp:
27072705
if resp.json()['binding']['status'] != 'ACTIVE':
27082706
self.activate_port_binding(context, vif['id'], dest_host)

nova/scheduler/client/report.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -247,36 +247,28 @@ def _create_client(self):
247247
return client
248248

249249
def get(self, url, version=None, global_request_id=None):
250-
headers = ({request_id.INBOUND_HEADER: global_request_id}
251-
if global_request_id else {})
252-
return self._client.get(url, microversion=version, headers=headers)
250+
return self._client.get(url, microversion=version,
251+
global_request_id=global_request_id)
253252

254253
def post(self, url, data, version=None, global_request_id=None):
255-
headers = ({request_id.INBOUND_HEADER: global_request_id}
256-
if global_request_id else {})
257254
# NOTE(sdague): using json= instead of data= sets the
258255
# media type to application/json for us. Placement API is
259256
# more sensitive to this than other APIs in the OpenStack
260257
# ecosystem.
261258
return self._client.post(url, json=data, microversion=version,
262-
headers=headers)
259+
global_request_id=global_request_id)
263260

264261
def put(self, url, data, version=None, global_request_id=None):
265262
# NOTE(sdague): using json= instead of data= sets the
266263
# media type to application/json for us. Placement API is
267264
# more sensitive to this than other APIs in the OpenStack
268265
# ecosystem.
269-
kwargs = {'microversion': version,
270-
'headers': {request_id.INBOUND_HEADER:
271-
global_request_id} if global_request_id else {}}
272-
if data is not None:
273-
kwargs['json'] = data
274-
return self._client.put(url, **kwargs)
266+
return self._client.put(url, json=data, microversion=version,
267+
global_request_id=global_request_id)
275268

276269
def delete(self, url, version=None, global_request_id=None):
277-
headers = ({request_id.INBOUND_HEADER: global_request_id}
278-
if global_request_id else {})
279-
return self._client.delete(url, microversion=version, headers=headers)
270+
return self._client.delete(url, microversion=version,
271+
global_request_id=global_request_id)
280272

281273
@safe_connect
282274
def get_allocation_candidates(self, context, resources):

nova/tests/unit/network/test_neutronv2.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5715,7 +5715,7 @@ def test_migrate_instance_start_activate(self, get_client_mock):
57155715
activate.assert_called_once_with(self.context, uuids.port_id, 'dest')
57165716
get_client_mock.return_value.get.assert_called_once_with(
57175717
'/v2.0/ports/%s/bindings/dest' % uuids.port_id, raise_exc=False,
5718-
headers={'X-Openstack-Request-Id': self.context.global_id})
5718+
global_request_id=self.context.global_id)
57195719

57205720
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
57215721
def test_migrate_instance_start_already_active(self, get_client_mock):
@@ -5738,7 +5738,7 @@ def test_migrate_instance_start_already_active(self, get_client_mock):
57385738
self.context, instance, migration)
57395739
get_client_mock.return_value.get.assert_called_once_with(
57405740
'/v2.0/ports/%s/bindings/dest' % uuids.port_id, raise_exc=False,
5741-
headers={'X-Openstack-Request-Id': self.context.global_id})
5741+
global_request_id=self.context.global_id)
57425742

57435743
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
57445744
def test_migrate_instance_start_no_bindings(self, get_client_mock):
@@ -5763,7 +5763,7 @@ def test_migrate_instance_start_no_bindings(self, get_client_mock):
57635763
self.context, instance, migration)
57645764
get_client_mock.return_value.get.assert_called_once_with(
57655765
'/v2.0/ports/%s/bindings/dest' % uuids.port1, raise_exc=False,
5766-
headers={'X-Openstack-Request-Id': self.context.global_id})
5766+
global_request_id=self.context.global_id)
57675767

57685768
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
57695769
def test_migrate_instance_start_get_error(self, get_client_mock):
@@ -5788,11 +5788,11 @@ def test_migrate_instance_start_get_error(self, get_client_mock):
57885788
mock.call(
57895789
'/v2.0/ports/%s/bindings/dest' % uuids.port1,
57905790
raise_exc=False,
5791-
headers={'X-Openstack-Request-Id': self.context.global_id}),
5791+
global_request_id=self.context.global_id),
57925792
mock.call(
57935793
'/v2.0/ports/%s/bindings/dest' % uuids.port2,
57945794
raise_exc=False,
5795-
headers={'X-Openstack-Request-Id': self.context.global_id})])
5795+
global_request_id=self.context.global_id)])
57965796

57975797

57985798
class TestNeutronv2ModuleMethods(test.NoDBTestCase):
@@ -6294,7 +6294,7 @@ def test_activate_port_binding(self, mock_client):
62946294
mock_client.return_value.put.assert_called_once_with(
62956295
'/v2.0/ports/%s/bindings/fake-host/activate' % uuids.port_id,
62966296
raise_exc=False,
6297-
headers={'X-Openstack-Request-Id': self.context.global_id})
6297+
global_request_id=self.context.global_id)
62986298

62996299
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
63006300
@mock.patch('nova.network.neutronv2.api.LOG.warning')
@@ -6307,7 +6307,7 @@ def test_activate_port_binding_already_active(
63076307
mock_client.return_value.put.assert_called_once_with(
63086308
'/v2.0/ports/%s/bindings/fake-host/activate' % uuids.port_id,
63096309
raise_exc=False,
6310-
headers={'X-Openstack-Request-Id': self.context.global_id})
6310+
global_request_id=self.context.global_id)
63116311
self.assertEqual(1, mock_log_warning.call_count)
63126312
self.assertIn('is already active', mock_log_warning.call_args[0][0])
63136313

@@ -6321,7 +6321,7 @@ def test_activate_port_binding_fails(self, mock_client):
63216321
mock_client.return_value.put.assert_called_once_with(
63226322
'/v2.0/ports/%s/bindings/fake-host/activate' % uuids.port_id,
63236323
raise_exc=False,
6324-
headers={'X-Openstack-Request-Id': self.context.global_id})
6324+
global_request_id=self.context.global_id)
63256325

63266326

63276327
class TestAllocateForInstance(test.NoDBTestCase):

0 commit comments

Comments
 (0)