Merge "Make the method to put allocations public"

This commit is contained in:
Jenkins 2017-05-25 21:28:27 +00:00 committed by Gerrit Code Review
commit d3a3e85570
2 changed files with 33 additions and 4 deletions

View File

@ -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})

View File

@ -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')