#!/bin/bash set -uo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" PYTHONPATH="$ROOT/lib" python3 - <<'PY' import tempfile from pathlib import Path from classroom_config import ensure_device_config, read_device_config passed = failed = 0 def check(label, condition, detail=""): global passed, failed if condition: print(f" ok {label}") passed += 1 else: print(f" FAIL {label}") if detail: print(f" {detail}") failed += 1 print("1. the room no longer keeps a list of dock buttons") check("dock_items is gone with the dock it described", not hasattr(__import__("classroom_config"), "dock_items")) check("and DVD_ENABLED with it, because the machine can be asked", "DVD_ENABLED" not in __import__("classroom_config").DEVICE_CONFIG_TEMPLATE) print("2. fresh device configuration") with tempfile.TemporaryDirectory() as directory: path = Path(directory) / "etc" / "device.conf" ensure_device_config(path) config = read_device_config(path) check("fresh config is created", path.is_file()) # Every classroom talks to the same broker, so a fresh machine is # pointed at it rather than left switched off waiting for somebody to # remember. The rooms that were set up before there was a broker are # brought to the same place by classroom-migrate. check("the broker is on by default", config.get("MQTT_ENABLED") == "true") check("and points at the church broker", config.get("MQTT_HOST") == "10.40.0.2") check("on the usual port", config.get("MQTT_PORT") == "1883") check("with no credentials invented for it", config.get("MQTT_USERNAME") == "" and config.get("MQTT_PASSWORD") == "") check("stable remains the fresh-install default", config.get("CHANNEL") == "stable") print() print("3. upgrade from 0.1.36") old = """# endpoint configuration from 0.1.36 UPDATE_URL=https://updates.example.test CHANNEL=canary DVD_ENABLED=true UI_SCALE=1.25 MQTT_ENABLED=true MQTT_HOST=broker.example.test MQTT_PORT=1884 MQTT_USERNAME=room MQTT_PASSWORD=secret CUSTOM_SETTING=keep-me """ with tempfile.TemporaryDirectory() as directory: path = Path(directory) / "device.conf" path.write_text(old) ensure_device_config(path) first = path.read_text() config = read_device_config(path) check("old bytes remain at the start", first.startswith(old)) check("channel survives", config.get("CHANNEL") == "canary") check("MQTT host survives", config.get("MQTT_HOST") == "broker.example.test") check("MQTT password survives", config.get("MQTT_PASSWORD") == "secret") check("unknown settings survive", config.get("CUSTOM_SETTING") == "keep-me") check("LIVE is appended once", first.count("LIVE_ENABLED=") == 1) ensure_device_config(path) second = path.read_text() check("reinstall makes no further change", second == first) check("LIVE still occurs once", second.count("LIVE_ENABLED=") == 1) print() print(f"passed: {passed} failed: {failed}") raise SystemExit(1 if failed else 0) PY