issue-7-config-cleanup-legacy-removal #18
@@ -83,7 +83,6 @@ OUTPUT_SCHEMA = Schema(
|
|||||||
GLOBAL_SCHEMA = Schema(
|
GLOBAL_SCHEMA = Schema(
|
||||||
fields={
|
fields={
|
||||||
"backup_root": FieldSpec(str, required=True),
|
"backup_root": FieldSpec(str, required=True),
|
||||||
"pobsync_home": FieldSpec(str, required=False, default="/opt/pobsync"),
|
|
||||||
"ssh": FieldSpec(dict, required=False, schema=SSH_SCHEMA),
|
"ssh": FieldSpec(dict, required=False, schema=SSH_SCHEMA),
|
||||||
"rsync": FieldSpec(dict, required=False, schema=RSYNC_SCHEMA),
|
"rsync": FieldSpec(dict, required=False, schema=RSYNC_SCHEMA),
|
||||||
"defaults": FieldSpec(dict, required=False, schema=DEFAULTS_SCHEMA),
|
"defaults": FieldSpec(dict, required=False, schema=DEFAULTS_SCHEMA),
|
||||||
@@ -131,4 +130,3 @@ HOST_SCHEMA = Schema(
|
|||||||
},
|
},
|
||||||
allow_unknown=False,
|
allow_unknown=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ class ConfigRepositoryError(RuntimeError):
|
|||||||
def _global_runtime_data(global_config: GlobalConfig) -> dict[str, Any]:
|
def _global_runtime_data(global_config: GlobalConfig) -> dict[str, Any]:
|
||||||
data = {
|
data = {
|
||||||
"backup_root": global_config.backup_root,
|
"backup_root": global_config.backup_root,
|
||||||
"pobsync_home": global_config.pobsync_home,
|
|
||||||
"ssh": {
|
"ssh": {
|
||||||
"user": global_config.ssh_user,
|
"user": global_config.ssh_user,
|
||||||
"port": global_config.ssh_port,
|
"port": global_config.ssh_port,
|
||||||
|
|||||||
@@ -119,7 +119,6 @@ class GlobalConfigForm(forms.ModelForm):
|
|||||||
def save(self, commit: bool = True):
|
def save(self, commit: bool = True):
|
||||||
instance = super().save(commit=False)
|
instance = super().save(commit=False)
|
||||||
instance.backup_root = settings.POBSYNC_BACKUP_ROOT
|
instance.backup_root = settings.POBSYNC_BACKUP_ROOT
|
||||||
instance.pobsync_home = settings.POBSYNC_HOME
|
|
||||||
if commit:
|
if commit:
|
||||||
instance.save()
|
instance.save()
|
||||||
self.save_m2m()
|
self.save_m2m()
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
|
||||||
from pobsync.config.retention import parse_retention
|
from pobsync.config.retention import parse_retention
|
||||||
@@ -18,7 +16,6 @@ class Command(BaseCommand):
|
|||||||
def add_arguments(self, parser) -> None:
|
def add_arguments(self, parser) -> None:
|
||||||
parser.add_argument("--name", default="default")
|
parser.add_argument("--name", default="default")
|
||||||
parser.add_argument("--backup-root", required=True)
|
parser.add_argument("--backup-root", required=True)
|
||||||
parser.add_argument("--pobsync-home", default=settings.POBSYNC_HOME, help="Runtime state root")
|
|
||||||
parser.add_argument("--ssh-user", default="root")
|
parser.add_argument("--ssh-user", default="root")
|
||||||
parser.add_argument("--ssh-port", type=int, default=22)
|
parser.add_argument("--ssh-port", type=int, default=22)
|
||||||
parser.add_argument("--source-root", default="/")
|
parser.add_argument("--source-root", default="/")
|
||||||
@@ -30,11 +27,9 @@ class Command(BaseCommand):
|
|||||||
if not is_absolute_non_root(backup_root):
|
if not is_absolute_non_root(backup_root):
|
||||||
raise CommandError("--backup-root must be an absolute path and must not be '/'")
|
raise CommandError("--backup-root must be an absolute path and must not be '/'")
|
||||||
|
|
||||||
pobsync_home = str(Path(options["pobsync_home"]))
|
|
||||||
retention = parse_retention(options["retention"])
|
retention = parse_retention(options["retention"])
|
||||||
defaults = {
|
defaults = {
|
||||||
"backup_root": backup_root,
|
"backup_root": backup_root,
|
||||||
"pobsync_home": pobsync_home,
|
|
||||||
"ssh_user": options["ssh_user"],
|
"ssh_user": options["ssh_user"],
|
||||||
"ssh_port": options["ssh_port"],
|
"ssh_port": options["ssh_port"],
|
||||||
"ssh_options": ["-oBatchMode=yes", "-oStrictHostKeyChecking=accept-new"],
|
"ssh_options": ["-oBatchMode=yes", "-oStrictHostKeyChecking=accept-new"],
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("pobsync_backend", "0009_remove_scheduleconfig_user"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="globalconfig",
|
||||||
|
name="pobsync_home",
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -14,7 +14,6 @@ class TimestampedModel(models.Model):
|
|||||||
class GlobalConfig(TimestampedModel):
|
class GlobalConfig(TimestampedModel):
|
||||||
name = models.CharField(max_length=64, default="default", unique=True)
|
name = models.CharField(max_length=64, default="default", unique=True)
|
||||||
backup_root = models.CharField(max_length=512)
|
backup_root = models.CharField(max_length=512)
|
||||||
pobsync_home = models.CharField(max_length=512, default="/opt/pobsync")
|
|
||||||
default_ssh_credential = models.ForeignKey(
|
default_ssh_credential = models.ForeignKey(
|
||||||
"SshCredential",
|
"SshCredential",
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ class ConfigRepositoryTests(TestCase):
|
|||||||
GlobalConfig.objects.create(
|
GlobalConfig.objects.create(
|
||||||
name="default",
|
name="default",
|
||||||
backup_root="/backups",
|
backup_root="/backups",
|
||||||
pobsync_home="/var/lib/pobsync",
|
|
||||||
ssh_user="backup",
|
ssh_user="backup",
|
||||||
ssh_port=2222,
|
ssh_port=2222,
|
||||||
rsync_args=["--archive"],
|
rsync_args=["--archive"],
|
||||||
@@ -22,7 +21,6 @@ class ConfigRepositoryTests(TestCase):
|
|||||||
retention_yearly=1,
|
retention_yearly=1,
|
||||||
data={
|
data={
|
||||||
"backup_root": "/ignored",
|
"backup_root": "/ignored",
|
||||||
"pobsync_home": "/ignored",
|
|
||||||
"ssh": {"user": "ignored", "port": 22, "options": []},
|
"ssh": {"user": "ignored", "port": 22, "options": []},
|
||||||
"unknown": "must-not-leak",
|
"unknown": "must-not-leak",
|
||||||
"retention_defaults": {"daily": 99, "weekly": 99, "monthly": 99, "yearly": 99},
|
"retention_defaults": {"daily": 99, "weekly": 99, "monthly": 99, "yearly": 99},
|
||||||
@@ -51,7 +49,6 @@ class ConfigRepositoryTests(TestCase):
|
|||||||
host_cfg = host_config_data("web-01")
|
host_cfg = host_config_data("web-01")
|
||||||
|
|
||||||
self.assertEqual(global_cfg["backup_root"], "/backups")
|
self.assertEqual(global_cfg["backup_root"], "/backups")
|
||||||
self.assertEqual(global_cfg["pobsync_home"], "/var/lib/pobsync")
|
|
||||||
self.assertEqual(global_cfg["ssh"]["user"], "backup")
|
self.assertEqual(global_cfg["ssh"]["user"], "backup")
|
||||||
self.assertEqual(global_cfg["ssh"]["port"], 2222)
|
self.assertEqual(global_cfg["ssh"]["port"], 2222)
|
||||||
self.assertEqual(global_cfg["retention_defaults"]["daily"], 7)
|
self.assertEqual(global_cfg["retention_defaults"]["daily"], 7)
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ class ConfigureCommandsTests(TestCase):
|
|||||||
call_command(
|
call_command(
|
||||||
"configure_pobsync_global",
|
"configure_pobsync_global",
|
||||||
backup_root="/backups",
|
backup_root="/backups",
|
||||||
pobsync_home="/opt/pobsync",
|
|
||||||
retention="daily=3,weekly=2,monthly=1,yearly=0",
|
retention="daily=3,weekly=2,monthly=1,yearly=0",
|
||||||
stdout=out,
|
stdout=out,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class DjangoConfigSourceTests(TestCase):
|
|||||||
GlobalConfig.objects.create(
|
GlobalConfig.objects.create(
|
||||||
name="default",
|
name="default",
|
||||||
backup_root="/backups",
|
backup_root="/backups",
|
||||||
pobsync_home="/opt/pobsync",
|
|
||||||
rsync_args=["--archive"],
|
rsync_args=["--archive"],
|
||||||
rsync_extra_args=["--numeric-ids"],
|
rsync_extra_args=["--numeric-ids"],
|
||||||
excludes_default=["/proc/***"],
|
excludes_default=["/proc/***"],
|
||||||
@@ -25,7 +24,6 @@ class DjangoConfigSourceTests(TestCase):
|
|||||||
retention_yearly=1,
|
retention_yearly=1,
|
||||||
data={
|
data={
|
||||||
"backup_root": "/ignored",
|
"backup_root": "/ignored",
|
||||||
"pobsync_home": "/ignored",
|
|
||||||
"ssh": {"user": "root", "port": 22, "options": []},
|
"ssh": {"user": "root", "port": 22, "options": []},
|
||||||
"rsync": {
|
"rsync": {
|
||||||
"binary": "rsync",
|
"binary": "rsync",
|
||||||
@@ -72,7 +70,6 @@ class DjangoConfigSourceTests(TestCase):
|
|||||||
GlobalConfig.objects.create(
|
GlobalConfig.objects.create(
|
||||||
name="default",
|
name="default",
|
||||||
backup_root="/backups",
|
backup_root="/backups",
|
||||||
pobsync_home="/opt/pobsync",
|
|
||||||
default_ssh_credential=credential,
|
default_ssh_credential=credential,
|
||||||
ssh_options=["-oBatchMode=yes"],
|
ssh_options=["-oBatchMode=yes"],
|
||||||
)
|
)
|
||||||
@@ -99,7 +96,6 @@ class DjangoConfigSourceTests(TestCase):
|
|||||||
GlobalConfig.objects.create(
|
GlobalConfig.objects.create(
|
||||||
name="default",
|
name="default",
|
||||||
backup_root="/backups",
|
backup_root="/backups",
|
||||||
pobsync_home="/opt/pobsync",
|
|
||||||
default_ssh_credential=global_credential,
|
default_ssh_credential=global_credential,
|
||||||
)
|
)
|
||||||
HostConfig.objects.create(
|
HostConfig.objects.create(
|
||||||
@@ -127,7 +123,6 @@ class DjangoConfigSourceTests(TestCase):
|
|||||||
GlobalConfig.objects.create(
|
GlobalConfig.objects.create(
|
||||||
name="default",
|
name="default",
|
||||||
backup_root="/backups",
|
backup_root="/backups",
|
||||||
pobsync_home="/opt/pobsync",
|
|
||||||
default_ssh_credential=credential,
|
default_ssh_credential=credential,
|
||||||
)
|
)
|
||||||
HostConfig.objects.create(host="web-01", address="web-01.example.test")
|
HostConfig.objects.create(host="web-01", address="web-01.example.test")
|
||||||
@@ -146,7 +141,6 @@ class DjangoConfigSourceTests(TestCase):
|
|||||||
GlobalConfig.objects.create(
|
GlobalConfig.objects.create(
|
||||||
name="default",
|
name="default",
|
||||||
backup_root="/backups",
|
backup_root="/backups",
|
||||||
pobsync_home="/opt/pobsync",
|
|
||||||
default_ssh_credential=credential,
|
default_ssh_credential=credential,
|
||||||
)
|
)
|
||||||
HostConfig.objects.create(host="web-01", address="web-01.example.test")
|
HostConfig.objects.create(host="web-01", address="web-01.example.test")
|
||||||
|
|||||||
@@ -475,7 +475,6 @@ class ViewTests(TestCase):
|
|||||||
self.assertContains(response, "Global config saved for default.")
|
self.assertContains(response, "Global config saved for default.")
|
||||||
config = GlobalConfig.objects.get(name="default")
|
config = GlobalConfig.objects.get(name="default")
|
||||||
self.assertEqual(config.backup_root, "/backups")
|
self.assertEqual(config.backup_root, "/backups")
|
||||||
self.assertEqual(config.pobsync_home, "/opt/pobsync")
|
|
||||||
self.assertEqual(config.default_ssh_credential, credential)
|
self.assertEqual(config.default_ssh_credential, credential)
|
||||||
self.assertEqual(config.ssh_user, "backup")
|
self.assertEqual(config.ssh_user, "backup")
|
||||||
self.assertEqual(config.ssh_port, 2222)
|
self.assertEqual(config.ssh_port, 2222)
|
||||||
@@ -502,7 +501,6 @@ class ViewTests(TestCase):
|
|||||||
GlobalConfig.objects.create(
|
GlobalConfig.objects.create(
|
||||||
name="default",
|
name="default",
|
||||||
backup_root="/mnt/pobsync/backups",
|
backup_root="/mnt/pobsync/backups",
|
||||||
pobsync_home="/custom/state/home",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
response = self.client.get(reverse("edit_global_config"))
|
response = self.client.get(reverse("edit_global_config"))
|
||||||
@@ -532,7 +530,6 @@ class ViewTests(TestCase):
|
|||||||
GlobalConfig.objects.create(
|
GlobalConfig.objects.create(
|
||||||
name="default",
|
name="default",
|
||||||
backup_root="/mnt/pobsync/backups",
|
backup_root="/mnt/pobsync/backups",
|
||||||
pobsync_home="/custom/state/home",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
@@ -561,7 +558,6 @@ class ViewTests(TestCase):
|
|||||||
self.assertRedirects(response, reverse("dashboard"))
|
self.assertRedirects(response, reverse("dashboard"))
|
||||||
config = GlobalConfig.objects.get(name="default")
|
config = GlobalConfig.objects.get(name="default")
|
||||||
self.assertEqual(config.backup_root, "/backups")
|
self.assertEqual(config.backup_root, "/backups")
|
||||||
self.assertEqual(config.pobsync_home, "/opt/pobsync")
|
|
||||||
|
|
||||||
def test_create_host_config_form_creates_host(self) -> None:
|
def test_create_host_config_form_creates_host(self) -> None:
|
||||||
self.client.force_login(self.staff_user)
|
self.client.force_login(self.staff_user)
|
||||||
|
|||||||
Reference in New Issue
Block a user