Fix no propagation of nova context request_id
Nova context request_id is not propagated for
port binding operations in neutron.
So fix it.
Conflicts:
nova/tests/unit/network/test_neutronv2.py
The conflict is due to not including
I1788389d11a9f3b6b0bd0b75d2184be9e90983bb in stable/stein
Change-Id: I76163c46b1f01ba7ff592d162b106ea2e5bb34cb
Closes-Bug: #1829914
(cherry picked from commit e11b589474
)
This commit is contained in:
parent
950e044af1
commit
bb551ddd74
|
@ -22,6 +22,7 @@ from keystoneauth1 import loading as ks_loading
|
|||
from neutronclient.common import exceptions as neutron_client_exc
|
||||
from neutronclient.v2_0 import client as clientv20
|
||||
from oslo_log import log as logging
|
||||
from oslo_middleware import request_id
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import uuidutils
|
||||
|
@ -1369,7 +1370,7 @@ class API(base_api.NetworkAPI):
|
|||
binding['profile'] = port_profiles[port_id]
|
||||
|
||||
data = dict(binding=binding)
|
||||
resp = self._create_port_binding(client, port_id, data)
|
||||
resp = self._create_port_binding(context, client, port_id, data)
|
||||
if resp:
|
||||
bindings_by_port_id[port_id] = resp.json()['binding']
|
||||
else:
|
||||
|
@ -1392,9 +1393,10 @@ class API(base_api.NetworkAPI):
|
|||
return bindings_by_port_id
|
||||
|
||||
@staticmethod
|
||||
def _create_port_binding(client, port_id, data):
|
||||
def _create_port_binding(context, client, port_id, data):
|
||||
"""Creates a port binding with the specified data.
|
||||
|
||||
:param context: The request context for the operation.
|
||||
:param client: keystoneauth1.adapter.Adapter
|
||||
:param port_id: The ID of the port on which to create the binding.
|
||||
:param data: dict of port binding data (requires at least the host),
|
||||
|
@ -1403,8 +1405,9 @@ class API(base_api.NetworkAPI):
|
|||
{'binding': {'host': 'dest.host.com'}}
|
||||
:return: requests.Response object
|
||||
"""
|
||||
return client.post('/v2.0/ports/%s/bindings' % port_id,
|
||||
json=data, raise_exc=False)
|
||||
return client.post(
|
||||
'/v2.0/ports/%s/bindings' % port_id, json=data, raise_exc=False,
|
||||
headers={request_id.INBOUND_HEADER: context.global_id})
|
||||
|
||||
def delete_port_binding(self, context, port_id, host):
|
||||
"""Delete the port binding for the given port ID and host
|
||||
|
@ -1419,7 +1422,7 @@ class API(base_api.NetworkAPI):
|
|||
response is received from neutron.
|
||||
"""
|
||||
client = _get_ksa_client(context, admin=True)
|
||||
resp = self._delete_port_binding(client, port_id, host)
|
||||
resp = self._delete_port_binding(context, client, port_id, host)
|
||||
if resp:
|
||||
LOG.debug('Deleted binding for port %s and host %s.',
|
||||
port_id, host)
|
||||
|
@ -1436,16 +1439,18 @@ class API(base_api.NetworkAPI):
|
|||
port_id=port_id, host=host)
|
||||
|
||||
@staticmethod
|
||||
def _delete_port_binding(client, port_id, host):
|
||||
def _delete_port_binding(context, client, port_id, host):
|
||||
"""Deletes the binding for the given host on the given port.
|
||||
|
||||
:param context: The request context for the operation.
|
||||
:param client: keystoneauth1.adapter.Adapter
|
||||
:param port_id: ID of the port from which to delete the binding
|
||||
:param host: A string name of the host on which the port is bound
|
||||
:return: requests.Response object
|
||||
"""
|
||||
return client.delete('/v2.0/ports/%s/bindings/%s' % (port_id, host),
|
||||
raise_exc=False)
|
||||
return client.delete(
|
||||
'/v2.0/ports/%s/bindings/%s' % (port_id, host), raise_exc=False,
|
||||
headers={request_id.INBOUND_HEADER: context.global_id})
|
||||
|
||||
def activate_port_binding(self, context, port_id, host):
|
||||
"""Activates an inactive port binding.
|
||||
|
@ -1466,7 +1471,8 @@ class API(base_api.NetworkAPI):
|
|||
# to ACTIVE, it's more like a POST action method in the compute API.
|
||||
resp = client.put(
|
||||
'/v2.0/ports/%s/bindings/%s/activate' % (port_id, host),
|
||||
raise_exc=False)
|
||||
raise_exc=False,
|
||||
headers={request_id.INBOUND_HEADER: context.global_id})
|
||||
if resp:
|
||||
LOG.debug('Activated binding for port %s and host %s.',
|
||||
port_id, host)
|
||||
|
@ -2772,8 +2778,10 @@ class API(base_api.NetworkAPI):
|
|||
# Not all compute migration flows use the port binding-extended
|
||||
# API yet, so first check to see if there is a binding for the
|
||||
# port and destination host.
|
||||
resp = client.get('/v2.0/ports/%s/bindings/%s' %
|
||||
(vif['id'], dest_host), raise_exc=False)
|
||||
resp = client.get(
|
||||
'/v2.0/ports/%s/bindings/%s' % (vif['id'], dest_host),
|
||||
raise_exc=False,
|
||||
headers={request_id.INBOUND_HEADER: context.global_id})
|
||||
if resp:
|
||||
if resp.json()['binding']['status'] != 'ACTIVE':
|
||||
self.activate_port_binding(context, vif['id'], dest_host)
|
||||
|
|
|
@ -1476,13 +1476,13 @@ class NeutronFixture(fixtures.Fixture):
|
|||
lambda *args, **kwargs: self)
|
||||
|
||||
@staticmethod
|
||||
def fake_create_port_binding(client, port_id, data):
|
||||
def fake_create_port_binding(context, client, port_id, data):
|
||||
# TODO(mriedem): Make this smarter by keeping track of our bindings
|
||||
# per port so we can reflect the status accurately.
|
||||
return fake_requests.FakeResponse(200, content=jsonutils.dumps(data))
|
||||
|
||||
@staticmethod
|
||||
def fake_delete_port_binding(client, port_id, host):
|
||||
def fake_delete_port_binding(context, client, port_id, host):
|
||||
# TODO(mriedem): Make this smarter by keeping track of our bindings
|
||||
# per port so we can reflect the status accurately.
|
||||
return fake_requests.FakeResponse(204)
|
||||
|
|
|
@ -5876,7 +5876,8 @@ class TestNeutronv2WithMock(_TestNeutronv2Common):
|
|||
self.context, instance, migration)
|
||||
activate.assert_called_once_with(self.context, uuids.port_id, 'dest')
|
||||
get_client_mock.return_value.get.assert_called_once_with(
|
||||
'/v2.0/ports/%s/bindings/dest' % uuids.port_id, raise_exc=False)
|
||||
'/v2.0/ports/%s/bindings/dest' % uuids.port_id, raise_exc=False,
|
||||
headers={'X-Openstack-Request-Id': self.context.global_id})
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
def test_migrate_instance_start_already_active(self, get_client_mock):
|
||||
|
@ -5898,7 +5899,8 @@ class TestNeutronv2WithMock(_TestNeutronv2Common):
|
|||
self.api.migrate_instance_start(
|
||||
self.context, instance, migration)
|
||||
get_client_mock.return_value.get.assert_called_once_with(
|
||||
'/v2.0/ports/%s/bindings/dest' % uuids.port_id, raise_exc=False)
|
||||
'/v2.0/ports/%s/bindings/dest' % uuids.port_id, raise_exc=False,
|
||||
headers={'X-Openstack-Request-Id': self.context.global_id})
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
def test_migrate_instance_start_no_bindings(self, get_client_mock):
|
||||
|
@ -5922,7 +5924,8 @@ class TestNeutronv2WithMock(_TestNeutronv2Common):
|
|||
self.api.migrate_instance_start(
|
||||
self.context, instance, migration)
|
||||
get_client_mock.return_value.get.assert_called_once_with(
|
||||
'/v2.0/ports/%s/bindings/dest' % uuids.port1, raise_exc=False)
|
||||
'/v2.0/ports/%s/bindings/dest' % uuids.port1, raise_exc=False,
|
||||
headers={'X-Openstack-Request-Id': self.context.global_id})
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
def test_migrate_instance_start_get_error(self, get_client_mock):
|
||||
|
@ -5944,10 +5947,14 @@ class TestNeutronv2WithMock(_TestNeutronv2Common):
|
|||
self.context, instance, migration)
|
||||
self.assertEqual(2, get_client_mock.return_value.get.call_count)
|
||||
get_client_mock.return_value.get.assert_has_calls([
|
||||
mock.call('/v2.0/ports/%s/bindings/dest' % uuids.port1,
|
||||
raise_exc=False),
|
||||
mock.call('/v2.0/ports/%s/bindings/dest' % uuids.port2,
|
||||
raise_exc=False)])
|
||||
mock.call(
|
||||
'/v2.0/ports/%s/bindings/dest' % uuids.port1,
|
||||
raise_exc=False,
|
||||
headers={'X-Openstack-Request-Id': self.context.global_id}),
|
||||
mock.call(
|
||||
'/v2.0/ports/%s/bindings/dest' % uuids.port2,
|
||||
raise_exc=False,
|
||||
headers={'X-Openstack-Request-Id': self.context.global_id})])
|
||||
|
||||
|
||||
class TestNeutronv2ModuleMethods(test.NoDBTestCase):
|
||||
|
@ -6456,7 +6463,8 @@ class TestPortBindingWithMock(test.NoDBTestCase):
|
|||
self.api.activate_port_binding(ctxt, uuids.port_id, 'fake-host')
|
||||
mock_client.return_value.put.assert_called_once_with(
|
||||
'/v2.0/ports/%s/bindings/fake-host/activate' % uuids.port_id,
|
||||
raise_exc=False)
|
||||
raise_exc=False,
|
||||
headers={'X-Openstack-Request-Id': ctxt.global_id})
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api._get_ksa_client')
|
||||
@mock.patch('nova.network.neutronv2.api.LOG.warning')
|
||||
|
@ -6468,7 +6476,8 @@ class TestPortBindingWithMock(test.NoDBTestCase):
|
|||
self.api.activate_port_binding(ctxt, uuids.port_id, 'fake-host')
|
||||
mock_client.return_value.put.assert_called_once_with(
|
||||
'/v2.0/ports/%s/bindings/fake-host/activate' % uuids.port_id,
|
||||
raise_exc=False)
|
||||
raise_exc=False,
|
||||
headers={'X-Openstack-Request-Id': ctxt.global_id})
|
||||
self.assertEqual(1, mock_log_warning.call_count)
|
||||
self.assertIn('is already active', mock_log_warning.call_args[0][0])
|
||||
|
||||
|
@ -6482,7 +6491,8 @@ class TestPortBindingWithMock(test.NoDBTestCase):
|
|||
ctxt, uuids.port_id, 'fake-host')
|
||||
mock_client.return_value.put.assert_called_once_with(
|
||||
'/v2.0/ports/%s/bindings/fake-host/activate' % uuids.port_id,
|
||||
raise_exc=False)
|
||||
raise_exc=False,
|
||||
headers={'X-Openstack-Request-Id': ctxt.global_id})
|
||||
|
||||
|
||||
class TestAllocateForInstance(test.NoDBTestCase):
|
||||
|
|
Loading…
Reference in New Issue