@@ -5384,6 +5384,13 @@ def setUp(self):
53845384 macvtap = self .neutron .port_macvtap_with_resource_request
53855385 self .neutron ._ports [macvtap ['id' ]] = copy .deepcopy (macvtap )
53865386
5387+ def assertComputeAllocationMatchesFlavor (
5388+ self , allocations , compute_rp_uuid , flavor ):
5389+ compute_allocations = allocations [compute_rp_uuid ]['resources' ]
5390+ self .assertEqual (
5391+ self ._resources_from_flavor (flavor ),
5392+ compute_allocations )
5393+
53875394 def _create_server (self , flavor , networks ):
53885395 server_req = self ._build_minimal_create_server_request (
53895396 self .api , 'bandwidth-aware-server' ,
@@ -5804,12 +5811,11 @@ def test_boot_server_with_two_ports_one_having_resource_request(self):
58045811 # compute rp and one set for the networking resources on the ovs bridge
58055812 # rp due to the qos_port resource request
58065813 self .assertEqual (2 , len (allocations ))
5807- compute_allocations = allocations [self .compute1_rp_uuid ]['resources' ]
5814+
5815+ self .assertComputeAllocationMatchesFlavor (
5816+ allocations , self .compute1_rp_uuid , self .flavor )
58085817 network_allocations = allocations [
58095818 self .ovs_bridge_rp_per_host [self .compute1_rp_uuid ]]['resources' ]
5810-
5811- self .assertEqual (self ._resources_from_flavor (self .flavor ),
5812- compute_allocations )
58135819 self .assertPortMatchesAllocation (qos_port , network_allocations )
58145820
58155821 # We expect that only the RP uuid of the networking RP having the port
@@ -5851,15 +5857,13 @@ def test_one_ovs_one_sriov_port(self):
58515857 # compute rp and one set for the networking resources on the ovs bridge
58525858 # rp and on the sriov PF rp.
58535859 self .assertEqual (3 , len (allocations ))
5854- compute_allocations = allocations [self .compute1_rp_uuid ]['resources' ]
5860+
5861+ self .assertComputeAllocationMatchesFlavor (
5862+ allocations , self .compute1_rp_uuid , self .flavor_with_group_policy )
5863+
58555864 ovs_allocations = allocations [
58565865 self .ovs_bridge_rp_per_host [self .compute1_rp_uuid ]]['resources' ]
58575866 sriov_allocations = allocations [self .sriov_pf2_rp_uuid ]['resources' ]
5858-
5859- self .assertEqual (
5860- self ._resources_from_flavor (self .flavor_with_group_policy ),
5861- compute_allocations )
5862-
58635867 self .assertPortMatchesAllocation (ovs_port , ovs_allocations )
58645868 self .assertPortMatchesAllocation (sriov_port , sriov_allocations )
58655869
@@ -5888,12 +5892,12 @@ def test_interface_detach_with_port_with_bandwidth_request(self):
58885892 # compute rp and one set for the networking resources on the ovs bridge
58895893 # rp due to the port resource request
58905894 self .assertEqual (2 , len (allocations ))
5891- compute_allocations = allocations [self .compute1_rp_uuid ]['resources' ]
5895+
5896+ self .assertComputeAllocationMatchesFlavor (
5897+ allocations , self .compute1_rp_uuid , self .flavor )
5898+
58925899 network_allocations = allocations [
58935900 self .ovs_bridge_rp_per_host [self .compute1_rp_uuid ]]['resources' ]
5894-
5895- self .assertEqual (self ._resources_from_flavor (self .flavor ),
5896- compute_allocations )
58975901 self .assertPortMatchesAllocation (port , network_allocations )
58985902
58995903 # We expect that only the RP uuid of the networking RP having the port
@@ -5918,9 +5922,9 @@ def test_interface_detach_with_port_with_bandwidth_request(self):
59185922
59195923 # We expect that the port related resource allocations are removed
59205924 self .assertEqual (1 , len (allocations ))
5921- compute_allocations = allocations [ self . compute1_rp_uuid ][ 'resources' ]
5922- self .assertEqual ( self . _resources_from_flavor ( self . flavor ),
5923- compute_allocations )
5925+
5926+ self .assertComputeAllocationMatchesFlavor (
5927+ allocations , self . compute1_rp_uuid , self . flavor )
59245928
59255929 # We expect that the allocation is removed from the port too
59265930 binding_profile = updated_port ['binding:profile' ]
@@ -6051,10 +6055,9 @@ def test_two_sriov_ports_one_with_request_two_available_pfs(self):
60516055 # compute rp and one set for the networking resources on the sriov PF2
60526056 # rp.
60536057 self .assertEqual (2 , len (allocations ))
6054- compute_allocations = allocations [self .compute1_rp_uuid ]['resources' ]
6055- self .assertEqual (
6056- self ._resources_from_flavor (self .flavor_with_group_policy ),
6057- compute_allocations )
6058+
6059+ self .assertComputeAllocationMatchesFlavor (
6060+ allocations , self .compute1_rp_uuid , self .flavor_with_group_policy )
60586061
60596062 sriov_allocations = allocations [self .sriov_pf2_rp_uuid ]['resources' ]
60606063 self .assertPortMatchesAllocation (
@@ -6073,11 +6076,15 @@ def test_two_sriov_ports_one_with_request_two_available_pfs(self):
60736076 # We expect that the selected PCI device matches with the RP from
60746077 # where the bandwidth is allocated from. The bandwidth is allocated
60756078 # from 0000:02:00 (PF2) so the PCI device should be a VF of that PF
6076- self .assertEqual ('0000:02:00.1' , sriov_with_req_binding ['pci_slot' ])
6079+ self .assertEqual (
6080+ fake .FakeDriverWithPciResources .PCI_ADDR_PF2_VF1 ,
6081+ sriov_with_req_binding ['pci_slot' ])
60776082 # But also the port that has no resource request still gets a pci slot
60786083 # allocated. The 0000:02:00 has no more VF available but 0000:03:00 has
60796084 # one VF available and that PF is also on physnet2
6080- self .assertEqual ('0000:03:00.1' , sriov_binding ['pci_slot' ])
6085+ self .assertEqual (
6086+ fake .FakeDriverWithPciResources .PCI_ADDR_PF3_VF1 ,
6087+ sriov_binding ['pci_slot' ])
60816088
60826089 def test_one_sriov_port_no_vf_and_bandwidth_available_on_the_same_pf (self ):
60836090 """Verify that if there is no PF that both provides bandwidth and VFs
@@ -6095,7 +6102,9 @@ def test_one_sriov_port_no_vf_and_bandwidth_available_on_the_same_pf(self):
60956102 sriov_binding = sriov_port ['binding:profile' ]
60966103
60976104 # We expect that this consume the last available VF from the PF2
6098- self .assertEqual ('0000:02:00.1' , sriov_binding ['pci_slot' ])
6105+ self .assertEqual (
6106+ fake .FakeDriverWithPciResources .PCI_ADDR_PF2_VF1 ,
6107+ sriov_binding ['pci_slot' ])
60996108
61006109 # Now boot a second server with a port that has resource request
61016110 # At this point PF2 has available bandwidth but no available VF
@@ -6141,10 +6150,8 @@ def test_sriov_macvtap_port_with_resource_request(self):
61416150 # rp.
61426151 self .assertEqual (2 , len (allocations ))
61436152
6144- compute_allocations = allocations [self .compute1_rp_uuid ]['resources' ]
6145- self .assertEqual (
6146- self ._resources_from_flavor (self .flavor ),
6147- compute_allocations )
6153+ self .assertComputeAllocationMatchesFlavor (
6154+ allocations , self .compute1_rp_uuid , self .flavor )
61486155
61496156 sriov_allocations = allocations [self .sriov_pf2_rp_uuid ]['resources' ]
61506157 self .assertPortMatchesAllocation (
@@ -6160,7 +6167,9 @@ def test_sriov_macvtap_port_with_resource_request(self):
61606167 # We expect that the selected PCI device matches with the RP from
61616168 # where the bandwidth is allocated from. The bandwidth is allocated
61626169 # from 0000:02:00 (PF2) so the PCI device should be a VF of that PF
6163- self .assertEqual ('0000:02:00.1' , port_binding ['pci_slot' ])
6170+ self .assertEqual (
6171+ fake .FakeDriverWithPciResources .PCI_ADDR_PF2_VF1 ,
6172+ port_binding ['pci_slot' ])
61646173
61656174
61666175class PortResourceRequestReSchedulingTest (
@@ -6207,12 +6216,12 @@ def test_boot_reschedule_success(self):
62076216 # compute rp and one set for the networking resources on the ovs bridge
62086217 # rp
62096218 self .assertEqual (2 , len (allocations ))
6210- compute_allocations = allocations [dest_compute_rp_uuid ]['resources' ]
6219+
6220+ self .assertComputeAllocationMatchesFlavor (
6221+ allocations , dest_compute_rp_uuid , self .flavor )
6222+
62116223 network_allocations = allocations [
62126224 self .ovs_bridge_rp_per_host [dest_compute_rp_uuid ]]['resources' ]
6213-
6214- self .assertEqual (self ._resources_from_flavor (self .flavor ),
6215- compute_allocations )
62166225 self .assertPortMatchesAllocation (port , network_allocations )
62176226
62186227 # assert that the allocations against the host where the spawn
0 commit comments