mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
feat(instances): a VM's power actions at a glance, a power cut asked first
The Power tab hid each action behind a sub-tab of one sentence and one button. The owner found the first rendered layouts crowded and chose a compact one: the VM's state, then the actions its state allows in two groups, those that keep the guest's data and the red ones that cut the power, each group with one short caption. Codex reviewed the power actions; these are fixed: - Power Cycle and Force Off ask first, naming the VM and what is lost, as the VM lists already did. - The words say what happens: Power Off asks the guest to shut down; Power Cycle cuts the power and starts the VM again, with its pending settings; Force Off cuts the power. - The tab follows states.allowed_actions, as the lists do; a running VM's actions now include Force Off there too. - A running template is not offered Power Cycle, which would start it again; a shut-off template says to clone it instead of showing a Power On button that only looked disabled. - A paused VM tells its owner that an administrator can resume it; it said an administrator had blocked it. - Power On's please-wait dialog opens on the form's submit, from the keyboard too.
This commit is contained in:
parent
f8e30d7668
commit
efb77dd866
5 changed files with 87 additions and 153 deletions
|
|
@ -88,7 +88,7 @@ class PageControls:
|
|||
"console": bool(doc.xpath("//button[@id='console_button']")),
|
||||
"vv file": bool(doc.xpath("//a[@href=$a]", a=reverse("instances:getvvfile", args=[pk]))),
|
||||
"vdi": bool(doc.xpath("//*[@id='vdiconsole']")),
|
||||
"power": form("poweroff") or form("poweron"),
|
||||
"power": form("poweron") or bool(doc.xpath("//button[@formaction=$a]", a=reverse("instances:poweroff", args=[pk]))),
|
||||
"root password": form("rootpasswd"),
|
||||
"ssh key": form("add_public_key"),
|
||||
# a running VM with hotplug shows per-vCPU buttons instead of the CPU form
|
||||
|
|
@ -197,6 +197,22 @@ class PageControlsTestCase(PageControls, TestCase):
|
|||
)
|
||||
self.assertEqual(bool(buttons), enabled)
|
||||
|
||||
def test_the_power_tab_offers_the_state_s_actions_and_confirms_a_power_cut(self):
|
||||
admin = get_user_model().objects.create_superuser("power_admin", "pa@example.com", "x")
|
||||
owner = self.user("power_owner", owner={})
|
||||
for user, status, names in ((admin, 1, ["poweroff", "suspend", "powercycle", "powerforce"]),
|
||||
(admin, 3, ["resume", "powerforce"]), (owner, 3, []), (admin, 5, ["poweron"])):
|
||||
with self.subTest(user=user.username, status=status):
|
||||
self.controls(user, status=status)
|
||||
(tab,) = lxml_html.fromstring(self.last_page).xpath("//div[@id='power']")
|
||||
self.assertEqual(tab.xpath(".//button/@name"), names)
|
||||
# the power-cut actions ask first
|
||||
self.assertTrue(all(b.get("data-confirm") for b in tab.xpath(".//button[contains(@class, 'btn-danger')]")))
|
||||
if user == owner:
|
||||
self.assertIn("The VM is paused. An administrator can resume it.", tab.text_content())
|
||||
if status == 5:
|
||||
self.assertEqual(tab.xpath(".//form/@onsubmit"), ["showPleaseWaitDialog()"])
|
||||
|
||||
def test_a_running_paused_or_shut_off_vm_can_be_cloned(self):
|
||||
changer = self.user("vm_cloner", perms=("clone_instances",), owner={"is_change": True})
|
||||
for status, enabled in ((1, True), (3, True), (5, True), (4, False)):
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ LABELS = {0: "No state", 1: "Active", 2: "Blocked", 3: "Suspended", 4: "Shutting
|
|||
# actions offered per state, for a superuser
|
||||
ACTIONS = {
|
||||
0: set(),
|
||||
1: {"poweroff", "powercycle", "suspend"},
|
||||
2: {"poweroff", "powercycle", "suspend"},
|
||||
1: {"poweroff", "powercycle", "force_off", "suspend"},
|
||||
2: {"poweroff", "powercycle", "force_off", "suspend"},
|
||||
3: {"resume", "force_off"},
|
||||
4: {"force_off"},
|
||||
5: {"poweron"},
|
||||
|
|
@ -248,6 +248,16 @@ class AllowedActionsTests(TestCase):
|
|||
self.assertEqual(allowed_actions(other, vm, state), set())
|
||||
|
||||
|
||||
class TemplatePowerTests(TestCase):
|
||||
"""A running template is not power cycled: that would start it again."""
|
||||
|
||||
def test_a_running_template_has_no_power_cycle(self):
|
||||
admin = get_user_model().objects.create_superuser("tp-admin", "tp@example.com", "pw")
|
||||
compute = Compute.objects.create(name="tp", hostname="10.0.0.5", login="u", password="p", type=1)
|
||||
vm = Instance.objects.create(compute=compute, name="tp-vm", uuid="dddddddd-0000-0000-0000-000000000000", is_template=True)
|
||||
self.assertEqual(allowed_actions(admin, vm, 1) - {"console"}, ACTIONS[1] - {"powercycle"})
|
||||
|
||||
|
||||
class TemplateCloneTests(TestCase):
|
||||
"""A shut-off template offers Clone to whoever may clone it, owner or not."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue