Nix update_instance_allocation, _allocate_for_instance
A previous change [1] removed the only usage of SchedulerReportClient method update_instance_allocation, which itself was the only user of the _allocate_for_instance method. Remove both of these methods and their test artifacts. [1] If272365e58a583e2831a15a5c2abad2d77921729 Change-Id: Iec02942d384620608e7c705f15f895105d90c882
This commit is contained in:
parent
6a68f9140d
commit
73d7ef4288
|
@ -1732,26 +1732,6 @@ class SchedulerReportClient(object):
|
|||
return allocations.get(
|
||||
rp_uuid, {}).get('resources', {})
|
||||
|
||||
def _allocate_for_instance(self, context, rp_uuid, instance):
|
||||
my_allocations = _instance_to_allocations_dict(instance)
|
||||
current_allocations = self.get_allocations_for_consumer_by_provider(
|
||||
context, rp_uuid, instance.uuid)
|
||||
if current_allocations == my_allocations:
|
||||
allocstr = ','.join(['%s=%s' % (k, v)
|
||||
for k, v in my_allocations.items()])
|
||||
LOG.debug('Instance %(uuid)s allocations are unchanged: %(alloc)s',
|
||||
{'uuid': instance.uuid, 'alloc': allocstr})
|
||||
return
|
||||
|
||||
LOG.debug('Sending allocation for instance %s',
|
||||
my_allocations,
|
||||
instance=instance)
|
||||
res = self.put_allocations(context, rp_uuid, instance.uuid,
|
||||
my_allocations, instance.project_id,
|
||||
instance.user_id)
|
||||
if res:
|
||||
LOG.info('Submitted allocation for instance', instance=instance)
|
||||
|
||||
# NOTE(jaypipes): Currently, this method is ONLY used in two places:
|
||||
# 1. By the scheduler to allocate resources on the selected destination
|
||||
# hosts.
|
||||
|
@ -1759,9 +1739,7 @@ class SchedulerReportClient(object):
|
|||
# destination host. This is a short-term fix for Pike which should be
|
||||
# replaced in Queens by conductor calling the scheduler in the force
|
||||
# host case.
|
||||
# This method should not be called by the resource tracker; instead, the
|
||||
# _allocate_for_instance() method is used which does not perform any
|
||||
# checking that a move operation is in place.
|
||||
# This method should not be called by the resource tracker.
|
||||
@safe_connect
|
||||
@retries
|
||||
def claim_resources(self, context, consumer_uuid, alloc_request,
|
||||
|
@ -1776,9 +1754,9 @@ class SchedulerReportClient(object):
|
|||
operations from being scheduled to improperly, we create a "doubled-up"
|
||||
allocation that consumes resources on *both* the source and the
|
||||
destination host during the move operation. When the move operation
|
||||
completes, the destination host (via _allocate_for_instance()) will
|
||||
end up setting allocations for the instance only on the destination
|
||||
host thereby freeing up resources on the source host appropriately.
|
||||
completes, the destination host will end up setting allocations for the
|
||||
instance only on the destination host thereby freeing up resources on
|
||||
the source host appropriately.
|
||||
|
||||
:param context: The security context
|
||||
:param consumer_uuid: The instance's UUID.
|
||||
|
@ -2085,13 +2063,6 @@ class SchedulerReportClient(object):
|
|||
'text': r.text})
|
||||
return False
|
||||
|
||||
def update_instance_allocation(self, context, compute_node, instance,
|
||||
sign):
|
||||
if sign > 0:
|
||||
self._allocate_for_instance(context, compute_node.uuid, instance)
|
||||
else:
|
||||
self.delete_allocation_for_instance(context, instance.uuid)
|
||||
|
||||
def get_allocations_for_resource_provider(self, context, rp_uuid):
|
||||
"""Retrieves the allocations for a specific provider.
|
||||
|
||||
|
|
|
@ -221,8 +221,11 @@ class SchedulerReportClientTests(SchedulerReportClientTestBase):
|
|||
self.assertTrue(ptree.has_inventory(self.compute_uuid))
|
||||
|
||||
# Update allocations with our instance
|
||||
self.client.update_instance_allocation(
|
||||
self.context, self.compute_node, self.instance, 1)
|
||||
alloc_dict = utils.resources_from_flavor(self.instance,
|
||||
self.instance.flavor)
|
||||
self.client.put_allocations(
|
||||
self.context, self.compute_uuid, self.instance_uuid,
|
||||
alloc_dict, self.instance.project_id, self.instance.user_id)
|
||||
|
||||
# Check that allocations were made
|
||||
resp = self.client.get('/allocations/%s' % self.instance_uuid)
|
||||
|
@ -238,8 +241,8 @@ class SchedulerReportClientTests(SchedulerReportClientTestBase):
|
|||
self.assertEqual(2, vcpu_data)
|
||||
|
||||
# Delete allocations with our instance
|
||||
self.client.update_instance_allocation(
|
||||
self.context, self.compute_node, self.instance, -1)
|
||||
self.client.delete_allocation_for_instance(self.context,
|
||||
self.instance.uuid)
|
||||
|
||||
# No usage
|
||||
resp = self.client.get('/resource_providers/%s/usages' %
|
||||
|
|
|
@ -3222,98 +3222,6 @@ class TestAllocations(SchedulerReportClientTestCase):
|
|||
}
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'put')
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'get')
|
||||
@mock.patch('nova.scheduler.client.report.'
|
||||
'_instance_to_allocations_dict')
|
||||
def test_update_instance_allocation_new(self, mock_a, mock_get,
|
||||
mock_put):
|
||||
cn = objects.ComputeNode(uuid=uuids.cn)
|
||||
inst = objects.Instance(uuid=uuids.inst, project_id=uuids.project,
|
||||
user_id=uuids.user)
|
||||
mock_get.return_value.json.return_value = {'allocations': {}}
|
||||
expected = {
|
||||
'allocations': [
|
||||
{'resource_provider': {'uuid': cn.uuid},
|
||||
'resources': mock_a.return_value}],
|
||||
'project_id': inst.project_id,
|
||||
'user_id': inst.user_id,
|
||||
}
|
||||
self.client.update_instance_allocation(self.context, cn, inst, 1)
|
||||
mock_put.assert_called_once_with(
|
||||
'/allocations/%s' % inst.uuid,
|
||||
expected, version='1.8',
|
||||
global_request_id=self.context.global_id)
|
||||
self.assertTrue(mock_get.called)
|
||||
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'put')
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'get')
|
||||
@mock.patch('nova.scheduler.client.report.'
|
||||
'_instance_to_allocations_dict')
|
||||
def test_update_instance_allocation_existing(self, mock_a, mock_get,
|
||||
mock_put):
|
||||
cn = objects.ComputeNode(uuid=uuids.cn)
|
||||
inst = objects.Instance(uuid=uuids.inst)
|
||||
mock_get.return_value.json.return_value = {'allocations': {
|
||||
cn.uuid: {
|
||||
'generation': 2,
|
||||
'resources': {
|
||||
'DISK_GB': 123,
|
||||
'MEMORY_MB': 456,
|
||||
}
|
||||
}}
|
||||
}
|
||||
mock_a.return_value = {
|
||||
'DISK_GB': 123,
|
||||
'MEMORY_MB': 456,
|
||||
}
|
||||
self.client.update_instance_allocation(self.context, cn, inst, 1)
|
||||
self.assertFalse(mock_put.called)
|
||||
mock_get.assert_called_once_with(
|
||||
'/allocations/%s' % inst.uuid, version='1.28',
|
||||
global_request_id=self.context.global_id)
|
||||
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'get')
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'put')
|
||||
@mock.patch('nova.scheduler.client.report.'
|
||||
'_instance_to_allocations_dict')
|
||||
@mock.patch.object(report.LOG, 'warning')
|
||||
def test_update_instance_allocation_new_failed(self, mock_warn, mock_a,
|
||||
mock_put, mock_get):
|
||||
cn = objects.ComputeNode(uuid=uuids.cn)
|
||||
inst = objects.Instance(uuid=uuids.inst, project_id=uuids.project,
|
||||
user_id=uuids.user)
|
||||
mock_put.return_value = fake_requests.FakeResponse(400)
|
||||
self.client.update_instance_allocation(self.context, cn, inst, 1)
|
||||
self.assertTrue(mock_warn.called)
|
||||
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'delete')
|
||||
def test_update_instance_allocation_delete(self, mock_delete):
|
||||
cn = objects.ComputeNode(uuid=uuids.cn)
|
||||
inst = objects.Instance(uuid=uuids.inst)
|
||||
self.client.update_instance_allocation(self.context, cn, inst, -1)
|
||||
mock_delete.assert_called_once_with(
|
||||
'/allocations/%s' % inst.uuid,
|
||||
global_request_id=self.context.global_id)
|
||||
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'delete')
|
||||
@mock.patch.object(report.LOG, 'warning')
|
||||
def test_update_instance_allocation_delete_failed(self, mock_warn,
|
||||
mock_delete):
|
||||
cn = objects.ComputeNode(uuid=uuids.cn)
|
||||
inst = objects.Instance(uuid=uuids.inst)
|
||||
mock_delete.return_value = fake_requests.FakeResponse(400)
|
||||
self.client.update_instance_allocation(self.context, cn, inst, -1)
|
||||
self.assertTrue(mock_warn.called)
|
||||
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'delete')
|
||||
@mock.patch('nova.scheduler.client.report.LOG')
|
||||
|
|
Loading…
Reference in New Issue