@mock.patch.object(quota, 'is_qfd_populated')
@mock.patch.object(objects.InstanceMappingList, 'get_counts')
@mock.patch.object(report.SchedulerReportClient, 'get_usages_counts_for_limits')
def test_get_usage_placement_fail(self, mock_placement, mock_inst, mock_qfd):
    resources = ['servers', 'class:VCPU', 'class:MEMORY_MB', 'class:CUSTOM_BAREMETAL']
    mock_qfd.return_value = True
    mock_placement.side_effect = exception.UsagesRetrievalFailed(project_id=uuids.project, user_id=uuids.user)
    mock_inst.return_value = {'project': {'instances': 42}}
    e = self.assertRaises(exception.UsagesRetrievalFailed, placement_limits._get_usage, self.context, uuids.project, resources)
    expected = ('Failed to retrieve usages from placement while enforcing %s quota limits.' % ', '.join(resources))
    self.assertEqual(expected, str(e))
@mock.patch.object(quota, 'is_qfd_populated')
@mock.patch.object(objects.InstanceMappingList, 'get_counts')
@mock.patch.object(report.SchedulerReportClient, 'get_usages_counts_for_limits')
def test_get_usage_placement_fail(self, mock_placement, mock_inst, mock_qfd):
    resources = ['servers', 'class:VCPU', 'class:MEMORY_MB', 'class:CUSTOM_BAREMETAL']
    mock_qfd.return_value = True
    mock_placement.side_effect = exception.UsagesRetrievalFailed(project_id=uuids.project, user_id=uuids.user)
    mock_inst.return_value = {'project': {'instances': 42}}
    e = self.assertRaises(exception.UsagesRetrievalFailed, placement_limits._get_usage, self.context, uuids.project, resources)
    expected = ('Failed to retrieve usages from placement while enforcing %s quota limits.' % ', '.join(resources))
    self.assertEqual(expected, str(e))