mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
fix(instances): a host in maintenance offers no new VM from its VM list
The host's VM list offered New Instance while the host was in maintenance; the create pages then refused it and sent the user to every VM's list. The button is disabled there, saying why, and a refused create page goes back to the page it was asked from, else the host's VM list.
This commit is contained in:
parent
adcf881028
commit
012eba0c80
3 changed files with 27 additions and 4 deletions
|
|
@ -7,10 +7,17 @@
|
|||
{% block page_heading %}{{ compute.name }} - {% trans "Instances" %}{% endblock page_heading %}
|
||||
|
||||
{% block page_heading_extra %}
|
||||
{% if compute.maintenance %}
|
||||
{# a disabled button shows no title: its wrapper says why #}
|
||||
<span class="d-inline-block mt-1 float-end" tabindex="0" title="{% blocktrans with compute=compute.name %}{{ compute }} is in maintenance: no new VM or migration comes to it{% endblocktrans %}">
|
||||
<button type="button" class="btn btn-success" disabled aria-label="{% trans "New Instance" %}">{% bs_icon 'plus-circle-fill' %}</button>
|
||||
</span>
|
||||
{% else %}
|
||||
<a href="{% url 'instances:create_instance_select_type' compute.id %}"
|
||||
class="btn btn-success mt-1 float-end" title="{% trans "New Instance" %}">
|
||||
{% bs_icon 'plus-circle-fill' %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if instances %}
|
||||
<a href="{% url 'bulk_migrate' compute.id %}" class="btn btn-outline-primary mt-1 me-1 float-end">{% trans "Bulk Migrate" %}</a>
|
||||
{% include 'search_block.html' %}
|
||||
|
|
|
|||
|
|
@ -55,12 +55,27 @@ class MaintenanceSwitchTests(TestCase):
|
|||
def test_a_vm_cannot_be_created_from_its_pages(self):
|
||||
self.compute.maintenance_since = timezone.now()
|
||||
self.compute.save()
|
||||
host_vms = reverse("instances", args=[self.compute.pk])
|
||||
for url in (reverse("instances:create_instance_select_type", args=[self.compute.pk]),
|
||||
reverse("instances:create_instance", args=[self.compute.pk, "x86_64", "q35"])):
|
||||
response = self.client.get(url, follow=True)
|
||||
self.assertRedirects(response, reverse("instances:index"))
|
||||
# back to the page it was asked from (the host's VM list), not every VM's
|
||||
response = self.client.get(url, HTTP_REFERER=f"http://testserver{host_vms}")
|
||||
self.assertEqual(response.url, f"http://testserver{host_vms}")
|
||||
response = self.client.get(url, follow=True) # typed in: the host's VM list too
|
||||
self.assertRedirects(response, host_vms)
|
||||
self.assertContains(response, f"mt {REFUSED}")
|
||||
|
||||
def test_the_host_vm_list_offers_no_new_vm(self):
|
||||
from lxml import html as lxml_html
|
||||
|
||||
page = lambda: lxml_html.fromstring(self.client.get(reverse("instances", args=[self.compute.pk])).content)
|
||||
create = reverse("instances:create_instance_select_type", args=[self.compute.pk])
|
||||
self.assertTrue(page().xpath("//a[@href=$u]", u=create))
|
||||
self.compute.maintenance_since = timezone.now()
|
||||
self.compute.save()
|
||||
self.assertFalse(page().xpath("//a[@href=$u]", u=create))
|
||||
self.assertTrue(page().xpath("//button[@disabled][contains(@aria-label, 'New Instance')]"))
|
||||
|
||||
|
||||
class MaintenanceGuardTests(TestCase):
|
||||
def setUp(self):
|
||||
|
|
|
|||
|
|
@ -2555,12 +2555,13 @@ def getvvfile(request, pk):
|
|||
|
||||
|
||||
def in_maintenance(request, compute):
|
||||
"""Back to the VM list, saying why, when the host a VM is made on is in maintenance."""
|
||||
"""Back to the page it was asked from (else the host's VM list), saying
|
||||
why, when the host a VM is made on is in maintenance."""
|
||||
try:
|
||||
compute.refuse_new_vms()
|
||||
except util.OperationError as err:
|
||||
messages.error(request, str(err))
|
||||
return redirect("instances:index")
|
||||
return redirect(same_origin_referer(request, reverse("instances", args=[compute.pk])))
|
||||
return None
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue