Commit fd09107b authored by rgaudin's avatar rgaudin
Browse files

Only start SSH manually during master creation

Wait 20s instead of 10s after startup before attempting to connect
Attempt 3 times to connect to Qemu over SSH with increasing delays in between
parent 910d4525
......@@ -3,6 +3,7 @@
* File size entry is now a selection list of standard SD cards sizes
* Rebranded as Kiwix-hotspot
* Disabled Metadata for windows binaries due to a bug [regression]
* More reliable SSH connections to Qemu
2.0-rc10
* Fixed wikifundi config regression
......
......@@ -68,17 +68,19 @@ class Emulator:
_kernel = None
_dtb = None
_logger = None
_is_master = False
# login=pi
# password=raspberry
# prompt end by ":~$ "
# sudo doesn't require password
def __init__(self, kernel, dtb, image, logger, ram):
def __init__(self, kernel, dtb, image, logger, ram, is_master=False):
self._kernel = kernel
self._dtb = dtb
self._image = image
self._logger = logger
self._binary = qemu_system_arm_exe_path
self._is_master = is_master
self._set_ram(ram.lower())
def _set_ram(self, requested_ram):
......@@ -226,40 +228,58 @@ class _RunningInstance:
cancel_register.register(self._qemu.pid)
self._wait_signal(stdout_reader, stdout_writer, b"login: ", timeout)
os.write(stdin_writer, b"pi\n")
tries = 0
while True:
signal = b"Password: "
buf_states = self._wait_signal(stdout_reader, stdout_writer, signal, timeout, True)
if not buf_states:
break
self._logger.err(str(buf_states))
self._logger.err("internal error: please report this log")
if tries > 3:
raise QemuException("wait signal timeout: %s" % signal)
# start SSH daemon
if self._emulation._is_master:
self._logger.std("Starting SSH daemon manually")
os.write(stdin_writer, b"pi\n")
tries += 1
os.write(stdin_writer, b"raspberry\n")
self._wait_signal(stdout_reader, stdout_writer, b":~$ ", timeout)
# TODO: This is a ugly hack. But writing all at once doesn't work
os.write(stdin_writer, b"sudo systemctl")
self._wait_signal(stdout_reader, stdout_writer, b"sudo systemctl", timeout)
os.write(stdin_writer, b" start ssh;")
self._wait_signal(stdout_reader, stdout_writer, b" start ssh;", timeout)
os.write(stdin_writer, b" exit\n")
self._wait_signal(stdout_reader, stdout_writer, b"login: ", timeout)
time.sleep(10);
tries = 0
while True:
signal = b"Password: "
buf_states = self._wait_signal(stdout_reader, stdout_writer, signal, timeout, True)
if not buf_states:
break
self._client = paramiko.SSHClient()
self._client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
self._client.connect("localhost", port=ssh_port,
username="pi", password="raspberry",
allow_agent=False, look_for_keys=False)
self._logger.err(str(buf_states))
self._logger.err("internal error: please report this log")
if tries > 3:
raise QemuException("wait signal timeout: %s" % signal)
os.write(stdin_writer, b"pi\n")
tries += 1
os.write(stdin_writer, b"raspberry\n")
self._wait_signal(stdout_reader, stdout_writer, b":~$ ", timeout)
# TODO: This is a ugly hack. But writing all at once doesn't work
os.write(stdin_writer, b"sudo systemctl")
self._wait_signal(stdout_reader, stdout_writer, b"sudo systemctl", timeout)
os.write(stdin_writer, b" start ssh;")
self._wait_signal(stdout_reader, stdout_writer, b" start ssh;", timeout)
os.write(stdin_writer, b" exit\n")
self._wait_signal(stdout_reader, stdout_writer, b"login: ", timeout)
time.sleep(20)
# connect to SSH
tries = 0
while True:
self._client = paramiko.SSHClient()
self._client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
try:
self._client.connect("localhost", port=ssh_port,
username="pi", password="raspberry",
allow_agent=False, look_for_keys=False)
except Exception as exp:
self._logger.err(exp)
tries += 1
if tries > 3:
raise exp
time.sleep(5 * tries)
continue
else:
self._logger.std("Successfuly connected to Qemu over SSH")
break
def _shutdown(self):
self.exec_cmd("sudo sync")
......
......@@ -37,7 +37,8 @@ def run_in_qemu(image_fpath, disk_size, root_size,
data.vexpress_boot_dtb,
image_fpath,
logger,
ram=qemu_ram)
ram=qemu_ram,
is_master=True)
logger.step("resizing QEMU image to {}GB".format(disk_size // ONE_GB))
emulator.resize_image(disk_size)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment