1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 01:16:10 +00:00

fix(vmbackups): a saved schedule says so; a finished job opens what it made

Saving a new or changed schedule took the user to the schedule's page,
which is its edit form and looked like the form they had just sent: it
seemed nothing was saved. Saving and deleting a schedule now go back to
the schedule list and say so; opening or closing a target to VM owners
says so too.

A finished job's page showed only its state and times: a restore did not
lead to the VM it made. The job page now opens what a job made (its
result's open), for every kind; reading a target's backups opens the
target. The one-disk restore form starts on the VM's host.
This commit is contained in:
catborise 2026-11-17 22:06:19 +03:00
parent 34dd721c11
commit 14ac7eba50
12 changed files with 154 additions and 85 deletions

Binary file not shown.

View file

@ -11,7 +11,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-17 17:12+0000\n"
"POT-Creation-Date: 2026-11-17 19:05+0000\n"
"PO-Revision-Date: 2020-11-04 12:00+0000\n"
"Last-Translator: catborise <muhammetalisag@gmail.com>, 2020\n"
"Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n"
@ -76,7 +76,7 @@ msgstr "Geçersiz anahtar"
#: networks/templates/network.html:373 nwfilters/templates/nwfilters.html:29
#: storages/templates/storage.html:123 virtsecrets/forms.py:34
#: virtsecrets/forms.py:36 vmbackups/forms.py:23 vmbackups/forms.py:36
#: vmbackups/forms.py:79 vmbackups/templates/vmbackups/policies.html:16
#: vmbackups/forms.py:81 vmbackups/templates/vmbackups/policies.html:16
#: vmbackups/templates/vmbackups/targets.html:17
msgid "Name"
msgstr "Ad"
@ -485,7 +485,7 @@ msgid "Starts with"
msgstr "Başlangıcı"
#: accounts/templates/api_token_list.html:18
#: operations/templates/operations/job.html:76
#: operations/templates/operations/job.html:79
msgid "Created"
msgstr "Oluşturulma"
@ -1013,7 +1013,7 @@ msgid "Done"
msgstr "Tamamlandı"
#: admin/templates/admin/logs.html:56 admin/views.py:395 logs/views.py:18
#: operations/templates/operations/job.html:107
#: operations/templates/operations/job.html:110
#: vmbackups/templates/vmbackups/index.html:33
#: vmbackups/templates/vmbackups/policy.html:38
#: vmbackups/templates/vmbackups/state.html:1
@ -8590,60 +8590,66 @@ msgid "Progress"
msgstr "İlerleme"
#: operations/templates/operations/job.html:54
#: operations/templatetags/operations.py:84
msgctxt "verb"
msgid "Open"
msgstr "Aç"
#: operations/templates/operations/job.html:57
msgid "Results"
msgstr "Sonuçlar"
#: operations/templates/operations/job.html:63
#: operations/templates/operations/job.html:66
msgid "Left behind"
msgstr "Geride kalanlar"
#: operations/templates/operations/job.html:69
#: operations/templates/operations/job.html:72
msgid "Resolution"
msgstr "Çözüm"
#: operations/templates/operations/job.html:81
#: operations/templates/operations/job.html:84
#: vmbackups/templates/vmbackups/policy.html:36
msgid "Started"
msgstr "Başlangıç"
#: operations/templates/operations/job.html:81
#: operations/templates/operations/job.html:84
#, python-format
msgid "queued for %(time)s"
msgstr "%(time)s kuyrukta"
#: operations/templates/operations/job.html:87
#: operations/templates/operations/job.html:90
msgid "Finished"
msgstr "Bitti"
#: operations/templates/operations/job.html:87
#: operations/templates/operations/job.html:90
#, python-format
msgid "ran for %(time)s"
msgstr "%(time)s çalıştı"
#: operations/templates/operations/job.html:97
#: operations/templates/operations/job.html:115
#: operations/templates/operations/job.html:100
#: operations/templates/operations/job.html:118
msgid "Resolve"
msgstr "Çöz"
#: operations/templates/operations/job.html:98
#: operations/templates/operations/job.html:101
msgid "Record what you checked; the job is marked succeeded or failed."
msgstr ""
"Neyi kontrol ettiğinizi kaydedin; iş başarılı ya da başarısız olarak "
"işaretlenir."
#: operations/templates/operations/job.html:101
#: operations/templates/operations/job.html:104
msgid "Resolve job form"
msgstr "İş çözme formu"
#: operations/templates/operations/job.html:104
#: operations/templates/operations/job.html:107
msgid "Outcome"
msgstr "Sonuç"
#: operations/templates/operations/job.html:106
#: operations/templates/operations/job.html:109
msgid "Succeeded"
msgstr "Başarılı"
#: operations/templates/operations/job.html:111
#: operations/templates/operations/job.html:114
msgid "What you checked"
msgstr "Neyi kontrol ettiniz"
@ -8727,11 +8733,6 @@ msgid_plural "%(count)d seconds"
msgstr[0] "%(count)d saniye"
msgstr[1] "%(count)d saniye"
#: operations/templatetags/operations.py:84
msgctxt "verb"
msgid "Open"
msgstr "Aç"
#: operations/templatetags/operations.py:86
msgid "Dismiss"
msgstr "Kapat"
@ -9790,39 +9791,39 @@ msgstr "Geri yüklendikten sonra başlat"
msgid "Volume name"
msgstr "Birim adı"
#: vmbackups/forms.py:79 vmbackups/templates/vmbackups/vm_tab.html:14
#: vmbackups/forms.py:81 vmbackups/templates/vmbackups/vm_tab.html:14
msgid "Backup target"
msgstr "Yedek hedefi"
#: vmbackups/forms.py:79
#: vmbackups/forms.py:81
msgid "Every VM of a compute"
msgstr "Bir sunucunun bütün sanal makineleri"
#: vmbackups/forms.py:80
#: vmbackups/forms.py:82
msgid "Or these VMs"
msgstr "Ya da bu sanal makineler"
#: vmbackups/forms.py:80 vmbackups/templates/vmbackups/policies.html:16
#: vmbackups/forms.py:82 vmbackups/templates/vmbackups/policies.html:16
msgid "Daily at"
msgstr "Her gün saat"
#: vmbackups/forms.py:80
#: vmbackups/forms.py:82
msgid "Backups kept per VM"
msgstr "VM başına tutulan yedek"
#: vmbackups/forms.py:81
#: vmbackups/forms.py:83
msgid "A full backup every N backups"
msgstr "Her N yedekte bir tam yedek"
#: vmbackups/forms.py:82 vmbackups/templates/vmbackups/vm_tab.html:22
#: vmbackups/forms.py:84 vmbackups/templates/vmbackups/vm_tab.html:22
msgid "Require frozen file systems"
msgstr "Dosya sistemlerinin dondurulmasını zorunlu kıl"
#: vmbackups/forms.py:82 vmbackups/templates/vmbackups/policies.html:28
#: vmbackups/forms.py:84 vmbackups/templates/vmbackups/policies.html:28
msgid "Enabled"
msgstr "Etkin"
#: vmbackups/forms.py:94
#: vmbackups/forms.py:96
msgid ""
"1: every backup is full. Above 1, the backups between copy only what changed "
"(running VMs with qcow2 disks)."
@ -9830,16 +9831,16 @@ msgstr ""
"1: her yedek tamdır. 1'den büyükse aradaki yedekler yalnızca değişenleri "
"kopyalar (qcow2 diskli, çalışan VM'ler)."
#: vmbackups/forms.py:101
#: vmbackups/forms.py:103
msgid "Choose a compute or VMs, not both"
msgstr "Bir sunucu ya da sanal makineler seçin, ikisini birden değil"
#: vmbackups/forms.py:106 vmbackups/jobs.py:106
#: vmbackups/forms.py:108 vmbackups/jobs.py:106
#, python-format
msgid "Backup target %(target)s has no storage pool on %(compute)s"
msgstr "%(target)s yedek hedefinin %(compute)s üzerinde depolama havuzu yok"
#: vmbackups/forms.py:113
#: vmbackups/forms.py:115
msgid "Keep one backup at least"
msgstr "En az bir yedek tutun"
@ -10631,7 +10632,7 @@ msgid "No backup target has a storage pool on this VM's host."
msgstr ""
"Hiçbir yedek hedefinin bu sanal makinenin sunucusunda depolama havuzu yok."
#: vmbackups/views.py:83 vmbackups/views.py:109
#: vmbackups/views.py:83 vmbackups/views.py:111
#, python-format
msgid "Backup target %(target)s has backups; delete them first"
msgstr "%(target)s yedek hedefinde yedekler var; önce onları silin"
@ -10641,7 +10642,18 @@ msgstr "%(target)s yedek hedefinde yedekler var; önce onları silin"
msgid "Backup target %(target)s has schedules; delete them first"
msgstr "%(target)s yedek hedefinin zamanlamaları var; önce onları silin"
#: vmbackups/views.py:126
#: vmbackups/views.py:95
#, python-format
msgid "VM owners with the backup permission may now use %(target)s."
msgstr ""
"Yedekleme izni olan VM sahipleri artık %(target)s hedefini kullanabilir."
#: vmbackups/views.py:96
#, python-format
msgid "Only superusers use %(target)s now."
msgstr "%(target)s hedefini artık yalnızca süper kullanıcılar kullanır."
#: vmbackups/views.py:128
#, python-format
msgid ""
"Storage pool %(pool)s of %(compute)s is not the same directory as storage "
@ -10650,15 +10662,25 @@ msgstr ""
"%(compute)s sunucusunun %(pool)s depolama havuzu, %(other_compute)s "
"sunucusunun %(other)s depolama havuzuyla aynı dizin değil"
#: vmbackups/views.py:162
#: vmbackups/views.py:164
msgid "Choose a backup target"
msgstr "Bir yedek hedefi seçin"
#: vmbackups/views.py:198
#: vmbackups/views.py:200
#, python-format
msgid "The backup of %(vm)s taken %(time)s is being deleted."
msgstr "%(vm)s VM'inin %(time)s tarihli yedeği siliniyor."
#: vmbackups/views.py:290 vmbackups/views.py:313
#, python-format
msgid "Backup schedule %(name)s is saved."
msgstr "%(name)s yedekleme zamanlaması kaydedildi."
#: vmbackups/views.py:304
#, python-format
msgid "Backup schedule %(name)s is deleted; its backups stay."
msgstr "%(name)s yedekleme zamanlaması silindi; yedekleri duruyor."
#: vrtManager/backup.py:35
#, python-format
msgid ""

Binary file not shown.

View file

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-17 17:12+0000\n"
"POT-Creation-Date: 2026-11-17 19:05+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
@ -73,7 +73,7 @@ msgstr "无效的密钥"
#: networks/templates/network.html:373 nwfilters/templates/nwfilters.html:29
#: storages/templates/storage.html:123 virtsecrets/forms.py:34
#: virtsecrets/forms.py:36 vmbackups/forms.py:23 vmbackups/forms.py:36
#: vmbackups/forms.py:79 vmbackups/templates/vmbackups/policies.html:16
#: vmbackups/forms.py:81 vmbackups/templates/vmbackups/policies.html:16
#: vmbackups/templates/vmbackups/targets.html:17
msgid "Name"
msgstr "名称"
@ -478,7 +478,7 @@ msgid "Starts with"
msgstr "开头"
#: accounts/templates/api_token_list.html:18
#: operations/templates/operations/job.html:76
#: operations/templates/operations/job.html:79
msgid "Created"
msgstr "创建时间"
@ -985,7 +985,7 @@ msgid "Done"
msgstr "完成"
#: admin/templates/admin/logs.html:56 admin/views.py:395 logs/views.py:18
#: operations/templates/operations/job.html:107
#: operations/templates/operations/job.html:110
#: vmbackups/templates/vmbackups/index.html:33
#: vmbackups/templates/vmbackups/policy.html:38
#: vmbackups/templates/vmbackups/state.html:1
@ -8091,58 +8091,64 @@ msgid "Progress"
msgstr "进度"
#: operations/templates/operations/job.html:54
#: operations/templatetags/operations.py:84
msgctxt "verb"
msgid "Open"
msgstr "打开"
#: operations/templates/operations/job.html:57
msgid "Results"
msgstr "结果"
#: operations/templates/operations/job.html:63
#: operations/templates/operations/job.html:66
msgid "Left behind"
msgstr "遗留项"
#: operations/templates/operations/job.html:69
#: operations/templates/operations/job.html:72
msgid "Resolution"
msgstr "处理结论"
#: operations/templates/operations/job.html:81
#: operations/templates/operations/job.html:84
#: vmbackups/templates/vmbackups/policy.html:36
msgid "Started"
msgstr "开始时间"
#: operations/templates/operations/job.html:81
#: operations/templates/operations/job.html:84
#, python-format
msgid "queued for %(time)s"
msgstr "排队 %(time)s"
#: operations/templates/operations/job.html:87
#: operations/templates/operations/job.html:90
msgid "Finished"
msgstr "完成时间"
#: operations/templates/operations/job.html:87
#: operations/templates/operations/job.html:90
#, python-format
msgid "ran for %(time)s"
msgstr "运行 %(time)s"
#: operations/templates/operations/job.html:97
#: operations/templates/operations/job.html:115
#: operations/templates/operations/job.html:100
#: operations/templates/operations/job.html:118
msgid "Resolve"
msgstr "处理"
#: operations/templates/operations/job.html:98
#: operations/templates/operations/job.html:101
msgid "Record what you checked; the job is marked succeeded or failed."
msgstr "记录你检查的内容;任务将被标记为成功或失败。"
#: operations/templates/operations/job.html:101
#: operations/templates/operations/job.html:104
msgid "Resolve job form"
msgstr "处理任务表单"
#: operations/templates/operations/job.html:104
#: operations/templates/operations/job.html:107
msgid "Outcome"
msgstr "处理结果"
#: operations/templates/operations/job.html:106
#: operations/templates/operations/job.html:109
msgid "Succeeded"
msgstr "成功"
#: operations/templates/operations/job.html:111
#: operations/templates/operations/job.html:114
msgid "What you checked"
msgstr "检查内容"
@ -8225,11 +8231,6 @@ msgid "%(count)d second"
msgid_plural "%(count)d seconds"
msgstr[0] "%(count)d 秒"
#: operations/templatetags/operations.py:84
msgctxt "verb"
msgid "Open"
msgstr "打开"
#: operations/templatetags/operations.py:86
msgid "Dismiss"
msgstr "关闭"
@ -9230,54 +9231,54 @@ msgstr "恢复后启动"
msgid "Volume name"
msgstr "卷名"
#: vmbackups/forms.py:79 vmbackups/templates/vmbackups/vm_tab.html:14
#: vmbackups/forms.py:81 vmbackups/templates/vmbackups/vm_tab.html:14
msgid "Backup target"
msgstr "备份目标"
#: vmbackups/forms.py:79
#: vmbackups/forms.py:81
msgid "Every VM of a compute"
msgstr "某计算节点的所有虚拟机"
#: vmbackups/forms.py:80
#: vmbackups/forms.py:82
msgid "Or these VMs"
msgstr "或这些虚拟机"
#: vmbackups/forms.py:80 vmbackups/templates/vmbackups/policies.html:16
#: vmbackups/forms.py:82 vmbackups/templates/vmbackups/policies.html:16
msgid "Daily at"
msgstr "每天时间"
#: vmbackups/forms.py:80
#: vmbackups/forms.py:82
msgid "Backups kept per VM"
msgstr "每台虚拟机保留的备份数"
#: vmbackups/forms.py:81
#: vmbackups/forms.py:83
msgid "A full backup every N backups"
msgstr "每 N 次备份进行一次完整备份"
#: vmbackups/forms.py:82 vmbackups/templates/vmbackups/vm_tab.html:22
#: vmbackups/forms.py:84 vmbackups/templates/vmbackups/vm_tab.html:22
msgid "Require frozen file systems"
msgstr "要求冻结文件系统"
#: vmbackups/forms.py:82 vmbackups/templates/vmbackups/policies.html:28
#: vmbackups/forms.py:84 vmbackups/templates/vmbackups/policies.html:28
msgid "Enabled"
msgstr "已启用"
#: vmbackups/forms.py:94
#: vmbackups/forms.py:96
msgid ""
"1: every backup is full. Above 1, the backups between copy only what changed "
"(running VMs with qcow2 disks)."
msgstr "1:每次备份都是完整备份。大于 1 时,中间的备份只复制变化的部分(适用于使用 qcow2 磁盘的运行中虚拟机)。"
#: vmbackups/forms.py:101
#: vmbackups/forms.py:103
msgid "Choose a compute or VMs, not both"
msgstr "请选择一个计算节点或若干虚拟机,不能同时选择"
#: vmbackups/forms.py:106 vmbackups/jobs.py:106
#: vmbackups/forms.py:108 vmbackups/jobs.py:106
#, python-format
msgid "Backup target %(target)s has no storage pool on %(compute)s"
msgstr "备份目标 %(target)s 在 %(compute)s 上没有存储池"
#: vmbackups/forms.py:113
#: vmbackups/forms.py:115
msgid "Keep one backup at least"
msgstr "至少保留一个备份"
@ -10001,7 +10002,7 @@ msgstr "没有向虚拟机所有者开放的备份目标在此虚拟机的主机
msgid "No backup target has a storage pool on this VM's host."
msgstr "没有备份目标在此虚拟机的主机上有存储池。"
#: vmbackups/views.py:83 vmbackups/views.py:109
#: vmbackups/views.py:83 vmbackups/views.py:111
#, python-format
msgid "Backup target %(target)s has backups; delete them first"
msgstr "备份目标 %(target)s 中有备份;请先删除它们"
@ -10011,22 +10012,42 @@ msgstr "备份目标 %(target)s 中有备份;请先删除它们"
msgid "Backup target %(target)s has schedules; delete them first"
msgstr "备份目标 %(target)s 有计划;请先删除它们"
#: vmbackups/views.py:126
#: vmbackups/views.py:95
#, python-format
msgid "VM owners with the backup permission may now use %(target)s."
msgstr "拥有备份权限的虚拟机所有者现在可以使用 %(target)s。"
#: vmbackups/views.py:96
#, python-format
msgid "Only superusers use %(target)s now."
msgstr "现在仅超级用户使用 %(target)s。"
#: vmbackups/views.py:128
#, python-format
msgid ""
"Storage pool %(pool)s of %(compute)s is not the same directory as storage "
"pool %(other)s of %(other_compute)s"
msgstr "%(compute)s 的存储池 %(pool)s 与 %(other_compute)s 的存储池 %(other)s 不是同一目录"
#: vmbackups/views.py:162
#: vmbackups/views.py:164
msgid "Choose a backup target"
msgstr "请选择备份目标"
#: vmbackups/views.py:198
#: vmbackups/views.py:200
#, python-format
msgid "The backup of %(vm)s taken %(time)s is being deleted."
msgstr "正在删除 %(vm)s 于 %(time)s 的备份。"
#: vmbackups/views.py:290 vmbackups/views.py:313
#, python-format
msgid "Backup schedule %(name)s is saved."
msgstr "备份计划 %(name)s 已保存。"
#: vmbackups/views.py:304
#, python-format
msgid "Backup schedule %(name)s is deleted; its backups stay."
msgstr "备份计划 %(name)s 已删除;其备份保留。"
#: vrtManager/backup.py:35
#, python-format
msgid ""

View file

@ -20,7 +20,7 @@
</div>
<div class="small text-body-secondary mt-1">{% trans "User" %}: {{ job.username }}</div>
</div>
{% if job.phase or op.progress_total or job.cancellable or job.error or job.result.links or job.result.warning or job.result.left_behind or job.resolution %}
{% if job.phase or op.progress_total or job.cancellable or job.error or job.result.open or job.result.links or job.result.warning or job.result.left_behind or job.resolution %}
<div class="card-body pb-0">
{% if job.phase or job.cancellable %}
<div class="d-flex flex-wrap align-items-center gap-2 mb-3">
@ -50,6 +50,9 @@
{% bs_icon 'exclamation-triangle' %} {{ job.error }}
</div>
{% endif %}
{% if job.result.open and op.state == "succeeded" %}
<a class="btn btn-primary mb-3" href="{{ job.result.open }}">{% trans "Open" context "verb" %} {% bs_icon 'arrow-right' %}</a>
{% endif %}
{% if job.result.links %}
<h2 class="h6">{% trans "Results" %}</h2>
<ul class="list-unstyled mb-3">

View file

@ -67,6 +67,15 @@ class JobsPageTestCase(TransactionTestCase):
self.assertContains(self.client.get(reverse("operations:jobs"), {"compute": "c"}), link)
self.assertNotContains(self.client.get(reverse("operations:jobs"), {"state": "failed"}), link)
def test_a_finished_job_opens_what_it_made(self):
from lxml import html as lxml_html
self.client.force_login(self.user)
page = lambda: lxml_html.fromstring(self.client.get(reverse("operations:job", args=[self.op.pk])).content)
self.assertFalse(page().xpath("//a[@href='/instances/7/']"))
jobs.finish(self.op, Outcome(Operation.SUCCEEDED, result={"open": "/instances/7/"}))
self.assertEqual(page().xpath("normalize-space(//a[@href='/instances/7/'])"), "Open")
def test_host_and_user_filters_match_part_of_the_name(self):
self.client.force_login(self.admin)
link = reverse("operations:job", args=[self.op.pk])

View file

@ -64,6 +64,8 @@ class RestoreDiskForm(forms.Form):
disks = list(backup.files.filter(role="disk").order_by("dev"))
self.fields["dev"].choices = [(d.dev, d.dev) for d in disks]
self.fields["compute"].queryset = Compute.objects.filter(backuptargetpool__target=backup.target).order_by("name")
if backup.instance_id: # the VM's host, when it has the target's pool
self.fields["compute"].initial = self.fields["compute"].queryset.filter(instance=backup.instance_id).first()
if disks:
first = disks[0]
self.fields["name"].initial = f"{backup.vm_name}-{first.dev}-restored.{'qcow2' if first.format == 'qcow2' else 'raw'}"

View file

@ -1295,7 +1295,7 @@ class ImportBackups(Kind):
Backup.objects.filter(pk=backup.pk).update(created_at=created_at)
BackupFile.objects.bulk_create(BackupFile(backup=backup, **f) for f in files)
added += 1
result = {"added": added}
result = {"added": added, "open": reverse("vmbackups:target", args=[target.pk])}
if incomplete:
result["warning"] = say(_("Not read, as a file of the backup is missing, changed or unreadable: %(names)s"),
names=", ".join(incomplete))

View file

@ -91,13 +91,15 @@ class ImportTests(TransactionTestCase):
return result
def test_new_manifests_are_added_once(self):
self.assertEqual(self.read(), {"added": 2})
result = self.read()
self.assertEqual(result["added"], 2)
self.assertEqual(result["open"], reverse("vmbackups:target", args=[self.target.pk])) # the job page opens it
backup = Backup.objects.get(uuid=self.a)
self.assertEqual((backup.state, backup.target, backup.instance, backup.vm_name, backup.consistency),
(Backup.READY, self.target, self.vm, "vm1", "frozen"))
self.assertEqual(backup.created_at.isoformat(), "2026-11-01T10:00:00+00:00")
self.assertEqual(sorted(backup.files.values_list("role", flat=True)), ["disk", "domain"])
self.assertEqual(self.read(), {"added": 0})
self.assertEqual(self.read()["added"], 0)
self.assertEqual(Backup.objects.count(), 2)
def test_a_chain_is_read_base_first_and_linked(self):
@ -109,7 +111,7 @@ class ImportTests(TransactionTestCase):
newer["parent"] = base
self.files[f"wvc-{base}-manifest.json"] = json.dumps(older).encode()
self.files[f"wvc-{top}-manifest.json"] = json.dumps(newer).encode()
self.assertEqual(self.read(), {"added": 2})
self.assertEqual(self.read()["added"], 2)
self.assertEqual(Backup.objects.get(uuid=top).parent, Backup.objects.get(uuid=base))
self.assertEqual(Backup.objects.get(uuid=base).checkpoint, f"wvc-{base}")

View file

@ -334,5 +334,6 @@ class OwnerTests(TransactionTestCase):
admin = get_user_model().objects.create_superuser("adm3", "c@example.com", "pw")
self.client.force_login(admin)
BackupTarget.objects.filter(pk=self.target.pk).update(owners=False)
self.client.post(reverse("vmbackups:target", args=[self.target.pk]), {"owners": "1"})
response = self.client.post(reverse("vmbackups:target", args=[self.target.pk]), {"owners": "1"}, follow=True)
self.assertTrue(BackupTarget.objects.get(pk=self.target.pk).owners)
self.assertContains(response, "VM owners with the backup permission may now use nfs1.")

View file

@ -34,7 +34,9 @@ class PolicyPageTests(TestCase):
def test_a_schedule_of_chosen_vms(self):
response = self.post(instances=[self.vm1.pk])
policy = BackupPolicy.objects.get()
self.assertRedirects(response, reverse("vmbackups:policy", args=[policy.pk]), fetch_redirect_response=False)
# back to the list, which says it is saved: the schedule's page is its edit form
self.assertRedirects(response, reverse("vmbackups:policies"), fetch_redirect_response=False)
self.assertContains(self.client.get(reverse("vmbackups:policies")), "Backup schedule nightly is saved.")
self.assertEqual((list(policy.instances.all()), policy.compute, policy.time, policy.keep, policy.owner),
([self.vm1], None, datetime.time(2), 7, self.admin))
self.assertTrue(Logs.objects.filter(message__contains="Backup schedule nightly").exists())
@ -82,6 +84,7 @@ class PolicyPageTests(TestCase):
"instances": [self.vm1.pk]})
policy.refresh_from_db()
self.assertEqual((policy.time, policy.keep, policy.enabled), (datetime.time(3, 30), 3, False))
self.assertContains(self.client.get(reverse("vmbackups:policies")), "Backup schedule nightly is saved.")
def test_delete_keeps_the_backups(self):
policy = self.schedule()
@ -91,6 +94,7 @@ class PolicyPageTests(TestCase):
self.assertRedirects(response, reverse("vmbackups:policies"), fetch_redirect_response=False)
self.assertFalse(BackupPolicy.objects.exists())
self.assertTrue(Backup.objects.filter(pk=backup.pk, policy=None).exists())
self.assertContains(self.client.get(reverse("vmbackups:policies")), "Backup schedule nightly is deleted")
def test_the_list_and_the_backups_page(self):
policy = self.schedule()

View file

@ -92,6 +92,8 @@ def target(request, target_id):
target.owners = request.POST["owners"] == "1"
with audit(request, None, subject, "open to VM owners" if target.owners else "closed to VM owners"):
target.save(update_fields=["owners"])
messages.success(request, _("VM owners with the backup permission may now use %(target)s.") % {"target": target.name}
if target.owners else _("Only superusers use %(target)s now.") % {"target": target.name})
return redirect("vmbackups:target", target.id)
if request.method == "POST" and "import" in request.POST:
try:
@ -285,7 +287,8 @@ def policies(request):
policy.owner = request.user
policy.save()
form.save_m2m()
return redirect("vmbackups:policy", policy.pk)
messages.success(request, _("Backup schedule %(name)s is saved.") % {"name": policy.name})
return redirect("vmbackups:policies")
rows = BackupPolicy.objects.select_related("target", "compute", "owner").annotate(vm_count=Count("instances"))
return render(request, "vmbackups/policies.html", {"policies": rows.order_by("name"), "form": form,
"time_zone": settings.TIME_ZONE})
@ -298,6 +301,7 @@ def policy(request, policy_id):
if request.method == "POST" and "delete" in request.POST:
with audit(request, None, subject, "delete"): # its backups stay, without a schedule
policy.delete()
messages.success(request, _("Backup schedule %(name)s is deleted; its backups stay.") % {"name": policy.name})
return redirect("vmbackups:policies")
form = PolicyForm(request.POST or None, instance=policy)
if form.is_valid():
@ -306,7 +310,8 @@ def policy(request, policy_id):
policy.owner = request.user
policy.save()
form.save_m2m()
return redirect("vmbackups:policy", policy.pk)
messages.success(request, _("Backup schedule %(name)s is saved.") % {"name": policy.name})
return redirect("vmbackups:policies")
runs = policy.runs.select_related("instance", "operation").order_by("-day", "instance__name")[:200]
return render(request, "vmbackups/policy.html", {"policy": policy, "form": form, "runs": runs,
"time_zone": settings.TIME_ZONE})