示例#1
0
    def test_node_info(self):
        """Test node information report generation.
        """
        # Access protected members
        # pylint: disable=W0212
        mock_tm_env = mock.Mock(
            spec_set=treadmill.appenv.AppEnvironment,
            svc_cgroup=mock.Mock(
                spec_set=treadmill.services._base_service.ResourceService, ),
            svc_localdisk=mock.Mock(
                spec_set=treadmill.services._base_service.ResourceService, ),
            svc_network=mock.Mock(
                spec_set=treadmill.services._base_service.ResourceService, ),
        )
        mock_tm_env.svc_localdisk.status.return_value = {
            'size': 100 * 1024**2,
        }

        res = sysinfo.node_info(mock_tm_env)

        mock_tm_env.svc_localdisk.status.assert_called_with(timeout=30)
        mock_tm_env.svc_cgroup.status.assert_called_with(timeout=30)
        self.assertEqual(
            res,
            {
                'cpu': '200%',  # 100% of 2 cores is available
                'memory': '42M',  # As read from cgroup
                'disk': '100M',  # As returned by localdisk service
                'up_since': 8,
            })
示例#2
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)

        # 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)

        # Invoke the local node initialization
        tm_env.initialize(node_info)

    except Exception:  # pylint: disable=W0703
        _LOGGER.exception('Node initialization failed')
        zkclient.stop()
示例#3
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()
示例#4
0
def _node_initialize(tm_env, zkclient, hostname, zk_server_path,
                     zk_presence_path):
    """Node initialization. Should only be done on a cold start.
    """
    tm_env.initialize()
    new_node_info = sysinfo.node_info(tm_env)

    # XXX: Why a get/update dance instead of set
    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)