From dbda7ef4b556a0d5729e6268b0b870ac7fff7341 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Sat, 11 Feb 2012 01:26:21 +0000 Subject: [PATCH] Test ssh on devstack nodes. Ensure ssh works before marking a devstack node as available. Change-Id: I45a3a75116b5208f47a67d523058c9ca4b8ebc84 --- slave_scripts/devstack-vm-launch.py | 35 ++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/slave_scripts/devstack-vm-launch.py b/slave_scripts/devstack-vm-launch.py index 3ca55181..ec3654b6 100755 --- a/slave_scripts/devstack-vm-launch.py +++ b/slave_scripts/devstack-vm-launch.py @@ -28,6 +28,8 @@ import libcloud import os, sys import getopt import time +import paramiko +import traceback import vmdatabase @@ -78,6 +80,20 @@ if CLOUD_SERVERS_DRIVER == 'rackspace': else: raise Exception ("Driver not supported") +def check_ssh(ip): + client = paramiko.SSHClient() + client.load_system_host_keys() + client.set_missing_host_key_policy(paramiko.WarningPolicy()) + client.connect(ip, timeout=10) + + stdin, stdout, stderr = client.exec_command("echo SSH check succeeded") + print stdout.read() + print stderr.read() + ret = stdout.channel.recv_exit_status() + if ret: + raise Exception("Echo command failed") + return True + if CLOUD_SERVERS_DRIVER == 'rackspace': last_name = '' error_counts = {} @@ -106,7 +122,12 @@ if CLOUD_SERVERS_DRIVER == 'rackspace': if not building_machines: print "Finished" break - provider_nodes = conn.list_nodes() + try: + provider_nodes = conn.list_nodes() + except Exception, e: + traceback.print_exc() + print "Unable to list nodes" + continue print "Waiting on %s machines" % len(building_machines) for my_node in building_machines: if my_node['uuid'] in to_ignore: continue @@ -117,8 +138,16 @@ if CLOUD_SERVERS_DRIVER == 'rackspace': else: p_node = p_nodes[0] if (p_node.public_ips and p_node.state == NodeState.RUNNING): - print "Node %s is ready" % my_node['id'] - db.setMachineState(my_node['uuid'], vmdatabase.READY) + print "Node %s is running, testing ssh" % my_node['id'] + try: + if check_ssh(p_node.public_ip[0]): + print "Node %s is ready" % my_node['id'] + db.setMachineState(my_node['uuid'], vmdatabase.READY) + except Exception, e: + traceback.print_exc() + print "Abandoning node %s due to ssh failure" % (my_node['id']) + db.setMachineState(my_node['uuid'], vmdatabase.ERROR) + error = True elif (p_node.public_ips and p_node.state in [NodeState.UNKNOWN, NodeState.REBOOTING,