@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_pcpu_as_vcpu(self, mock_placement, mock_inst, mock_qfd):
    self.flags(unified_limits_count_pcpu_as_vcpu=True, group='workarounds')
    mock_qfd.return_value = True
    mock_inst.return_value = {'project': {'instances': 42}}
    resources = ['servers', 'class:VCPU', 'class:MEMORY_MB']
    mock_placement.return_value = {'VCPU': 1, 'PCPU': 2}
    usage = placement_limits._get_usage(self.context, uuids.project, resources)
    expected = {'class:MEMORY_MB': 0, 'class:VCPU': 3, 'servers': 42}
    self.assertDictEqual(expected, usage)
    resources = ['servers', 'class:VCPU', 'class:MEMORY_MB']
    mock_placement.return_value = {'PCPU': 1}
    usage = placement_limits._get_usage(self.context, uuids.project, resources)
    expected = {'class:MEMORY_MB': 0, 'class:VCPU': 1, 'servers': 42}
    self.assertDictEqual(expected, usage)
    resources = ['servers', 'class:VCPU', 'class:MEMORY_MB']
    mock_placement.return_value = {'VCPU': 1}
    usage = placement_limits._get_usage(self.context, uuids.project, resources)
    expected = {'class:MEMORY_MB': 0, 'class:VCPU': 1, 'servers': 42}
    self.assertDictEqual(expected, usage)
    resources = ['servers', 'class:VCPU', 'class:MEMORY_MB', 'class:PCPU']
    mock_placement.return_value = {'VCPU': 1, 'PCPU': 2}
    usage = placement_limits._get_usage(self.context, uuids.project, resources)
    expected = {'class:MEMORY_MB': 0, 'class:VCPU': 1, 'servers': 42, 'class:PCPU': 2}
    self.assertDictEqual(expected, usage)
@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_pcpu_as_vcpu(self, mock_placement, mock_inst, mock_qfd):
    self.flags(unified_limits_count_pcpu_as_vcpu=True, group='workarounds')
    mock_qfd.return_value = True
    mock_inst.return_value = {'project': {'instances': 42}}
    resources = ['servers', 'class:VCPU', 'class:MEMORY_MB']
    mock_placement.return_value = {'VCPU': 1, 'PCPU': 2}
    usage = placement_limits._get_usage(self.context, uuids.project, resources)
    expected = {'class:MEMORY_MB': 0, 'class:VCPU': 3, 'servers': 42}
    self.assertDictEqual(expected, usage)
    resources = ['servers', 'class:VCPU', 'class:MEMORY_MB']
    mock_placement.return_value = {'PCPU': 1}
    usage = placement_limits._get_usage(self.context, uuids.project, resources)
    expected = {'class:MEMORY_MB': 0, 'class:VCPU': 1, 'servers': 42}
    self.assertDictEqual(expected, usage)
    resources = ['servers', 'class:VCPU', 'class:MEMORY_MB']
    mock_placement.return_value = {'VCPU': 1}
    usage = placement_limits._get_usage(self.context, uuids.project, resources)
    expected = {'class:MEMORY_MB': 0, 'class:VCPU': 1, 'servers': 42}
    self.assertDictEqual(expected, usage)
    resources = ['servers', 'class:VCPU', 'class:MEMORY_MB', 'class:PCPU']
    mock_placement.return_value = {'VCPU': 1, 'PCPU': 2}
    usage = placement_limits._get_usage(self.context, uuids.project, resources)
    expected = {'class:MEMORY_MB': 0, 'class:VCPU': 1, 'servers': 42, 'class:PCPU': 2}
    self.assertDictEqual(expected, usage)