@@ -21177,6 +21177,54 @@ def test_update_provider_tree(self):
2117721177 for trait in ['HW_CPU_X86_AVX512F', 'HW_CPU_X86_BMI']:
2117821178 self.assertIn(trait, self.pt.data(self.cn_rp['uuid']).traits)
2117921179
21180+ @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_gpu_inventories')
21181+ @mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
21182+ '_get_cpu_feature_traits',
21183+ new=mock.Mock(return_value=cpu_traits))
21184+ @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_local_gb_info',
21185+ new=mock.Mock(return_value={'total': 0}))
21186+ @mock.patch('nova.virt.libvirt.host.Host.get_memory_mb_total',
21187+ new=mock.Mock(return_value=0))
21188+ @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_pcpu_available',
21189+ new=mock.Mock(return_value=range(0)))
21190+ @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_vcpu_available',
21191+ new=mock.Mock(return_value=range(0)))
21192+ @mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
21193+ '_update_provider_tree_for_pcpu',
21194+ new=mock.Mock())
21195+ def test_update_provider_tree_zero_total(self, mock_gpu_invs):
21196+ # Verify that we omit various resources from inventory when there are
21197+ # zero total quantity of those resources. Placement does not allow
21198+ # inventory updates with total=0 as they fail API schema validation.
21199+
21200+ # Use total=0 for vgpus.
21201+ gpu_inventory_dicts = {
21202+ 'pci_0000_06_00_0': {'total': 0,
21203+ 'max_unit': 16,
21204+ 'min_unit': 1,
21205+ 'step_size': 1,
21206+ 'reserved': 0,
21207+ 'allocation_ratio': 1.0,
21208+ },
21209+ }
21210+ mock_gpu_invs.return_value = gpu_inventory_dicts
21211+ # Use an empty list for vpmems.
21212+ self.driver._vpmems_by_rc = {'CUSTOM_PMEM_NAMESPACE_4GB': []}
21213+ # Before we update_provider_tree, we have 2 providers from setUp():
21214+ # self.cn_rp and self.shared_rp and they are both empty {}.
21215+ self.assertEqual(2, len(self.pt.get_provider_uuids()))
21216+ # Update the provider tree.
21217+ self.driver.update_provider_tree(self.pt, self.cn_rp['name'])
21218+ # After we update_provider_tree, we should still have 2 providers
21219+ # because VGPU has total=0 and we would skip adding a child provider
21220+ # for it.
21221+ self.assertEqual(2, len(self.pt.get_provider_uuids()))
21222+ # All providers should have an empty dict because (1) we never updated
21223+ # the self.shared_rp provider and (2) the other 2 providers have zero
21224+ # for resource totals.
21225+ for uuid in self.pt.get_provider_uuids():
21226+ self.assertEqual({}, self.pt.data(uuid).inventory)
21227+
2118021228 def test_update_provider_tree_with_vgpus(self):
2118121229 pci_devices = ['pci_0000_06_00_0', 'pci_0000_07_00_0']
2118221230 gpu_inventory_dicts = {
0 commit comments