Skip to content

Commit 749274d

Browse files
authored
Dev: migration: allow to run migration locally (jsc#PED-8252) (#1836)
2 parents 8c82cb6 + 4ea7742 commit 749274d

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

crmsh/migration.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,12 @@ def to_check_return_code(self) -> CheckReturnCode:
156156
return ret
157157

158158

159-
def migrate():
159+
def migrate(args: typing.Sequence[str]):
160+
parser = argparse.ArgumentParser(args[0])
161+
parser.add_argument('--local', action='store_true')
162+
parsed_args = parser.parse_args(args[1:])
160163
try:
161-
match _check_impl(local=False, json='', summary=False):
164+
match _check_impl(local=parsed_args.local, json='', summary=False):
162165
case CheckReturnCode.ALREADY_MIGRATED:
163166
logger.info("This cluster works on SLES 16. No migration is needed.")
164167
return 0
@@ -167,7 +170,7 @@ def migrate():
167170
return 0
168171
case CheckReturnCode.PASS_NEED_AUTO_FIX:
169172
logger.info('Starting migration...')
170-
migrate_corosync_conf()
173+
migrate_corosync_conf(local=parsed_args.local)
171174
logger.info('Finished migration.')
172175
return 0
173176
case _:
@@ -372,7 +375,7 @@ def _check_unsupported_corosync_transport(handler: CheckResultHandler, dom):
372375
)
373376

374377

375-
def migrate_corosync_conf():
378+
def migrate_corosync_conf(local: bool):
376379
conf_path = corosync.conf()
377380
with open(conf_path, 'r', encoding='utf-8') as f:
378381
config = corosync_config_format.DomParser(f).dom()
@@ -387,16 +390,17 @@ def migrate_corosync_conf():
387390
'Finish migrating corosync configuration. The original configuration is renamed to %s.bak',
388391
os.path.basename(conf_path),
389392
)
390-
for host, result in prun.pcopy_to_remote(
391-
conf_path,
392-
utils.list_cluster_nodes_except_me(), conf_path,
393-
atomic_write=True,
394-
).items():
395-
match result:
396-
case None:
397-
pass
398-
case prun.PRunError() as e:
399-
logger.error("Failed to copy crmsh.conf to host %s: %s", host, e)
393+
if not local:
394+
for host, result in prun.pcopy_to_remote(
395+
conf_path,
396+
utils.list_cluster_nodes_except_me(), conf_path,
397+
atomic_write=True,
398+
).items():
399+
match result:
400+
case None:
401+
pass
402+
case prun.PRunError() as e:
403+
logger.error("Failed to copy crmsh.conf to host %s: %s", host, e)
400404

401405

402406
def migrate_corosync_conf_impl(config):

crmsh/ui_cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ def do_health(self, context, *args):
839839
case 'sles16':
840840
try:
841841
if parsed_args.fix:
842-
migration.migrate()
842+
migration.migrate(['sles16'] + remaining_args)
843843
else:
844844
return 0 == migration.check(['sles16'] + remaining_args)
845845
except migration.MigrationFailure as e:

doc/crm.8.adoc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,20 +1010,16 @@ Usage 2: Topic-Specified Health Check
10101010
Verifies the health of a specified topic.
10111011

10121012
...............
1013-
health hawk2|sles16 [--fix]
1013+
health hawk2|sles16 [--local] [--fix]
10141014
...............
10151015

10161016
* `hawk2`: check or fix key-based ssh authentication for user hacluster, which
1017-
is needed by hawk2.
1017+
is needed by hawk2.
1018+
** `--fix`: attempts to automatically resolve any detected issues, eg.
1019+
hacluster passwordless
10181020
* `sles16`: check whether the cluster is good to migrate to SLES 16.
1019-
1020-
The optional `--fix` argument attempts to automatically resolve any detected
1021-
issues.
1022-
1023-
.Note on sles16
1024-
****************************
1025-
`--fix` is only available after the OS is migrated to SLES 16.
1026-
****************************
1021+
** `--local`: run checks in local mode
1022+
** `--fix`: attempts to automatically resolve any detected issues.
10271023

10281024
[[cmdhelp.cluster.init,Initializes a new HA cluster,From Code]]
10291025
==== `init`

0 commit comments

Comments
 (0)