39
39
from nova .network import model
40
40
from nova .network import neutron as neutronapi
41
41
from nova import objects
42
+ from nova .objects import fields as obj_fields
42
43
from nova .objects import network_request as net_req_obj
43
44
from nova .objects import virtual_interface as obj_vif
44
45
from nova .pci import manager as pci_manager
@@ -4494,17 +4495,21 @@ def test_update_port_bindings_for_instance_with_pci(self,
4494
4495
instance = fake_instance .fake_instance_obj (self .context )
4495
4496
instance .migration_context = objects .MigrationContext ()
4496
4497
instance .migration_context .old_pci_devices = objects .PciDeviceList (
4497
- objects = [objects .PciDevice (vendor_id = '1377' ,
4498
- product_id = '0047' ,
4499
- address = '0000:0a:00.1' ,
4500
- compute_node_id = 1 ,
4501
- request_id = '1234567890' )])
4498
+ objects = [objects .PciDevice (
4499
+ vendor_id = '1377' ,
4500
+ product_id = '0047' ,
4501
+ address = '0000:0a:00.1' ,
4502
+ compute_node_id = 1 ,
4503
+ request_id = '1234567890' ,
4504
+ dev_type = obj_fields .PciDeviceType .SRIOV_VF )])
4502
4505
instance .migration_context .new_pci_devices = objects .PciDeviceList (
4503
- objects = [objects .PciDevice (vendor_id = '1377' ,
4504
- product_id = '0047' ,
4505
- address = '0000:0b:00.1' ,
4506
- compute_node_id = 2 ,
4507
- request_id = '1234567890' )])
4506
+ objects = [objects .PciDevice (
4507
+ vendor_id = '1377' ,
4508
+ product_id = '0047' ,
4509
+ address = '0000:0b:00.1' ,
4510
+ compute_node_id = 2 ,
4511
+ request_id = '1234567890' ,
4512
+ dev_type = obj_fields .PciDeviceType .SRIOV_VF )])
4508
4513
instance .pci_devices = instance .migration_context .old_pci_devices
4509
4514
4510
4515
# Validate that non-direct port aren't updated (fake-port-2).
@@ -5928,14 +5933,14 @@ def test_unbind_ports_reset_binding_profile(self, mock_show):
5928
5933
'id' : uuids .port ,
5929
5934
'binding:profile' : {'pci_vendor_info' : '1377:0047' ,
5930
5935
'pci_slot' : '0000:0a:00.1' ,
5936
+ 'card_serial_number' : 'MT2113X00000' ,
5931
5937
'physical_network' : 'physnet1' ,
5932
5938
'capabilities' : ['switchdev' ]}
5933
5939
}
5934
5940
self .api ._unbind_ports (self .context , ports , neutron , port_client )
5935
5941
port_req_body = {'port' : {'binding:host_id' : None ,
5936
5942
'binding:profile' :
5937
- {'physical_network' : 'physnet1' ,
5938
- 'capabilities' : ['switchdev' ]},
5943
+ {'capabilities' : ['switchdev' ]},
5939
5944
'device_id' : '' ,
5940
5945
'device_owner' : '' }
5941
5946
}
@@ -7402,9 +7407,12 @@ def test_populate_neutron_extension_values_binding_sriov(self,
7402
7407
pci_dev = {'vendor_id' : '1377' ,
7403
7408
'product_id' : '0047' ,
7404
7409
'address' : '0000:0a:00.1' ,
7410
+ 'card_serial_number' : None ,
7411
+ 'dev_type' : 'TEST_TYPE' ,
7405
7412
}
7406
7413
PciDevice = collections .namedtuple ('PciDevice' ,
7407
- ['vendor_id' , 'product_id' , 'address' ])
7414
+ ['vendor_id' , 'product_id' , 'address' ,
7415
+ 'card_serial_number' , 'dev_type' ])
7408
7416
mydev = PciDevice (** pci_dev )
7409
7417
profile = {'pci_vendor_info' : '1377:0047' ,
7410
7418
'pci_slot' : '0000:0a:00.1' ,
@@ -7422,6 +7430,43 @@ def test_populate_neutron_extension_values_binding_sriov(self,
7422
7430
port_req_body ['port' ][
7423
7431
constants .BINDING_PROFILE ])
7424
7432
7433
+ @mock .patch .object (pci_whitelist .Whitelist , 'get_devspec' )
7434
+ @mock .patch .object (pci_manager , 'get_instance_pci_devs' )
7435
+ def test_populate_neutron_extension_values_binding_sriov_card_serial (
7436
+ self , mock_get_instance_pci_devs , mock_get_pci_device_devspec ):
7437
+ host_id = 'my_host_id'
7438
+ instance = {'host' : host_id }
7439
+ port_req_body = {'port' : {}}
7440
+ pci_req_id = 'my_req_id'
7441
+ pci_dev = {'vendor_id' : 'a2d6' ,
7442
+ 'product_id' : '15b3' ,
7443
+ 'address' : '0000:82:00.1' ,
7444
+ 'card_serial_number' : 'MT2113X00000' ,
7445
+ 'dev_type' : obj_fields .PciDeviceType .SRIOV_VF ,
7446
+ }
7447
+ PciDevice = collections .namedtuple ('PciDevice' ,
7448
+ ['vendor_id' , 'product_id' , 'address' ,
7449
+ 'card_serial_number' , 'dev_type' ])
7450
+ mydev = PciDevice (** pci_dev )
7451
+ profile = {'pci_vendor_info' : 'a2d6:15b3' ,
7452
+ 'pci_slot' : '0000:82:00.1' ,
7453
+ 'physical_network' : 'physnet1' ,
7454
+ # card_serial_number is a property of the object obtained
7455
+ # from extra_info.
7456
+ 'card_serial_number' : 'MT2113X00000' ,
7457
+ }
7458
+
7459
+ mock_get_instance_pci_devs .return_value = [mydev ]
7460
+ devspec = mock .Mock ()
7461
+ devspec .get_tags .return_value = {'physical_network' : 'physnet1' }
7462
+ mock_get_pci_device_devspec .return_value = devspec
7463
+ self .api ._populate_neutron_binding_profile (
7464
+ instance , pci_req_id , port_req_body , None )
7465
+
7466
+ self .assertEqual (profile ,
7467
+ port_req_body ['port' ][
7468
+ constants .BINDING_PROFILE ])
7469
+
7425
7470
def test_populate_neutron_extension_values_binding_arq (self ):
7426
7471
host_id = 'my_host_id'
7427
7472
instance = {'host' : host_id }
@@ -7474,9 +7519,12 @@ def test_populate_neutron_extension_values_binding_sriov_with_cap(self,
7474
7519
pci_dev = {'vendor_id' : '1377' ,
7475
7520
'product_id' : '0047' ,
7476
7521
'address' : '0000:0a:00.1' ,
7522
+ 'card_serial_number' : None ,
7523
+ 'dev_type' : 'TEST_TYPE' ,
7477
7524
}
7478
7525
PciDevice = collections .namedtuple ('PciDevice' ,
7479
- ['vendor_id' , 'product_id' , 'address' ])
7526
+ ['vendor_id' , 'product_id' , 'address' ,
7527
+ 'card_serial_number' , 'dev_type' ])
7480
7528
mydev = PciDevice (** pci_dev )
7481
7529
profile = {'pci_vendor_info' : '1377:0047' ,
7482
7530
'pci_slot' : '0000:0a:00.1' ,
@@ -7547,6 +7595,7 @@ def test_pci_parse_whitelist_called_once(self,
7547
7595
pci_dev = {'vendor_id' : '1377' ,
7548
7596
'product_id' : '0047' ,
7549
7597
'address' : '0000:0a:00.1' ,
7598
+ 'dev_type' : obj_fields .PciDeviceType .SRIOV_VF ,
7550
7599
}
7551
7600
7552
7601
whitelist = pci_whitelist .Whitelist (CONF .pci .passthrough_whitelist )
0 commit comments