def test_bind_port_front_end(self): given_front_end = mech_driver.OpenDaylightMechanismDriver() if hasattr(given_front_end, 'check_segment'): self.skip( "Old version of driver front-end doesn't delegate bind_port to" " back-end.") given_vif_type = "MY_VIF_TYPE" given_port_context = self.given_port_context() given_back_end = mech_driver.OpenDaylightDriver() given_back_end._get_vif_type = mock.Mock(return_value=given_vif_type) given_front_end.odl_drv = given_back_end # when port is bound given_front_end.bind_port(given_port_context) # then vif type is got calling _get_vif_type given_back_end._get_vif_type.assert_called_once_with( given_port_context) # then context binding is setup wit returned vif_type and valid # segment api ID given_port_context.set_binding.assert_called_once_with( self.valid_segment[api.ID], given_vif_type, given_back_end.vif_details, status=n_constants.PORT_STATUS_ACTIVE)
def test_bind_port_from_mech_driver_with_vhostuser(self): given_client = self.mock_client('vhostuser_topology.json') self.mock_get_addresses_by_name(['127.0.0.1', '192.168.66.1']) given_network_topology = network_topology.NetworkTopologyManager( vif_details={'some': 'detail'}, client=given_client) self.patch( network_topology, 'NetworkTopologyManager', return_value=given_network_topology) given_driver = mech_driver.OpenDaylightMechanismDriver() given_driver.odl_drv = mech_driver.OpenDaylightDriver() given_port_context = self.given_port_context() # when port is bound given_driver.bind_port(given_port_context) expected_vif_details = { 'vhostuser_socket': '/var/run/openvswitch/vhuCURRENT_CON', 'vhostuser_ovs_plug': True, 'some': 'detail', 'vhostuser_mode': 'client'} # then context binding is setup with returned vif_type and valid # segment api ID given_port_context.set_binding.assert_called_once_with( self.valid_segment[api.ID], portbindings.VIF_TYPE_VHOST_USER, expected_vif_details, status=n_constants.PORT_STATUS_ACTIVE)
def test_get_vif_type(self, cfg): given_port_context = mock.MagicMock(spec=api.PortContext) given_back_end = mech_driver.OpenDaylightDriver() # when getting VIF type vif_type = given_back_end._get_vif_type(given_port_context) # then VIF type is ovs self.assertIs(vif_type, portbindings.VIF_TYPE_OVS)
def initialize(self): self.url = cfg.CONF.ml2_odl.url self.timeout = cfg.CONF.ml2_odl.timeout self.username = cfg.CONF.ml2_odl.username self.password = cfg.CONF.ml2_odl.password required_opts = ('url', 'username', 'password') for opt in required_opts: if not getattr(self, opt): raise cfg.RequiredOptError(opt, 'ml2_odl') self.odl_drv = mech_driver.OpenDaylightDriver()
def initialize(self): self.url = cfg.CONF.ml2_odl.url self.timeout = cfg.CONF.ml2_odl.timeout self.username = cfg.CONF.ml2_odl.username self.password = cfg.CONF.ml2_odl.password required_opts = ('url', 'username', 'password') for opt in required_opts: if not getattr(self, opt): raise cfg.RequiredOptError(opt, 'ml2_odl') self.vif_type = portbindings.VIF_TYPE_OVS self.vif_details = {portbindings.CAP_PORT_FILTER: True} self.odl_drv = mech_driver.OpenDaylightDriver()
def test_bind_port_front_end(self): given_front_end = mech_driver.OpenDaylightMechanismDriver() given_port_context = self.given_port_context() given_back_end = mech_driver.OpenDaylightDriver() given_front_end.odl_drv = given_back_end # when port is bound given_front_end.bind_port(given_port_context) # then context binding is setup with returned vif_type and valid # segment API ID given_port_context.set_binding.assert_called_once_with( self.valid_segment[api.ID], portbindings.VIF_TYPE_OVS, given_back_end.vif_details, status=n_constants.PORT_STATUS_ACTIVE)
def test_bind_port_back_end(self): given_vif_type = "MY_VIF_TYPE" given_port_context = self.given_port_context() given_back_end = mech_driver.OpenDaylightDriver() given_back_end._get_vif_type = mock.Mock(return_value=given_vif_type) # when port is bound given_back_end.bind_port(given_port_context) # then vif type is got calling _get_vif_type given_back_end._get_vif_type.assert_called_once_with( given_port_context) # then context binding is setup wit returned vif_type and valid # segment api ID given_port_context.set_binding.assert_called_once_with( self.valid_segment[api.ID], given_vif_type, given_back_end.vif_details, status=n_constants.PORT_STATUS_ACTIVE)
def test_bind_port_from_mech_driver_with_ovs(self): given_client = self.mock_client('ovs_topology.json') self.mock_get_addresses_by_name(['127.0.0.1', '10.237.214.247']) given_network_topology = network_topology.NetworkTopologyManager( vif_details={'some': 'detail'}, client=given_client) self.patch( network_topology, 'NetworkTopologyManager', return_value=given_network_topology) given_driver = mech_driver.OpenDaylightMechanismDriver() given_driver.odl_drv = mech_driver.OpenDaylightDriver() given_port_context = self.given_port_context() # when port is bound given_driver.bind_port(given_port_context) # then context binding is setup with returned vif_type and valid # segment api ID given_port_context.set_binding.assert_called_once_with( self.valid_segment[api.ID], portbindings.VIF_TYPE_OVS, {'some': 'detail'}, status=n_constants.PORT_STATUS_ACTIVE)
def test_check_segment(self): """Validate the _check_segment method.""" # given driver and all network types given_back_end = mech_driver.OpenDaylightDriver() all_network_types = [ constants.TYPE_FLAT, constants.TYPE_GRE, constants.TYPE_LOCAL, constants.TYPE_VXLAN, constants.TYPE_VLAN, constants.TYPE_NONE ] # when checking segments network type valid_types = { network_type for network_type in all_network_types if given_back_end._check_segment({api.NETWORK_TYPE: network_type}) } # then true is returned only for valid network types self.assertEqual( { constants.TYPE_LOCAL, constants.TYPE_GRE, constants.TYPE_VXLAN, constants.TYPE_VLAN }, valid_types)
def setUp(self): super(OpenDaylightSyncTestCase, self).setUp() self.given_back_end = mech_driver.OpenDaylightDriver()