From 301c5d9ed6fc5f6c4c30d747fe844bd15e341b8f Mon Sep 17 00:00:00 2001 From: Steve Noyes Date: Mon, 22 Feb 2016 12:09:40 -0500 Subject: [PATCH] add new --predeploy option to host check Jira-Issue: OPENSTACK-663 --- kollacli/commands/host.py | 28 ++++++++++++++++++++++++++-- kollacli/common/inventory.py | 14 ++++++++++++++ tests/host.py | 9 +++------ 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/kollacli/commands/host.py b/kollacli/commands/host.py index 0d914f4..b0c22dd 100644 --- a/kollacli/commands/host.py +++ b/kollacli/commands/host.py @@ -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='', 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: diff --git a/kollacli/common/inventory.py b/kollacli/common/inventory.py index ca099b5..0c1979f 100644 --- a/kollacli/common/inventory.py +++ b/kollacli/common/inventory.py @@ -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()) diff --git a/tests/host.py b/tests/host.py index 9290283..782e29a 100644 --- a/tests/host.py +++ b/tests/host.py @@ -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