13
13
# under the License.
14
14
from unittest import mock
15
15
16
+ import ddt
16
17
import fixtures
17
18
import os_resource_classes
18
19
import os_traits
@@ -1613,12 +1614,12 @@ def test_heal_allocation_during_same_host_resize(self):
1613
1614
"compute1" , ** compute1_expected_placement_view )
1614
1615
1615
1616
1616
- class RCAndTraitBasedPCIAliasTests (PlacementPCIReportingTests ):
1617
+ @ddt .ddt
1618
+ class SimpleRCAndTraitBasedPCIAliasTests (PlacementPCIReportingTests ):
1617
1619
def setUp (self ):
1618
1620
super ().setUp ()
1619
1621
self .flags (group = 'filter_scheduler' , pci_in_placement = True )
1620
1622
1621
- def test_boot_with_custom_rc_and_traits (self ):
1622
1623
# The fake libvirt will emulate on the host:
1623
1624
# * one type-PCI in slot 0
1624
1625
pci_info = fakelibvirt .HostPCIDevicesInfo (
@@ -1642,7 +1643,7 @@ def test_boot_with_custom_rc_and_traits(self):
1642
1643
self .start_compute (hostname = "compute1" , pci_info = pci_info )
1643
1644
1644
1645
self .assertPCIDeviceCounts ("compute1" , total = 1 , free = 1 )
1645
- compute1_expected_placement_view = {
1646
+ self . compute1_expected_placement_view = {
1646
1647
"inventories" : {
1647
1648
"0000:81:00.0" : {"CUSTOM_GPU" : 1 },
1648
1649
},
@@ -1659,73 +1660,74 @@ def test_boot_with_custom_rc_and_traits(self):
1659
1660
"allocations" : {},
1660
1661
}
1661
1662
self .assert_placement_pci_view (
1662
- "compute1" , ** compute1_expected_placement_view )
1663
+ "compute1" , ** self . compute1_expected_placement_view )
1663
1664
1664
- pci_alias_wrong_rc = {
1665
+ @ddt .data (
1666
+ {
1665
1667
"vendor_id" : fakelibvirt .PCI_VEND_ID ,
1666
1668
"product_id" : fakelibvirt .PCI_PROD_ID ,
1667
1669
"name" : "a-gpu-wrong-rc" ,
1668
- }
1669
- pci_alias_wrong_rc_2 = {
1670
+ },
1671
+ {
1670
1672
"resource_class" : os_resource_classes .PGPU ,
1671
1673
"name" : "a-gpu-wrong-rc-2" ,
1672
- }
1673
- pci_alias_asking_for_missing_trait = {
1674
+ },
1675
+ {
1674
1676
"resource_class" : "GPU" ,
1675
1677
# NOTE(gibi): "big" is missing from device spec
1676
1678
"traits" : "purple,big" ,
1677
1679
"name" : "a-gpu-missing-trait" ,
1678
- }
1680
+ },
1681
+ )
1682
+ def test_boot_with_custom_rc_and_traits_no_matching_device (
1683
+ self , pci_alias
1684
+ ):
1685
+ self .flags (group = "pci" , alias = self ._to_list_of_json_str ([pci_alias ]))
1686
+ extra_spec = {"pci_passthrough:alias" : f"{ pci_alias ['name' ]} :1" }
1687
+ flavor_id = self ._create_flavor (extra_spec = extra_spec )
1688
+ server = self ._create_server (
1689
+ flavor_id = flavor_id , networks = [], expected_state = "ERROR"
1690
+ )
1691
+ self .assertIn ("fault" , server )
1692
+ self .assertIn ("No valid host" , server ["fault" ]["message" ])
1693
+
1694
+ self .assertPCIDeviceCounts ("compute1" , total = 1 , free = 1 )
1695
+ self .assert_placement_pci_view (
1696
+ "compute1" , ** self .compute1_expected_placement_view
1697
+ )
1698
+
1699
+ def test_boot_with_custom_rc_and_traits_succeeds (self ):
1679
1700
pci_alias_gpu = {
1680
1701
"resource_class" : "GPU" ,
1681
1702
"traits" : "HW_GPU_API_VULKAN,PURPLE" ,
1682
1703
"name" : "a-gpu" ,
1683
1704
}
1684
1705
self .flags (
1685
- group = "pci" ,
1686
- alias = self ._to_list_of_json_str (
1687
- [
1688
- pci_alias_wrong_rc ,
1689
- pci_alias_wrong_rc_2 ,
1690
- pci_alias_asking_for_missing_trait ,
1691
- pci_alias_gpu ,
1692
- ]
1693
- ),
1694
- )
1695
-
1696
- # try to boot with each alias that does not match
1697
- for alias in [
1698
- "a-gpu-wrong-rc" ,
1699
- "a-gpu-wrong-rc-2" ,
1700
- "a-gpu-missing-trait" ,
1701
- ]:
1702
- extra_spec = {"pci_passthrough:alias" : f"{ alias } :1" }
1703
- flavor_id = self ._create_flavor (extra_spec = extra_spec )
1704
- server = self ._create_server (
1705
- flavor_id = flavor_id , networks = [], expected_state = 'ERROR' )
1706
- self .assertIn ('fault' , server )
1707
- self .assertIn ('No valid host' , server ['fault' ]['message' ])
1708
-
1709
- self .assertPCIDeviceCounts ("compute1" , total = 1 , free = 1 )
1710
- self .assert_placement_pci_view (
1711
- "compute1" , ** compute1_expected_placement_view )
1712
-
1713
- # then boot with the matching alias
1706
+ group = "pci" , alias = self ._to_list_of_json_str ([pci_alias_gpu ])
1707
+ )
1708
+
1714
1709
extra_spec = {"pci_passthrough:alias" : "a-gpu:1" }
1715
1710
flavor_id = self ._create_flavor (extra_spec = extra_spec )
1716
- server = self ._create_server (
1717
- flavor_id = flavor_id , networks = [])
1711
+ server = self ._create_server (flavor_id = flavor_id , networks = [])
1718
1712
1719
1713
self .assertPCIDeviceCounts ("compute1" , total = 1 , free = 0 )
1720
- compute1_expected_placement_view [
1721
- "usages" ]["0000:81:00.0" ]["CUSTOM_GPU" ] = 1
1722
- compute1_expected_placement_view ["allocations" ][server ["id" ]] = {
1714
+ self .compute1_expected_placement_view ["usages" ]["0000:81:00.0" ][
1715
+ "CUSTOM_GPU"
1716
+ ] = 1
1717
+ self .compute1_expected_placement_view ["allocations" ][server ["id" ]] = {
1723
1718
"0000:81:00.0" : {"CUSTOM_GPU" : 1 }
1724
1719
}
1725
1720
self .assert_placement_pci_view (
1726
- "compute1" , ** compute1_expected_placement_view )
1721
+ "compute1" , ** self .compute1_expected_placement_view
1722
+ )
1727
1723
self .assert_no_pci_healing ("compute1" )
1728
1724
1725
+
1726
+ class RCAndTraitBasedPCIAliasTests (PlacementPCIReportingTests ):
1727
+ def setUp (self ):
1728
+ super ().setUp ()
1729
+ self .flags (group = 'filter_scheduler' , pci_in_placement = True )
1730
+
1729
1731
def test_device_claim_consistent_with_placement_allocation (self ):
1730
1732
"""As soon as [filter_scheduler]pci_in_placement is enabled the
1731
1733
nova-scheduler will allocate PCI devices in placement. Then on the
0 commit comments