mirror of
https://github.com/Such-Software/adaptive-multi-protocol-gateway.git
synced 2026-10-17 07:31:32 +02:00
Add health deploy apply stage
This commit is contained in:
+118
-1
@@ -5,7 +5,13 @@ import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from ampg.addresses import address_registry_path
|
||||
from ampg.apply import CommandRunResult, apply_start, apply_state, apply_supervisor
|
||||
from ampg.apply import (
|
||||
CommandRunResult,
|
||||
apply_health,
|
||||
apply_start,
|
||||
apply_state,
|
||||
apply_supervisor,
|
||||
)
|
||||
from ampg.cli import main
|
||||
from ampg.config import load_config
|
||||
from ampg.platforms import PlatformProvider
|
||||
@@ -566,6 +572,117 @@ class DeployApplyTest(unittest.TestCase):
|
||||
self.assertIn("status=written", output)
|
||||
self.assertIn("http://captureexample.b32.i2p/", registry_text)
|
||||
|
||||
def test_deploy_apply_health_blocks_placeholder_addresses(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp).resolve()
|
||||
config_path = _init_i2p_config(root)
|
||||
|
||||
status, output, error = _run_cli(
|
||||
[
|
||||
"--config",
|
||||
str(config_path),
|
||||
"deploy",
|
||||
"apply",
|
||||
"--stage",
|
||||
"health",
|
||||
"--dry-run",
|
||||
"--profile",
|
||||
"mobile-i2p",
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEqual(1, status)
|
||||
self.assertEqual("", error)
|
||||
self.assertIn("AMPG_DEPLOY_HEALTH", output)
|
||||
self.assertIn("status=blocked", output)
|
||||
self.assertIn("placeholder address", output)
|
||||
|
||||
def test_deploy_apply_health_dry_run_after_address_capture(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp).resolve()
|
||||
config_path = _init_i2p_config(root)
|
||||
_write_i2p_address_file(root)
|
||||
status, _, error = _run_cli(
|
||||
[
|
||||
"--config",
|
||||
str(config_path),
|
||||
"deploy",
|
||||
"apply",
|
||||
"--stage",
|
||||
"addresses",
|
||||
"--profile",
|
||||
"mobile-i2p",
|
||||
"--yes",
|
||||
]
|
||||
)
|
||||
if status != 0:
|
||||
raise AssertionError(error)
|
||||
|
||||
status, output, error = _run_cli(
|
||||
[
|
||||
"--config",
|
||||
str(config_path),
|
||||
"deploy",
|
||||
"apply",
|
||||
"--stage",
|
||||
"health",
|
||||
"--dry-run",
|
||||
"--profile",
|
||||
"mobile-i2p",
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEqual(0, status, error)
|
||||
self.assertIn("AMPG_DEPLOY_HEALTH", output)
|
||||
self.assertIn("status=planned", output)
|
||||
self.assertIn("curl --proxy http://127.0.0.1:4444 -fsSL", output)
|
||||
self.assertIn("http://captureexample.b32.i2p/", output)
|
||||
|
||||
def test_deploy_apply_health_live_invokes_runner(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp).resolve()
|
||||
config_path = _init_i2p_config(root)
|
||||
_write_i2p_address_file(root)
|
||||
status, _, error = _run_cli(
|
||||
[
|
||||
"--config",
|
||||
str(config_path),
|
||||
"deploy",
|
||||
"apply",
|
||||
"--stage",
|
||||
"addresses",
|
||||
"--profile",
|
||||
"mobile-i2p",
|
||||
"--yes",
|
||||
]
|
||||
)
|
||||
if status != 0:
|
||||
raise AssertionError(error)
|
||||
config = load_config(config_path)
|
||||
commands: list[tuple[str, ...]] = []
|
||||
|
||||
def runner(command: tuple[str, ...]) -> CommandRunResult:
|
||||
commands.append(command)
|
||||
return CommandRunResult(return_code=0)
|
||||
|
||||
results = apply_health(
|
||||
config,
|
||||
dry_run=False,
|
||||
command_runner=runner,
|
||||
)
|
||||
|
||||
self.assertTrue(all(result.status == "passed" for result in results))
|
||||
self.assertIn(
|
||||
(
|
||||
"curl",
|
||||
"--proxy",
|
||||
"http://127.0.0.1:4444",
|
||||
"-fsSL",
|
||||
"http://captureexample.b32.i2p/",
|
||||
),
|
||||
commands,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -61,6 +61,7 @@ class DeployPlanTest(unittest.TestCase):
|
||||
self.assertIn("AMPG_DEPLOY_STEP stage=build status=todo", output)
|
||||
self.assertIn("AMPG_DEPLOY_STEP stage=dns status=skipped", output)
|
||||
self.assertIn("AMPG_DEPLOY_STEP stage=artifacts status=todo", output)
|
||||
self.assertIn("AMPG_DEPLOY_STEP stage=health status=todo", output)
|
||||
self.assertIn("AMPG_DEPLOY_NEXT step=1 stage=build", output)
|
||||
self.assertIn("build --profile mobile-i2p", output)
|
||||
self.assertIn("deploy apply --stage addresses --dry-run --profile mobile-i2p", output)
|
||||
@@ -137,6 +138,7 @@ class DeployPlanTest(unittest.TestCase):
|
||||
self.assertEqual(0, status, error)
|
||||
self.assertIn("AMPG_DEPLOY_STEP stage=build status=ready", output)
|
||||
self.assertIn("AMPG_DEPLOY_STEP stage=artifacts status=todo", output)
|
||||
self.assertIn("AMPG_DEPLOY_STEP stage=health status=review", output)
|
||||
|
||||
def test_deploy_plan_guides_staged_apply_after_approval(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
|
||||
Reference in New Issue
Block a user