'Create some resource providers that can satisfy the request for
resources with local (non-shared) resources and verify that the
allocation requests returned by AllocationCandidates correspond with
each of these resource providers.'

def test_all_local(self):

    cn1_uuid = uuidsentinel.cn1
    cn1 = objects.ResourceProvider(self.ctx, name='cn1', uuid=cn1_uuid)
    cn1.create()
    cn2_uuid = uuidsentinel.cn2
    cn2 = objects.ResourceProvider(self.ctx, name='cn2', uuid=cn2_uuid)
    cn2.create()
    cn3_uuid = uuidsentinel.cn3
    cn3 = objects.ResourceProvider(self.ctx, name='cn3', uuid=cn3_uuid)
    cn3.create()
    for cn in (cn1, cn2, cn3):
        vcpu = objects.Inventory(resource_provider=cn, resource_class=fields.ResourceClass.VCPU, total=24, reserved=0, min_unit=1, max_unit=24, step_size=1, allocation_ratio=16.0)
        memory_mb = objects.Inventory(resource_provider=cn, resource_class=fields.ResourceClass.MEMORY_MB, total=32768, reserved=0, min_unit=64, max_unit=32768, step_size=64, allocation_ratio=1.5)
        if (cn.uuid == cn3_uuid):
            disk_gb = objects.Inventory(resource_provider=cn, resource_class=fields.ResourceClass.DISK_GB, total=1000, reserved=100, min_unit=10, max_unit=1000, step_size=10, allocation_ratio=1.0)
        else:
            disk_gb = objects.Inventory(resource_provider=cn, resource_class=fields.ResourceClass.DISK_GB, total=2000, reserved=100, min_unit=10, max_unit=2000, step_size=10, allocation_ratio=1.0)
        disk_gb.obj_set_defaults()
        inv_list = objects.InventoryList(objects=[vcpu, memory_mb, disk_gb])
        cn.set_inventory(inv_list)
    requested_resources = self._requested_resources()
    p_alts = rp_obj.AllocationCandidates.get_by_filters(self.ctx, filters={'resources': requested_resources})
    p_sums = p_alts.provider_summaries
    self.assertEqual(2, len(p_sums))
    p_sum_rps = set([ps.resource_provider.uuid for ps in p_sums])
    self.assertEqual(set([cn1_uuid, cn2_uuid]), p_sum_rps)
    cn1_p_sum = self._find_summary_for_provider(p_sums, cn1_uuid)
    self.assertIsNotNone(cn1_p_sum)
    self.assertEqual(3, len(cn1_p_sum.resources))
    cn1_p_sum_vcpu = self._find_summary_for_resource(cn1_p_sum, 'VCPU')
    self.assertIsNotNone(cn1_p_sum_vcpu)
    expected_capacity = (24 * 16.0)
    self.assertEqual(expected_capacity, cn1_p_sum_vcpu.capacity)
    self.assertEqual(0, cn1_p_sum_vcpu.used)
    cn2_p_sum = self._find_summary_for_provider(p_sums, cn2_uuid)
    self.assertIsNotNone(cn2_p_sum)
    self.assertEqual(3, len(cn2_p_sum.resources))
    cn2_p_sum_disk = self._find_summary_for_resource(cn2_p_sum, 'DISK_GB')
    self.assertIsNotNone(cn2_p_sum_disk)
    expected_capacity = ((2000 - 100) * 1.0)
    self.assertEqual(expected_capacity, cn2_p_sum_disk.capacity)
    self.assertEqual(0, cn2_p_sum_disk.used)
    a_reqs = p_alts.allocation_requests
    self.assertEqual(2, len(a_reqs))
    a_req_rps = set()
    for ar in a_reqs:
        for rr in ar.resource_requests:
            a_req_rps.add(rr.resource_provider.uuid)
    self.assertEqual(set([cn1_uuid, cn2_uuid]), a_req_rps)
    cn1_reqs = self._find_requests_for_provider(a_reqs, cn1_uuid)
    self.assertEqual(3, len(cn1_reqs))
    cn1_req_vcpu = self._find_request_for_resource(cn1_reqs, 'VCPU')
    self.assertIsNotNone(cn1_req_vcpu)
    self.assertEqual(requested_resources['VCPU'], cn1_req_vcpu.amount)
    cn2_req_disk = self._find_request_for_resource(cn1_reqs, 'DISK_GB')
    self.assertIsNotNone(cn2_req_disk)
    self.assertEqual(requested_resources['DISK_GB'], cn2_req_disk.amount)
