Esempio n. 1
0
    def plug(self, instance, vif):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port. Then boot the
        VIF on the linux bridge using standard libvirt mechanisms.
        """
        iface_id = vif.ovs_interfaceid
        br_name = vif.br_name
        v1_name, v2_name = vif.veth_pair_names

        if not linux_net.device_exists(br_name):
            processutils.execute('brctl', 'addbr', br_name,
                                 run_as_root=True)
            processutils.execute('brctl', 'setfd', br_name, 0,
                                 run_as_root=True)
            processutils.execute('brctl', 'stp', br_name, 'off',
                                 run_as_root=True)
            syspath = '/sys/class/net/%s/bridge/multicast_snooping'
            syspath = syspath % br_name
            processutils.execute('tee', syspath, process_input='0',
                                 check_exit_code=[0, 1],
                                 run_as_root=True)

        if not linux_net.device_exists(v2_name):
            linux_net.create_veth_pair(v1_name, v2_name, self.network_device_mtu)
            processutils.execute('ip', 'link', 'set', br_name, 'up',
                                 run_as_root=True)
            processutils.execute('brctl', 'addif', br_name, v1_name,
                                 run_as_root=True)
            linux_net.create_ovs_vif_port(vif.bridge_name,
                                          v2_name, iface_id,
                                          vif.address, instance.uuid)
    def plug(self, vif, instance_info):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port. Then boot the
        VIF on the linux bridge using standard libvirt mechanisms.
        """

        if not hasattr(vif, "port_profile"):
            raise exception.MissingPortProfile()
        if not isinstance(vif.port_profile,
                          objects.vif.VIFPortProfileOpenVSwitch):
            raise exception.WrongPortProfile(
                profile=vif.port_profile.__class__.__name__)

        v1_name, v2_name = self.get_veth_pair_names(vif)

        if not linux_net.device_exists(vif.bridge_name):
            processutils.execute('brctl', 'addbr', vif.bridge_name,
                                 run_as_root=True)
            processutils.execute('brctl', 'setfd', vif.bridge_name, 0,
                                 run_as_root=True)
            processutils.execute('brctl', 'stp', vif.bridge_name, 'off',
                                 run_as_root=True)
            syspath = '/sys/class/net/%s/bridge/multicast_snooping'
            syspath = syspath % vif.bridge_name
            processutils.execute('tee', syspath, process_input='0',
                                 check_exit_code=[0, 1],
                                 run_as_root=True)
            disv6 = ('/proc/sys/net/ipv6/conf/%s/disable_ipv6' %
                     vif.bridge_name)
            if os.path.exists(disv6):
                processutils.execute('tee',
                                     disv6,
                                     process_input='1',
                                     run_as_root=True,
                                     check_exit_code=[0, 1])

        if not linux_net.device_exists(v2_name):
            linux_net.create_veth_pair(v1_name, v2_name,
                                       self.config.network_device_mtu)
            processutils.execute('ip', 'link', 'set', vif.bridge_name, 'up',
                                 run_as_root=True)
            processutils.execute('brctl', 'addif', vif.bridge_name, v1_name,
                                 run_as_root=True)
            linux_net.create_ovs_vif_port(
                vif.network.bridge,
                v2_name,
                vif.port_profile.interface_id,
                vif.address, instance_info.uuid,
                self.config.network_device_mtu,
                timeout=self.config.ovs_vsctl_timeout)
Esempio n. 3
0
    def _plug_vif_windows(self, vif, instance_info):
        """Create a per-VIF OVS port."""

        if not linux_net.device_exists(vif.id):
            linux_net.ensure_ovs_bridge(vif.network.bridge,
                                        self._get_vif_datapath_type(vif))
            self._create_vif_port(vif, vif.id, instance_info)
Esempio n. 4
0
    def _plug_bridge(self, vif, instance_info):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port. Then boot the
        VIF on the linux bridge using standard libvirt mechanisms.
        """

        v1_name, v2_name = self.get_veth_pair_names(vif)

        linux_net.ensure_bridge(vif.bridge_name)

        mtu = self._get_mtu(vif)
        if not linux_net.device_exists(v2_name):
            linux_net.create_veth_pair(v1_name, v2_name, mtu)
            linux_net.add_bridge_port(vif.bridge_name, v1_name)
            linux_net.ensure_ovs_bridge(vif.network.bridge,
                self._get_vif_datapath_type(vif),
                timeout=self.config.ovs_vsctl_timeout,
                ovsdb_connection=self.config.ovsdb_connection)
            self._create_vif_port(vif, v2_name, instance_info)
        else:
            linux_net.update_veth_pair(v1_name, v2_name, mtu)
            self._update_vif_port(vif, v2_name)
Esempio n. 5
0
    def _plug_vif_windows(self, vif, instance_info):
        """Create a per-VIF OVS port."""

        if not linux_net.device_exists(vif.id):
            linux_net.ensure_ovs_bridge(vif.network.bridge,
                                            constants.OVS_DATAPATH_SYSTEM)
            self._create_vif_port(vif, vif.id, instance_info)
    def unplug(self, vif, instance_info):
        """UnPlug using hybrid strategy

        Unhook port from OVS, unhook port from bridge, delete
        bridge, and delete both veth devices.
        """
        if not hasattr(vif, "port_profile"):
            raise exception.MissingPortProfile()
        if not isinstance(vif.port_profile,
                          objects.vif.VIFPortProfileOpenVSwitch):
            raise exception.WrongPortProfile(
                profile=vif.port_profile.__class__.__name__)

        v1_name, v2_name = self.get_veth_pair_names(vif)

        if linux_net.device_exists(vif.bridge_name):
            processutils.execute('brctl', 'delif', vif.bridge_name, v1_name,
                                 run_as_root=True)
            processutils.execute('ip', 'link', 'set', vif.bridge_name, 'down',
                                 run_as_root=True)
            processutils.execute('brctl', 'delbr', vif.bridge_name,
                                 run_as_root=True)

        linux_net.delete_ovs_vif_port(vif.network.bridge, v2_name,
                                      timeout=self.config.ovs_vsctl_timeout)
Esempio n. 7
0
    def _plug_vif_windows(self, vif, instance_info):
        """Create a per-VIF OVS port."""

        if not linux_net.device_exists(vif.id):
            linux_net.ensure_ovs_bridge(vif.network.bridge,
                                        constants.OVS_DATAPATH_SYSTEM)
            self._create_vif_port(vif, vif.id, instance_info)
Esempio n. 8
0
    def test_plug_ovs_bridge(self, mock_sys, ensure_bridge, device_exists,
                             create_veth_pair, update_veth_pair,
                             add_bridge_port, _create_vif_port,
                             _update_vif_port, ensure_ovs_bridge):
        calls = {
            'device_exists': [mock.call('qvob679325f-ca')],
            'create_veth_pair': [mock.call('qvbb679325f-ca',
                                           'qvob679325f-ca',
                                           1500)],
            'update_veth_pair': [mock.call('qvbb679325f-ca',
                                           'qvob679325f-ca',
                                           1500)],
            'ensure_bridge': [mock.call('qbrvif-xxx-yyy')],
            'add_bridge_port': [mock.call('qbrvif-xxx-yyy',
                                          'qvbb679325f-ca')],
            '_update_vif_port': [mock.call(self.vif_ovs_hybrid,
                                           'qvob679325f-ca')],
            '_create_vif_port': [mock.call(self.vif_ovs_hybrid,
                                           'qvob679325f-ca',
                                           self.instance)],
            'ensure_ovs_bridge': [mock.call('br0',
                                            constants.OVS_DATAPATH_SYSTEM)]
        }

        # plugging new devices should result in devices being created

        device_exists.return_value = False
        mock_sys.platform = 'linux'
        plugin = ovs.OvsPlugin.load('ovs')
        plugin.plug(self.vif_ovs_hybrid, self.instance)
        ensure_bridge.assert_has_calls(calls['ensure_bridge'])
        device_exists.assert_has_calls(calls['device_exists'])
        create_veth_pair.assert_has_calls(calls['create_veth_pair'])
        self.assertFalse(update_veth_pair.called)
        self.assertFalse(_update_vif_port.called)
        add_bridge_port.assert_has_calls(calls['add_bridge_port'])
        _create_vif_port.assert_has_calls(calls['_create_vif_port'])
        ensure_ovs_bridge.assert_has_calls(calls['ensure_ovs_bridge'])

        # reset call stacks

        create_veth_pair.reset_mock()
        _create_vif_port.reset_mock()

        # plugging existing devices should result in devices being updated

        device_exists.return_value = True
        self.assertTrue(linux_net.device_exists('test'))
        plugin.plug(self.vif_ovs_hybrid, self.instance)
        self.assertFalse(create_veth_pair.called)
        self.assertFalse(_create_vif_port.called)
        update_veth_pair.assert_has_calls(calls['update_veth_pair'])
        _update_vif_port.assert_has_calls(calls['_update_vif_port'])
Esempio n. 9
0
    def test_plug_ovs_bridge(self, mock_sys, ensure_bridge, device_exists,
                             create_veth_pair, update_veth_pair,
                             add_bridge_port, _create_vif_port,
                             _update_vif_port, ensure_ovs_bridge,
                             set_interface_state):
        dp_type = ovs.OvsPlugin._get_vif_datapath_type(self.vif_ovs_hybrid)
        calls = {
            'device_exists': [mock.call('qvob679325f-ca')],
            'create_veth_pair':
            [mock.call('qvbb679325f-ca', 'qvob679325f-ca', 1500)],
            'update_veth_pair':
            [mock.call('qvbb679325f-ca', 'qvob679325f-ca', 1500)],
            'ensure_bridge': [mock.call('qbrvif-xxx-yyy')],
            'set_interface_state': [mock.call('qbrvif-xxx-yyy', 'up')],
            'add_bridge_port': [mock.call('qbrvif-xxx-yyy', 'qvbb679325f-ca')],
            '_update_vif_port':
            [mock.call(self.vif_ovs_hybrid, 'qvob679325f-ca')],
            '_create_vif_port':
            [mock.call(self.vif_ovs_hybrid, 'qvob679325f-ca', self.instance)],
            'ensure_ovs_bridge':
            [mock.call('br0', dp_type, ovsdb_connection=None, timeout=120)]
        }

        # plugging new devices should result in devices being created

        device_exists.return_value = False
        mock_sys.platform = 'linux'
        plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
        plugin.plug(self.vif_ovs_hybrid, self.instance)
        ensure_bridge.assert_has_calls(calls['ensure_bridge'])
        device_exists.assert_has_calls(calls['device_exists'])
        create_veth_pair.assert_has_calls(calls['create_veth_pair'])
        update_veth_pair.assert_not_called()
        _update_vif_port.assert_not_called()
        add_bridge_port.assert_has_calls(calls['add_bridge_port'])
        _create_vif_port.assert_has_calls(calls['_create_vif_port'])
        ensure_ovs_bridge.assert_has_calls(calls['ensure_ovs_bridge'])

        # reset call stacks

        create_veth_pair.reset_mock()
        _create_vif_port.reset_mock()

        # plugging existing devices should result in devices being updated

        device_exists.return_value = True
        self.assertTrue(linux_net.device_exists('test'))
        plugin.plug(self.vif_ovs_hybrid, self.instance)
        create_veth_pair.assert_not_called()
        _create_vif_port.assert_not_called()
        update_veth_pair.assert_has_calls(calls['update_veth_pair'])
        _update_vif_port.assert_has_calls(calls['_update_vif_port'])
Esempio n. 10
0
    def unplug(self, vif):
        """UnPlug using hybrid strategy

        Unhook port from OVS, unhook port from bridge, delete
        bridge, and delete both veth devices.
        """
        br_name = vif.br_name
        v1_name, v2_name = vif.veth_pair_names

        if linux_net.device_exists(br_name):
            processutils.execute('brctl', 'delif', br_name, v1_name,
                                 run_as_root=True)
            processutils.execute('ip', 'link', 'set', br_name, 'down',
                                 run_as_root=True)
            processutils.execute('brctl', 'delbr', br_name,
                                 run_as_root=True)

        linux_net.delete_ovs_vif_port(vif.bridge_name, v2_name)
Esempio n. 11
0
    def _plug_bridge(self, vif, instance_info):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port. Then boot the
        VIF on the linux bridge using standard libvirt mechanisms.
        """

        v1_name, v2_name = self.get_veth_pair_names(vif)

        linux_net.ensure_bridge(vif.bridge_name)

        if not linux_net.device_exists(v2_name):
            linux_net.create_veth_pair(v1_name, v2_name,
                                       self.config.network_device_mtu)
            linux_net.add_bridge_port(vif.bridge_name, v1_name)
            linux_net.ensure_ovs_bridge(vif.network.bridge,
                                        constants.OVS_DATAPATH_SYSTEM)
            self._create_vif_port(vif, v2_name, instance_info)
Esempio n. 12
0
    def _plug_bridge(self, vif, instance_info):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port. Then boot the
        VIF on the linux bridge using standard libvirt mechanisms.
        """

        v1_name, v2_name = self.get_veth_pair_names(vif)

        linux_net.ensure_bridge(vif.bridge_name)

        if not linux_net.device_exists(v2_name):
            if vif.network and vif.network.mtu:
                mtu = vif.network.mtu
            else:
                mtu = self.config.network_device_mtu
            linux_net.create_veth_pair(v1_name, v2_name, mtu)
            linux_net.add_bridge_port(vif.bridge_name, v1_name)
            linux_net.ensure_ovs_bridge(vif.network.bridge,
                                        constants.OVS_DATAPATH_SYSTEM)
            self._create_vif_port(vif, v2_name, instance_info)