Esempio n. 1
0
    def test_atomic_set(self):
        """Test atomic replacement of IPSet content.
        """
        test_content = (x for x in ['a', 'b', 'c'])
        iptables.atomic_set('target', test_content,
                            'some:type', foo='bar')

        iptables.create_set.assert_called_with(
            mock.ANY, set_type='some:type', foo='bar'
        )
        tmp_set = iptables.create_set.call_args[0][0]

        iptables.ipset_restore.assert_called_with(
            (
                "add {tmp_set} a\n"
                "add {tmp_set} b\n"
                "add {tmp_set} c"
            ).format(tmp_set=tmp_set)
        )
        iptables.swap_set.assert_called_with(
            'target', tmp_set
        )
        iptables.destroy_set.assert_called_with(
            tmp_set
        )
Esempio n. 2
0
def _update_nodes_change(data):
    """Update local Treadmill Nodes IP IPSet when the globals server list gets
    updated."""
    servers = yaml.load(data)

    server_ips = []
    for server in servers:
        try:
            server_ip = socket.gethostbyname(server)
            server_ips.append(server_ip)

        except socket.gaierror:
            _LOGGER.warning('Unable to resolve %r', server)
            continue

    iptables.atomic_set(iptables.SET_TM_NODES,
                        content=server_ips,
                        set_type='hash:ip',
                        family='inet')
Esempio n. 3
0
    def synchronize(self):
        """Cleanup state resource.
        """
        for app_unique_name in six.viewkeys(self._devices.copy()):
            if not self._devices[app_unique_name].get('stale', False):
                continue

            # This is a stale device, destroy it.
            self.on_delete_request(app_unique_name)

        # Reset the container environment sets to the IP we have now cleaned
        # up.  This is more complex than expected because multiple environment
        # can be merged in the same set in _SET_BY_ENVIRONMENT.
        container_env_ips = {}
        for set_name in set(_SET_BY_ENVIRONMENT.values()):
            key = sorted(
                [
                    env for env in _SET_BY_ENVIRONMENT
                    if _SET_BY_ENVIRONMENT[env] == set_name
                ]
            )
            container_env_ips[tuple(key)] = set()

        for set_envs, set_ips in six.viewitems(container_env_ips):
            for device in six.viewvalues(self._devices):
                if device['environment'] not in set_envs:
                    continue
                set_ips.add(device['ip'])

        for set_envs, set_ips in six.viewitems(container_env_ips):
            iptables.atomic_set(
                _SET_BY_ENVIRONMENT[set_envs[0]],
                set_ips,
                set_type='hash:ip',
                family='inet', hashsize=1024, maxelem=65536
            )

        # It is now safe to clean up all remaining vIPs without resource.
        self._vips.garbage_collect()

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