Merge lp:~allenap/maas/no-such-cluster-for-all-the-things into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 3163
Proposed branch: lp:~allenap/maas/no-such-cluster-for-all-the-things
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 74 lines (+23/-7)
3 files modified
src/maasserver/rpc/leases.py (+13/-6)
src/maasserver/rpc/tests/test_regionservice.py (+7/-0)
src/provisioningserver/rpc/region.py (+3/-1)
To merge this branch: bzr merge lp:~allenap/maas/no-such-cluster-for-all-the-things
Reviewer Review Type Date Requested Status
Newell Jensen (community) Approve
Review via email: mp+236797@code.launchpad.net

Commit message

When update_leases() does not find the given cluster, raise NoSuchCluster.

Previously it was raising a Django HTTP 404 error.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

I was seeing logs like the following in maas.log when starting from a
clean-slate (i.e. no auto-accepted master cluster yet exists in the
database):

  maas.lease_upload_service: [ERROR] Failed to upload leases:
  Code<UNKNOWN>: Unknown Error

The RPC connection was dropped after this because that's what AMP does:
it drops connections when unrecognised exceptions are transmitted. The
cluster would eventually be registered, but there can be more failures
before it does.

With this branch I get:

  maas.lease_upload_service: [ERROR] Failed to upload leases: The
  cluster (a.k.a. node-group) with UUID
  d791c8c0-244e-4144-8cfc-b4dbc8cba188 could not be found.

and the RPC connection does not drop. This means that when
start-cluster-controller (upstart job: maas-cluster-register) wakes up
(every 60 seconds) there's a good chance that the cluster will be
connected to the region, and the registration will be successful.

Revision history for this message
Newell Jensen (newell-jensen) wrote :

Straight forward change. Approved.

Revision history for this message
Newell Jensen (newell-jensen) :
review: Approve
Revision history for this message
Graham Binns (gmb) wrote :

Whilst you're playing in this paddling pool, would it be worth
updating the (API)RPCErrorMiddleware to handle NoSuchCluster nicely?
(I don't know if this would ever arise in the UI, but if it arises in
the API we could certainly catch the error and do something
meaningful.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/rpc/leases.py'
2--- src/maasserver/rpc/leases.py 2014-09-10 16:20:31 +0000
3+++ src/maasserver/rpc/leases.py 2014-10-01 23:28:16 +0000
4@@ -16,7 +16,6 @@
5 "update_leases",
6 ]
7
8-from django.shortcuts import get_object_or_404
9 from maasserver.models.dhcplease import DHCPLease
10 from maasserver.models.macaddress import update_mac_cluster_interfaces
11 from maasserver.models.nodegroup import NodeGroup
12@@ -24,6 +23,7 @@
13 from provisioningserver.pserv_services.lease_upload_service import (
14 convert_mappings_to_leases,
15 )
16+from provisioningserver.rpc.exceptions import NoSuchCluster
17 from provisioningserver.utils.twisted import synchronous
18
19
20@@ -39,9 +39,16 @@
21
22 Converts the mappings format into a dict that
23 DHCPLease.objects.update_leases needs and then calls it.
24+
25+ :raises NoSuchCluster: If the cluster identified by `uuid` does not
26+ exist.
27 """
28- nodegroup = get_object_or_404(NodeGroup, uuid=uuid)
29- leases = convert_mappings_to_leases(mappings)
30- DHCPLease.objects.update_leases(nodegroup, leases)
31- update_mac_cluster_interfaces(leases, nodegroup)
32- return {}
33+ try:
34+ nodegroup = NodeGroup.objects.get_by_natural_key(uuid)
35+ except NodeGroup.DoesNotExist:
36+ raise NoSuchCluster.from_uuid(uuid)
37+ else:
38+ leases = convert_mappings_to_leases(mappings)
39+ DHCPLease.objects.update_leases(nodegroup, leases)
40+ update_mac_cluster_interfaces(leases, nodegroup)
41+ return {}
42
43=== modified file 'src/maasserver/rpc/tests/test_regionservice.py'
44--- src/maasserver/rpc/tests/test_regionservice.py 2014-10-01 18:41:08 +0000
45+++ src/maasserver/rpc/tests/test_regionservice.py 2014-10-01 23:28:16 +0000
46@@ -333,6 +333,13 @@
47 observed = yield deferToThread(get_cluster_interface)
48 self.assertThat(observed, Equals(cluster_interface))
49
50+ @wait_for_reactor
51+ def test__raises_NoSuchCluster_if_cluster_not_found(self):
52+ uuid = factory.make_name("uuid")
53+ d = call_responder(
54+ Region(), UpdateLeases, {b"uuid": uuid, b"mappings": []})
55+ return assert_fails_with(d, NoSuchCluster)
56+
57
58 class TestRegionProtocol_GetBootSources(TransactionTestCase):
59
60
61=== modified file 'src/provisioningserver/rpc/region.py'
62--- src/provisioningserver/rpc/region.py 2014-09-24 22:20:11 +0000
63+++ src/provisioningserver/rpc/region.py 2014-10-01 23:28:16 +0000
64@@ -121,7 +121,9 @@
65 (b"mac", amp.Unicode())]))
66 ]
67 response = []
68- errors = []
69+ errors = {
70+ NoSuchCluster: b"NoSuchCluster",
71+ }
72
73
74 class GetArchiveMirrors(amp.Command):