test(hosts): render the host_agent fragments whether or not the plugin is enabled (#5122)
The unit app does not register plugin blueprints, so render_template could not find _host_vitals.html or _host_metrics.html (TemplateNotFound, CI run 8384). tests/_templates.render_plugin_template renders a plugin's template through the app's own Jinja environment and request context, with the plugin's template folder ahead of the app's loader. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,10 +5,10 @@ from datetime import datetime, timedelta, timezone
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from quart import render_template
|
||||
|
||||
from steward.core.formatting import worst_reading
|
||||
from steward.core.settings import to_thresholds_cfg
|
||||
from tests._templates import render_plugin_template
|
||||
from tests.test_style_tokens import hex_colours
|
||||
|
||||
TH = to_thresholds_cfg({}) # cpu/mem/disk warn 80 crit 90; load warn 80 crit 100
|
||||
@@ -29,8 +29,8 @@ async def _vitals(app, *, cpu=40.0, mem=50.0, stale=False, seen_min=1):
|
||||
readings = (("CPU", cpu, "cpu"), ("Memory", mem, "mem"), ("Disk /", 30.0, "disk"),
|
||||
("Load per core", 20, "load"))
|
||||
async with app.test_request_context("/plugins/host_agent/vitals/h1"):
|
||||
page = await render_template(
|
||||
"_host_vitals.html", reporting=True, stale=stale,
|
||||
page = await render_plugin_template(
|
||||
app, "host_agent", "_host_vitals.html", reporting=True, stale=stale,
|
||||
reg=SimpleNamespace(last_seen_at=datetime.now(timezone.utc) - timedelta(minutes=seen_min),
|
||||
agent_version="1.9.0"),
|
||||
cpu=cpu, mem=mem, disk_root=30.0, load_per_core=20,
|
||||
@@ -63,8 +63,8 @@ async def test_a_stale_host_says_since_when_before_any_reading(app):
|
||||
async def test_the_metrics_page_grades_by_the_same_cutoffs(app):
|
||||
# 75 % was amber under the old hard-coded 70/90; Settings → Thresholds says warn at 80.
|
||||
async with app.test_request_context("/plugins/host_agent/h1/metrics"):
|
||||
page = await render_template(
|
||||
"_host_metrics.html", host=SimpleNamespace(address="10.0.0.2"), stale=False,
|
||||
page = await render_plugin_template(
|
||||
app, "host_agent", "_host_metrics.html", host=SimpleNamespace(address="10.0.0.2"), stale=False,
|
||||
reg=SimpleNamespace(distro=None, kernel=None, arch=None, agent_version=None,
|
||||
last_seen_at=datetime.now(timezone.utc)),
|
||||
hostlvl={"cpu_pct": 75.0, "mem_used_pct": 95.0, "temp_c_max": 72.0},
|
||||
|
||||
Reference in New Issue
Block a user