Merge lp:~allenap/maas/dont-crash-when-selecting-fpi--bug-1293676 into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: 2223
Merged at revision: 2221
Proposed branch: lp:~allenap/maas/dont-crash-when-selecting-fpi--bug-1293676
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 132 lines (+59/-4)
3 files modified
src/maasserver/models/node.py (+4/-4)
src/maasserver/node_action.py (+25/-0)
src/maasserver/tests/test_node_action.py (+30/-0)
To merge this branch: bzr merge lp:~allenap/maas/dont-crash-when-selecting-fpi--bug-1293676
Reviewer Review Type Date Requested Status
Graham Binns (community) Approve
Review via email: mp+213887@code.launchpad.net

Commit message

Inhibit the controls to change between fast and default installers when the use-fastpath-installer tag is defined with an expression.

Description of the change

Drive-by change: I updated the error messages in the Node model (relating to installer choice) to match the terminology used in the UI.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/models/node.py'
2--- src/maasserver/models/node.py 2014-03-27 17:52:53 +0000
3+++ src/maasserver/models/node.py 2014-04-02 16:50:35 +0000
4@@ -837,8 +837,8 @@
5 if uti_tag.is_defined:
6 raise RuntimeError(
7 "The use-fastpath-installer tag is defined with an "
8- "expression. This expression must be updated to prevent "
9- "this node from booting with the Fast Path installer.")
10+ "expression. This expression must instead be updated to set "
11+ "this node to install with the default installer.")
12 self.tags.remove(uti_tag)
13
14 def use_fastpath_installer(self):
15@@ -856,6 +856,6 @@
16 if uti_tag.is_defined:
17 raise RuntimeError(
18 "The use-fastpath-installer tag is defined with an "
19- "expression. This expression must be updated to make this "
20- "node boot with the Fast Path Installer.")
21+ "expression. This expression must instead be updated to set "
22+ "this node to install with the fast installer.")
23 self.tags.add(uti_tag)
24
25=== modified file 'src/maasserver/node_action.py'
26--- src/maasserver/node_action.py 2013-11-15 18:15:51 +0000
27+++ src/maasserver/node_action.py 2014-04-02 16:50:35 +0000
28@@ -44,6 +44,7 @@
29 Node,
30 SSHKey,
31 )
32+from maasserver.models.tag import Tag
33 from maasserver.utils import map_enum
34
35 # All node statuses.
36@@ -198,6 +199,18 @@
37 self.node.use_fastpath_installer()
38 return "Node marked as using curtin for install."
39
40+ def inhibit(self):
41+ """Inhibit if ``use-fastpath-installer`` uses an expression."""
42+ tag, _ = Tag.objects.get_or_create(name="use-fastpath-installer")
43+ if tag.is_defined:
44+ return dedent("""\
45+ The use-fastpath-installer tag is defined with an
46+ expression. This expression must instead be updated to set
47+ this node to install with the fast installer.
48+ """)
49+ else:
50+ return None
51+
52
53 class UseDI(NodeAction):
54 """Set this node to use d-i for installation."""
55@@ -216,6 +229,18 @@
56 self.node.use_traditional_installer()
57 return "Node marked as using the default installer."
58
59+ def inhibit(self):
60+ """Inhibit if ``use-fastpath-installer`` uses an expression."""
61+ tag, _ = Tag.objects.get_or_create(name="use-fastpath-installer")
62+ if tag.is_defined:
63+ return dedent("""\
64+ The use-fastpath-installer tag is defined with an
65+ expression. This expression must instead be updated to set
66+ this node to install with the default installer.
67+ """)
68+ else:
69+ return None
70+
71
72 class StartNode(NodeAction):
73 """Acquire and start a node."""
74
75=== modified file 'src/maasserver/tests/test_node_action.py'
76--- src/maasserver/tests/test_node_action.py 2014-01-14 00:43:21 +0000
77+++ src/maasserver/tests/test_node_action.py 2014-04-02 16:50:35 +0000
78@@ -23,6 +23,7 @@
79 NODE_STATUS_CHOICES_DICT,
80 )
81 from maasserver.exceptions import Redirect
82+from maasserver.models import Tag
83 from maasserver.node_action import (
84 Commission,
85 compile_node_actions,
86@@ -264,6 +265,11 @@
87 self.celery.tasks[0]['task'].name)
88
89
90+def make_use_fastpath_installer_tag_with_expression():
91+ Tag.objects.get_or_create(
92+ name="use-fastpath-installer", definition="true()")
93+
94+
95 class TestUseCurtinNodeAction(MAASServerTestCase):
96
97 def test_sets_tag(self):
98@@ -287,6 +293,18 @@
99 user = factory.make_admin()
100 self.assertFalse(UseCurtin(node, user).is_permitted())
101
102+ def test_inhibited_if_use_fastpath_installer_tag_uses_expr(self):
103+ make_use_fastpath_installer_tag_with_expression()
104+ node = factory.make_node()
105+ user = factory.make_admin()
106+ self.assertDocTestMatches(
107+ """\
108+ The use-fastpath-installer tag is defined with an
109+ expression. This expression must instead be updated to set
110+ this node to install with the fast installer.
111+ """,
112+ UseCurtin(node, user).inhibit())
113+
114
115 class TestUseDINodeAction(MAASServerTestCase):
116
117@@ -310,3 +328,15 @@
118 node.use_traditional_installer()
119 user = factory.make_admin()
120 self.assertFalse(UseDI(node, user).is_permitted())
121+
122+ def test_inhibited_if_use_fastpath_installer_tag_uses_expr(self):
123+ make_use_fastpath_installer_tag_with_expression()
124+ node = factory.make_node()
125+ user = factory.make_admin()
126+ self.assertDocTestMatches(
127+ """\
128+ The use-fastpath-installer tag is defined with an
129+ expression. This expression must instead be updated to set
130+ this node to install with the default installer.
131+ """,
132+ UseDI(node, user).inhibit())