wallet_dist_health: argparse instead of click — match repo convention
Every other CLI in the repo (crypto_watcher/__init__, digest_sender, offer_tick, fix_s3_acls, lib/un.py) uses stdlib argparse. The mps_wallet_dist_health module imported click out of habit, breaking that pattern and forcing a new install_requires entry that wasn't declared (516 ModuleNotFoundError test errors on master CI). Swap to argparse, drop the click dep. Same interface: mps_wallet_dist_health [config_path] [--timeout SECS] Same exit codes (0 OK, 2 config, 3 RPC failure). Defaults preserved.
This commit is contained in:
parent
e96c32502e
commit
c97a7c6ee1
2 changed files with 49 additions and 52 deletions
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue