From 139a82349040983a4af7ebd7e09e32a96bc00667 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Thu, 26 Nov 2015 10:40:05 -0400 Subject: Block re-use of master/node as load balancer in attended install. Code was present to catch this in unattended installs but was looking for a host record with both master/node and master_lb set to true, but in the attended installs we were adding a separate host record with the same connect_to. Attended tests can now optionally specify multiple "attempted" strings for the master_lb specification, we'll try to input each if multiple are specified. Cleanup some empty defaults and error messages as well. --- utils/src/ooinstall/cli_installer.py | 35 +++++++++++++++++++++++++---------- utils/src/ooinstall/oo_config.py | 4 ++-- 2 files changed, 27 insertions(+), 12 deletions(-) (limited to 'utils/src') diff --git a/utils/src/ooinstall/cli_installer.py b/utils/src/ooinstall/cli_installer.py index d7c06745e..a016a5597 100644 --- a/utils/src/ooinstall/cli_installer.py +++ b/utils/src/ooinstall/cli_installer.py @@ -106,8 +106,7 @@ http://docs.openshift.com/enterprise/latest/architecture/infrastructure_componen num_masters = 0 while more_hosts: host_props = {} - host_props['connect_to'] = click.prompt('Enter hostname or IP address:', - default='', + host_props['connect_to'] = click.prompt('Enter hostname or IP address', value_proc=validate_prompt_hostname) if not masters_set: @@ -144,13 +143,17 @@ http://docs.openshift.com/enterprise/latest/architecture/infrastructure_componen more_hosts = click.confirm('Do you want to add additional hosts?') if num_masters > 1: - hosts.append(collect_master_lb()) + collect_master_lb(hosts) return hosts -def collect_master_lb(): +def collect_master_lb(hosts): """ - Get an HA proxy from the user + Get a valid load balancer from the user and append it to the list of + hosts. + + Ensure user does not specify a system already used as a master/node as + this is an invalid configuration. """ message = """ Setting up High Availability Masters requires a load balancing solution. @@ -166,17 +169,28 @@ hostname. """ click.echo(message) host_props = {} - host_props['connect_to'] = click.prompt('Enter hostname or IP address:', - default='', - value_proc=validate_prompt_hostname) + + # Using an embedded function here so we have access to the hosts list: + def validate_prompt_lb(hostname): + # Run the standard hostname check first: + hostname = validate_prompt_hostname(hostname) + + # Make sure this host wasn't already specified: + for host in hosts: + if host.connect_to == hostname and (host.master or host.node): + raise click.BadParameter('Cannot re-use "%s" as a load balancer, ' + 'please specify a separate host' % hostname) + return hostname + + host_props['connect_to'] = click.prompt('Enter hostname or IP address', + value_proc=validate_prompt_lb) install_haproxy = click.confirm('Should the reference haproxy load balancer be installed on this host?') host_props['preconfigured'] = not install_haproxy host_props['master'] = False host_props['node'] = False host_props['master_lb'] = True master_lb = Host(**host_props) - - return master_lb + hosts.append(master_lb) def confirm_hosts_facts(oo_cfg, callback_facts): hosts = oo_cfg.hosts @@ -261,6 +275,7 @@ def check_hosts_config(oo_cfg): if master_lb[0].master or master_lb[0].node: click.echo('The Master load balancer is configured as a master or node. Please correct this.') sys.exit(0) + # Check for another host with same connect_to? else: message = """ No HAProxy given in config. Either specify one or provide a load balancing solution diff --git a/utils/src/ooinstall/oo_config.py b/utils/src/ooinstall/oo_config.py index b6f0cdce3..37aaf9197 100644 --- a/utils/src/ooinstall/oo_config.py +++ b/utils/src/ooinstall/oo_config.py @@ -50,8 +50,8 @@ class Host(object): self.containerized = kwargs.get('containerized', False) if self.connect_to is None: - raise OOConfigInvalidHostError("You must specify either and 'ip' " \ - "or 'hostname' to connect to.") + raise OOConfigInvalidHostError("You must specify either an ip " \ + "or hostname as 'connect_to'") if self.master is False and self.node is False and self.master_lb is False: raise OOConfigInvalidHostError( -- cgit v1.2.3