##// END OF EJS Templates
contrib: add a hint if the Windows dependency MSI is already installed...
contrib: add a hint if the Windows dependency MSI is already installed In the past, I've gotten confused when the script failed on seemingly random python installs (and thus the py3.8 install was commented out from the last time this happened to me, which has been reverted here). This particular error code means the package was already installed. For python, it means the major and minor version are the same, but the micro version may differ. In practice, ignoring the python installation failure will cause the pip installation that happens next to fail, because python.exe for that version is somewhere else on the system. This could probably be fixed by running py.exe with the major and minor version, but that is skipped during the install for some reason. I didn't feel like over complicating this though, and at least there's a better hint when the problem occurs. Differential Revision: https://phab.mercurial-scm.org/D12560

File last commit:

r43346:2372284d default
r49955:246ee748 default
Show More
ssh.py
72 lines | 2.1 KiB | text/x-python | PythonLexer
Gregory Szorc
automation: initial support for running Linux tests...
r42471 # ssh.py - Interact with remote SSH servers
#
# Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
# no-check-code because Python 3 native.
import socket
import time
import warnings
Augie Fackler
formatting: blacken the codebase...
r43346 from cryptography.utils import CryptographyDeprecationWarning
Gregory Szorc
automation: initial support for running Linux tests...
r42471 import paramiko
def wait_for_ssh(hostname, port, timeout=60, username=None, key_filename=None):
"""Wait for an SSH server to start on the specified host and port."""
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
automation: initial support for running Linux tests...
r42471 class IgnoreHostKeyPolicy(paramiko.MissingHostKeyPolicy):
def missing_host_key(self, client, hostname, key):
return
end_time = time.time() + timeout
# paramiko triggers a CryptographyDeprecationWarning in the cryptography
# package. Let's suppress
with warnings.catch_warnings():
Augie Fackler
formatting: blacken the codebase...
r43346 warnings.filterwarnings(
'ignore', category=CryptographyDeprecationWarning
)
Gregory Szorc
automation: initial support for running Linux tests...
r42471
while True:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(IgnoreHostKeyPolicy())
try:
Augie Fackler
formatting: blacken the codebase...
r43346 client.connect(
hostname,
port=port,
username=username,
key_filename=key_filename,
timeout=5.0,
allow_agent=False,
look_for_keys=False,
)
Gregory Szorc
automation: initial support for running Linux tests...
r42471
return client
except socket.error:
pass
except paramiko.AuthenticationException:
raise
except paramiko.SSHException:
pass
if time.time() >= end_time:
raise Exception('Timeout reached waiting for SSH')
time.sleep(1.0)
def exec_command(client, command):
"""exec_command wrapper that combines stderr/stdout and returns channel"""
chan = client.get_transport().open_session()
chan.exec_command(command)
chan.set_combine_stderr(True)
stdin = chan.makefile('wb', -1)
stdout = chan.makefile('r', -1)
return chan, stdin, stdout