(refactor) Remove unused schedule user field

Drop the legacy schedule user setting from the Django model, form, defaults,
and configure command.

Schedules are executed by the pobsync scheduler service under the configured
systemd service user, while remote SSH login users are configured separately
on global or host backup config.

Add a migration to remove the unused database column and update schedule
view tests around the simplified form.
This commit is contained in:
2026-05-19 23:41:55 +02:00
parent 5ca2733ea9
commit c2d7342a47
6 changed files with 15 additions and 11 deletions

View File

@@ -277,7 +277,6 @@ class ScheduleConfigForm(forms.ModelForm):
model = ScheduleConfig
fields = (
"cron_expr",
"user",
"enabled",
"prune",
"prune_max_delete",

View File

@@ -14,7 +14,6 @@ class Command(BaseCommand):
def add_arguments(self, parser) -> None:
parser.add_argument("host")
parser.add_argument("--cron", help='Cron expression, e.g. "15 2 * * *"')
parser.add_argument("--user", default="root")
parser.add_argument("--prune", action="store_true")
parser.add_argument("--prune-max-delete", type=int, default=10)
parser.add_argument("--prune-protect-bases", action="store_true")
@@ -43,7 +42,6 @@ class Command(BaseCommand):
host=host,
defaults={
"cron_expr": options["cron"],
"user": options["user"],
"enabled": not options["disabled"],
"prune": bool(options["prune"]),
"prune_max_delete": int(options["prune_max_delete"]),

View File

@@ -0,0 +1,14 @@
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("pobsync_backend", "0008_alter_backuprun_status"),
]
operations = [
migrations.RemoveField(
model_name="scheduleconfig",
name="user",
),
]

View File

@@ -174,7 +174,6 @@ class SnapshotRecord(models.Model):
class ScheduleConfig(TimestampedModel):
host = models.OneToOneField(HostConfig, on_delete=models.CASCADE, related_name="schedule")
cron_expr = models.CharField(max_length=128)
user = models.CharField(max_length=64, default="root")
enabled = models.BooleanField(default=True)
prune = models.BooleanField(default=False)
prune_max_delete = models.PositiveIntegerField(default=10)

View File

@@ -1162,7 +1162,6 @@ class ViewTests(TestCase):
reverse("edit_host_schedule", args=[host.host]),
{
"cron_expr": "30 3 * * *",
"user": "root",
"enabled": "on",
"prune": "on",
"prune_max_delete": "4",
@@ -1189,7 +1188,6 @@ class ViewTests(TestCase):
reverse("edit_host_schedule", args=[host.host]),
{
"cron_expr": "45 4 * * 1",
"user": "backup",
"prune_max_delete": "8",
},
follow=True,
@@ -1198,7 +1196,6 @@ class ViewTests(TestCase):
self.assertRedirects(response, reverse("host_detail", args=[host.host]))
schedule.refresh_from_db()
self.assertEqual(schedule.cron_expr, "45 4 * * 1")
self.assertEqual(schedule.user, "backup")
self.assertFalse(schedule.enabled)
self.assertFalse(schedule.prune)
self.assertEqual(schedule.prune_max_delete, 8)
@@ -1209,7 +1206,6 @@ class ViewTests(TestCase):
ScheduleConfig.objects.create(
host=host,
cron_expr="45 4 * * 1",
user="backup",
enabled=True,
prune_max_delete=8,
)
@@ -1219,9 +1215,9 @@ class ViewTests(TestCase):
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Edit Schedule")
self.assertContains(response, 'value="45 4 * * 1"', html=False)
self.assertContains(response, 'value="backup"', html=False)
self.assertContains(response, 'value="8"', html=False)
self.assertNotContains(response, 'value="15 2 * * *"', html=False)
self.assertNotContains(response, ">User<", html=False)
def test_schedule_form_rejects_invalid_cron(self) -> None:
self.client.force_login(self.staff_user)
@@ -1231,7 +1227,6 @@ class ViewTests(TestCase):
reverse("edit_host_schedule", args=[host.host]),
{
"cron_expr": "bad cron",
"user": "root",
"enabled": "on",
"prune_max_delete": "10",
},

View File

@@ -575,7 +575,6 @@ def _next_run_for_schedule(schedule: ScheduleConfig | None, host_config: HostCon
def _default_schedule_initial() -> dict[str, object]:
return {
"cron_expr": "15 2 * * *",
"user": "root",
"enabled": True,
"prune_max_delete": 10,
}