Handle focal's insistence we don't use root in launch-node.py

It seems newer focal images force you to use the ubuntu user account. We
already have code that attempts to fallback to ubuntu, but we were not
properly catching the error when root fails which caused the whole
script to fail.

Address this by catching the exception, logging a message, then
continuing to the next possible option. If no possible options are found
we raise an exception already which handles the worst case situation.

Change-Id: Ie6013763daff01063840abce193050b33120a7a2
This commit is contained in:
Clark Boylan 2021-04-21 16:51:46 -07:00
parent ada70387e9
commit bc82cc3e90
1 changed files with 9 additions and 2 deletions

View File

@ -34,6 +34,8 @@ import utils
import openstack
import paramiko
from sshclient import SSHException
SCRIPT_DIR = os.path.dirname(sys.argv[0])
try:
@ -100,9 +102,14 @@ def bootstrap_server(server, key, name, volume_device, keep,
ssh_kwargs = dict(pkey=key)
print("--- Running initial configuration on host %s ---" % ip)
ssh_client = None
for username in ['root', 'ubuntu', 'centos', 'admin']:
ssh_client = utils.ssh_connect(ip, username, ssh_kwargs,
timeout=timeout)
try:
ssh_client = utils.ssh_connect(ip, username, ssh_kwargs,
timeout=timeout)
except SSHException:
print("Username: " + username + " failed to ssh. "
"Trying next option.")
if ssh_client:
break