Test hosts by attempting to connect to ssh port

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=888281

This test replaces the ping test we were doing
This commit is contained in:
Derek Higgins
2012-12-18 19:16:57 -05:00
parent 02ae338d73
commit 8d3d008e03
11 changed files with 54 additions and 14 deletions

View File

@@ -6,6 +6,7 @@ import re
import logging
import output_messages
import basedefs
import socket
import types
import traceback
import os
@@ -289,6 +290,44 @@ def validateMultiPing(param, options=[]):
print "\n" + output_messages.ERR_PING + ".\n"
return False
_testedPorts = []
def validatePort(host, port):
"""
Check that provided host is listening on provided port
"""
key = "%s:%d"%(host, port)
# No need to keep checking the same port multiple times
if key in _testedPorts:
return True
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((host, port))
s.shutdown(socket.SHUT_RDWR)
s.close()
except socket.error as msg:
return False
_testedPorts.append(key)
return True
def validateSSH(param, options=[]):
"""
Check that provided host is listening on port 22
"""
if validatePort(param.strip(), 22):
return True
print "\n" + output_messages.ERR_SSH%param
return False
def validateMultiSSH(param, options=[]):
if validateStringNotEmpty(param):
hosts = param.split(",")
for host in hosts:
if validateSSH(host) == False:
return False
return True
print "\n" + output_messages.ERR_SSH%param + ".\n"
return False
def _validateString(string, minLen, maxLen, regex=".*"):
"""
Generic func to verify a string

View File

@@ -54,6 +54,7 @@ INFO_STRING_CONTAINS_ILLEGAL_CHARS="String contains illegal characters"
WARN_WEAK_PASS="Warning: Weak Password."
ERR_PING = "Error: the provided hostname is unreachable"
ERR_SSH = "Error: could not connect to the ssh server: %s"
ERR_FILE = "Error: the provided file is not present"
ERR_CHECK_LOG_FILE_FOR_MORE_INFO="Please check log file %s for more information"
ERR_YUM_LOCK="Internal Error: Can't edit versionlock "

View File

@@ -29,7 +29,7 @@ def initConfig(controllerObject):
"USAGE" : "The IP address of the server on which to install Cinder",
"PROMPT" : "The IP address of the server on which to install Cinder",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validatePing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"PROCESSOR_ARGS" : {"allow_localhost": True},
"PROCESSOR_FUNC" : process.processHost,

View File

@@ -30,7 +30,7 @@ def initConfig(controllerObject):
"USAGE" : "The IP address of the server on which to install Horizon",
"PROMPT" : "The IP address of the server on which to install Horizon",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validatePing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"PROCESSOR_ARGS" : {"allow_localhost": True},
"PROCESSOR_FUNC" : process.processHost,

View File

@@ -29,7 +29,7 @@ def initConfig(controllerObject):
"USAGE" : "The IP address of the server on which to install Glance",
"PROMPT" : "The IP address of the server on which to install Glance",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validatePing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"PROCESSOR_ARGS" : {"allow_localhost": True},
"PROCESSOR_FUNC" : process.processHost,

View File

@@ -31,7 +31,7 @@ def initConfig(controllerObject):
"USAGE" : "The IP address of the server on which to install Keystone",
"PROMPT" : "The IP address of the server on which to install Keystone",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validatePing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"PROCESSOR_ARGS" : {"allow_localhost": True},
"PROCESSOR_FUNC" : process.processHost,

View File

@@ -30,7 +30,7 @@ def initConfig(controllerObject):
"USAGE" : "The IP address of the server on which to install MySQL",
"PROMPT" : "The IP address of the server on which to install MySQL",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validatePing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"PROCESSOR_ARGS" : {"allow_localhost": True},
"PROCESSOR_FUNC" : process.processHost,

View File

@@ -27,7 +27,7 @@ def initConfig(controllerObject):
"USAGE" : "The IP address of the server on which to install the Nova API service",
"PROMPT" : "The IP address of the server on which to install the Nova API service",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validatePing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"PROCESSOR_ARGS" : {"allow_localhost": True},
"PROCESSOR_FUNC" : process.processHost,
@@ -42,7 +42,7 @@ def initConfig(controllerObject):
"USAGE" : "The IP address of the server on which to install the Nova Cert service",
"PROMPT" : "The IP address of the server on which to install the Nova Cert service",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validatePing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"PROCESSOR_ARGS" : {"allow_localhost": True},
"PROCESSOR_FUNC" : process.processHost,
@@ -57,7 +57,7 @@ def initConfig(controllerObject):
"USAGE" : "The IP address of the server on which to install the Nova VNC proxy",
"PROMPT" : "The IP address of the server on which to install the Nova VNC proxy",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validateMultiPing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"PROCESSOR_ARGS" : {"allow_localhost": True},
"PROCESSOR_FUNC" : process.processHost,
@@ -72,7 +72,7 @@ def initConfig(controllerObject):
"USAGE" : "A comma seperated list of IP addresses on which to install the Nova Compute services",
"PROMPT" : "A comma seperated list of IP addresses on which to install the Nova Compute services",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validateMultiPing,
"VALIDATION_FUNC" : validate.validateMultiSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": True,
@@ -108,7 +108,7 @@ def initConfig(controllerObject):
"USAGE" : "The IP address of the server on which to install the Nova Network service",
"PROMPT" : "The IP address of the server on which to install the Nova Network service",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validatePing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"PROCESSOR_ARGS" : {"allow_localhost": True},
"PROCESSOR_FUNC" : process.processHost,
@@ -171,7 +171,7 @@ def initConfig(controllerObject):
"USAGE" : "The IP address of the server on which to install the Nova Scheduler service",
"PROMPT" : "The IP address of the server on which to install the Nova Scheduler service",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validatePing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"PROCESSOR_ARGS" : {"allow_localhost": True},
"PROCESSOR_FUNC" : process.processHost,

View File

@@ -29,7 +29,7 @@ def initConfig(controllerObject):
"USAGE" : "The IP address of the server on which to install the openstack client packages, an admin \"rc\" file will also be installed",
"PROMPT" : "The IP address of the server on which to install the openstack client packages, an admin \"rc\" file will also be installed",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validatePing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"PROCESSOR_ARGS" : {"allow_localhost": True},
"PROCESSOR_FUNC" : process.processHost,

View File

@@ -29,7 +29,7 @@ def initConfig(controllerObject):
"USAGE" : "The IP address of the server on which to install the QPID service",
"PROMPT" : "The IP address of the server on which to install the QPID service",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validatePing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"PROCESSOR_ARGS" : {"allow_localhost": True},
"PROCESSOR_FUNC" : process.processHost,

View File

@@ -30,7 +30,7 @@ def initConfig(controllerObject):
"USAGE" : "A comma seperated list of IP addresses on which to install the Swift proxy services",
"PROMPT" : "A comma seperated list of IP addresses on which to install the Swift proxy services",
"OPTION_LIST" : [],
"VALIDATION_FUNC" : validate.validatePing,
"VALIDATION_FUNC" : validate.validateSSH,
"DEFAULT_VALUE" : "127.0.0.1",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": True,