diff --git a/make_post_sell/lib/crypto_watcher/wallet_dist_health.py b/make_post_sell/lib/crypto_watcher/wallet_dist_health.py index 3978b34..e1fc221 100644 --- a/make_post_sell/lib/crypto_watcher/wallet_dist_health.py +++ b/make_post_sell/lib/crypto_watcher/wallet_dist_health.py @@ -20,48 +20,55 @@ Exit code: from __future__ import annotations +import argparse import sys import traceback -import click - from make_post_sell.lib.crypto_watcher.wallet_dist_config import ( WalletDistConfig, load_wallet_dist_config, ) -@click.command(name="mps-wallet-dist-health") -@click.argument( - "config_path", - type=click.Path(dir_okay=False, exists=True, readable=True), - default="/opt/make_post_sell/production.ini", -) -@click.option( - "--timeout", - type=float, - default=10.0, - show_default=True, - help="dist call timeout in seconds.", -) -def cli(config_path: str, timeout: float) -> None: - """Verify MPS can talk to wallet@cammy over Erlang dist.""" +def _parse_args(argv: list[str] | None = None) -> argparse.Namespace: + parser = argparse.ArgumentParser( + prog="mps_wallet_dist_health", + description="Verify MPS can talk to wallet@cammy over Erlang dist.", + ) + parser.add_argument( + "config_path", + nargs="?", + default="/opt/make_post_sell/production.ini", + help="path to production.ini (default: /opt/make_post_sell/production.ini)", + ) + parser.add_argument( + "--timeout", + type=float, + default=10.0, + help="dist call timeout in seconds (default: 10.0)", + ) + return parser.parse_args(argv) + + +def main(argv: list[str] | None = None) -> int: + args = _parse_args(argv) + try: - cfg = load_wallet_dist_config(config_path) + cfg = load_wallet_dist_config(args.config_path) except Exception as e: - click.echo(f"config error: {e}", err=True) - raise SystemExit(2) from None + print(f"config error: {e}", file=sys.stderr) + return 2 if not cfg.enabled: - click.echo("wallet_dist.enabled = false (nothing to test)", err=True) - raise SystemExit(2) + print("wallet_dist.enabled = false (nothing to test)", file=sys.stderr) + return 2 - click.echo("=== MPS wallet-dist health check ===") - click.echo(f"our_node_name : {cfg.our_node_name}") - click.echo(f"peer : {cfg.peer_name}@{cfg.peer_host}") - click.echo(f"registered_name : {cfg.registered_name}") - click.echo(f"tls : {'mTLS' if cfg.tls_cert else 'plain'}") - click.echo("") + print("=== MPS wallet-dist health check ===") + print(f"our_node_name : {cfg.our_node_name}") + print(f"peer : {cfg.peer_name}@{cfg.peer_host}") + print(f"registered_name : {cfg.registered_name}") + print(f"tls : {'mTLS' if cfg.tls_cert else 'plain'}") + print("") # Local import — erldistpy is a runtime-optional dep (only required # when wallet_dist is enabled). Importing at module top would force @@ -71,34 +78,30 @@ def cli(config_path: str, timeout: float) -> None: ErlangDistMoneroClient, ) except ImportError as e: - click.echo(f"erldistpy not installed: {e}", err=True) - click.echo("hint: pip install 'erldistpy>=0.1.6'", err=True) - raise SystemExit(3) from None + print(f"erldistpy not installed: {e}", file=sys.stderr) + print("hint: pip install 'erldistpy>=0.1.6'", file=sys.stderr) + return 3 try: with ErlangDistMoneroClient( **cfg.client_kwargs(), - call_timeout=timeout, + call_timeout=args.timeout, ) as client: - click.echo("connected ✓") + print("connected") height = client.get_height() - click.echo(f"monero height: {height}") + print(f"monero height: {height}") synced = client.is_synced() - click.echo(f"synced: {synced}") + print(f"synced: {synced}") except Exception as e: - click.echo(f"\nDIST RPC FAILED: {type(e).__name__}: {e}", err=True) - click.echo("traceback:", err=True) + print(f"\nDIST RPC FAILED: {type(e).__name__}: {e}", file=sys.stderr) + print("traceback:", file=sys.stderr) traceback.print_exc() - raise SystemExit(3) from None + return 3 - click.echo("") - click.echo("OK — MPS can reach Wallet.Service on the cluster ✓") - - -def main() -> None: - # The console_script entry point. Click handles arg parsing. - cli(standalone_mode=True) # standard click flow + print("") + print("OK - MPS can reach Wallet.Service on the cluster") + return 0 if __name__ == "__main__": # pragma: no cover - cli(standalone_mode=True) + sys.exit(main()) diff --git a/requirements.py3.txt b/requirements.py3.txt index 66802f5..a5693e2 100644 --- a/requirements.py3.txt +++ b/requirements.py3.txt @@ -68,9 +68,3 @@ html5lib # included here; see lib/crypto_watcher/erldist_clients.py for the # drop-in clients). erldistpy>=0.1.6 - -# Used by mps_wallet_dist_health CLI (lib/crypto_watcher/wallet_dist_health.py) -# for argument parsing + colored output. Already a transitive dep of pyramid -# in most cases, but pin it explicitly so test imports don't break in cleaner -# CI envs. -click