Skip to content

Commit c6cd605

Browse files
Dev: ui_cluster: add 'crm cluster health sles [--fix]' (jsc#PED-8252)
1 parent 010cdb6 commit c6cd605

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

crmsh/migration.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,3 @@ def nodes(self):
243243
assert uname
244244
result.append(Cib.Node(int(node_id), uname))
245245
return result
246-
247-
248-
if __name__ == '__main__':
249-
# for demo only
250-
# usage: python -m crmsh.migration
251-
logging.basicConfig(level=logging.INFO)
252-
from crmsh.main import envsetup
253-
import sys
254-
envsetup()
255-
sys.exit(migrate())

crmsh/ui_cluster.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from argparse import ArgumentParser, RawDescriptionHelpFormatter
1010

1111
import crmsh.parallax
12-
from . import command, sh, healthcheck
12+
from . import command, sh, healthcheck, migration
1313
from . import utils
1414
from . import scripts
1515
from . import completers as compl
@@ -767,37 +767,51 @@ def do_health(self, context, *args):
767767
if not args:
768768
return self._do_health_legacy(context, *args)
769769
parser = argparse.ArgumentParser()
770-
parser.add_argument('component', choices=['hawk2'])
770+
parser.add_argument('component', choices=['hawk2', 'sles16'])
771771
parser.add_argument('-f', '--fix', action='store_true')
772772
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
777787
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
783791
except healthcheck.FixFailure:
784-
logger.error('Cannot fix automatically.')
792+
logger.error("hawk2: passwordless ssh authentication: FAIL.")
785793
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':
786803
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()
796808
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)
800811
return False
812+
case _:
813+
logger.error('Unknown component: %s', parsed_args.component)
814+
return False
801815

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

0 commit comments

Comments
 (0)