mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(tags): second audit: unchanged saves, report, other lists, hosts list
- Saving a VM's tags unchanged writes no audit row. - The VM report has a Tags column. - A host's VM list and a user's VMs (account page) show the VMs' tags. - The hosts list says "No host matches the filters." with Clear the filters, as the VM list does; the tag list keeps to a phone's width with a long tag. - A removed VM's delete page says its owners and tags no longer come back; the VM history rows say "owners and tags kept/restored". - The API's ?tag= is trimmed; Tom Select's "Add tag" line shows the name in lower case as it is made; Bulk Migrate's tag list goes back to its title after a choice, so the same tag can be chosen again.
This commit is contained in:
parent
45225df1a4
commit
b74e798e70
23 changed files with 376 additions and 324 deletions
|
|
@ -40,6 +40,11 @@ class VmTagsTests(TestCase):
|
|||
self.assertEqual(list(Logs.objects.filter(message__startswith="VM").order_by("id").values_list("message", flat=True)),
|
||||
["VM vt-vm: tags new-one, prod", "VM vt-vm: tags none"])
|
||||
|
||||
def test_the_same_tags_again_are_no_change(self):
|
||||
self.post(self.admin, ["prod"])
|
||||
self.post(self.admin, ["PROD"])
|
||||
self.assertEqual(Logs.objects.filter(message__startswith="VM vt-vm: tags").count(), 1)
|
||||
|
||||
def test_a_bad_name_changes_nothing(self):
|
||||
self.vm.tags.add(Tag.objects.create(name="prod"))
|
||||
self.post(self.admin, ["two words"])
|
||||
|
|
@ -64,6 +69,14 @@ class VmTagsTests(TestCase):
|
|||
self.assertEqual(InstanceTombstone.objects.get().tags, ["prod"])
|
||||
self.assertFalse(Logs.objects.filter(message__startswith="VM vt-vm: tags").exists())
|
||||
|
||||
def test_the_host_s_vm_list_and_the_user_s_vms_show_them(self):
|
||||
self.vm.tags.add(Tag.objects.create(name="prod"))
|
||||
self.client.force_login(self.admin)
|
||||
with patch("computes.views.utils.refresh_instance_database"), patch("computes.views.vm_states", return_value={}), \
|
||||
patch("computes.views.read_list_rows"):
|
||||
self.assertContains(self.client.get(reverse("instances", args=[self.vm.compute_id])), "prod")
|
||||
self.assertContains(self.client.get(reverse("accounts:account", args=[self.owner.id])), "prod")
|
||||
|
||||
def test_the_vm_list_shows_them(self):
|
||||
self.vm.tags.add(Tag.objects.create(name="prod"))
|
||||
html = render_to_string("instance_name_cell.html", {"instance": self.vm})
|
||||
|
|
@ -138,11 +151,16 @@ class TagsApiTests(TestCase):
|
|||
self.assertEqual([(c["name"], c["tags"]) for c in self.client.get("/api/v1/computes/").json()],
|
||||
[("ta", ["prod"]), ("ta2", [])])
|
||||
self.assertEqual([c["name"] for c in self.client.get("/api/v1/computes/?tag=prod").json()], ["ta"])
|
||||
self.assertEqual([c["name"] for c in self.client.get("/api/v1/computes/?tag=PROD").json()], ["ta"])
|
||||
self.assertEqual([c["name"] for c in self.client.get("/api/v1/computes/?tag=%20PROD%20").json()], ["ta"])
|
||||
|
||||
def test_a_tag_asked_of_one_host_is_no_filter(self):
|
||||
self.assertEqual(self.client.get(f"/api/v1/computes/{self.compute.id}/?tag=other").status_code, 200)
|
||||
|
||||
def test_the_tags_are_not_set_through_the_api(self):
|
||||
self.client.patch(f"/api/v1/computes/{self.compute.id}/", {"tags": []}, content_type="application/json")
|
||||
self.assertTrue(self.compute.tags.exists())
|
||||
with patch("computes.models.Compute.clean"): # the host is not reached
|
||||
response = self.client.patch(f"/api/v1/computes/{self.compute.id}/", {"tags": [], "details": "rack 2"},
|
||||
content_type="application/json")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.compute.refresh_from_db()
|
||||
self.assertEqual((self.compute.details, list(self.compute.tags.values_list("name", flat=True))),
|
||||
("rack 2", ["prod"]))
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from io import BytesIO
|
|||
from unittest.mock import patch
|
||||
|
||||
from accounts.models import UserInstance
|
||||
from computes.models import Compute
|
||||
from computes.models import Compute, Tag
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.messages import get_messages
|
||||
|
|
@ -35,6 +35,7 @@ class VmReportTests(TestCase):
|
|||
self.c1 = Compute.objects.create(name="host-one", hostname="192.0.2.1", login="u", password="p", type=1)
|
||||
self.c2 = Compute.objects.create(name="host-two", hostname="192.0.2.2", login="u", password="p", type=1)
|
||||
self.a = Instance.objects.create(compute=self.c1, name="vm-a", uuid=UUID_A)
|
||||
self.a.tags.add(Tag.objects.create(name="web"), Tag.objects.create(name="prod"))
|
||||
Instance.objects.create(compute=self.c2, name="vm-b", uuid=UUID_B)
|
||||
UserInstance.objects.create(user=self.owner, instance=self.a)
|
||||
|
||||
|
|
@ -71,9 +72,9 @@ class VmReportTests(TestCase):
|
|||
self.assertRegex(response["Content-Disposition"], r'attachment; filename="vms-\d{8}-\d{4}\.xlsx"')
|
||||
rows, coverage = self.sheets(response)
|
||||
self.assertEqual(rows[0], ["VM", "State", "Host", "OS", "OS family", "vCPUs", "Memory (MiB)", "IP addresses",
|
||||
"Address sources", "MAC addresses", "Owners", "In the panel"])
|
||||
"Address sources", "MAC addresses", "Owners", "Tags", "In the panel"])
|
||||
self.assertEqual(rows[1], ["vm-a", "Active", "host-one", "AlmaLinux 10.0", "Linux", 2, 2048,
|
||||
"192.0.2.10, 2001:db8::10", "ARP, agent", "52:54:00:00:00:01", "vr-owner", "yes"])
|
||||
"192.0.2.10, 2001:db8::10", "ARP, agent", "52:54:00:00:00:01", "vr-owner", "prod, web", "yes"])
|
||||
self.assertEqual(rows[2][:3] + rows[2][-1:], ["made-with-virsh", "Off", "host-two", "no"])
|
||||
self.assertIn("Hosts not reached: host-three", coverage)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue