Example #1
0
def _node_initialize(tm_env, runtime, zkclient, hostname,
                     zk_server_path, zk_presence_path):
    """Node initialization. Should only be done on a cold start.
    """
    try:
        new_node_info = sysinfo.node_info(tm_env, runtime)

        traitz = zkutils.get(zkclient, z.path.traits())
        new_node_info['traits'] = traits.detect(traitz)

        # Merging scheduler data with node_info data
        node_info = zkutils.get(zkclient, zk_server_path)
        node_info.update(new_node_info)
        _LOGGER.info('Registering node: %s: %s, %r',
                     zk_server_path, hostname, node_info)

        zkutils.update(zkclient, zk_server_path, node_info)
        host_acl = zkutils.make_host_acl(hostname, 'rwcda')
        _LOGGER.debug('host_acl: %r', host_acl)
        zkutils.put(zkclient,
                    zk_presence_path, {'seen': False},
                    acl=[host_acl],
                    ephemeral=True)

        # TODO: Fix the network initialization. Then the below can be part of
        # appenv.initialize()
        if os.name == 'posix':
            # Flush all rules in iptables nat and mangle tables (it is assumed
            # that none but Treadmill manages these tables) and bulk load all
            # the Treadmill static rules
            iptables.initialize(node_info['network']['external_ip'])

    except Exception:  # pylint: disable=W0703
        _LOGGER.exception('Node initialization failed')
        zkclient.stop()
Example #2
0
    def test_initialize(self):
        """Test iptables initialization"""
        # Disable protected-access: Test access protected members .
        # pylint: disable=protected-access

        # NOTE: keep this IP in sync with the tests' state file dumps
        iptables.initialize('1.2.3.4')

        treadmill.iptables.ipset_restore.assert_called_with(self.ipset_state)
        treadmill.iptables._iptables_restore.assert_called_with(
            self.iptables_state)
Example #3
0
    def initialize(self):
        """One time initialization of the Treadmill environment."""
        _LOGGER.info('Initializing once.')

        # Flush all rules in iptables nat and mangle tables (it is assumed that
        # none but Treadmill manages these tables) and bulk load all the
        # Treadmill static rules
        iptables.initialize(self.host_ip)

        # Initialize network rules
        self.rules.initialize()

        # Initialize FS plugins.
        fs.init_plugins(self.root)
Example #4
0
    def initialize(self, params):
        """One time initialization of the Treadmill environment."""
        _LOGGER.info('Initializing once.')

        # Flush all rules in iptables nat and mangle tables (it is assumed that
        # none but Treadmill manages these tables) and bulk load all the
        # Treadmill static rules
        iptables.initialize(params['network']['external_ip'])

        # Initialize network rules
        self.rules.initialize()

        # Initialize FS plugins.
        image_fs.init_plugins(self)

        # Initialize container plugin hooks
        apphook.init(self)
Example #5
0
    def test_initialize(self):
        """Test iptables initialization"""
        # Disable protected-access: Test access protected members .
        # pylint: disable=protected-access
        treadmill.iptables._iptables_restore.side_effect = [
            None,
            subproc.CalledProcessError(2, 'failed'),
            None,
        ]

        # NOTE(boysson): keep this IP in sync with the tests' states
        iptables.initialize('1.2.3.4')

        treadmill.iptables.ipset_restore.assert_called_with(self.ipset_state)

        treadmill.iptables._iptables_restore.assert_has_calls([
            mock.call(self.iptables_state),
            mock.call(self.iptables_filter_state, noflush=True),
            mock.call(self.iptables_filter_drop_state, noflush=True),
        ])
Example #6
0
    def test_initialize(self):
        """Test iptables initialization"""
        # Disable W0212: Test access protected members of admin module.
        # pylint: disable=W0212
        treadmill.iptables._iptables_restore.side_effect = [
            None,
            subprocess.CalledProcessError(2, 'failed'),
            None,
        ]

        # NOTE(boysson): keep this IP in sync with the tests' states
        iptables.initialize('1.2.3.4')

        treadmill.iptables.ipset_restore.assert_called_with(
            open(self.IPSET_STATE).read(), )

        treadmill.iptables._iptables_restore.assert_has_calls([
            mock.call(open(self.IPTABLES_STATE).read()),
            mock.call(open(self.IPTABLES_FILTER_STATE).read(), noflush=True),
            mock.call(open(self.IPTABLES_FILTER_DROP_STATE).read(),
                      noflush=True),
        ])