Make the method to put allocations public
The report client for the scheduler has a private method for putting allocations that was previously only used internally. In order to have the scheduler claim resources directly, it should be changed to a public method. Partially-Implements: blueprint placement-claims Change-Id: Ie96265846b0acf74c5f61817a5b1ce10c7292ead
This commit is contained in:
parent
439f67e7bc
commit
203aacc3b9
|
@ -842,13 +842,13 @@ class SchedulerReportClient(object):
|
||||||
LOG.debug('Sending allocation for instance %s',
|
LOG.debug('Sending allocation for instance %s',
|
||||||
my_allocations,
|
my_allocations,
|
||||||
instance=instance)
|
instance=instance)
|
||||||
res = self._put_allocations(rp_uuid, instance.uuid, my_allocations)
|
res = self.put_allocations(rp_uuid, instance.uuid, my_allocations)
|
||||||
if res:
|
if res:
|
||||||
LOG.info(_LI('Submitted allocation for instance'),
|
LOG.info(_LI('Submitted allocation for instance'),
|
||||||
instance=instance)
|
instance=instance)
|
||||||
|
|
||||||
@safe_connect
|
@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
|
"""Creates allocation records for the supplied instance UUID against
|
||||||
the supplied resource provider.
|
the supplied resource provider.
|
||||||
|
|
||||||
|
@ -876,8 +876,8 @@ class SchedulerReportClient(object):
|
||||||
r = self.put(url, payload)
|
r = self.put(url, payload)
|
||||||
if r.status_code != 204:
|
if r.status_code != 204:
|
||||||
LOG.warning(
|
LOG.warning(
|
||||||
_LW('Unable to submit allocation for instance '
|
'Unable to submit allocation for instance '
|
||||||
'%(uuid)s (%(code)i %(text)s)'),
|
'%(uuid)s (%(code)i %(text)s)',
|
||||||
{'uuid': consumer_uuid,
|
{'uuid': consumer_uuid,
|
||||||
'code': r.status_code,
|
'code': r.status_code,
|
||||||
'text': r.text})
|
'text': r.text})
|
||||||
|
|
|
@ -178,6 +178,35 @@ class SchedulerReportClientTestCase(test.NoDBTestCase):
|
||||||
self.client = report.SchedulerReportClient()
|
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):
|
class TestProviderOperations(SchedulerReportClientTestCase):
|
||||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||||
'_create_resource_provider')
|
'_create_resource_provider')
|
||||||
|
|
Loading…
Reference in New Issue