17
17
from neutron_lib .api .definitions import portbindings
18
18
from neutron_lib .callbacks import exceptions as n_exc
19
19
from 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
21
21
from neutron_lib .plugins import utils
22
22
from neutron_lib .services .trunk import constants as trunk_consts
23
23
from oslo_utils import uuidutils
30
30
31
31
class TestOVNTrunkDriver (base .TestOVNFunctionalBase ):
32
32
33
- def setUp (self , ** kwargs ):
34
- super ().setUp (** kwargs )
33
+ def setUp (self ):
34
+ super (TestOVNTrunkDriver , self ).setUp ()
35
35
self .trunk_plugin = trunk_plugin .TrunkPlugin ()
36
36
self .trunk_plugin .add_segmentation_type (
37
37
trunk_consts .SEGMENTATION_TYPE_VLAN ,
@@ -42,8 +42,7 @@ def trunk(self, sub_ports=None):
42
42
sub_ports = sub_ports or []
43
43
with self .network () as network :
44
44
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 :
47
46
tenant_id = uuidutils .generate_uuid ()
48
47
trunk = {'trunk' : {
49
48
'port_id' : parent_port ['port' ]['id' ],
@@ -68,14 +67,17 @@ def _get_ovn_trunk_info(self):
68
67
if row .parent_name and row .tag :
69
68
device_owner = row .external_ids [
70
69
ovn_const .OVN_DEVICE_OWNER_EXT_ID_KEY ]
70
+ revision_number = row .external_ids [
71
+ ovn_const .OVN_REV_NUM_EXT_ID_KEY ]
71
72
ovn_trunk_info .append ({'port_id' : row .name ,
72
73
'parent_port_id' : row .parent_name ,
73
74
'tag' : row .tag ,
74
75
'device_owner' : device_owner ,
76
+ 'revision_number' : revision_number ,
75
77
})
76
78
return ovn_trunk_info
77
79
78
- def _verify_trunk_info (self , trunk , has_items , host = '' ):
80
+ def _verify_trunk_info (self , trunk , has_items ):
79
81
ovn_subports_info = self ._get_ovn_trunk_info ()
80
82
neutron_subports_info = []
81
83
for subport in trunk .get ('sub_ports' , []):
@@ -84,27 +86,19 @@ def _verify_trunk_info(self, trunk, has_items, host=''):
84
86
'parent_port_id' : [trunk ['port_id' ]],
85
87
'tag' : [subport ['segmentation_id' ]],
86
88
'device_owner' : trunk_consts .TRUNK_SUBPORT_OWNER ,
89
+ 'revision_number' : '2' ,
87
90
})
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' ])
93
95
94
96
self .assertCountEqual (ovn_subports_info , neutron_subports_info )
95
97
self .assertEqual (has_items , len (neutron_subports_info ) != 0 )
96
98
97
99
if trunk .get ('status' ):
98
100
self .assertEqual (trunk_consts .TRUNK_ACTIVE_STATUS , trunk ['status' ])
99
101
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
-
108
102
def test_trunk_create (self ):
109
103
with self .trunk () as trunk :
110
104
self ._verify_trunk_info (trunk , has_items = False )
@@ -141,22 +135,10 @@ def test_subport_add(self):
141
135
new_trunk = self .trunk_plugin .get_trunk (self .context ,
142
136
trunk ['id' ])
143
137
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' )
150
138
151
139
def test_subport_delete (self ):
152
140
with self .subport () as subport :
153
141
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
-
160
142
self .trunk_plugin .remove_subports (self .context , trunk ['id' ],
161
143
{'sub_ports' : [subport ]})
162
144
new_trunk = self .trunk_plugin .get_trunk (self .context ,
0 commit comments