diff --git a/nova/scheduler/client/report.py b/nova/scheduler/client/report.py index 6295ddfe2709..e42e7817540d 100644 --- a/nova/scheduler/client/report.py +++ b/nova/scheduler/client/report.py @@ -842,13 +842,13 @@ class SchedulerReportClient(object): LOG.debug('Sending allocation for instance %s', my_allocations, instance=instance) - res = self._put_allocations(rp_uuid, instance.uuid, my_allocations) + res = self.put_allocations(rp_uuid, instance.uuid, my_allocations) if res: LOG.info(_LI('Submitted allocation for instance'), instance=instance) @safe_connect - def _put_allocations(self, rp_uuid, consumer_uuid, alloc_data): + def put_allocations(self, rp_uuid, consumer_uuid, alloc_data): """Creates allocation records for the supplied instance UUID against the supplied resource provider. @@ -876,8 +876,8 @@ class SchedulerReportClient(object): r = self.put(url, payload) if r.status_code != 204: LOG.warning( - _LW('Unable to submit allocation for instance ' - '%(uuid)s (%(code)i %(text)s)'), + 'Unable to submit allocation for instance ' + '%(uuid)s (%(code)i %(text)s)', {'uuid': consumer_uuid, 'code': r.status_code, 'text': r.text}) diff --git a/nova/tests/unit/scheduler/client/test_report.py b/nova/tests/unit/scheduler/client/test_report.py index 48b29a07c5f0..8f70c6cd818f 100644 --- a/nova/tests/unit/scheduler/client/test_report.py +++ b/nova/tests/unit/scheduler/client/test_report.py @@ -178,6 +178,35 @@ class SchedulerReportClientTestCase(test.NoDBTestCase): self.client = report.SchedulerReportClient() +class TestPutAllocations(SchedulerReportClientTestCase): + @mock.patch('nova.scheduler.client.report.SchedulerReportClient.put') + def test_put_allocations(self, mock_put): + mock_put.return_value.status_code = 204 + mock_put.return_value.text = "cool" + rp_uuid = mock.sentinel.rp + consumer_uuid = mock.sentinel.consumer + data = {"MEMORY_MB": 1024} + expected_url = "/allocations/%s" % consumer_uuid + resp = self.client.put_allocations(rp_uuid, consumer_uuid, data) + self.assertTrue(resp) + mock_put.assert_called_once_with(expected_url, mock.ANY) + + @mock.patch.object(report.LOG, 'warning') + @mock.patch('nova.scheduler.client.report.SchedulerReportClient.put') + def test_put_allocations_fail(self, mock_put, mock_warn): + mock_put.return_value.status_code = 400 + mock_put.return_value.text = "not cool" + rp_uuid = mock.sentinel.rp + consumer_uuid = mock.sentinel.consumer + data = {"MEMORY_MB": 1024} + expected_url = "/allocations/%s" % consumer_uuid + resp = self.client.put_allocations(rp_uuid, consumer_uuid, data) + self.assertFalse(resp) + mock_put.assert_called_once_with(expected_url, mock.ANY) + log_msg = mock_warn.call_args[0][0] + self.assertIn("Unable to submit allocation for instance", log_msg) + + class TestProviderOperations(SchedulerReportClientTestCase): @mock.patch('nova.scheduler.client.report.SchedulerReportClient.' '_create_resource_provider')