Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fx_authorized_sftp fixture unexpectedly crashed when trying to make a Transport #29

Open
dahlia opened this issue Jan 25, 2018 · 0 comments
Assignees
Labels

Comments

@dahlia
Copy link
Contributor

dahlia commented Jan 25, 2018

It maybe because concurrent build jobs share the ports.

_______________ ERROR at setup of test_authorized_keys_list_len ________________
fx_sftpd = {12254: (<Thread(Thread-379, initial)>, local('/tmp/pytest-of-travis/pytest-0/test_authorized_keys_list_len0/12254'), ...al('/tmp/pytest-of-travis/pytest-0/test_authorized_keys_list_len0/12255'), <threading.Event object at 0x7f6f0e21ed30>)}
fx_authorized_keys = [<paramiko.rsakey.RSAKey object at 0x7f6f0e21e1d0>, <paramiko.rsakey.RSAKey object at 0x7f6f0e1c4e80>, <paramiko.rsake... 0x7f6f0e1c4c50>, <paramiko.rsakey.RSAKey object at 0x7f6f0e1c4a58>, <paramiko.rsakey.RSAKey object at 0x7f6f0e1c4940>]
    @yield_fixture
    def fx_authorized_sftp(fx_sftpd, fx_authorized_keys):
        port, (thread, path, ev) = fx_sftpd.popitem()
        thread.start()
        key = RSAKey.generate(1024)
        dot_ssh = path.mkdir('.ssh')
        with dot_ssh.join('authorized_keys').open('w') as f:
            print(format_openssh_pubkey(key), file=f)
            for authorized_key in fx_authorized_keys:
                print(format_openssh_pubkey(authorized_key), file=f)
>       transport = Transport(('127.0.0.1', port))
tests/conftest.py:200: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <paramiko.Transport at 0xe1c41d0 (unconnected)>
sock = <socket.socket fd=14, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('0.0.0.0', 48758)>
default_window_size = 2097152, default_max_packet_size = 32768, gss_kex = False
gss_deleg_creds = True
    def __init__(self,
                 sock,
                 default_window_size=DEFAULT_WINDOW_SIZE,
                 default_max_packet_size=DEFAULT_MAX_PACKET_SIZE,
                 gss_kex=False,
                 gss_deleg_creds=True):
        """
            Create a new SSH session over an existing socket, or socket-like
            object.  This only creates the `.Transport` object; it doesn't begin
            the SSH session yet.  Use `connect` or `start_client` to begin a client
            session, or `start_server` to begin a server session.
    
            If the object is not actually a socket, it must have the following
            methods:
    
            - ``send(str)``: Writes from 1 to ``len(str)`` bytes, and returns an
              int representing the number of bytes written.  Returns
              0 or raises ``EOFError`` if the stream has been closed.
            - ``recv(int)``: Reads from 1 to ``int`` bytes and returns them as a
              string.  Returns 0 or raises ``EOFError`` if the stream has been
              closed.
            - ``close()``: Closes the socket.
            - ``settimeout(n)``: Sets a (float) timeout on I/O operations.
    
            For ease of use, you may also pass in an address (as a tuple) or a host
            string as the ``sock`` argument.  (A host string is a hostname with an
            optional port (separated by ``":"``) which will be converted into a
            tuple of ``(hostname, port)``.)  A socket will be connected to this
            address and used for communication.  Exceptions from the ``socket``
            call may be thrown in this case.
    
            .. note::
                Modifying the the window and packet sizes might have adverse
                effects on your channels created from this transport. The default
                values are the same as in the OpenSSH code base and have been
                battle tested.
    
            :param socket sock:
                a socket or socket-like object to create the session over.
            :param int default_window_size:
                sets the default window size on the transport. (defaults to
                2097152)
            :param int default_max_packet_size:
                sets the default max packet size on the transport. (defaults to
                32768)
    
            .. versionchanged:: 1.15
                Added the ``default_window_size`` and ``default_max_packet_size``
                arguments.
            """
        self.active = False
        self.hostname = None
    
        if isinstance(sock, string_types):
            # convert "host:port" into (host, port)
            hl = sock.split(':', 1)
            self.hostname = hl[0]
            if len(hl) == 1:
                sock = (hl[0], 22)
            else:
                sock = (hl[0], int(hl[1]))
        if type(sock) is tuple:
            # connect to the given (host, port)
            hostname, port = sock
            self.hostname = hostname
            reason = 'No suitable address family'
            addrinfos = socket.getaddrinfo(
                hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM
            )
            for family, socktype, proto, canonname, sockaddr in addrinfos:
                if socktype == socket.SOCK_STREAM:
                    af = family
                    # addr = sockaddr
                    sock = socket.socket(af, socket.SOCK_STREAM)
                    try:
                        retry_on_signal(lambda: sock.connect((hostname, port)))
                    except socket.error as e:
                        reason = str(e)
                    else:
                        break
            else:
                raise SSHException(
>                   'Unable to connect to {}: {}'.format(hostname, reason))
E               paramiko.ssh_exception.SSHException: Unable to connect to 127.0.0.1: [Errno 111] Connection refused
.tox/py35/lib/python3.5/site-packages/paramiko/transport.py:332: SSHException
@dahlia dahlia added the bug label Jan 25, 2018
@dahlia dahlia self-assigned this Jan 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant