Esempio n. 1
0
    def test__populate_pool(self, m_time):
        cls = vif_pool.NestedVIFPool
        m_driver = mock.MagicMock(spec=cls)

        cls_vif_driver = nested_vlan_vif.NestedVlanPodVIFDriver
        vif_driver = mock.MagicMock(spec=cls_vif_driver)
        m_driver._drv_vif = vif_driver

        pod = mock.sentinel.pod
        project_id = mock.sentinel.project_id
        subnets = mock.sentinel.subnets
        security_groups = [mock.sentinel.security_groups]
        pool_key = (mock.sentinel.host_addr, project_id,
                    tuple(security_groups))
        vif = osv_vif.VIFOpenVSwitch(id='0fa0e837-d34e-4580-a6c4-04f5f607d93e')
        vifs = [vif]

        m_driver._existing_vifs = {}
        m_driver._available_ports_pools = {}
        m_driver._last_update = {pool_key: 1}

        oslo_cfg.CONF.set_override('ports_pool_update_frequency',
                                   15,
                                   group='vif_pool')
        oslo_cfg.CONF.set_override('ports_pool_min', 5, group='vif_pool')
        m_driver._get_pool_size.return_value = 2
        vif_driver.request_vifs.return_value = vifs

        cls._populate_pool(m_driver, pool_key, pod, subnets)
        m_driver._get_pool_size.assert_called_once()
        m_driver._drv_vif.request_vifs.assert_called_once()
Esempio n. 2
0
    def test_release_vif(self):
        cls = vif_pool.NestedVIFPool
        m_driver = mock.MagicMock(spec=cls)
        m_driver._recyclable_ports = {}

        pod = get_pod_obj()
        project_id = mock.sentinel.project_id
        security_groups = [mock.sentinel.security_groups]
        vif = osv_vif.VIFOpenVSwitch(id='0fa0e837-d34e-4580-a6c4-04f5f607d93e')

        m_driver._return_ports_to_pool.return_value = None

        cls.release_vif(m_driver, pod, vif, project_id, security_groups)

        m_driver._return_ports_to_pool.assert_not_called()
Esempio n. 3
0
def neutron_to_osvif_vif_ovs(vif_plugin, neutron_port, subnets):
    """Converts Neutron port to VIF object for os-vif 'ovs' plugin.

    :param vif_plugin: name of the os-vif plugin to use (i.e. 'ovs')
    :param neutron_port: dict containing port information as returned by
                         neutron client's 'show_port'
    :param subnets: subnet mapping as returned by PodSubnetsDriver.get_subnets
    :return: os-vif VIF object
    """

    profile = osv_vif.VIFPortProfileOpenVSwitch(
        interface_id=neutron_port['id'])

    details = neutron_port.get('binding:vif_details', {})
    ovs_bridge = details.get('bridge_name',
                             config.CONF.neutron_defaults.ovs_bridge)
    if not ovs_bridge:
        raise oslo_cfg.RequiredOptError('ovs_bridge', 'neutron_defaults')

    network = _make_vif_network(neutron_port, subnets)
    network.bridge = ovs_bridge

    if details.get('ovs_hybrid_plug'):
        vif = osv_vif.VIFBridge(
            id=neutron_port['id'],
            address=neutron_port['mac_address'],
            network=network,
            has_traffic_filtering=details.get('port_filter', False),
            preserve_on_delete=False,
            active=_is_port_active(neutron_port),
            port_profile=profile,
            plugin=vif_plugin,
            vif_name=_get_vif_name(neutron_port),
            bridge_name=_get_ovs_hybrid_bridge_name(neutron_port))
    else:
        vif = osv_vif.VIFOpenVSwitch(id=neutron_port['id'],
                                     address=neutron_port['mac_address'],
                                     network=network,
                                     has_traffic_filtering=details.get(
                                         'port_filter', False),
                                     preserve_on_delete=False,
                                     active=_is_port_active(neutron_port),
                                     port_profile=profile,
                                     plugin=vif_plugin,
                                     vif_name=_get_vif_name(neutron_port),
                                     bridge_name=network.bridge)

    return vif
Esempio n. 4
0
def neutron_to_osvif_vif_ovs(vif_plugin, os_port, subnets):
    """Converts Neutron port to VIF object for os-vif 'ovs' plugin.

    :param vif_plugin: name of the os-vif plugin to use (i.e. 'ovs')
    :param os_port: openstack.network.v2.port.Port object
    :param subnets: subnet mapping as returned by PodSubnetsDriver.get_subnets
    :return: os-vif VIF object
    """
    profile = osv_vif.VIFPortProfileOpenVSwitch(interface_id=os_port.id)

    details = os_port.binding_vif_details or {}
    ovs_bridge = details.get('bridge_name',
                             config.CONF.neutron_defaults.ovs_bridge)
    if not ovs_bridge:
        raise oslo_cfg.RequiredOptError('ovs_bridge', 'neutron_defaults')

    network = _make_vif_network(os_port, subnets)
    network.bridge = ovs_bridge

    if details.get('ovs_hybrid_plug'):
        vif = osv_vif.VIFBridge(
            id=os_port.id,
            address=os_port.mac_address,
            network=network,
            has_traffic_filtering=details.get('port_filter', False),
            preserve_on_delete=False,
            active=_is_port_active(os_port),
            port_profile=profile,
            plugin=vif_plugin,
            vif_name=_get_vif_name(os_port),
            bridge_name=_get_ovs_hybrid_bridge_name(os_port))
    else:
        vif = osv_vif.VIFOpenVSwitch(id=os_port.id,
                                     address=os_port.mac_address,
                                     network=network,
                                     has_traffic_filtering=details.get(
                                         'port_filter', False),
                                     preserve_on_delete=False,
                                     active=_is_port_active(os_port),
                                     port_profile=profile,
                                     plugin=vif_plugin,
                                     vif_name=_get_vif_name(os_port),
                                     bridge_name=network.bridge)

    return vif
Esempio n. 5
0
def neutron_to_osvif_vif_ovs(vif_plugin, os_port, subnets):
    """Converts Neutron port to VIF object for os-vif 'ovs' plugin.

    :param vif_plugin: name of the os-vif plugin to use (i.e. 'ovs')
    :param os_port: openstack.network.v2.port.Port object
    :param subnets: subnet mapping as returned by PodSubnetsDriver.get_subnets
    :return: os-vif VIF object
    """
    profile = osv_vif.VIFPortProfileOpenVSwitch(interface_id=os_port.id)

    details = os_port.binding_vif_details or {}
    ovs_bridge = details.get('bridge_name',
                             config.CONF.neutron_defaults.ovs_bridge)
    if not ovs_bridge:
        raise oslo_cfg.RequiredOptError('ovs_bridge', 'neutron_defaults')

    network = _make_vif_network(os_port, subnets)
    network.bridge = ovs_bridge
    vhostuser_mode = details.get('vhostuser_mode', False)

    LOG.debug('Detected vhostuser_mode=%s for port %s', vhostuser_mode,
              os_port.id)
    if vhostuser_mode:
        # TODO(a.perevalov) obtain path to mount point from pod's mountVolumes
        vhostuser_mount_point = (config.CONF.vhostuser.mount_point)
        if not vhostuser_mount_point:
            raise oslo_cfg.RequiredOptError('vhostuser_mount_point',
                                            'neutron_defaults')
        vif_name = _get_vhu_vif_name(os_port.id)
        vif = osv_vif.VIFVHostUser(
            id=os_port.id,
            address=os_port.mac_address,
            network=network,
            has_traffic_filtering=details.get('port_filter', False),
            preserve_on_delete=False,
            active=_is_port_active(os_port),
            port_profile=profile,
            plugin='ovs',
            path=os.path.join(vhostuser_mount_point, vif_name),
            mode=vhostuser_mode,
            vif_name=vif_name,
            bridge_name=network.bridge)
    elif details.get('ovs_hybrid_plug'):
        vif = osv_vif.VIFBridge(
            id=os_port.id,
            address=os_port.mac_address,
            network=network,
            has_traffic_filtering=details.get('port_filter', False),
            preserve_on_delete=False,
            active=_is_port_active(os_port),
            port_profile=profile,
            plugin=vif_plugin,
            vif_name=_get_vif_name(os_port),
            bridge_name=_get_ovs_hybrid_bridge_name(os_port))
    else:
        vif = osv_vif.VIFOpenVSwitch(
            id=os_port.id,
            address=os_port.mac_address,
            network=network,
            has_traffic_filtering=details.get('port_filter', False),
            preserve_on_delete=False,
            active=_is_port_active(os_port),
            port_profile=profile,
            plugin=vif_plugin,
            vif_name=_get_vif_name(os_port),
            bridge_name=network.bridge)

    return vif