Merge lp:~gmb/maas/start-and-allocate-bug-1365591 into lp:~maas-committers/maas/trunk

Proposed by Graham Binns
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 3243
Proposed branch: lp:~gmb/maas/start-and-allocate-bug-1365591
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 70 lines (+37/-2)
2 files modified
src/maasserver/node_action.py (+12/-2)
src/maasserver/tests/test_node_action.py (+25/-0)
To merge this branch: bzr merge lp:~gmb/maas/start-and-allocate-bug-1365591
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Gavin Panella (community) Approve
Review via email: mp+238130@code.launchpad.net

Commit message

The "Start node" button in the UI now:
 - Also acquires the node for the user if it hasn't already been acquired.
 - Displays "Acquire and start node" if the node isn't allocated to the user, and "Start node" if it is.

Per comments on bug 1365591, I considered adding "(with default options)" to the button label, but until bug 1379187 is fixed, this is kind of meaningless and confusing.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) :
review: Approve
Revision history for this message
Raphaël Badin (rvb) wrote :

I think there is a small problem with this branch: you've implemented this in the UI code and thus if you try to 'start' a non-allocated from the API, it will fail. I think this difference is bad because you'll get two different behavior depending on where you perform the same action (UI vs. API).

Maybe you can salvage something from this: https://code.launchpad.net/~rvb/maas/bug-1365591-transparent-allocation/+merge/237778 (complete WIP that I started last week but didn't finish yet)

Revision history for this message
Raphaël Badin (rvb) wrote :

> I think this difference is bad because you'll get two different behavior depending on where you perform the same action (UI vs. API).

On second thought, this is wrong: this branch is adding a shortcut that we're free to decide not to add to the API.

review: Approve
Revision history for this message
Julian Edwards (julian-edwards) wrote :

On Monday 13 Oct 2014 10:44:27 you wrote:
> + @property
> + def display(self):
> + if self.node.owner == self.user:
> + label = "Start node"
> + else:
> + label = "Acquire and start node"
> + return label

Can we ever get in the situation where self.node.owner is set but is != to
self.user?

Revision history for this message
Graham Binns (gmb) wrote :

On 14 October 2014 00:12, Julian Edwards <email address hidden> wrote:
>
> Can we ever get in the situation where self.node.owner is set but is != to
> self.user?

Not one where this button will still be displayed, AFAICT, but I'll
double-check.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/node_action.py'
2--- src/maasserver/node_action.py 2014-10-08 22:56:31 +0000
3+++ src/maasserver/node_action.py 2014-10-13 10:43:54 +0000
4@@ -304,12 +304,19 @@
5 class StartNode(NodeAction):
6 """Start a node."""
7 name = "start"
8- display = "Start node"
9 display_bulk = "Start selected nodes"
10 actionable_statuses = (
11- NODE_STATUS.ALLOCATED, NODE_STATUS.DEPLOYED)
12+ NODE_STATUS.READY, NODE_STATUS.ALLOCATED, NODE_STATUS.DEPLOYED)
13 permission = NODE_PERMISSION.EDIT
14
15+ @property
16+ def display(self):
17+ if self.node.owner == self.user:
18+ label = "Start node"
19+ else:
20+ label = "Acquire and start node"
21+ return label
22+
23 def inhibit(self):
24 """The user must have an SSH key, so that they access the node."""
25 if not SSHKey.objects.get_keys_for_user(self.user).exists():
26@@ -323,6 +330,9 @@
27
28 def execute(self, allow_redirect=True):
29 """See `NodeAction.execute`."""
30+ if self.node.owner is None:
31+ self.node.acquire(self.user, token=None)
32+
33 try:
34 Node.objects.start_nodes([self.node.system_id], self.user)
35 except StaticIPAddressExhaustion:
36
37=== modified file 'src/maasserver/tests/test_node_action.py'
38--- src/maasserver/tests/test_node_action.py 2014-10-08 09:43:51 +0000
39+++ src/maasserver/tests/test_node_action.py 2014-10-13 10:43:54 +0000
40@@ -338,6 +338,31 @@
41 user.has_perm(NODE_PERMISSION.EDIT, node))
42 self.assertFalse(StartNode(node, user).is_permitted())
43
44+ def test_StartNode_allocates_node_if_node_not_already_allocated(self):
45+ self.patch(Node.objects, "start_nodes")
46+ user = factory.make_User()
47+ node = factory.make_Node(status=NODE_STATUS.READY)
48+ action = StartNode(node, user)
49+ action.execute()
50+
51+ self.assertEqual(user, node.owner)
52+ self.assertEqual(NODE_STATUS.ALLOCATED, node.status)
53+
54+ def test_StartNode_label_shows_allocate_if_unallocated(self):
55+ self.patch(Node.objects, "start_nodes")
56+ user = factory.make_User()
57+ node = factory.make_Node(status=NODE_STATUS.READY)
58+ action = StartNode(node, user)
59+ self.assertEqual("Acquire and start node", action.display)
60+
61+ def test_StartNode_label_hids_allocate_if_allocated(self):
62+ self.patch(Node.objects, "start_nodes")
63+ user = factory.make_User()
64+ node = factory.make_Node(status=NODE_STATUS.READY)
65+ node.acquire(user)
66+ action = StartNode(node, user)
67+ self.assertEqual("Start node", action.display)
68+
69
70 class TestStopNodeNodeAction(MAASServerTestCase):
71