mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 13:57:43 +00:00
Merge branch 'main' into feature/store-i18n
# Conflicts: # README.md # roles/web-app-odoo/README.md # roles/web-app-odoo/tasks/03_install_modules/module_ops.yml # roles/web-app-odoo/templates/playwright.env.j2 # roles/web-app-pihole/README.md
This commit is contained in:
commit
e714039515
36 files changed
+416
-76
No files matched your search
@@ -0,0 +1,57 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from utils.cache.files import PROJECT_ROOT, iter_project_files
|
||||
from utils.cache.yaml import load_yaml_any
|
||||
|
||||
TASKS_DIR = str(PROJECT_ROOT / "roles/web-app-keycloak/tasks") + "/"
|
||||
LOCK_RETRYING_MODULE = "keycloak_kcadm_update"
|
||||
|
||||
|
||||
def tasks_of(node):
|
||||
for task in node or []:
|
||||
if not isinstance(task, dict):
|
||||
continue
|
||||
yield task
|
||||
for nested in ("block", "rescue", "always"):
|
||||
yield from tasks_of(task.get(nested))
|
||||
|
||||
|
||||
def async_kcadm_jobs():
|
||||
for path in iter_project_files(extensions=(".yml",)):
|
||||
if not path.startswith(TASKS_DIR):
|
||||
continue
|
||||
for task in tasks_of(load_yaml_any(path)):
|
||||
if "async" in task and "kcadm" in str(task).lower():
|
||||
yield f"{path[len(TASKS_DIR) :]}: {task.get('name')}", task
|
||||
|
||||
|
||||
class TestAsyncKcadmJobs(unittest.TestCase):
|
||||
def test_the_role_runs_kcadm_jobs_async(self):
|
||||
self.assertTrue(list(async_kcadm_jobs()))
|
||||
|
||||
def test_every_async_kcadm_job_goes_through_the_lock_retrying_module(self):
|
||||
for label, task in async_kcadm_jobs():
|
||||
with self.subTest(task=label):
|
||||
self.assertIn(
|
||||
LOCK_RETRYING_MODULE,
|
||||
task,
|
||||
"kcadm gives up its config lock to a concurrent kcadm at once; "
|
||||
"only keycloak_kcadm_update repeats such a call, so no other "
|
||||
"kcadm task may run async",
|
||||
)
|
||||
|
||||
def test_every_async_kcadm_job_is_registered_for_the_reap(self):
|
||||
for label, task in async_kcadm_jobs():
|
||||
with self.subTest(task=label):
|
||||
self.assertIn(
|
||||
"register",
|
||||
task,
|
||||
"an async job without a register cannot be reaped, so nobody "
|
||||
"sees it fail",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Whitespace-only changes.
@@ -0,0 +1,43 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import unittest
|
||||
|
||||
from utils.cache.files import PROJECT_ROOT, read_text
|
||||
|
||||
MANIFEST = (
|
||||
PROJECT_ROOT / "roles/web-app-odoo/files/addons/auth_oauth_https/__manifest__.py"
|
||||
)
|
||||
|
||||
|
||||
def manifest_version() -> str:
|
||||
return ast.literal_eval(read_text(str(MANIFEST)))["version"]
|
||||
|
||||
|
||||
def installable_on(series: str, version: str) -> bool:
|
||||
parts = version.split(".")
|
||||
if not 2 <= len(parts) <= 5 or not all(part.isdigit() for part in parts):
|
||||
return False
|
||||
if len(parts) <= 3 and not version.startswith(series):
|
||||
version = f"{series}.{version}"
|
||||
return version.startswith(series + ".")
|
||||
|
||||
|
||||
class TestAddonManifestVersion(unittest.TestCase):
|
||||
def test_odoo_installs_the_addon_on_every_series(self):
|
||||
for series in ("19.0", "20.0", "21.0"):
|
||||
with self.subTest(series=series):
|
||||
self.assertTrue(
|
||||
installable_on(series, manifest_version()),
|
||||
f"Odoo {series} marks a module whose version names another "
|
||||
"series as not installable and only warns about it; keep the "
|
||||
"version in the form x.y.z so Odoo prefixes its own series",
|
||||
)
|
||||
|
||||
def test_a_version_that_names_a_series_is_refused_by_the_next_one(self):
|
||||
self.assertTrue(installable_on("19.0", "19.0.1.8.0"))
|
||||
self.assertFalse(installable_on("20.0", "19.0.1.8.0"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Whitespace-only changes.
@@ -0,0 +1,90 @@
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from jinja2 import Environment, StrictUndefined, select_autoescape
|
||||
|
||||
from utils import PROJECT_ROOT
|
||||
from utils.cache.files import read_text
|
||||
from utils.cache.yaml import load_yaml
|
||||
from utils.roles.mapping import ROLE_FILE_TEMPL_COMPOSE, ROLE_FILE_VARS_MAIN
|
||||
|
||||
ROLE_DIR = PROJECT_ROOT / "roles/web-app-penpot"
|
||||
|
||||
GETENT_STUB = """#!/usr/bin/env bash
|
||||
name="${2:-}"
|
||||
if [[ "${name}" != *. ]]; then
|
||||
\techo "172.30.0.10 ${name}.infinito.test"
|
||||
\texit 0
|
||||
fi
|
||||
lookups=$(( $(cat "${STUB_DIR}/absolute-lookups" 2>/dev/null || echo 0) + 1 ))
|
||||
echo "${lookups}" >"${STUB_DIR}/absolute-lookups"
|
||||
if [ "${lookups}" -le "${STUB_UNKNOWN_LOOKUPS}" ]; then
|
||||
\texit 2
|
||||
fi
|
||||
echo "192.168.48.5 ${name%.}"
|
||||
"""
|
||||
|
||||
NGINX_STUB = """#!/usr/bin/env bash
|
||||
cat "${STUB_DIR}/absolute-lookups" 2>/dev/null || echo 0
|
||||
"""
|
||||
|
||||
QUIET_STUB = """#!/usr/bin/env bash
|
||||
exit 0
|
||||
"""
|
||||
|
||||
|
||||
def start_guard() -> str:
|
||||
template = read_text(str(ROLE_DIR / ROLE_FILE_TEMPL_COMPOSE))
|
||||
guard = re.search(r"^\s+- '(until getent hosts .+)'$", template, re.MULTILINE)
|
||||
names = load_yaml(str(ROLE_DIR / ROLE_FILE_VARS_MAIN))
|
||||
env = Environment(
|
||||
undefined=StrictUndefined,
|
||||
autoescape=select_autoescape(default_for_string=False),
|
||||
)
|
||||
return env.from_string(guard.group(1)).render(
|
||||
PENPOT_BACKEND_SERVICE=names["PENPOT_BACKEND_SERVICE"],
|
||||
PENPOT_EXPORTER_SERVICE=names["PENPOT_EXPORTER_SERVICE"],
|
||||
)
|
||||
|
||||
|
||||
class TestFrontendStartGuard(unittest.TestCase):
|
||||
def absolute_lookups_until_nginx_starts(self, failing_absolute_lookups: int) -> int:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
bin_dir = Path(tmp)
|
||||
stubs = (
|
||||
("getent", GETENT_STUB),
|
||||
("nginx", NGINX_STUB),
|
||||
("sleep", QUIET_STUB),
|
||||
)
|
||||
for name, body in stubs:
|
||||
stub = bin_dir / name
|
||||
stub.write_text(body)
|
||||
stub.chmod(0o755)
|
||||
env = {k: v for k, v in os.environ.items() if k != "BASH_ENV"}
|
||||
env["PATH"] = f"{bin_dir}{os.pathsep}{env['PATH']}"
|
||||
env["STUB_DIR"] = tmp
|
||||
env["STUB_UNKNOWN_LOOKUPS"] = str(failing_absolute_lookups)
|
||||
done = subprocess.run(
|
||||
["bash", "-c", start_guard()],
|
||||
env=env,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
timeout=30,
|
||||
)
|
||||
self.assertEqual(done.returncode, 0, done.stderr)
|
||||
return int(done.stdout)
|
||||
|
||||
def test_nginx_waits_until_the_services_resolve_without_the_search_domain(self):
|
||||
self.assertEqual(self.absolute_lookups_until_nginx_starts(3), 5)
|
||||
|
||||
def test_nginx_starts_at_once_when_the_services_are_known(self):
|
||||
self.assertEqual(self.absolute_lookups_until_nginx_starts(0), 2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,42 @@
|
||||
import importlib.util
|
||||
import unittest
|
||||
|
||||
from utils import PROJECT_ROOT
|
||||
|
||||
_spec = importlib.util.spec_from_file_location(
|
||||
"xwiki_filters",
|
||||
PROJECT_ROOT / "roles/web-app-xwiki/filter_plugins/xwiki_filters.py",
|
||||
)
|
||||
_mod = importlib.util.module_from_spec(_spec)
|
||||
_spec.loader.exec_module(_mod)
|
||||
xwiki_extension_status = _mod.xwiki_extension_status
|
||||
|
||||
EXTENSION = "org.xwiki.contrib.oidc:oidc-authenticator"
|
||||
|
||||
|
||||
class TestExtensionStatus(unittest.TestCase):
|
||||
def test_the_pinned_version_counts_as_installed(self):
|
||||
page = f"<p>INSTALLED::{EXTENSION}::2.28.1</p>"
|
||||
self.assertEqual(xwiki_extension_status(page, "2.28.1"), 200)
|
||||
|
||||
def test_another_installed_version_is_not_the_pinned_one(self):
|
||||
page = f"INSTALLED::{EXTENSION}::2.19.6"
|
||||
self.assertEqual(xwiki_extension_status(page, "2.28.1"), 404)
|
||||
|
||||
def test_a_version_does_not_pass_for_one_it_only_starts_or_ends_like(self):
|
||||
self.assertEqual(
|
||||
xwiki_extension_status(f"INSTALLED::{EXTENSION}::0.10", "0.1"), 404
|
||||
)
|
||||
self.assertEqual(
|
||||
xwiki_extension_status(f"INSTALLED::{EXTENSION}::10.1", "0.1"), 404
|
||||
)
|
||||
|
||||
def test_no_pin_accepts_any_installed_version(self):
|
||||
self.assertEqual(xwiki_extension_status(f"INSTALLED::{EXTENSION}::2.19.6"), 200)
|
||||
|
||||
def test_a_missing_extension_is_not_installed(self):
|
||||
self.assertEqual(xwiki_extension_status(f"MISSING::{EXTENSION}", "2.28.1"), 404)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -15,6 +15,10 @@ if TYPE_CHECKING:
|
||||
ROLE_DIR = PROJECT_ROOT / "roles" / "web-app-keycloak"
|
||||
LIB_PATH = PROJECT_ROOT / "library" / "keycloak_kcadm_update.py"
|
||||
MODUTILS_PATH = PROJECT_ROOT / "utils" / "kcadm_json.py"
|
||||
LOCK_ERROR = (
|
||||
"Failed to refresh access token - "
|
||||
"Failed to get lock on /opt/keycloak/.keycloak/kcadm.config"
|
||||
)
|
||||
|
||||
|
||||
def _load_py_module(name: str, path: Path):
|
||||
@@ -214,6 +218,46 @@ class TestKeycloakKcadmUpdate(unittest.TestCase):
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertEqual(len(calls), 1)
|
||||
|
||||
def test_run_kcadm_repeats_a_call_that_lost_the_config_lock(self):
|
||||
m = self.mod
|
||||
outcomes = [
|
||||
DummyCompleted(1, "", LOCK_ERROR),
|
||||
DummyCompleted(1, "", LOCK_ERROR),
|
||||
DummyCompleted(0, "[]", ""),
|
||||
]
|
||||
calls = []
|
||||
|
||||
def fake_run(cmd, **kwargs):
|
||||
calls.append(cmd)
|
||||
return outcomes[len(calls) - 1]
|
||||
|
||||
with (
|
||||
patch.object(m.subprocess, "run", side_effect=fake_run),
|
||||
patch.object(m.time, "sleep", return_value=None) as sleep,
|
||||
):
|
||||
rc, out, _err = m.run_kcadm(DummyModule(), "kcadm get clients")
|
||||
|
||||
self.assertEqual((rc, out), (0, "[]"))
|
||||
self.assertEqual(calls, ["kcadm get clients"] * 3)
|
||||
self.assertEqual(sleep.call_count, 2)
|
||||
|
||||
def test_run_kcadm_gives_up_on_a_config_lock_that_never_frees(self):
|
||||
m = self.mod
|
||||
calls = []
|
||||
|
||||
def fake_run(cmd, **kwargs):
|
||||
calls.append(cmd)
|
||||
return DummyCompleted(1, "", LOCK_ERROR)
|
||||
|
||||
with (
|
||||
patch.object(m.subprocess, "run", side_effect=fake_run),
|
||||
patch.object(m.time, "sleep", return_value=None),
|
||||
self.assertRaises(m.subprocess.CalledProcessError),
|
||||
):
|
||||
m.run_kcadm(DummyModule(), "kcadm get clients")
|
||||
|
||||
self.assertEqual(len(calls), m.CONFIG_LOCK_MAX_RETRIES + 1)
|
||||
|
||||
def test_get_current_object_parses_noisy(self):
|
||||
m = self.mod
|
||||
dummy = DummyModule()
|
||||
|
||||
Reference in new issue
Block a user