1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

feat(operations): job panel on the VM page

This commit is contained in:
catborise 2026-10-13 19:59:19 +03:00
parent 9c125aedd2
commit 9c7943a0c8
10 changed files with 469 additions and 13 deletions

View file

@ -64,6 +64,7 @@
<hr>
</div>
<div id="job-panel" aria-live="polite"></div>
<div id="mainTabMenu">
<!-- Nav tabs -->
<ul class="nav nav-pills nav-fill" id="navbtn" role="tablist" aria-label="Instance actions">
@ -681,6 +682,14 @@
return true;
});
</script>
<script src="{% static 'operations/job_panel.js' %}"></script>
<script>
jobPanel(document.getElementById("job-panel"), {
resource: "{% url 'operation-resource' %}?key=instance%3A{{ instance.uuid|urlencode }}",
job: function (id) { return "{% url 'operation-list' %}" + id + "/"; },
cancel: function (id) { return "{% url 'operation-list' %}" + id + "/cancel/"; },
}, "{{ csrf_token }}", {{ remembered_jobs|safe }});
</script>
<script src="{% static 'js/instance_tabs.js' %}"></script>
<script>
// Open the tab whose control targets "#<pane id>"

View file

@ -25,9 +25,7 @@
<div class="tab-content">
{% if busy %}
<div class="alert alert-warning mt-3" role="status">
{% trans "A snapshot job is running:" %}
{% for job in busy %}{{ job.dev }} {% widthratio job.cur job.end 100 %}%{% if not forloop.last %}, {% endif %}{% endfor %}.
{% trans "Reload the page to see its progress." %}
{% trans "A disk job is running on this VM; snapshot actions are unavailable until it ends." %}
</div>
{% endif %}
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="takesnapshot">

View file

@ -130,6 +130,21 @@ class PageControlsTestCase(PageControls, TestCase):
| {"clone", "snapshots", "console settings", "destroy", "host links"},
)
def test_the_job_panel_gets_the_jobs_just_submitted_once(self):
superuser = get_user_model().objects.create_superuser("ctl_jobs", "ctl_jobs@example.com", "x")
self.client.force_login(superuser)
session = self.client.session
other = {"resource": "instance:aaaaaaaa-bbbb-cccc-0000-111111111111", "id": "4343"}
session["operations_shown"] = [{"resource": f"instance:{self.instance.uuid}", "id": "4242"}, other]
session.save()
self.controls(superuser)
self.assertIn('["4242"]', self.last_page)
self.assertNotIn('"4343"', self.last_page)
# a job remembered for another VM waits for that VM's page
self.assertEqual(self.client.session["operations_shown"], [other])
self.controls(superuser)
self.assertNotIn('"4242"', self.last_page)
def test_global_viewers_see_nothing_to_act_on(self):
perms = ("view_instances", "clone_instances", "snapshot_instances")
for user in (self.user("ctl_viewer", perms=perms), self.user("ctl_staff", staff=True, perms=perms)):

View file

@ -191,9 +191,13 @@ class SnapshotTabTestCase(TestCase):
self.assertFalse(self.page(status=1).xpath("//input[@name='memory']")[0].get("disabled"))
self.assertIsNotNone(self.page(status=5).xpath("//input[@name='memory']")[0].get("disabled"))
def test_a_running_job_shows_progress_and_disables_actions(self):
def test_a_running_job_disables_actions(self):
# its progress shows in the job panel, not in the tab; the tab says why the actions are off
line = "A disk job is running on this VM; snapshot actions are unavailable until it ends."
doc = self.page(external=[self.snap("e")], jobs=[{"dev": "vda", "cur": 1, "end": 4}])
self.assertIn("vda 25%", doc.text_content())
self.assertIn(line, doc.text_content())
self.assertNotIn("vda 25%", doc.text_content())
self.assertNotIn(line, self.page(external=[self.snap("e")]).text_content())
self.assertTrue(all(b.get("disabled") is not None
for b in doc.xpath("//div[@id='snapshots']//button[@type='submit']")))

View file

@ -205,6 +205,7 @@ def _instance_page(request, pk, instance, compute):
instance.drbd = drbd_status(request, pk)
instance.save()
remembered_jobs = json.dumps(jobs.take_remembered(request, claims.instance_key(instance.uuid)))
return render(request, "instance.html", locals(),)