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

#475 wait for ssh using ssh #486

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 21 additions & 6 deletions nixops/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re
import sys
import time
import subprocess

import nixops.util
Expand Down Expand Up @@ -259,12 +260,26 @@ def wait_for_ssh(self, check=False):
"""Wait until the SSH port is open on this machine."""
if self.ssh_pinged and (not check or self._ssh_pinged_this_time): return
self.log_start("waiting for SSH...")
nixops.util.wait_for_tcp_port(self.get_ssh_name(), self.ssh_port, callback=lambda: self.log_continue("."))
self.log_end("")
if self.state != self.RESCUE:
self.state = self.UP
self.ssh_pinged = True
self._ssh_pinged_this_time = True

n = 0
timeout = 60

while True:
try:
self.ssh.run_command("exit", self.get_ssh_flags(),
logged=False, timeout=timeout)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This timeout value changes behaviour, it used to be 1 second, now it's 60.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. Also this changed introduced "global" timeout, after 60 tries it stops, when previous method was checking forever I think. But those are details to this change and I can adjust it as you prefer, for me the core idea here is to use SSH.

self.log_end("")
if self.state != self.RESCUE:
self.state = self.UP
self.ssh_pinged = True
self._ssh_pinged_this_time = True
return True
except nixops.ssh_util.SSHConnectionFailed as error:
time.sleep(1)
n = n + 1
self.log_continue('.')
if timeout != -1 and n >= timeout:
raise Exception("timed out waiting for ssh: {}".format(error))

def write_ssh_private_key(self, private_key):
key_file = "{0}/id_nixops-{1}".format(self.depl.tempdir, self.name)
Expand Down