add new --predeploy option to host check

Jira-Issue: OPENSTACK-663
This commit is contained in:
Steve Noyes 2016-02-22 12:09:40 -05:00
parent ea7f0915dc
commit 301c5d9ed6
3 changed files with 43 additions and 8 deletions

View File

@ -168,12 +168,14 @@ class HostList(Lister):
class HostCheck(Command):
"""Check if openstack-kollacli is setup"""
"""Check configuration of host(s)"""
def get_parser(self, prog_name):
parser = super(HostCheck, self).get_parser(prog_name)
parser.add_argument('hostname', metavar='<hostname>',
help=u._('Host name or "all"'))
parser.add_argument('--predeploy', action='store_true',
help=u._('Run pre-deploy host checks.'))
return parser
def take_action(self, parsed_args):
@ -184,7 +186,29 @@ class HostCheck(Command):
inventory = Inventory.load()
if not inventory.get_host(hostname):
_host_not_found(hostname)
precheck(hostname)
if parsed_args.predeploy:
# run pre-deploy checks
precheck(hostname)
else:
# run ssh checks
all_ok = True
hostnames = [hostname]
if hostname == 'all':
inventory = Inventory.load()
hostnames = inventory.get_hostnames()
summary = inventory.ssh_check_hosts(hostnames)
for hostname, info in summary.items():
status = 'success'
msg = ''
if not info['success']:
status = 'failed- '
msg = info['msg']
all_ok = False
LOG.info('Host (%s): %s %s' % (hostname, status, msg))
if not all_ok:
raise CommandError('Host check failed.')
except CommandError as e:
raise e
except Exception as e:

View File

@ -496,6 +496,20 @@ class Inventory(object):
.format(host=hostname, error=str(e)))
return True
def ssh_check_hosts(self, hostnames):
"""ssh check for hosts
return {hostname: {'success': True|False,
'msg': message}}
"""
summary = {}
for hostname in hostnames:
is_ok, msg = self.ssh_check_host(hostname)
summary[hostname] = {}
summary[hostname]['success'] = is_ok
summary[hostname]['msg'] = msg
return summary
def ssh_check_host(self, hostname):
command_string = '/usr/bin/sudo -u %s %s -vvv ' % \
(get_admin_user(), get_ansible_command())

View File

@ -105,12 +105,8 @@ class TestFunctional(KollaCliTest):
# setup the host
self.run_cli_cmd('host setup %s --insecure %s'
% (hostname, pwd))
msg = self.run_cli_cmd('host check %s' % hostname, True)
self.assertNotIn('ERROR:', msg, 'Check after setup failed on ' +
'host: (%s)' % hostname)
# check again using all
self.run_cli_cmd('host check all')
self.run_cli_cmd('host check %s' % hostname)
self.run_cli_cmd('host check --predeploy %s' % hostname)
def test_hosts_setup(self):
"""test multi-host setup"""
@ -143,6 +139,7 @@ class TestFunctional(KollaCliTest):
# run check with 'all'
self.run_cli_cmd('host check all')
self.run_cli_cmd('host check all --predeploy')
# failure paths