Пример #1
0
    def test_bridge_brif(self):
        """Test reading of bridge interfaces.
        """
        res = netdev.bridge_brif('foo')

        os.listdir.assert_called_with('/sys/class/net/foo/brif')
        self.assertEqual(res, ['a', 'b', 'c'])
Пример #2
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