Skip to content

Commit 4a8ef26

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Refactor bandwidth related functional tests"
2 parents fe4ee1a + c0c6afd commit 4a8ef26

File tree

2 files changed

+61
-45
lines changed

2 files changed

+61
-45
lines changed

nova/tests/functional/test_servers.py

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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

61666175
class 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

nova/virt/fake.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,13 @@ class FakeLiveMigrateDriverWithNestedCustomResources(
839839

840840
class FakeDriverWithPciResources(SmallFakeDriver):
841841

842+
PCI_ADDR_PF1 = '0000:01:00.0'
843+
PCI_ADDR_PF1_VF1 = '0000:01:00.1'
844+
PCI_ADDR_PF2 = '0000:02:00.0'
845+
PCI_ADDR_PF2_VF1 = '0000:02:00.1'
846+
PCI_ADDR_PF3 = '0000:03:00.0'
847+
PCI_ADDR_PF3_VF1 = '0000:03:00.1'
848+
842849
# NOTE(gibi): Always use this fixture along with the
843850
# FakeDriverWithPciResources to make the necessary configuration for the
844851
# driver.
@@ -898,17 +905,17 @@ def setUp(self):
898905
def get_available_resource(self, nodename):
899906
host_status = super(
900907
FakeDriverWithPciResources, self).get_available_resource(nodename)
901-
# 01:00 - PF - ens1
908+
# 01:00.0 - PF - ens1
902909
# |---- 01:00.1 - VF
903910
#
904-
# 02:00 - PF - ens2
911+
# 02:00.0 - PF - ens2
905912
# |---- 02:00.1 - VF
906913
#
907-
# 03:00 - PF - ens3
914+
# 03:00.0 - PF - ens3
908915
# |---- 03:00.1 - VF
909916
host_status['pci_passthrough_devices'] = jsonutils.dumps([
910917
{
911-
'address': '0000:01:00.0',
918+
'address': self.PCI_ADDR_PF1,
912919
'product_id': 'fake-product_id',
913920
'vendor_id': 'fake-vendor_id',
914921
'status': 'available',
@@ -918,18 +925,18 @@ def get_available_resource(self, nodename):
918925
'label': 'fake-label',
919926
},
920927
{
921-
'address': '0000:01:00.1',
928+
'address': self.PCI_ADDR_PF1_VF1,
922929
'product_id': 'fake-product_id',
923930
'vendor_id': 'fake-vendor_id',
924931
'status': 'available',
925932
'dev_type': 'type-VF',
926-
'parent_addr': '0000:01:00',
933+
'parent_addr': self.PCI_ADDR_PF1,
927934
'numa_node': 0,
928935
'label': 'fake-label',
929936
"parent_ifname": "ens1",
930937
},
931938
{
932-
'address': '0000:02:00.0',
939+
'address': self.PCI_ADDR_PF2,
933940
'product_id': 'fake-product_id',
934941
'vendor_id': 'fake-vendor_id',
935942
'status': 'available',
@@ -939,18 +946,18 @@ def get_available_resource(self, nodename):
939946
'label': 'fake-label',
940947
},
941948
{
942-
'address': '0000:02:00.1',
949+
'address': self.PCI_ADDR_PF2_VF1,
943950
'product_id': 'fake-product_id',
944951
'vendor_id': 'fake-vendor_id',
945952
'status': 'available',
946953
'dev_type': 'type-VF',
947-
'parent_addr': '0000:02:00',
954+
'parent_addr': self.PCI_ADDR_PF2,
948955
'numa_node': 0,
949956
'label': 'fake-label',
950957
"parent_ifname": "ens2",
951958
},
952959
{
953-
'address': '0000:03:00.0',
960+
'address': self.PCI_ADDR_PF3,
954961
'product_id': 'fake-product_id',
955962
'vendor_id': 'fake-vendor_id',
956963
'status': 'available',
@@ -960,12 +967,12 @@ def get_available_resource(self, nodename):
960967
'label': 'fake-label',
961968
},
962969
{
963-
'address': '0000:03:00.1',
970+
'address': self.PCI_ADDR_PF3_VF1,
964971
'product_id': 'fake-product_id',
965972
'vendor_id': 'fake-vendor_id',
966973
'status': 'available',
967974
'dev_type': 'type-VF',
968-
'parent_addr': '0000:03:00',
975+
'parent_addr': self.PCI_ADDR_PF3,
969976
'numa_node': 0,
970977
'label': 'fake-label',
971978
"parent_ifname": "ens3",

0 commit comments

Comments
 (0)