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
=== modified file 'src/maasserver/rpc/leases.py'
--- src/maasserver/rpc/leases.py 2014-09-10 16:20:31 +0000
+++ src/maasserver/rpc/leases.py 2014-10-01 23:28:16 +0000
@@ -16,7 +16,6 @@
16 "update_leases",16 "update_leases",
17]17]
1818
19from django.shortcuts import get_object_or_404
20from maasserver.models.dhcplease import DHCPLease19from maasserver.models.dhcplease import DHCPLease
21from maasserver.models.macaddress import update_mac_cluster_interfaces20from maasserver.models.macaddress import update_mac_cluster_interfaces
22from maasserver.models.nodegroup import NodeGroup21from maasserver.models.nodegroup import NodeGroup
@@ -24,6 +23,7 @@
24from provisioningserver.pserv_services.lease_upload_service import (23from provisioningserver.pserv_services.lease_upload_service import (
25 convert_mappings_to_leases,24 convert_mappings_to_leases,
26 )25 )
26from provisioningserver.rpc.exceptions import NoSuchCluster
27from provisioningserver.utils.twisted import synchronous27from provisioningserver.utils.twisted import synchronous
2828
2929
@@ -39,9 +39,16 @@
3939
40 Converts the mappings format into a dict that40 Converts the mappings format into a dict that
41 DHCPLease.objects.update_leases needs and then calls it.41 DHCPLease.objects.update_leases needs and then calls it.
42
43 :raises NoSuchCluster: If the cluster identified by `uuid` does not
44 exist.
42 """45 """
43 nodegroup = get_object_or_404(NodeGroup, uuid=uuid)46 try:
44 leases = convert_mappings_to_leases(mappings)47 nodegroup = NodeGroup.objects.get_by_natural_key(uuid)
45 DHCPLease.objects.update_leases(nodegroup, leases)48 except NodeGroup.DoesNotExist:
46 update_mac_cluster_interfaces(leases, nodegroup)49 raise NoSuchCluster.from_uuid(uuid)
47 return {}50 else:
51 leases = convert_mappings_to_leases(mappings)
52 DHCPLease.objects.update_leases(nodegroup, leases)
53 update_mac_cluster_interfaces(leases, nodegroup)
54 return {}
4855
=== modified file 'src/maasserver/rpc/tests/test_regionservice.py'
--- src/maasserver/rpc/tests/test_regionservice.py 2014-10-01 18:41:08 +0000
+++ src/maasserver/rpc/tests/test_regionservice.py 2014-10-01 23:28:16 +0000
@@ -333,6 +333,13 @@
333 observed = yield deferToThread(get_cluster_interface)333 observed = yield deferToThread(get_cluster_interface)
334 self.assertThat(observed, Equals(cluster_interface))334 self.assertThat(observed, Equals(cluster_interface))
335335
336 @wait_for_reactor
337 def test__raises_NoSuchCluster_if_cluster_not_found(self):
338 uuid = factory.make_name("uuid")
339 d = call_responder(
340 Region(), UpdateLeases, {b"uuid": uuid, b"mappings": []})
341 return assert_fails_with(d, NoSuchCluster)
342
336343
337class TestRegionProtocol_GetBootSources(TransactionTestCase):344class TestRegionProtocol_GetBootSources(TransactionTestCase):
338345
339346
=== modified file 'src/provisioningserver/rpc/region.py'
--- src/provisioningserver/rpc/region.py 2014-09-24 22:20:11 +0000
+++ src/provisioningserver/rpc/region.py 2014-10-01 23:28:16 +0000
@@ -121,7 +121,9 @@
121 (b"mac", amp.Unicode())]))121 (b"mac", amp.Unicode())]))
122 ]122 ]
123 response = []123 response = []
124 errors = []124 errors = {
125 NoSuchCluster: b"NoSuchCluster",
126 }
125127
126128
127class GetArchiveMirrors(amp.Command):129class GetArchiveMirrors(amp.Command):