fix: name the user with getpass in sync failure alerts, which cron broke

This commit is contained in:
ponas committed 2026-11-02 01:31:03 +01:00
1 parent cb2784eec5
commit d43aa43186
4 files changed
+9 -7

No files matched your search

+2 -1
View File
@@ -1,3 +1,4 @@
import getpass
import os
from django.core.management.base import BaseCommand
@@ -64,7 +65,7 @@ class Command(BaseCommand):
self.stdout.write("fail\n")
message = (
"Failed to restart isc-dhcp-server, please inspect...\n\n"
f"{os.getlogin()}@{os.uname()[1]}$ {service.restart_command}\n{output}"
f"{getpass.getuser()}@{os.uname()[1]}$ {service.restart_command}\n{output}"
)
discord.notify(
subject=f"⚠️ FAIL: dhcpd {old_serial} -> {config.active_serial}",
+2 -1
View File
@@ -1,3 +1,4 @@
import getpass
import os
from django.core.management.base import BaseCommand
@@ -120,7 +121,7 @@ class Command(BaseCommand):
self, summary, failed_command, output, zones, errors="", diffs=""
):
zone_list = "\n".join("- " + z for z in zones)
message = f"{summary}, please inspect...\n\n{os.getlogin()}@{os.uname()[1]}$ {failed_command}\n{output}\n{zone_list}"
message = f"{summary}, please inspect...\n\n{getpass.getuser()}@{os.uname()[1]}$ {failed_command}\n{output}\n{zone_list}"
if errors:
message += "\n\n" + errors
discord.notify(
+2 -2
View File
@@ -115,7 +115,7 @@ def test_restart_and_notify_success_passes_diff_as_preformatted(cmd):
def test_restart_and_notify_failure_writes_fail_and_exits(cmd):
svc, config = make_service(restart_success=False, restart_output="Job failed")
with patch("mdb.management.commands.dhcp_sync.discord"):
with patch("os.getlogin", return_value="testuser"):
with patch("getpass.getuser", return_value="testuser"):
with pytest.raises(SystemExit) as exc:
cmd.restart_and_notify(svc, config, old_serial=1, diff="")
assert exc.value.code == 1
@@ -125,7 +125,7 @@ def test_restart_and_notify_failure_writes_fail_and_exits(cmd):
def test_restart_and_notify_failure_discord_includes_command_and_output(cmd):
svc, config = make_service(restart_success=False, restart_output="Job failed")
with patch("mdb.management.commands.dhcp_sync.discord") as mock_discord:
with patch("os.getlogin", return_value="testuser"):
with patch("getpass.getuser", return_value="testuser"):
with pytest.raises(SystemExit):
cmd.restart_and_notify(svc, config, old_serial=1, diff="")
subject = mock_discord.notify.call_args.kwargs["subject"]
+3 -3
View File
@@ -99,7 +99,7 @@ def test_reload_and_notify_failure_writes_fail_and_exits(cmd):
svc = make_service()
svc.reload.return_value = (False, "/usr/sbin/rndc reload", "timed out")
with patch("mdb.management.commands.zone_sync.discord"):
with patch("os.getlogin", return_value="testuser"):
with patch("getpass.getuser", return_value="testuser"):
with pytest.raises(SystemExit) as exc:
cmd.reload_and_notify(svc, svc.changes)
assert exc.value.code == 1
@@ -110,7 +110,7 @@ def test_reload_and_notify_failure_discord_includes_command_and_output(cmd):
svc = make_service()
svc.reload.return_value = (False, "/usr/sbin/rndc reload", "timed out")
with patch("mdb.management.commands.zone_sync.discord") as mock_discord:
with patch("os.getlogin", return_value="testuser"):
with patch("getpass.getuser", return_value="testuser"):
with pytest.raises(SystemExit):
cmd.reload_and_notify(svc, svc.changes)
subject = mock_discord.notify.call_args.kwargs["subject"]
@@ -187,7 +187,7 @@ def test_handle_writes_nothing_when_freeze_fails(cmd, db_domain):
),
patch.object(ZoneSyncService, "run_commands") as mock_run,
patch("mdb.management.commands.zone_sync.discord") as mock_discord,
patch("os.getlogin", return_value="testuser"),
patch("getpass.getuser", return_value="testuser"),
pytest.raises(SystemExit),
):
cmd.handle(debug=False, force=False, zone=None)