Merge lp:~rbanffy/maas/1484698-prevent-node-release-when-dhcp-down into lp:~maas-committers/maas/trunk

Proposed by Ricardo Bánffy
Status: Rejected
Rejected by: Ricardo Bánffy
Proposed branch: lp:~rbanffy/maas/1484698-prevent-node-release-when-dhcp-down
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 57 lines (+21/-1)
2 files modified
src/maasserver/exceptions.py (+5/-0)
src/maasserver/models/node.py (+16/-1)
To merge this branch: bzr merge lp:~rbanffy/maas/1484698-prevent-node-release-when-dhcp-down
Reviewer Review Type Date Requested Status
MAAS Maintainers Pending
Review via email: mp+274551@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/exceptions.py'
2--- src/maasserver/exceptions.py 2015-10-07 04:53:58 +0000
3+++ src/maasserver/exceptions.py 2015-10-15 12:02:57 +0000
4@@ -132,6 +132,11 @@
5 api_error = httplib.SERVICE_UNAVAILABLE
6
7
8+class DHCPNotAvailable(MAASAPIException):
9+ """A DHCP server is not available."""
10+ api_error = httplib.SERVICE_UNAVAILABLE
11+
12+
13 class IteratorReusedError(Exception):
14 """Raise when a :class:`UseOnceIterator` gets reused."""
15
16
17=== modified file 'src/maasserver/models/node.py'
18--- src/maasserver/models/node.py 2015-10-09 20:37:14 +0000
19+++ src/maasserver/models/node.py 2015-10-15 12:02:57 +0000
20@@ -74,7 +74,10 @@
21 POWER_STATE_CHOICES,
22 PRESEED_TYPE,
23 )
24-from maasserver.exceptions import NodeStateViolation
25+from maasserver.exceptions import (
26+ DHCPNotAvailable,
27+ NodeStateViolation,
28+)
29 from maasserver.fields import (
30 JSONObjectField,
31 MAASIPAddressField,
32@@ -141,6 +144,7 @@
33 )
34 from twisted.internet import reactor
35 from twisted.internet.defer import Deferred
36+from provisioningserver.dhcp.omshell import Omshell
37
38
39 maaslog = get_maas_logger("node")
40@@ -1664,6 +1668,17 @@
41 """
42 maaslog.info("%s: Releasing node", self.hostname)
43
44+ # Check whether the DHCP server is available. If not, raise an error
45+ # that can boil up to the UI and fail the node release.
46+ omshell = Omshell(server_address='127.0.0.1', shared_key="")
47+ if omshell.try_connection():
48+ maaslog.error(
49+ "%s: Unable to reach the DHCP server. Node can't be released "
50+ "at this time.", self.hostname)
51+ raise DHCPNotAvailable(
52+ 'DHCP server not available. The node could not be released')
53+
54+
55 # Don't perform stop the node if its already off. Doing so will
56 # place an action in the power registry which is not needed and can
57 # block a following deploy action. See bug 1453954 for an example of