Пример #1
0
    def initialize(self, service_dir):
        super(NetworkResourceService, self).initialize(service_dir)
        # The <svcroot>/vips directory is used to allocate/de-allocate
        # container vips.
        vips_dir = os.path.join(service_dir, self._VIPS_DIR)
        # Initialize vips
        self._vips = vipfile.VipMgr(vips_dir, self._service_rsrc_dir)

        # Clear all environment assignments here. They will be re-assigned
        # below.
        for containers_set in set(_SET_BY_ENVIRONMENT.values()):
            iptables.create_set(containers_set,
                                set_type='hash:ip',
                                family='inet',
                                hashsize=1024,
                                maxelem=65536)

        need_init = False
        try:
            netdev.link_set_up(self._TM_DEV0)
            netdev.link_set_up(self._TM_DEV1)
            netdev.link_set_up(self._TMBR_DEV)

        except subproc.CalledProcessError:
            need_init = True

        if need_init:
            # Reset the bridge
            self._bridge_initialize()

        # These two are also done here because they are idempotent
        # Disable bridge forward delay
        netdev.bridge_setfd(self._TMBR_DEV, 0)
        # Enable route_localnet so that we can redirect traffic from the
        # container to the node's loopback address.
        netdev.dev_conf_route_localnet_set(self._TM_DEV0, True)

        # Read bridge status
        self._bridge_mtu = netdev.dev_mtu(self._TMBR_DEV)

        # Read current status
        self._devices = {}
        for device in netdev.bridge_brif(self._TMBR_DEV):
            # Ignore local device that is used pass external traffic into the
            # Treadmill container network.
            if device == self._TM_DEV1:
                continue

            dev_info = _device_info(device)
            self._devices[dev_info['alias']] = dev_info

        # Read the currently assigned vIPs
        for (ip, resource) in self._vips.list():
            self._devices.setdefault(resource, {})['ip'] = ip

        # Mark all the above information as stale
        for device in self._devices:
            self._devices[device]['stale'] = True
Пример #2
0
    def test_dev_conf_route_lnet_set(self):
        """Test enabling to local network routing on interface.
        """
        mock_handle = io.open.return_value

        netdev.dev_conf_route_localnet_set('foo', True)

        io.open.assert_called_with(
            '/proc/sys/net/ipv4/conf/foo/route_localnet', 'w')
        mock_handle.write.assert_called_with('1')
Пример #3
0
    def test_dev_conf_route_lnet_set(self, mock_open):
        """Test enabling to local network routing on interface.
        """
        mock_file = mock_open.return_value
        mock_filectx = mock_file.__enter__.return_value

        netdev.dev_conf_route_localnet_set('foo', True)

        mock_open.assert_called_with(
            '/proc/sys/net/ipv4/conf/foo/route_localnet', 'w')
        mock_filectx.write.assert_called_with('1')
Пример #4
0
    def _bridge_initialize(self):
        """Reset/initialize the Treadmill node bridge.
        """
        try:
            # FIXME(boysson): This is for migration when TM_DEV0 used to be a
            #                 bridge.
            netdev.link_set_down(self._TM_DEV0)
            netdev.bridge_delete(self._TM_DEV0)
        except subproc.CalledProcessError:
            pass

        try:
            netdev.link_set_down(self._TM_DEV0)
            netdev.link_del_veth(self._TM_DEV0)
        except subproc.CalledProcessError:
            pass

        try:
            netdev.link_set_down(self._TMBR_DEV)
            netdev.bridge_delete(self._TMBR_DEV)
        except subproc.CalledProcessError:
            pass

        netdev.bridge_create(self._TMBR_DEV)
        netdev.bridge_setfd(self._TMBR_DEV, 0)
        netdev.link_add_veth(self._TM_DEV0, self._TM_DEV1)
        netdev.link_set_mtu(self._TM_DEV0, self.ext_mtu)
        netdev.link_set_mtu(self._TM_DEV1, self.ext_mtu)
        netdev.bridge_addif(self._TMBR_DEV, self._TM_DEV1)
        # Force the bridge MAC address to the Treadmill device. This
        # prevents the bridge's MAC from changing when adding/removing
        # container interfaces.
        # (Default Linux bridge behavior is to set the bridge's MAC to be
        # lowest of it's ports).
        tm_mac = netdev.dev_mac(self._TM_DEV1)
        netdev.link_set_addr(self._TMBR_DEV, tm_mac)
        # Bring up the bridge interface
        netdev.link_set_up(self._TMBR_DEV)
        netdev.link_set_up(self._TM_DEV1)
        netdev.addr_add(
            addr='{ip}/16'.format(ip=self._TM_IP),
            devname=self._TM_DEV0
        )
        # Enable route_localnet so that we can redirect traffic from the
        # container to the node's loopback address.
        netdev.dev_conf_route_localnet_set(self._TM_DEV0, True)
        # Bring up the TM interface
        netdev.link_set_up(self._TM_DEV0)