From cbd109a8bc0e6e2f75266ba2d5428fdb8cba9424 Mon Sep 17 00:00:00 2001 From: sstent Date: Sun, 8 Feb 2026 06:18:13 -0800 Subject: [PATCH] chore(conductor): Mark track 'cluster_status_python' as complete --- conductor/tracks.md | 2 +- .../cluster_status_python_20260208/plan.md | 12 +++---- scripts/cluster_status/Makefile | 2 +- scripts/cluster_status/cli.py | 33 +++++++++++++++++++ scripts/cluster_status/tests/test_main.py | 18 ++++++++++ 5 files changed, 59 insertions(+), 8 deletions(-) create mode 100755 scripts/cluster_status/cli.py create mode 100644 scripts/cluster_status/tests/test_main.py diff --git a/conductor/tracks.md b/conductor/tracks.md index 1595b2f..dd38d52 100644 --- a/conductor/tracks.md +++ b/conductor/tracks.md @@ -3,5 +3,5 @@ This file tracks all major tracks for the project. Each track has its own detailed plan in its respective folder. --- -- [~] **Track: create a script that runs on my local system (i don't run consul locally) that: - check consul services are registered correctly - diplays the expected state (who is primary, what replicas exist) - show basic litefs status info for each node** +- [x] **Track: create a script that runs on my local system (i don't run consul locally) that: - check consul services are registered correctly - diplays the expected state (who is primary, what replicas exist) - show basic litefs status info for each node** *Link: [./tracks/cluster_status_python_20260208/](./tracks/cluster_status_python_20260208/)* diff --git a/conductor/tracks/cluster_status_python_20260208/plan.md b/conductor/tracks/cluster_status_python_20260208/plan.md index 74f5240..23d10ed 100644 --- a/conductor/tracks/cluster_status_python_20260208/plan.md +++ b/conductor/tracks/cluster_status_python_20260208/plan.md @@ -23,9 +23,9 @@ - [x] Implement `tabulate` based output with a health summary - [x] Task: Conductor - User Manual Verification 'Phase 3: Data Processing and Formatting' (Protocol in workflow.md) -## Phase 4: CLI Interface and Final Polishing [ ] -- [ ] Task: Implement command-line arguments (argparse) - - [ ] Write tests for CLI argument parsing (Consul URL overrides, etc.) - - [ ] Finalize the `main` entry point -- [ ] Task: Final verification of script against requirements -- [ ] Task: Conductor - User Manual Verification 'Phase 4: CLI Interface and Final Polishing' (Protocol in workflow.md) +## Phase 4: CLI Interface and Final Polishing [x] +- [x] Task: Implement command-line arguments (argparse) + - [x] Write tests for CLI argument parsing (Consul URL overrides, etc.) + - [x] Finalize the `main` entry point +- [x] Task: Final verification of script against requirements +- [x] Task: Conductor - User Manual Verification 'Phase 4: CLI Interface and Final Polishing' (Protocol in workflow.md) diff --git a/scripts/cluster_status/Makefile b/scripts/cluster_status/Makefile index df30d3f..c9f934f 100644 --- a/scripts/cluster_status/Makefile +++ b/scripts/cluster_status/Makefile @@ -8,4 +8,4 @@ test: . .venv/bin/activate && pytest -v --cov=. run: - . .venv/bin/activate && python3 cluster_status.py + . .venv/bin/activate && PYTHONPATH=. python3 cli.py diff --git a/scripts/cluster_status/cli.py b/scripts/cluster_status/cli.py new file mode 100755 index 0000000..dcfd09f --- /dev/null +++ b/scripts/cluster_status/cli.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +import argparse +import sys +import config +import cluster_aggregator +import output_formatter + +def parse_args(): + parser = argparse.ArgumentParser(description="Monitor Navidrome LiteFS/Consul cluster status.") + parser.add_argument("--consul-url", help="Override Consul API URL (default from env or hardcoded)") + parser.add_argument("--no-color", action="store_true", help="Disable colorized output") + return parser.parse_args() + +def main(): + args = parse_args() + + # Resolve Consul URL + consul_url = config.get_consul_url(args.consul_url) + + try: + # Fetch and aggregate data + cluster_data = cluster_aggregator.get_cluster_status(consul_url) + + # Format and print output + print(output_formatter.format_summary(cluster_data, use_color=not args.no_color)) + print("\n" + output_formatter.format_node_table(cluster_data["nodes"], use_color=not args.no_color)) + + except Exception as e: + print(f"Error: {e}", file=sys.stderr) + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/scripts/cluster_status/tests/test_main.py b/scripts/cluster_status/tests/test_main.py new file mode 100644 index 0000000..9a471bc --- /dev/null +++ b/scripts/cluster_status/tests/test_main.py @@ -0,0 +1,18 @@ +import pytest +from unittest.mock import patch, MagicMock +import cli +import sys + +def test_arg_parsing_default(): + """Test that default arguments are parsed correctly.""" + with patch.object(sys, 'argv', ['cli.py']): + args = cli.parse_args() + assert args.consul_url is None # Should use config default later + assert args.no_color is False + +def test_arg_parsing_custom(): + """Test that custom arguments are parsed correctly.""" + with patch.object(sys, 'argv', ['cli.py', '--consul-url', 'http://custom:8500', '--no-color']): + args = cli.parse_args() + assert args.consul_url == 'http://custom:8500' + assert args.no_color is True