1717from neutron_lib .api .definitions import portbindings
1818from neutron_lib .callbacks import exceptions as n_exc
1919from neutron_lib import constants as n_consts
20- from neutron_lib .db import api as db_api
20+ from neutron_lib .objects import registry as obj_reg
2121from neutron_lib .plugins import utils
2222from neutron_lib .services .trunk import constants as trunk_consts
2323from oslo_utils import uuidutils
3030
3131class TestOVNTrunkDriver (base .TestOVNFunctionalBase ):
3232
33- def setUp (self , ** kwargs ):
34- super ().setUp (** kwargs )
33+ def setUp (self ):
34+ super (TestOVNTrunkDriver , self ).setUp ()
3535 self .trunk_plugin = trunk_plugin .TrunkPlugin ()
3636 self .trunk_plugin .add_segmentation_type (
3737 trunk_consts .SEGMENTATION_TYPE_VLAN ,
@@ -42,8 +42,7 @@ def trunk(self, sub_ports=None):
4242 sub_ports = sub_ports or []
4343 with self .network () as network :
4444 with self .subnet (network = network ) as subnet :
45- with self .port (subnet = subnet ,
46- device_owner = 'compute:nova' ) as parent_port :
45+ with self .port (subnet = subnet ) as parent_port :
4746 tenant_id = uuidutils .generate_uuid ()
4847 trunk = {'trunk' : {
4948 'port_id' : parent_port ['port' ]['id' ],
@@ -68,14 +67,17 @@ def _get_ovn_trunk_info(self):
6867 if row .parent_name and row .tag :
6968 device_owner = row .external_ids [
7069 ovn_const .OVN_DEVICE_OWNER_EXT_ID_KEY ]
70+ revision_number = row .external_ids [
71+ ovn_const .OVN_REV_NUM_EXT_ID_KEY ]
7172 ovn_trunk_info .append ({'port_id' : row .name ,
7273 'parent_port_id' : row .parent_name ,
7374 'tag' : row .tag ,
7475 'device_owner' : device_owner ,
76+ 'revision_number' : revision_number ,
7577 })
7678 return ovn_trunk_info
7779
78- def _verify_trunk_info (self , trunk , has_items , host = '' ):
80+ def _verify_trunk_info (self , trunk , has_items ):
7981 ovn_subports_info = self ._get_ovn_trunk_info ()
8082 neutron_subports_info = []
8183 for subport in trunk .get ('sub_ports' , []):
@@ -84,27 +86,19 @@ def _verify_trunk_info(self, trunk, has_items, host=''):
8486 'parent_port_id' : [trunk ['port_id' ]],
8587 'tag' : [subport ['segmentation_id' ]],
8688 'device_owner' : trunk_consts .TRUNK_SUBPORT_OWNER ,
89+ 'revision_number' : '2' ,
8790 })
88- # Check the subport binding.
89- pb = port_obj .PortBinding .get_object (
90- self .context , port_id = subport ['port_id' ], host = host )
91- self .assertEqual (n_consts .PORT_STATUS_ACTIVE , pb .status )
92- self .assertEqual (host , pb .host )
91+ # Check that the subport has the binding is active.
92+ binding = obj_reg .load_class ('PortBinding' ).get_object (
93+ self .context , port_id = subport ['port_id' ], host = '' )
94+ self .assertEqual (n_consts .PORT_STATUS_ACTIVE , binding ['status' ])
9395
9496 self .assertCountEqual (ovn_subports_info , neutron_subports_info )
9597 self .assertEqual (has_items , len (neutron_subports_info ) != 0 )
9698
9799 if trunk .get ('status' ):
98100 self .assertEqual (trunk_consts .TRUNK_ACTIVE_STATUS , trunk ['status' ])
99101
100- def _bind_port (self , port_id , host ):
101- with db_api .CONTEXT_WRITER .using (self .context ):
102- pb = port_obj .PortBinding .get_object (self .context ,
103- port_id = port_id , host = '' )
104- pb .delete ()
105- port_obj .PortBinding (self .context , port_id = port_id , host = host ,
106- vif_type = portbindings .VIF_TYPE_OVS ).create ()
107-
108102 def test_trunk_create (self ):
109103 with self .trunk () as trunk :
110104 self ._verify_trunk_info (trunk , has_items = False )
@@ -141,22 +135,10 @@ def test_subport_add(self):
141135 new_trunk = self .trunk_plugin .get_trunk (self .context ,
142136 trunk ['id' ])
143137 self ._verify_trunk_info (new_trunk , has_items = True )
144- # Bind parent port. That will trigger the binding of the
145- # trunk subports too, using the same host ID.
146- self ._bind_port (trunk ['port_id' ], 'host1' )
147- self .mech_driver .set_port_status_up (trunk ['port_id' ])
148- self ._verify_trunk_info (new_trunk , has_items = True ,
149- host = 'host1' )
150138
151139 def test_subport_delete (self ):
152140 with self .subport () as subport :
153141 with self .trunk ([subport ]) as trunk :
154- # Bind parent port.
155- self ._bind_port (trunk ['port_id' ], 'host1' )
156- self .mech_driver .set_port_status_up (trunk ['port_id' ])
157- self ._verify_trunk_info (trunk , has_items = True ,
158- host = 'host1' )
159-
160142 self .trunk_plugin .remove_subports (self .context , trunk ['id' ],
161143 {'sub_ports' : [subport ]})
162144 new_trunk = self .trunk_plugin .get_trunk (self .context ,
0 commit comments