Skip to content

Commit

Permalink
Dev: ui_cluster: add 'crm cluster health sles [--fix]' (jsc#PED-8252)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasyang2022 committed Oct 23, 2024
1 parent 010cdb6 commit c6cd605
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
10 changes: 0 additions & 10 deletions crmsh/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,3 @@ def nodes(self):
assert uname
result.append(Cib.Node(int(node_id), uname))
return result

Check warning on line 245 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L234-L245

Added lines #L234 - L245 were not covered by tests


if __name__ == '__main__':
# for demo only
# usage: python -m crmsh.migration
logging.basicConfig(level=logging.INFO)
from crmsh.main import envsetup
import sys
envsetup()
sys.exit(migrate())
62 changes: 38 additions & 24 deletions crmsh/ui_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from argparse import ArgumentParser, RawDescriptionHelpFormatter

import crmsh.parallax
from . import command, sh, healthcheck
from . import command, sh, healthcheck, migration
from . import utils
from . import scripts
from . import completers as compl
Expand Down Expand Up @@ -767,37 +767,51 @@ def do_health(self, context, *args):
if not args:
return self._do_health_legacy(context, *args)
parser = argparse.ArgumentParser()
parser.add_argument('component', choices=['hawk2'])
parser.add_argument('component', choices=['hawk2', 'sles16'])
parser.add_argument('-f', '--fix', action='store_true')
parsed_args = parser.parse_args(args)
if parsed_args.component == 'hawk2':
nodes = utils.list_cluster_nodes()
if parsed_args.fix:
if not healthcheck.feature_full_check(healthcheck.PasswordlessPrimaryUserAuthenticationFeature(), nodes):
match parsed_args.component:
case 'hawk2':
nodes = utils.list_cluster_nodes()
if parsed_args.fix:
if not healthcheck.feature_full_check(healthcheck.PasswordlessPrimaryUserAuthenticationFeature(), nodes):
try:
healthcheck.feature_fix(
healthcheck.PasswordlessPrimaryUserAuthenticationFeature(),
nodes,
utils.ask,
)
except healthcheck.FixFailure:
logger.error('Cannot fix automatically.')
return False
try:
healthcheck.feature_fix(
healthcheck.PasswordlessPrimaryUserAuthenticationFeature(),
nodes,
utils.ask,
)
healthcheck.feature_fix(healthcheck.PasswordlessHaclusterAuthenticationFeature(), nodes, utils.ask)
logger.info("hawk2: passwordless ssh authentication: OK.")
return True
except healthcheck.FixFailure:
logger.error('Cannot fix automatically.')
logger.error("hawk2: passwordless ssh authentication: FAIL.")

Check warning on line 792 in crmsh/ui_cluster.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_cluster.py#L792

Added line #L792 was not covered by tests
return False
else:
if healthcheck.feature_full_check(healthcheck.PasswordlessHaclusterAuthenticationFeature(), nodes):
logger.info("hawk2: passwordless ssh authentication: OK.")
return True

Check warning on line 797 in crmsh/ui_cluster.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_cluster.py#L796-L797

Added lines #L796 - L797 were not covered by tests
else:
logger.error("hawk2: passwordless ssh authentication: FAIL.")
logger.warning('Please run "crm cluster health hawk2 --fix"')
return False
case 'sles16':

Check warning on line 802 in crmsh/ui_cluster.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_cluster.py#L802

Added line #L802 was not covered by tests
try:
healthcheck.feature_fix(healthcheck.PasswordlessHaclusterAuthenticationFeature(), nodes, utils.ask)
logger.info("hawk2: passwordless ssh authentication: OK.")
return True
except healthcheck.FixFailure:
logger.error("hawk2: passwordless ssh authentication: FAIL.")
return False
else:
if healthcheck.feature_full_check(healthcheck.PasswordlessHaclusterAuthenticationFeature(), nodes):
logger.info("hawk2: passwordless ssh authentication: OK.")
if parsed_args.fix:
migration.migrate()

Check warning on line 805 in crmsh/ui_cluster.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_cluster.py#L804-L805

Added lines #L804 - L805 were not covered by tests
else:
migration.check()

Check warning on line 807 in crmsh/ui_cluster.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_cluster.py#L807

Added line #L807 was not covered by tests
return True
else:
logger.error("hawk2: passwordless ssh authentication: FAIL.")
logger.warning('Please run "crm cluster health hawk2 --fix"')
except migration.MigrationFailure as e:
logger.error('%s', e)

Check warning on line 810 in crmsh/ui_cluster.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_cluster.py#L809-L810

Added lines #L809 - L810 were not covered by tests
return False
case _:
logger.error('Unknown component: %s', parsed_args.component)
return False

Check warning on line 814 in crmsh/ui_cluster.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_cluster.py#L812-L814

Added lines #L812 - L814 were not covered by tests

def _do_health_legacy(self, context, *args):
params = self._args_implicit(context, args, 'nodes')
Expand Down

0 comments on commit c6cd605

Please sign in to comment.