Test release installer against real Core and Manager health handlers
Device Core qualification / qualify (push) Successful in 7m18s
Device Core qualification / qualify (push) Successful in 7m18s
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
},
|
||||
"platform": {
|
||||
"url": "https://git.dcserve.ru/SILVER/NODEDC_PLATFORM.git",
|
||||
"commit": "11b73e64681f83aa2ebfd89ef266d3be2869f7e1"
|
||||
"commit": "ed500278a04affa93228b14d97a6c6b6c1f82a07"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// Real application handlers; only external dependencies are replaced in this fixture.
|
||||
import { createControlCoreApp } from "../../services/device-control-core/src/app.mjs";
|
||||
import { createDeviceManagerServer } from "../../apps/device-manager/server/device-manager-server.mjs";
|
||||
|
||||
const servers = [];
|
||||
const urls = {};
|
||||
for (const mode of ["healthy", "database", "discovery", "management", "transport", "auth", "coreClient"]) {
|
||||
const core = createControlCoreApp({
|
||||
repository: {
|
||||
health: async () => mode === "database" ? "unavailable" : "ready",
|
||||
upsertQuarantineDiscovery() {}, acceptAdapterMessage() {}, executeManagementCommand() {},
|
||||
},
|
||||
gatewayToken: "fixture-only-".repeat(4), identifierPepper: "fixture-only-".repeat(4),
|
||||
managementToken: "fixture-only-".repeat(4),
|
||||
discoveryIngestEnabled: mode !== "discovery", managementApiEnabled: mode !== "management",
|
||||
gatewayIngest: { observeDiscovery() {}, acceptMessage() {} },
|
||||
typedCommandRuntime: mode === "transport" ? null : { planServicePing() {}, status() {} },
|
||||
edgeChannelStatusProvider: () => ({ enabled: true, configured: 1, accepted: 1, degraded: 0 }),
|
||||
});
|
||||
const manager = createDeviceManagerServer({
|
||||
auth: { authRequired: mode !== "auth", authorize() {} },
|
||||
coreClient: { configured: mode !== "coreClient", listProjects() {} },
|
||||
presentationStore: {},
|
||||
});
|
||||
urls[mode] = [];
|
||||
for (const server of [core, manager]) {
|
||||
await new Promise((resolve, reject) => {
|
||||
server.once("error", reject);
|
||||
server.listen(0, "127.0.0.1", resolve);
|
||||
});
|
||||
servers.push(server);
|
||||
urls[mode].push(`http://127.0.0.1:${server.address().port}/healthz`);
|
||||
}
|
||||
}
|
||||
process.stdout.write(JSON.stringify(urls) + "\n");
|
||||
process.stdin.resume();
|
||||
process.stdin.on("end", async () => {
|
||||
await Promise.all(servers.map(server => new Promise(resolve => server.close(resolve))));
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
"""Exercise the pinned production installer against real Core/Manager HTTP handlers."""
|
||||
import importlib.machinery
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import select
|
||||
import subprocess
|
||||
import unittest
|
||||
import urllib.request
|
||||
from unittest import mock
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
RUNNER_PATH = Path(os.environ.get("NODEDC_DEPLOY_RUNNER", HERE.parents[2] / "platform/infra/deploy-runner/nodedc-deploy"))
|
||||
loader = importlib.machinery.SourceFileLoader("release_health_runner", str(RUNNER_PATH))
|
||||
spec = importlib.util.spec_from_loader(loader.name, loader)
|
||||
R = importlib.util.module_from_spec(spec)
|
||||
loader.exec_module(R)
|
||||
|
||||
|
||||
class ActualApplicationHealthContractTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.process = subprocess.Popen(
|
||||
["node", str(HERE / "health-contract-servers.mjs")],
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True,
|
||||
)
|
||||
cls.addClassCleanup(cls.stop_servers)
|
||||
if not select.select([cls.process.stdout], [], [], 15)[0]:
|
||||
raise AssertionError("health fixture did not listen within 15 seconds")
|
||||
line = cls.process.stdout.readline()
|
||||
if not line:
|
||||
raise AssertionError("health fixture failed: " + cls.process.stderr.read())
|
||||
cls.urls = json.loads(line)
|
||||
|
||||
@classmethod
|
||||
def stop_servers(cls):
|
||||
cls.process.stdin.close()
|
||||
try:
|
||||
cls.process.wait(timeout=5)
|
||||
except subprocess.TimeoutExpired:
|
||||
cls.process.kill()
|
||||
cls.process.wait(timeout=5)
|
||||
cls.process.stdout.close()
|
||||
cls.process.stderr.close()
|
||||
|
||||
def check_actual_handlers(self, mode):
|
||||
health = R.healthcheck_url
|
||||
calls = []
|
||||
def local_check(check):
|
||||
index = 0 if check["url"].endswith(":18120/healthz") else 1
|
||||
calls.append(index)
|
||||
return health({**check, "url": self.urls[mode][index]})
|
||||
with mock.patch.object(R, "healthcheck_compose_service_with_grace"), \
|
||||
mock.patch.object(R, "healthcheck_url", side_effect=local_check), \
|
||||
mock.patch.object(R.time, "sleep"), \
|
||||
mock.patch.object(R, "NO_REDIRECT_OPENER", urllib.request.build_opener(urllib.request.ProxyHandler({}))):
|
||||
# Real release selection and real HTTP contract comparison, not a copied expectation.
|
||||
R.run_healthchecks("device-core-release", R.DEVICE_RELEASE_ENTRIES, R.DEVICE_RELEASE_SERVICES)
|
||||
return calls
|
||||
|
||||
def test_enabled_production_foundation_passes_actual_installer(self):
|
||||
self.assertEqual(self.check_actual_handlers("healthy"), [0, 1])
|
||||
|
||||
def test_unavailable_database_fails(self):
|
||||
with self.assertRaisesRegex(R.DeployError, "contract mismatch"):
|
||||
self.check_actual_handlers("database")
|
||||
|
||||
def test_disabled_required_core_capabilities_fail(self):
|
||||
for mode in ["discovery", "management", "transport"]:
|
||||
with self.subTest(mode=mode), self.assertRaisesRegex(R.DeployError, "contract mismatch"):
|
||||
self.check_actual_handlers(mode)
|
||||
|
||||
def test_manager_without_auth_or_core_fails(self):
|
||||
for mode in ["auth", "coreClient"]:
|
||||
with self.subTest(mode=mode), self.assertRaisesRegex(R.DeployError, "contract mismatch"):
|
||||
self.check_actual_handlers(mode)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user