diff --git a/nova/scheduler/client/report.py b/nova/scheduler/client/report.py index fd2e8c49489e..889b10f510ad 100644 --- a/nova/scheduler/client/report.py +++ b/nova/scheduler/client/report.py @@ -240,7 +240,7 @@ class SchedulerReportClient(object): """Create the HTTP session accessing the placement service.""" # Flush provider tree and associations so we start from a clean slate. self.clear_provider_cache(init=True) - client = self._adapter or utils.get_ksa_adapter('placement') + client = self._adapter or utils.get_sdk_adapter('placement') # Set accept header on every request to ensure we notify placement # service of our response body media type preferences. client.additional_headers = {'accept': 'application/json'} diff --git a/nova/tests/unit/scheduler/client/test_report.py b/nova/tests/unit/scheduler/client/test_report.py index c15c5ac25a10..d2a60e3a51ee 100644 --- a/nova/tests/unit/scheduler/client/test_report.py +++ b/nova/tests/unit/scheduler/client/test_report.py @@ -152,27 +152,29 @@ class SafeConnectedTestCase(test.NoDBTestCase): class TestConstructor(test.NoDBTestCase): - @mock.patch('keystoneauth1.loading.load_session_from_conf_options') - @mock.patch('keystoneauth1.loading.load_auth_from_conf_options') - def test_constructor(self, load_auth_mock, load_sess_mock): + def setUp(self): + super(TestConstructor, self).setUp() + ksafx = self.useFixture(nova_fixtures.KSAFixture()) + self.load_auth_mock = ksafx.mock_load_auth + self.load_sess_mock = ksafx.mock_load_sess + + def test_constructor(self): client = report.SchedulerReportClient() - load_auth_mock.assert_called_once_with(CONF, 'placement') - load_sess_mock.assert_called_once_with(CONF, 'placement', - auth=load_auth_mock.return_value) + self.load_auth_mock.assert_called_once_with(CONF, 'placement') + self.load_sess_mock.assert_called_once_with( + CONF, 'placement', auth=self.load_auth_mock.return_value) self.assertEqual(['internal', 'public'], client._client.interface) self.assertEqual({'accept': 'application/json'}, client._client.additional_headers) - @mock.patch('keystoneauth1.loading.load_session_from_conf_options') - @mock.patch('keystoneauth1.loading.load_auth_from_conf_options') - def test_constructor_admin_interface(self, load_auth_mock, load_sess_mock): + def test_constructor_admin_interface(self): self.flags(valid_interfaces='admin', group='placement') client = report.SchedulerReportClient() - load_auth_mock.assert_called_once_with(CONF, 'placement') - load_sess_mock.assert_called_once_with(CONF, 'placement', - auth=load_auth_mock.return_value) + self.load_auth_mock.assert_called_once_with(CONF, 'placement') + self.load_sess_mock.assert_called_once_with( + CONF, 'placement', auth=self.load_auth_mock.return_value) self.assertEqual(['admin'], client._client.interface) self.assertEqual({'accept': 'application/json'}, client._client.additional_headers) @@ -183,6 +185,7 @@ class SchedulerReportClientTestCase(test.NoDBTestCase): def setUp(self): super(SchedulerReportClientTestCase, self).setUp() self.context = context.get_admin_context() + self.useFixture(nova_fixtures.KSAFixture()) self.ks_adap_mock = mock.Mock() self.compute_node = objects.ComputeNode( uuid=uuids.compute_node, @@ -195,12 +198,7 @@ class SchedulerReportClientTestCase(test.NoDBTestCase): disk_allocation_ratio=1.0, ) - with test.nested( - mock.patch('keystoneauth1.adapter.Adapter', - return_value=self.ks_adap_mock), - mock.patch('keystoneauth1.loading.load_auth_from_conf_options') - ): - self.client = report.SchedulerReportClient() + self.client = report.SchedulerReportClient(self.ks_adap_mock) def _init_provider_tree(self, generation_override=None, resources_override=None):