|
9 | 9 | from argparse import ArgumentParser, RawDescriptionHelpFormatter
|
10 | 10 |
|
11 | 11 | import crmsh.parallax
|
12 |
| -from . import command, sh, healthcheck |
| 12 | +from . import command, sh, healthcheck, migration |
13 | 13 | from . import utils
|
14 | 14 | from . import scripts
|
15 | 15 | from . import completers as compl
|
@@ -767,37 +767,51 @@ def do_health(self, context, *args):
|
767 | 767 | if not args:
|
768 | 768 | return self._do_health_legacy(context, *args)
|
769 | 769 | parser = argparse.ArgumentParser()
|
770 |
| - parser.add_argument('component', choices=['hawk2']) |
| 770 | + parser.add_argument('component', choices=['hawk2', 'sles16']) |
771 | 771 | parser.add_argument('-f', '--fix', action='store_true')
|
772 | 772 | parsed_args = parser.parse_args(args)
|
773 |
| - if parsed_args.component == 'hawk2': |
774 |
| - nodes = utils.list_cluster_nodes() |
775 |
| - if parsed_args.fix: |
776 |
| - if not healthcheck.feature_full_check(healthcheck.PasswordlessPrimaryUserAuthenticationFeature(), nodes): |
| 773 | + match parsed_args.component: |
| 774 | + case 'hawk2': |
| 775 | + nodes = utils.list_cluster_nodes() |
| 776 | + if parsed_args.fix: |
| 777 | + if not healthcheck.feature_full_check(healthcheck.PasswordlessPrimaryUserAuthenticationFeature(), nodes): |
| 778 | + try: |
| 779 | + healthcheck.feature_fix( |
| 780 | + healthcheck.PasswordlessPrimaryUserAuthenticationFeature(), |
| 781 | + nodes, |
| 782 | + utils.ask, |
| 783 | + ) |
| 784 | + except healthcheck.FixFailure: |
| 785 | + logger.error('Cannot fix automatically.') |
| 786 | + return False |
777 | 787 | try:
|
778 |
| - healthcheck.feature_fix( |
779 |
| - healthcheck.PasswordlessPrimaryUserAuthenticationFeature(), |
780 |
| - nodes, |
781 |
| - utils.ask, |
782 |
| - ) |
| 788 | + healthcheck.feature_fix(healthcheck.PasswordlessHaclusterAuthenticationFeature(), nodes, utils.ask) |
| 789 | + logger.info("hawk2: passwordless ssh authentication: OK.") |
| 790 | + return True |
783 | 791 | except healthcheck.FixFailure:
|
784 |
| - logger.error('Cannot fix automatically.') |
| 792 | + logger.error("hawk2: passwordless ssh authentication: FAIL.") |
785 | 793 | return False
|
| 794 | + else: |
| 795 | + if healthcheck.feature_full_check(healthcheck.PasswordlessHaclusterAuthenticationFeature(), nodes): |
| 796 | + logger.info("hawk2: passwordless ssh authentication: OK.") |
| 797 | + return True |
| 798 | + else: |
| 799 | + logger.error("hawk2: passwordless ssh authentication: FAIL.") |
| 800 | + logger.warning('Please run "crm cluster health hawk2 --fix"') |
| 801 | + return False |
| 802 | + case 'sles16': |
786 | 803 | try:
|
787 |
| - healthcheck.feature_fix(healthcheck.PasswordlessHaclusterAuthenticationFeature(), nodes, utils.ask) |
788 |
| - logger.info("hawk2: passwordless ssh authentication: OK.") |
789 |
| - return True |
790 |
| - except healthcheck.FixFailure: |
791 |
| - logger.error("hawk2: passwordless ssh authentication: FAIL.") |
792 |
| - return False |
793 |
| - else: |
794 |
| - if healthcheck.feature_full_check(healthcheck.PasswordlessHaclusterAuthenticationFeature(), nodes): |
795 |
| - logger.info("hawk2: passwordless ssh authentication: OK.") |
| 804 | + if parsed_args.fix: |
| 805 | + migration.migrate() |
| 806 | + else: |
| 807 | + migration.check() |
796 | 808 | return True
|
797 |
| - else: |
798 |
| - logger.error("hawk2: passwordless ssh authentication: FAIL.") |
799 |
| - logger.warning('Please run "crm cluster health hawk2 --fix"') |
| 809 | + except migration.MigrationFailure as e: |
| 810 | + logger.error('%s', e) |
800 | 811 | return False
|
| 812 | + case _: |
| 813 | + logger.error('Unknown component: %s', parsed_args.component) |
| 814 | + return False |
801 | 815 |
|
802 | 816 | def _do_health_legacy(self, context, *args):
|
803 | 817 | params = self._args_implicit(context, args, 'nodes')
|
|
0 commit comments