conductor(checkpoint): Checkpoint end of Phase 1
This commit is contained in:
11
scripts/cluster_status/Makefile
Normal file
11
scripts/cluster_status/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
.PHONY: setup test run
|
||||
|
||||
setup:
|
||||
python3 -m venv .venv
|
||||
. .venv/bin/activate && pip install -r requirements.txt
|
||||
|
||||
test:
|
||||
. .venv/bin/activate && pytest -v --cov=.
|
||||
|
||||
run:
|
||||
. .venv/bin/activate && python3 cluster_status.py
|
||||
0
scripts/cluster_status/__init__.py
Normal file
0
scripts/cluster_status/__init__.py
Normal file
15
scripts/cluster_status/config.py
Normal file
15
scripts/cluster_status/config.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
DEFAULT_CONSUL_URL = "http://consul.service.dc1.consul:8500"
|
||||
|
||||
def get_consul_url(url_arg=None):
|
||||
"""
|
||||
Resolves the Consul URL in the following order:
|
||||
1. CLI Argument (url_arg)
|
||||
2. Environment Variable (CONSUL_HTTP_ADDR)
|
||||
3. Default (http://localhost:8500)
|
||||
"""
|
||||
if url_arg:
|
||||
return url_arg
|
||||
|
||||
return os.environ.get("CONSUL_HTTP_ADDR", DEFAULT_CONSUL_URL)
|
||||
4
scripts/cluster_status/requirements.txt
Normal file
4
scripts/cluster_status/requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
requests
|
||||
tabulate
|
||||
pytest
|
||||
pytest-cov
|
||||
0
scripts/cluster_status/tests/__init__.py
Normal file
0
scripts/cluster_status/tests/__init__.py
Normal file
27
scripts/cluster_status/tests/test_config.py
Normal file
27
scripts/cluster_status/tests/test_config.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
import pytest
|
||||
import config
|
||||
|
||||
def test_default_consul_url():
|
||||
"""Test that the default Consul URL is returned when no env var is set."""
|
||||
# Ensure env var is not set
|
||||
if "CONSUL_HTTP_ADDR" in os.environ:
|
||||
del os.environ["CONSUL_HTTP_ADDR"]
|
||||
|
||||
assert config.get_consul_url() == "http://consul.service.dc1.consul:8500"
|
||||
|
||||
def test_env_var_consul_url():
|
||||
"""Test that the environment variable overrides the default."""
|
||||
os.environ["CONSUL_HTTP_ADDR"] = "http://10.0.0.1:8500"
|
||||
try:
|
||||
assert config.get_consul_url() == "http://10.0.0.1:8500"
|
||||
finally:
|
||||
del os.environ["CONSUL_HTTP_ADDR"]
|
||||
|
||||
def test_cli_arg_consul_url():
|
||||
"""Test that the CLI argument overrides everything."""
|
||||
os.environ["CONSUL_HTTP_ADDR"] = "http://10.0.0.1:8500"
|
||||
try:
|
||||
assert config.get_consul_url("http://cli-override:8500") == "http://cli-override:8500"
|
||||
finally:
|
||||
del os.environ["CONSUL_HTTP_ADDR"]
|
||||
Reference in New Issue
Block a user