Use Adapter global_request_id kwarg

Release 3.15.0 of keystoneauth1 introduced the ability to pass
X-Openstack-Request-Id to request methods (get/put/etc) via a
global_request_id kwarg rather than having to put it in a headers dict.

This commit bumps the minimum ksa level to 3.15.0 and takes advantage of
the new kwarg to replace explicit header construction in
SchedulerReportClient (Placement) and neutronv2/api methods.

Also normalizes the way param lists were being passed from
SchedulerReportClient's REST primitives (get/put/post/delete) into the
Adapter equivalents. There was no reason for them to be different.

Change-Id: I2f6eb50f4cb428179ec788de8b7bd6ef9bbeeaf9
This commit is contained in:
Eric Fried 2019-07-15 14:30:35 -05:00
parent 78f9961d29
commit 8068bb3f4a
6 changed files with 70 additions and 81 deletions

View File

@ -44,7 +44,7 @@ jsonpath-rw==1.4.0
jsonpath-rw-ext==1.1.3 jsonpath-rw-ext==1.1.3
jsonpointer==2.0 jsonpointer==2.0
jsonschema==2.6.0 jsonschema==2.6.0
keystoneauth1==3.9.0 keystoneauth1==3.15.0
keystonemiddleware==4.20.0 keystonemiddleware==4.20.0
kombu==4.1.0 kombu==4.1.0
linecache2==1.0.0 linecache2==1.0.0

View File

@ -22,7 +22,6 @@ from keystoneauth1 import loading as ks_loading
from neutronclient.common import exceptions as neutron_client_exc from neutronclient.common import exceptions as neutron_client_exc
from neutronclient.v2_0 import client as clientv20 from neutronclient.v2_0 import client as clientv20
from oslo_log import log as logging from oslo_log import log as logging
from oslo_middleware import request_id
from oslo_utils import excutils from oslo_utils import excutils
from oslo_utils import strutils from oslo_utils import strutils
from oslo_utils import uuidutils from oslo_utils import uuidutils
@ -1328,7 +1327,7 @@ class API(base_api.NetworkAPI):
""" """
return client.post( return client.post(
'/v2.0/ports/%s/bindings' % port_id, json=data, raise_exc=False, '/v2.0/ports/%s/bindings' % port_id, json=data, raise_exc=False,
headers={request_id.INBOUND_HEADER: context.global_id}) global_request_id=context.global_id)
def delete_port_binding(self, context, port_id, host): def delete_port_binding(self, context, port_id, host):
"""Delete the port binding for the given port ID and host """Delete the port binding for the given port ID and host
@ -1371,7 +1370,7 @@ class API(base_api.NetworkAPI):
""" """
return client.delete( return client.delete(
'/v2.0/ports/%s/bindings/%s' % (port_id, host), raise_exc=False, '/v2.0/ports/%s/bindings/%s' % (port_id, host), raise_exc=False,
headers={request_id.INBOUND_HEADER: context.global_id}) global_request_id=context.global_id)
def activate_port_binding(self, context, port_id, host): def activate_port_binding(self, context, port_id, host):
"""Activates an inactive port binding. """Activates an inactive port binding.
@ -1393,7 +1392,7 @@ class API(base_api.NetworkAPI):
resp = client.put( resp = client.put(
'/v2.0/ports/%s/bindings/%s/activate' % (port_id, host), '/v2.0/ports/%s/bindings/%s/activate' % (port_id, host),
raise_exc=False, raise_exc=False,
headers={request_id.INBOUND_HEADER: context.global_id}) global_request_id=context.global_id)
if resp: if resp:
LOG.debug('Activated binding for port %s and host %s.', LOG.debug('Activated binding for port %s and host %s.',
port_id, host) port_id, host)
@ -2701,8 +2700,7 @@ class API(base_api.NetworkAPI):
# port and destination host. # port and destination host.
resp = client.get( resp = client.get(
'/v2.0/ports/%s/bindings/%s' % (vif['id'], dest_host), '/v2.0/ports/%s/bindings/%s' % (vif['id'], dest_host),
raise_exc=False, raise_exc=False, global_request_id=context.global_id)
headers={request_id.INBOUND_HEADER: context.global_id})
if resp: if resp:
if resp.json()['binding']['status'] != 'ACTIVE': if resp.json()['binding']['status'] != 'ACTIVE':
self.activate_port_binding(context, vif['id'], dest_host) self.activate_port_binding(context, vif['id'], dest_host)

View File

@ -247,36 +247,28 @@ class SchedulerReportClient(object):
return client return client
def get(self, url, version=None, global_request_id=None): def get(self, url, version=None, global_request_id=None):
headers = ({request_id.INBOUND_HEADER: global_request_id} return self._client.get(url, microversion=version,
if global_request_id else {}) global_request_id=global_request_id)
return self._client.get(url, microversion=version, headers=headers)
def post(self, url, data, version=None, global_request_id=None): def post(self, url, data, version=None, global_request_id=None):
headers = ({request_id.INBOUND_HEADER: global_request_id}
if global_request_id else {})
# NOTE(sdague): using json= instead of data= sets the # NOTE(sdague): using json= instead of data= sets the
# media type to application/json for us. Placement API is # media type to application/json for us. Placement API is
# more sensitive to this than other APIs in the OpenStack # more sensitive to this than other APIs in the OpenStack
# ecosystem. # ecosystem.
return self._client.post(url, json=data, microversion=version, return self._client.post(url, json=data, microversion=version,
headers=headers) global_request_id=global_request_id)
def put(self, url, data, version=None, global_request_id=None): def put(self, url, data, version=None, global_request_id=None):
# NOTE(sdague): using json= instead of data= sets the # NOTE(sdague): using json= instead of data= sets the
# media type to application/json for us. Placement API is # media type to application/json for us. Placement API is
# more sensitive to this than other APIs in the OpenStack # more sensitive to this than other APIs in the OpenStack
# ecosystem. # ecosystem.
kwargs = {'microversion': version, return self._client.put(url, json=data, microversion=version,
'headers': {request_id.INBOUND_HEADER: global_request_id=global_request_id)
global_request_id} if global_request_id else {}}
if data is not None:
kwargs['json'] = data
return self._client.put(url, **kwargs)
def delete(self, url, version=None, global_request_id=None): def delete(self, url, version=None, global_request_id=None):
headers = ({request_id.INBOUND_HEADER: global_request_id} return self._client.delete(url, microversion=version,
if global_request_id else {}) global_request_id=global_request_id)
return self._client.delete(url, microversion=version, headers=headers)
@safe_connect @safe_connect
def get_allocation_candidates(self, context, resources): def get_allocation_candidates(self, context, resources):

View File

@ -5715,7 +5715,7 @@ class TestNeutronv2WithMock(TestNeutronv2Base):
activate.assert_called_once_with(self.context, uuids.port_id, 'dest') activate.assert_called_once_with(self.context, uuids.port_id, 'dest')
get_client_mock.return_value.get.assert_called_once_with( 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}) global_request_id=self.context.global_id)
@mock.patch('nova.network.neutronv2.api._get_ksa_client') @mock.patch('nova.network.neutronv2.api._get_ksa_client')
def test_migrate_instance_start_already_active(self, get_client_mock): def test_migrate_instance_start_already_active(self, get_client_mock):
@ -5738,7 +5738,7 @@ class TestNeutronv2WithMock(TestNeutronv2Base):
self.context, instance, migration) self.context, instance, migration)
get_client_mock.return_value.get.assert_called_once_with( 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}) global_request_id=self.context.global_id)
@mock.patch('nova.network.neutronv2.api._get_ksa_client') @mock.patch('nova.network.neutronv2.api._get_ksa_client')
def test_migrate_instance_start_no_bindings(self, get_client_mock): def test_migrate_instance_start_no_bindings(self, get_client_mock):
@ -5763,7 +5763,7 @@ class TestNeutronv2WithMock(TestNeutronv2Base):
self.context, instance, migration) self.context, instance, migration)
get_client_mock.return_value.get.assert_called_once_with( 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}) global_request_id=self.context.global_id)
@mock.patch('nova.network.neutronv2.api._get_ksa_client') @mock.patch('nova.network.neutronv2.api._get_ksa_client')
def test_migrate_instance_start_get_error(self, get_client_mock): def test_migrate_instance_start_get_error(self, get_client_mock):
@ -5788,11 +5788,11 @@ class TestNeutronv2WithMock(TestNeutronv2Base):
mock.call( mock.call(
'/v2.0/ports/%s/bindings/dest' % uuids.port1, '/v2.0/ports/%s/bindings/dest' % uuids.port1,
raise_exc=False, raise_exc=False,
headers={'X-Openstack-Request-Id': self.context.global_id}), global_request_id=self.context.global_id),
mock.call( mock.call(
'/v2.0/ports/%s/bindings/dest' % uuids.port2, '/v2.0/ports/%s/bindings/dest' % uuids.port2,
raise_exc=False, raise_exc=False,
headers={'X-Openstack-Request-Id': self.context.global_id})]) global_request_id=self.context.global_id)])
class TestNeutronv2ModuleMethods(test.NoDBTestCase): class TestNeutronv2ModuleMethods(test.NoDBTestCase):
@ -6294,7 +6294,7 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
mock_client.return_value.put.assert_called_once_with( mock_client.return_value.put.assert_called_once_with(
'/v2.0/ports/%s/bindings/fake-host/activate' % uuids.port_id, '/v2.0/ports/%s/bindings/fake-host/activate' % uuids.port_id,
raise_exc=False, raise_exc=False,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
@mock.patch('nova.network.neutronv2.api._get_ksa_client') @mock.patch('nova.network.neutronv2.api._get_ksa_client')
@mock.patch('nova.network.neutronv2.api.LOG.warning') @mock.patch('nova.network.neutronv2.api.LOG.warning')
@ -6307,7 +6307,7 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
mock_client.return_value.put.assert_called_once_with( mock_client.return_value.put.assert_called_once_with(
'/v2.0/ports/%s/bindings/fake-host/activate' % uuids.port_id, '/v2.0/ports/%s/bindings/fake-host/activate' % uuids.port_id,
raise_exc=False, raise_exc=False,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertEqual(1, mock_log_warning.call_count) self.assertEqual(1, mock_log_warning.call_count)
self.assertIn('is already active', mock_log_warning.call_args[0][0]) self.assertIn('is already active', mock_log_warning.call_args[0][0])
@ -6321,7 +6321,7 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
mock_client.return_value.put.assert_called_once_with( mock_client.return_value.put.assert_called_once_with(
'/v2.0/ports/%s/bindings/fake-host/activate' % uuids.port_id, '/v2.0/ports/%s/bindings/fake-host/activate' % uuids.port_id,
raise_exc=False, raise_exc=False,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
class TestAllocateForInstance(test.NoDBTestCase): class TestAllocateForInstance(test.NoDBTestCase):

View File

@ -438,7 +438,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
expected_payload['user_id'] = user_id expected_payload['user_id'] = user_id
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.12', json=expected_payload, expected_url, microversion='1.12', json=expected_payload,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertTrue(res) self.assertTrue(res)
@ -482,7 +482,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
'user_id': user_id} 'user_id': user_id}
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.12', json=expected_payload, expected_url, microversion='1.12', json=expected_payload,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertTrue(res) self.assertTrue(res)
def test_claim_resources_success_resize_to_same_host_no_shared(self): def test_claim_resources_success_resize_to_same_host_no_shared(self):
@ -548,7 +548,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
'user_id': user_id} 'user_id': user_id}
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.28', json=mock.ANY, expected_url, microversion='1.28', json=mock.ANY,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
# We have to pull the json body from the mock call_args to validate # We have to pull the json body from the mock call_args to validate
# it separately otherwise hash seed issues get in the way. # it separately otherwise hash seed issues get in the way.
actual_payload = self.ks_adap_mock.put.call_args[1]['json'] actual_payload = self.ks_adap_mock.put.call_args[1]['json']
@ -628,7 +628,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
'user_id': user_id} 'user_id': user_id}
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.28', json=mock.ANY, expected_url, microversion='1.28', json=mock.ANY,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
# We have to pull the json body from the mock call_args to validate # We have to pull the json body from the mock call_args to validate
# it separately otherwise hash seed issues get in the way. # it separately otherwise hash seed issues get in the way.
actual_payload = self.ks_adap_mock.put.call_args[1]['json'] actual_payload = self.ks_adap_mock.put.call_args[1]['json']
@ -715,7 +715,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
'user_id': user_id} 'user_id': user_id}
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.28', json=mock.ANY, expected_url, microversion='1.28', json=mock.ANY,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
# We have to pull the json body from the mock call_args to validate # We have to pull the json body from the mock call_args to validate
# it separately otherwise hash seed issues get in the way. # it separately otherwise hash seed issues get in the way.
actual_payload = self.ks_adap_mock.put.call_args[1]['json'] actual_payload = self.ks_adap_mock.put.call_args[1]['json']
@ -814,7 +814,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
'user_id': user_id} 'user_id': user_id}
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.28', json=mock.ANY, expected_url, microversion='1.28', json=mock.ANY,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
# We have to pull the json body from the mock call_args to validate # We have to pull the json body from the mock call_args to validate
# it separately otherwise hash seed issues get in the way. # it separately otherwise hash seed issues get in the way.
actual_payload = self.ks_adap_mock.put.call_args[1]['json'] actual_payload = self.ks_adap_mock.put.call_args[1]['json']
@ -904,7 +904,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
'user_id': user_id} 'user_id': user_id}
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.28', json=mock.ANY, expected_url, microversion='1.28', json=mock.ANY,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
# We have to pull the json body from the mock call_args to validate # We have to pull the json body from the mock call_args to validate
# it separately otherwise hash seed issues get in the way. # it separately otherwise hash seed issues get in the way.
actual_payload = self.ks_adap_mock.put.call_args[1]['json'] actual_payload = self.ks_adap_mock.put.call_args[1]['json']
@ -1007,7 +1007,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
'user_id': user_id} 'user_id': user_id}
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.28', json=mock.ANY, expected_url, microversion='1.28', json=mock.ANY,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
# We have to pull the json body from the mock call_args to validate # We have to pull the json body from the mock call_args to validate
# it separately otherwise hash seed issues get in the way. # it separately otherwise hash seed issues get in the way.
actual_payload = self.ks_adap_mock.put.call_args[1]['json'] actual_payload = self.ks_adap_mock.put.call_args[1]['json']
@ -1063,8 +1063,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
# identical since we're retrying the same HTTP request # identical since we're retrying the same HTTP request
expected_calls = [ expected_calls = [
mock.call(expected_url, microversion='1.28', json=expected_payload, mock.call(expected_url, microversion='1.28', json=expected_payload,
headers={'X-Openstack-Request-Id': global_request_id=self.context.global_id)] * 2
self.context.global_id})] * 2
self.assertEqual(len(expected_calls), self.assertEqual(len(expected_calls),
self.ks_adap_mock.put.call_count) self.ks_adap_mock.put.call_count)
self.ks_adap_mock.put.assert_has_calls(expected_calls) self.ks_adap_mock.put.assert_has_calls(expected_calls)
@ -1115,7 +1114,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
expected_payload['consumer_generation'] = None expected_payload['consumer_generation'] = None
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.28', json=expected_payload, expected_url, microversion='1.28', json=expected_payload,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertFalse(res) self.assertFalse(res)
self.assertTrue(mock_log.called) self.assertTrue(mock_log.called)
@ -1163,7 +1162,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
'consumer_generation': None} 'consumer_generation': None}
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.28', json=expected_payload, expected_url, microversion='1.28', json=expected_payload,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
def test_remove_provider_from_inst_alloc_no_shared(self): def test_remove_provider_from_inst_alloc_no_shared(self):
"""Tests that the method which manipulates an existing doubled-up """Tests that the method which manipulates an existing doubled-up
@ -1235,7 +1234,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
self.assertEqual(expected_payload, actual_payload) self.assertEqual(expected_payload, actual_payload)
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.28', json=mock.ANY, expected_url, microversion='1.28', json=mock.ANY,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertTrue(res) self.assertTrue(res)
@ -1322,7 +1321,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
self.assertEqual(expected_payload, actual_payload) self.assertEqual(expected_payload, actual_payload)
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.28', json=mock.ANY, expected_url, microversion='1.28', json=mock.ANY,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertTrue(res) self.assertTrue(res)
@ -1507,12 +1506,12 @@ class TestPutAllocations(SchedulerReportClientTestCase):
[ [
mock.call( mock.call(
'/allocations/%s' % consumer_uuid, '/allocations/%s' % consumer_uuid,
headers=mock.ANY, global_request_id=self.context.global_id,
microversion='1.28' microversion='1.28'
), ),
mock.call( mock.call(
'/resource_providers?in_tree=%s' % uuids.source_compute, '/resource_providers?in_tree=%s' % uuids.source_compute,
headers=mock.ANY, global_request_id=self.context.global_id,
microversion='1.14' microversion='1.14'
) )
], ],
@ -1524,7 +1523,7 @@ class TestPutAllocations(SchedulerReportClientTestCase):
self.assertEqual(expected_payload, actual_payload) self.assertEqual(expected_payload, actual_payload)
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
expected_url, microversion='1.28', json=mock.ANY, expected_url, microversion='1.28', json=mock.ANY,
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertTrue(res) self.assertTrue(res)
@ -2115,7 +2114,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
expected_query) expected_query)
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, microversion='1.31', expected_url, microversion='1.31',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertEqual(mock.sentinel.alloc_reqs, alloc_reqs) self.assertEqual(mock.sentinel.alloc_reqs, alloc_reqs)
self.assertEqual(mock.sentinel.p_sums, p_sums) self.assertEqual(mock.sentinel.p_sums, p_sums)
@ -2155,7 +2154,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
self.assertEqual(mock.sentinel.alloc_reqs, alloc_reqs) self.assertEqual(mock.sentinel.alloc_reqs, alloc_reqs)
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, microversion='1.31', expected_url, microversion='1.31',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertEqual(mock.sentinel.p_sums, p_sums) self.assertEqual(mock.sentinel.p_sums, p_sums)
def test_get_allocation_candidates_not_found(self): def test_get_allocation_candidates_not_found(self):
@ -2177,7 +2176,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
mock.ANY, microversion='1.31', mock.ANY, microversion='1.31',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
url = self.ks_adap_mock.get.call_args[0][0] url = self.ks_adap_mock.get.call_args[0][0]
split_url = parse.urlsplit(url) split_url = parse.urlsplit(url)
query = parse.parse_qs(split_url.query) query = parse.parse_qs(split_url.query)
@ -2210,7 +2209,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
expected_url = '/resource_providers/' + uuid expected_url = '/resource_providers/' + uuid
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, microversion='1.14', expected_url, microversion='1.14',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertEqual(expected_provider_dict, result) self.assertEqual(expected_provider_dict, result)
def test_get_resource_provider_not_found(self): def test_get_resource_provider_not_found(self):
@ -2225,7 +2224,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
expected_url = '/resource_providers/' + uuid expected_url = '/resource_providers/' + uuid
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, microversion='1.14', expected_url, microversion='1.14',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertIsNone(result) self.assertIsNone(result)
@mock.patch.object(report.LOG, 'error') @mock.patch.object(report.LOG, 'error')
@ -2246,7 +2245,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
expected_url = '/resource_providers/' + uuid expected_url = '/resource_providers/' + uuid
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, microversion='1.14', expected_url, microversion='1.14',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
# A 503 Service Unavailable should trigger an error log that # A 503 Service Unavailable should trigger an error log that
# includes the placement request id and return None # includes the placement request id and return None
# from _get_resource_provider() # from _get_resource_provider()
@ -2285,7 +2284,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
'&required=MISC_SHARES_VIA_AGGREGATE') '&required=MISC_SHARES_VIA_AGGREGATE')
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, microversion='1.18', expected_url, microversion='1.18',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertEqual(rpjson, result) self.assertEqual(rpjson, result)
def test_get_sharing_providers_emptylist(self): def test_get_sharing_providers_emptylist(self):
@ -2311,7 +2310,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
'&required=MISC_SHARES_VIA_AGGREGATE') '&required=MISC_SHARES_VIA_AGGREGATE')
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, microversion='1.18', expected_url, microversion='1.18',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
# A 503 Service Unavailable should trigger an error log that # A 503 Service Unavailable should trigger an error log that
# includes the placement request id # includes the placement request id
self.assertTrue(logging_mock.called) self.assertTrue(logging_mock.called)
@ -2346,7 +2345,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
expected_url = '/resource_providers?in_tree=' + root expected_url = '/resource_providers?in_tree=' + root
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, microversion='1.14', expected_url, microversion='1.14',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertEqual(rpjson, result) self.assertEqual(rpjson, result)
@mock.patch.object(report.LOG, 'error') @mock.patch.object(report.LOG, 'error')
@ -2366,7 +2365,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
expected_url = '/resource_providers?in_tree=' + uuid expected_url = '/resource_providers?in_tree=' + uuid
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, microversion='1.14', expected_url, microversion='1.14',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
# A 503 Service Unavailable should trigger an error log that includes # A 503 Service Unavailable should trigger an error log that includes
# the placement request id # the placement request id
self.assertTrue(logging_mock.called) self.assertTrue(logging_mock.called)
@ -2400,7 +2399,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
expected_url = '/resource_providers' expected_url = '/resource_providers'
self.ks_adap_mock.post.assert_called_once_with( self.ks_adap_mock.post.assert_called_once_with(
expected_url, json=expected_payload, microversion='1.20', expected_url, json=expected_payload, microversion='1.20',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
def test_create_resource_provider_with_parent(self): def test_create_resource_provider_with_parent(self):
"""Test that when specifying a parent provider UUID, that the """Test that when specifying a parent provider UUID, that the
@ -2430,7 +2429,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
expected_url = '/resource_providers' expected_url = '/resource_providers'
self.ks_adap_mock.post.assert_called_once_with( self.ks_adap_mock.post.assert_called_once_with(
expected_url, json=expected_payload, microversion='1.20', expected_url, json=expected_payload, microversion='1.20',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
@mock.patch.object(report.LOG, 'info') @mock.patch.object(report.LOG, 'info')
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.' @mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
@ -2460,7 +2459,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
expected_url = '/resource_providers' expected_url = '/resource_providers'
self.ks_adap_mock.post.assert_called_once_with( self.ks_adap_mock.post.assert_called_once_with(
expected_url, json=expected_payload, microversion='1.20', expected_url, json=expected_payload, microversion='1.20',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertEqual(mock.sentinel.get_rp, result) self.assertEqual(mock.sentinel.get_rp, result)
# The 409 response will produce a message to the info log. # The 409 response will produce a message to the info log.
self.assertTrue(logging_mock.called) self.assertTrue(logging_mock.called)
@ -2500,7 +2499,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
expected_url = '/resource_providers' expected_url = '/resource_providers'
self.ks_adap_mock.post.assert_called_once_with( self.ks_adap_mock.post.assert_called_once_with(
expected_url, json=expected_payload, microversion='1.20', expected_url, json=expected_payload, microversion='1.20',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
# A 503 Service Unavailable should log an error that # A 503 Service Unavailable should log an error that
# includes the placement request id and # includes the placement request id and
# _create_resource_provider() should return None # _create_resource_provider() should return None
@ -2515,7 +2514,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
url = '/resource_providers/%s/aggregates' % uuids.foo url = '/resource_providers/%s/aggregates' % uuids.foo
self.client.put(url, []) self.client.put(url, [])
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
url, json=[], microversion=None, headers={}) url, json=[], microversion=None, global_request_id=None)
def test_delete_provider(self): def test_delete_provider(self):
delete_mock = fake_requests.FakeResponse(None) delete_mock = fake_requests.FakeResponse(None)
@ -2532,7 +2531,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
self.ks_adap_mock.delete.assert_called_once_with( self.ks_adap_mock.delete.assert_called_once_with(
'/resource_providers/' + uuids.root, '/resource_providers/' + uuids.root,
headers={'X-Openstack-Request-Id': 'gri'}, microversion=None) global_request_id='gri', microversion=None)
self.assertFalse(self.client._provider_tree.exists(uuids.root)) self.assertFalse(self.client._provider_tree.exists(uuids.root))
self.assertNotIn(uuids.root, self.client._association_refresh_time) self.assertNotIn(uuids.root, self.client._association_refresh_time)
@ -2549,7 +2548,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
self.assertRaises(exc, self.client._delete_provider, uuids.root) self.assertRaises(exc, self.client._delete_provider, uuids.root)
self.ks_adap_mock.delete.assert_called_once_with( self.ks_adap_mock.delete.assert_called_once_with(
'/resource_providers/' + uuids.root, microversion=None, '/resource_providers/' + uuids.root, microversion=None,
headers={}) global_request_id=None)
self.ks_adap_mock.delete.reset_mock() self.ks_adap_mock.delete.reset_mock()
@ -2572,7 +2571,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
'/resource_providers/%s/aggregates' % uuids.rp, json=exp_payload, '/resource_providers/%s/aggregates' % uuids.rp, json=exp_payload,
microversion='1.19', microversion='1.19',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
# Cache was updated # Cache was updated
ptree_data = self.client._provider_tree.data(uuids.rp) ptree_data = self.client._provider_tree.data(uuids.rp)
self.assertEqual(set(aggs), ptree_data.aggregates) self.assertEqual(set(aggs), ptree_data.aggregates)
@ -2634,7 +2633,7 @@ class TestProviderOperations(SchedulerReportClientTestCase):
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
'/resource_providers/%s/aggregates' % uuids.rp, json=exp_payload, '/resource_providers/%s/aggregates' % uuids.rp, json=exp_payload,
microversion='1.19', microversion='1.19',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
# Cache was updated # Cache was updated
ptree_data = self.client._provider_tree.data(uuids.rp) ptree_data = self.client._provider_tree.data(uuids.rp)
self.assertEqual(set(), ptree_data.aggregates) self.assertEqual(set(), ptree_data.aggregates)
@ -2712,7 +2711,7 @@ class TestAggregates(SchedulerReportClientTestCase):
expected_url = '/resource_providers/' + uuid + '/aggregates' expected_url = '/resource_providers/' + uuid + '/aggregates'
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, microversion='1.19', expected_url, microversion='1.19',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertEqual(set(aggs), result) self.assertEqual(set(aggs), result)
self.assertEqual(42, gen) self.assertEqual(42, gen)
@ -2735,7 +2734,7 @@ class TestAggregates(SchedulerReportClientTestCase):
expected_url = '/resource_providers/' + uuid + '/aggregates' expected_url = '/resource_providers/' + uuid + '/aggregates'
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, microversion='1.19', expected_url, microversion='1.19',
headers={'X-Openstack-Request-Id': self.context.global_id}) global_request_id=self.context.global_id)
self.assertTrue(log_mock.called) self.assertTrue(log_mock.called)
self.assertEqual(uuids.request_id, self.assertEqual(uuids.request_id,
log_mock.call_args[0][1]['placement_req_id']) log_mock.call_args[0][1]['placement_req_id'])
@ -2762,7 +2761,7 @@ class TestTraits(SchedulerReportClientTestCase):
expected_url = '/resource_providers/' + uuid + '/traits' expected_url = '/resource_providers/' + uuid + '/traits'
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, expected_url,
headers={'X-Openstack-Request-Id': self.context.global_id}, global_request_id=self.context.global_id,
**self.trait_api_kwargs) **self.trait_api_kwargs)
self.assertEqual(set(traits), result) self.assertEqual(set(traits), result)
self.assertEqual(42, gen) self.assertEqual(42, gen)
@ -2786,7 +2785,7 @@ class TestTraits(SchedulerReportClientTestCase):
expected_url = '/resource_providers/' + uuid + '/traits' expected_url = '/resource_providers/' + uuid + '/traits'
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, expected_url,
headers={'X-Openstack-Request-Id': self.context.global_id}, global_request_id=self.context.global_id,
**self.trait_api_kwargs) **self.trait_api_kwargs)
self.assertTrue(log_mock.called) self.assertTrue(log_mock.called)
self.assertEqual(uuids.request_id, self.assertEqual(uuids.request_id,
@ -2803,7 +2802,7 @@ class TestTraits(SchedulerReportClientTestCase):
expected_url = '/resource_providers/' + uuid + '/traits' expected_url = '/resource_providers/' + uuid + '/traits'
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
expected_url, expected_url,
headers={'X-Openstack-Request-Id': self.context.global_id}, global_request_id=self.context.global_id,
**self.trait_api_kwargs) **self.trait_api_kwargs)
def test_ensure_traits(self): def test_ensure_traits(self):
@ -2822,12 +2821,12 @@ class TestTraits(SchedulerReportClientTestCase):
self.client._ensure_traits(self.context, all_traits) self.client._ensure_traits(self.context, all_traits)
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
'/traits?name=in:' + ','.join(all_traits), '/traits?name=in:' + ','.join(all_traits),
headers={'X-Openstack-Request-Id': self.context.global_id}, global_request_id=self.context.global_id,
**self.trait_api_kwargs) **self.trait_api_kwargs)
self.ks_adap_mock.put.assert_has_calls( self.ks_adap_mock.put.assert_has_calls(
[mock.call('/traits/' + trait, [mock.call('/traits/' + trait,
headers={'X-Openstack-Request-Id': self.context.global_id}, global_request_id=self.context.global_id, json=None,
**self.trait_api_kwargs) **self.trait_api_kwargs)
for trait in custom_traits], any_order=True) for trait in custom_traits], any_order=True)
self.ks_adap_mock.reset_mock() self.ks_adap_mock.reset_mock()
@ -2837,7 +2836,7 @@ class TestTraits(SchedulerReportClientTestCase):
self.client._ensure_traits(self.context, standard_traits) self.client._ensure_traits(self.context, standard_traits)
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
'/traits?name=in:' + ','.join(standard_traits), '/traits?name=in:' + ','.join(standard_traits),
headers={'X-Openstack-Request-Id': self.context.global_id}, global_request_id=self.context.global_id,
**self.trait_api_kwargs) **self.trait_api_kwargs)
self.ks_adap_mock.put.assert_not_called() self.ks_adap_mock.put.assert_not_called()
@ -2858,7 +2857,7 @@ class TestTraits(SchedulerReportClientTestCase):
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
'/traits?name=in:FOO', '/traits?name=in:FOO',
headers={'X-Openstack-Request-Id': self.context.global_id}, global_request_id=self.context.global_id,
**self.trait_api_kwargs) **self.trait_api_kwargs)
self.ks_adap_mock.put.assert_not_called() self.ks_adap_mock.put.assert_not_called()
@ -2874,11 +2873,11 @@ class TestTraits(SchedulerReportClientTestCase):
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
'/traits?name=in:FOO', '/traits?name=in:FOO',
headers={'X-Openstack-Request-Id': self.context.global_id}, global_request_id=self.context.global_id,
**self.trait_api_kwargs) **self.trait_api_kwargs)
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
'/traits/FOO', '/traits/FOO',
headers={'X-Openstack-Request-Id': self.context.global_id}, global_request_id=self.context.global_id, json=None,
**self.trait_api_kwargs) **self.trait_api_kwargs)
def test_set_traits_for_provider(self): def test_set_traits_for_provider(self):
@ -2904,12 +2903,12 @@ class TestTraits(SchedulerReportClientTestCase):
# Verify API calls # Verify API calls
self.ks_adap_mock.get.assert_called_once_with( self.ks_adap_mock.get.assert_called_once_with(
'/traits?name=in:' + ','.join(traits), '/traits?name=in:' + ','.join(traits),
headers={'X-Openstack-Request-Id': self.context.global_id}, global_request_id=self.context.global_id,
**self.trait_api_kwargs) **self.trait_api_kwargs)
self.ks_adap_mock.put.assert_called_once_with( self.ks_adap_mock.put.assert_called_once_with(
'/resource_providers/%s/traits' % uuids.rp, '/resource_providers/%s/traits' % uuids.rp,
json={'traits': traits, 'resource_provider_generation': 0}, json={'traits': traits, 'resource_provider_generation': 0},
headers={'X-Openstack-Request-Id': self.context.global_id}, global_request_id=self.context.global_id,
**self.trait_api_kwargs) **self.trait_api_kwargs)
# And ensure the provider tree cache was updated appropriately # And ensure the provider tree cache was updated appropriately

View File

@ -27,7 +27,7 @@ enum34>=1.0.4;python_version=='2.7' or python_version=='2.6' or python_version==
iso8601>=0.1.11 # MIT iso8601>=0.1.11 # MIT
jsonschema>=2.6.0 # MIT jsonschema>=2.6.0 # MIT
python-cinderclient!=4.0.0,>=3.3.0 # Apache-2.0 python-cinderclient!=4.0.0,>=3.3.0 # Apache-2.0
keystoneauth1>=3.9.0 # Apache-2.0 keystoneauth1>=3.15.0 # Apache-2.0
python-neutronclient>=6.7.0 # Apache-2.0 python-neutronclient>=6.7.0 # Apache-2.0
python-glanceclient>=2.8.0 # Apache-2.0 python-glanceclient>=2.8.0 # Apache-2.0
requests>=2.14.2 # Apache-2.0 requests>=2.14.2 # Apache-2.0