From 8d3d008e03aac5523324559c569e3006dae1fe68 Mon Sep 17 00:00:00 2001 From: Derek Higgins Date: Tue, 18 Dec 2012 19:16:57 -0500 Subject: [PATCH] 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 --- packstack/installer/engine_validators.py | 39 +++++++++++++++++++++++ packstack/installer/output_messages.py | 1 + packstack/plugins/cinder_250.py | 2 +- packstack/plugins/dashboard_500.py | 2 +- packstack/plugins/glance_200.py | 2 +- packstack/plugins/keystone_100.py | 2 +- packstack/plugins/mysql_001.py | 2 +- packstack/plugins/nova_300.py | 12 +++---- packstack/plugins/openstack_client_400.py | 2 +- packstack/plugins/qpid_002.py | 2 +- packstack/plugins/swift_600.py | 2 +- 11 files changed, 54 insertions(+), 14 deletions(-) diff --git a/packstack/installer/engine_validators.py b/packstack/installer/engine_validators.py index 32cb63216..1f9ffd229 100644 --- a/packstack/installer/engine_validators.py +++ b/packstack/installer/engine_validators.py @@ -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 diff --git a/packstack/installer/output_messages.py b/packstack/installer/output_messages.py index ef1855f94..184e64ff3 100644 --- a/packstack/installer/output_messages.py +++ b/packstack/installer/output_messages.py @@ -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 " diff --git a/packstack/plugins/cinder_250.py b/packstack/plugins/cinder_250.py index 92b317391..9e064ab21 100644 --- a/packstack/plugins/cinder_250.py +++ b/packstack/plugins/cinder_250.py @@ -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, diff --git a/packstack/plugins/dashboard_500.py b/packstack/plugins/dashboard_500.py index 1dea76b5f..17d46ac16 100644 --- a/packstack/plugins/dashboard_500.py +++ b/packstack/plugins/dashboard_500.py @@ -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, diff --git a/packstack/plugins/glance_200.py b/packstack/plugins/glance_200.py index e32d5ac91..af15a8f0a 100644 --- a/packstack/plugins/glance_200.py +++ b/packstack/plugins/glance_200.py @@ -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, diff --git a/packstack/plugins/keystone_100.py b/packstack/plugins/keystone_100.py index d4d774572..4001ab93b 100644 --- a/packstack/plugins/keystone_100.py +++ b/packstack/plugins/keystone_100.py @@ -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, diff --git a/packstack/plugins/mysql_001.py b/packstack/plugins/mysql_001.py index 004a188a8..6b39b6937 100644 --- a/packstack/plugins/mysql_001.py +++ b/packstack/plugins/mysql_001.py @@ -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, diff --git a/packstack/plugins/nova_300.py b/packstack/plugins/nova_300.py index d1a6418f3..058704b6d 100644 --- a/packstack/plugins/nova_300.py +++ b/packstack/plugins/nova_300.py @@ -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, diff --git a/packstack/plugins/openstack_client_400.py b/packstack/plugins/openstack_client_400.py index f008e5abc..e1c086344 100644 --- a/packstack/plugins/openstack_client_400.py +++ b/packstack/plugins/openstack_client_400.py @@ -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, diff --git a/packstack/plugins/qpid_002.py b/packstack/plugins/qpid_002.py index c87f47edf..afb0a4b54 100644 --- a/packstack/plugins/qpid_002.py +++ b/packstack/plugins/qpid_002.py @@ -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, diff --git a/packstack/plugins/swift_600.py b/packstack/plugins/swift_600.py index f120bc2e1..5ce746fa3 100644 --- a/packstack/plugins/swift_600.py +++ b/packstack/plugins/swift_600.py @@ -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,