'Tests that when a move operation is detected (existing allocations
for the same instance UUID) that we end up constructing an appropriate
allocation that contains the original resources on the source host
as well as the resources on the destination host but that when a shared
storage provider is claimed against in both the original allocation as
well as the new allocation request, we don\'t double that allocation
resource request up.'

def test_claim_resources_success_move_operation_with_shared(self):

    get_resp_mock = mock.Mock(status_code=200)
    get_resp_mock.json.return_value = {'allocations': {uuids.source: {'resource_provider_generation': 42, 'resources': {'VCPU': 1, 'MEMORY_MB': 1024}}, uuids.shared_storage: {'resource_provider_generation': 42, 'resources': {'DISK_GB': 100}}}}
    self.ks_sess_mock.get.return_value = get_resp_mock
    resp_mock = mock.Mock(status_code=204)
    self.ks_sess_mock.put.return_value = resp_mock
    consumer_uuid = uuids.consumer_uuid
    alloc_req = {'allocations': [{'resource_provider': {'uuid': uuids.destination}, 'resources': {'VCPU': 1, 'MEMORY_MB': 1024}}, {'resource_provider': {'uuid': uuids.shared_storage}, 'resources': {'DISK_GB': 100}}]}
    project_id = uuids.project_id
    user_id = uuids.user_id
    res = self.client.claim_resources(consumer_uuid, alloc_req, project_id, user_id)
    expected_url = ('/allocations/%s' % consumer_uuid)
    expected_payload = {'allocations': [{'resource_provider': {'uuid': uuids.source}, 'resources': {'VCPU': 1, 'MEMORY_MB': 1024}}, {'resource_provider': {'uuid': uuids.shared_storage}, 'resources': {'DISK_GB': 100}}, {'resource_provider': {'uuid': uuids.destination}, 'resources': {'VCPU': 1, 'MEMORY_MB': 1024}}]}
    expected_payload['project_id'] = project_id
    expected_payload['user_id'] = user_id
    self.ks_sess_mock.put.assert_called_once_with(expected_url, endpoint_filter=mock.ANY, headers={'OpenStack-API-Version': 'placement    1.10'}, json=mock.ANY, raise_exc=False)
    actual_payload = self.ks_sess_mock.put.call_args[1]['json']
    sort_by_uuid = (lambda x: x['resource_provider']['uuid'])
    expected_allocations = sorted(expected_payload['allocations'], key=sort_by_uuid)
    actual_allocations = sorted(actual_payload['allocations'], key=sort_by_uuid)
    self.assertEqual(expected_allocations, actual_allocations)
    self.assertTrue(res)
