How to use the execnet.gateway_bootstrap.HostNotFound function in execnet

To help you get started, we’ve selected a few execnet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytest-dev / execnet / execnet / gateway_bootstrap.py View on Github external
def bootstrap_exec(io, spec):
    try:
        sendexec(
            io,
            inspect.getsource(gateway_base),
            "execmodel = get_execmodel(%r)" % spec.execmodel,
            "io = init_popen_io(execmodel)",
            "io.write('1'.encode('ascii'))",
            "serve(io, id='%s-worker')" % spec.id,
        )
        s = io.read(1)
        assert s == "1".encode("ascii")
    except EOFError:
        ret = io.wait()
        if ret == 255:
            raise HostNotFound(io.remoteaddress)
github pytest-dev / execnet / execnet / gateway_socket.py View on Github external
assert not spec.python, "socket: specifying python executables not yet supported"
    gateway_id = spec.installvia
    if gateway_id:
        host, port = start_via(group[gateway_id])
    else:
        host, port = spec.socket.split(":")
        port = int(port)

    socket = execmodel.socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    io = SocketIO(sock, execmodel)
    io.remoteaddress = "%s:%d" % (host, port)
    try:
        sock.connect((host, port))
    except execmodel.socket.gaierror:
        raise HostNotFound(str(sys.exc_info()[1]))
    return io
github alfredodeza / remoto / remoto / lib / execnet / gateway_socket.py View on Github external
"socket: specifying python executables not yet supported")
    gateway_id = spec.installvia
    if gateway_id:
        host, port = start_via(group[gateway_id])
    else:
        host, port = spec.socket.split(":")
        port = int(port)

    socket = execmodel.socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    io = SocketIO(sock, execmodel)
    io.remoteaddress = '%s:%d' % (host, port)
    try:
        sock.connect((host, port))
    except execmodel.socket.gaierror:
        raise HostNotFound(str(sys.exc_info()[1]))
    return io
github ceph / ceph-medic / ceph_medic / connection.py View on Github external
if ceph_medic.config.ssh_config:
        hostname = "-F %s %s" % (ceph_medic.config.ssh_config, hostname)
    try:
        deployment_type = kw.get(
            'deployment_type',
            ceph_medic.config.file.get_safe(
                'global', 'deployment_type', 'baremetal')
        )
        conn_obj = remoto.connection.get(deployment_type)
        if deployment_type in ['k8s', 'kubernetes', 'openshift', 'oc']:
            conn = container_platform_conn(hostname, conn_obj, deployment_type)
            # check if conn is ok
            stdout, stderr, code = remoto.process.check(conn, ['true'])
            if code:
                raise HostNotFound(
                    'Remote connection failed while testing connection:\n %s' % '\n'.join(stderr))
        elif deployment_type in ['docker', 'podman']:
            if kw.get('logger', True):
                remote_logger = logging.getLogger(kw['container'])
            conn = conn_obj(
                hostname,
                container_name=kw['container'],
                logger=remote_logger,
                detect_sudo=detect_sudo,
            )
        elif deployment_type in ['ssh', 'baremetal']:
            conn = conn_obj(
                hostname,
                logger=remote_logger,
                threads=threads,
                detect_sudo=detect_sudo,
github ceph / ceph-medic / ceph_medic / main.py View on Github external
    @catches((RuntimeError, KeyboardInterrupt, HostNotFound))
    def main(self, argv):
        options = [
            '--cluster', '--ssh-config', '--inventory',
            '--config', '--verbosity',
        ]
        parser = Transport(
            argv, options=options,
            check_help=False,
            check_version=False
        )
        parser.parse_args()

        self.config_path = parser.get('--config', configuration.location())

        # load medic configuration
        loaded_config = configuration.load(path=parser.get('--config', self.config_path))
github ceph / ceph-medic / ceph_medic / collector.py View on Github external
msg = "Skipping node {} from unknown host group: {}".format(node, node_type)
                logger.warning(msg)
                continue

            total_nodes += 1
            hostname = node['host']
            loader.write('Host: %-40s  connection: [%-20s]' % (hostname, terminal.yellow('connecting')))
            # TODO: make sure that the hostname is resolvable, trying to
            # debug SSH issues with execnet is pretty hard/impossible, use
            # util.net.host_is_resolvable
            try:
                logger.debug('attempting connection to host: %s', node['host'])
                conn = get_connection(node['host'], container=node.get('container'))
                loader.write('Host: %-40s  connection: [%-20s]' % (hostname, terminal.green('connected')))
                loader.write('\n')
            except HostNotFound as err:
                logger.exception('connection failed')
                loader.write('Host: %-40s  connection: [%-20s]' % (hostname, terminal.red('failed')))
                loader.write('\n')
                failed_nodes += 1
                if metadata[node_type].get(hostname):
                    metadata[node_type].pop(hostname)
                metadata['nodes'][node_type] = [i for i in metadata['nodes'][node_type] if i['host'] != hostname]
                metadata['failed_nodes'].update({hostname: str(err)})
                continue

            # send the full node metadata for global scope so that the checks
            # can consume this
            metadata[node_type][hostname] = get_node_metadata(conn, hostname, cluster_nodes)
            if node_type == 'mons':  # if node type is monitor, admin privileges are most likely authorized
                if not has_cluster_data:
                    cluster_data = collect_cluster(conn)