@ -21,6 +21,7 @@ from pstats import Stats
from neutron_lib.api.definitions import portbindings
from neutron_lib import constants as n_const
import neutron_lib.context
from neutron_lib.db import api as db_api
from neutron_lib.plugins import constants as p_const
from neutron_lib.plugins import directory
from oslo_config import cfg
@ -29,6 +30,7 @@ from neutron.api.rpc.handlers import l3_rpc
from neutron.common import constants as c_const
from neutron.common import utils as common_utils
from neutron.plugins.ml2.drivers import type_vxlan # noqa
from neutron.plugins.ml2 import models as ml2_models
from neutron.services.trunk import constants as trunk_const
from neutron.tests.common import helpers
from neutron.tests.unit.plugins.ml2 import test_plugin
@ -269,16 +271,36 @@ class MechTestBase(test_plugin.Ml2PluginV2TestCase):
portbindings . VIF_TYPE : portbindings . VIF_TYPE_UNBOUND } }
self . plugin . update_port ( self . context , port_id , p_dict )
def bind_dvr_to_host ( self , port , host ) :
p_dict = { ' port ' :
{ ' device_id ' : port [ ' device_id ' ] ,
' device_owner ' : port [ ' device_owner ' ] ,
portbindings . HOST_ID : host } }
self . plugin . update_distributed_port_binding ( self . context ,
port [ ' id ' ] , p_dict )
self . plugin . update_port_status ( self . context , port [ ' id ' ] ,
n_const . PORT_STATUS_ACTIVE ,
host )
def bind_dvr_to_host ( self , port , host , notify_ml2 = True , seg_id = None ) :
if notify_ml2 :
p_dict = { ' port ' :
{ ' device_id ' : port [ ' device_id ' ] ,
' device_owner ' : port [ ' device_owner ' ] ,
portbindings . HOST_ID : host } }
self . plugin . update_distributed_port_binding ( self . context ,
port [ ' id ' ] , p_dict )
self . plugin . update_port_status ( self . context , port [ ' id ' ] ,
n_const . PORT_STATUS_ACTIVE ,
host )
else :
session = db_api . get_writer_session ( )
with session . begin ( ) :
distributed_binding = { ' port_id ' : port [ ' id ' ] ,
' host ' : host ,
' router_id ' : port [ ' device_id ' ] ,
' status ' : ' ACTIVE ' ,
' vif_type ' : ' distributed ' ,
' vnic_type ' : portbindings . VNIC_NORMAL ,
' profile ' : ' ' ,
' vif_details ' : ' ' }
session . add ( ml2_models . DistributedPortBinding (
* * distributed_binding ) )
binding_level = { ' port_id ' : port [ ' id ' ] ,
' host ' : host ,
' segment_id ' : seg_id ,
' level ' : 0 ,
' driver ' : ' ovs ' }
session . add ( ml2_models . PortBindingLevel ( * * binding_level ) )
p_ctx = self . plugin . get_bound_port_context ( self . context , port [ ' id ' ] ,
host )
return port , p_ctx