diff --git a/src/coulobre/hosting/templates/hosting/operator_tools.html b/src/coulobre/hosting/templates/hosting/operator_tools.html
index e761e9f..bcc2316 100644
--- a/src/coulobre/hosting/templates/hosting/operator_tools.html
+++ b/src/coulobre/hosting/templates/hosting/operator_tools.html
@@ -19,8 +19,8 @@
{% if job.action == 'package-preview' and job.result.fingerprint %}
{{ job.result.count }} package{{ job.result.count|pluralize }} ready to update.
{% for package in job.result.packages %}{{ package }} {% endfor %}
- {% elif job.action == 'database-report' and job.result.version %}
- MariaDB {{ job.result.version }} · Slow query logging {{ job.result.slow_logging|yesno:"enabled,disabled" }}
+ {% elif job.action == 'database-report' and job.result.database_version %}
+ MariaDB {{ job.result.database_version }} · Slow query logging {{ job.result.slow_logging|yesno:"enabled,disabled" }}
{% for key, value in job.result.counters.items %}- {{ key }}
- {{ value }}
{% endfor %}
{% endif %}
diff --git a/src/coulobre/hosting/test_operator_workspaces.py b/src/coulobre/hosting/test_operator_workspaces.py
index dbc32d1..9f5a5ac 100644
--- a/src/coulobre/hosting/test_operator_workspaces.py
+++ b/src/coulobre/hosting/test_operator_workspaces.py
@@ -1,4 +1,6 @@
import json
+from io import BytesIO, StringIO
+from types import SimpleNamespace
from unittest.mock import patch
from django.contrib.auth import get_user_model
@@ -8,12 +10,38 @@ from django.urls import reverse
from django_otp.plugins.otp_totp.models import TOTPDevice
from coulobre.mail_queue import MailQueueAction, change_queue_entry
-from coulobre.operator_node import OperatorRequest, packages
+from coulobre.operator_node import OperatorRequest, main, packages
from .models import PanelTheme
class OperatorRequestTests(SimpleTestCase):
+ def test_database_report_preserves_the_request_protocol_version(self):
+ request = OperatorRequest("database-report").manifest()
+ source = BytesIO(json.dumps(request).encode())
+ response = StringIO()
+ with (
+ patch("sys.stdin", SimpleNamespace(buffer=source)),
+ patch("sys.stdout", response),
+ patch("coulobre.operator_node.os.geteuid", return_value=0),
+ patch(
+ "coulobre.operator_node.command",
+ return_value="11.8.6-MariaDB\t0\nSlow_queries\t7\n",
+ ),
+ ):
+ self.assertEqual(main(), 0)
+ self.assertEqual(
+ json.loads(response.getvalue()),
+ request
+ | {
+ "state": "configured",
+ "problem": None,
+ "database_version": "11.8.6-MariaDB",
+ "slow_logging": False,
+ "counters": {"Slow_queries": "7"},
+ },
+ )
+
def test_unknown_services_and_changed_package_plans_are_rejected(self):
with self.assertRaises(ValueError):
OperatorRequest("restart", "ssh.service")
diff --git a/src/coulobre/operator_node.py b/src/coulobre/operator_node.py
index 4c79dd7..3599ff9 100644
--- a/src/coulobre/operator_node.py
+++ b/src/coulobre/operator_node.py
@@ -160,7 +160,7 @@ def database_report():
version, slow_log = rows[0]
counters = {key: value for key, value in rows[1:] if value.isdecimal()}
return {
- "version": version[:80],
+ "database_version": version[:80],
"slow_logging": slow_log == "1",
"counters": counters,
}