Merge lp:~allenap/maas/spurious-regionservice-tests into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 5553
Proposed branch: lp:~allenap/maas/spurious-regionservice-tests
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 99 lines (+20/-20)
2 files modified
src/maasserver/rpc/regionservice.py (+16/-19)
src/maasserver/rpc/tests/test_regionservice.py (+4/-1)
To merge this branch: bzr merge lp:~allenap/maas/spurious-regionservice-tests
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
Review via email: mp+310742@code.launchpad.net

Commit message

Fix a couple of leaking RegionService tests, and tidy up exception handling a bit.

Description of the change

This was a leftover from a brief attempt to fix bug 1555236.

To post a comment you must log in.
Revision history for this message
Lee Trager (ltrager) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/rpc/regionservice.py'
2--- src/maasserver/rpc/regionservice.py 2016-10-28 15:58:32 +0000
3+++ src/maasserver/rpc/regionservice.py 2016-11-14 07:34:58 +0000
4@@ -642,19 +642,17 @@
5 # and into the database.
6 self.ident = rack_controller.system_id
7 self.factory.service._addConnectionFor(self.ident, self)
8+
9+ # A local rack is treated differently to one that's remote.
10 self.host = self.transport.getHost()
11 self.hostIsRemote = isinstance(
12 self.host, (IPv4Address, IPv6Address))
13
14- # Get the region ID if we're dealing with a non-local rack; we
15- # won't need to bother for local racks.
16+ # Only register the connection into the database when it's a valid
17+ # IPv4 or IPv6. Only time it is not an IPv4 or IPv6 address is
18+ # when mocking a connection.
19 if self.hostIsRemote:
20 region_id = yield getRegionID()
21-
22- # Only register the connection into the database when its a valid
23- # IPv4 and IPv6. Only time it is not an IPv4 or IPv6 address is
24- # when mocking a connection.
25- if self.hostIsRemote:
26 yield deferToDatabase(
27 registerConnection, region_id, rack_controller, self.host)
28
29@@ -663,22 +661,21 @@
30 "Process [%s] - registered rack controller '%s'." % (
31 os.getpid(), self.ident))
32
33- # Done registering the rack controller and connection.
34- return {'system_id': self.ident}
35- except Exception as exc:
36- # Some error occurred here. Remove the connection in the database,
37- # log the error and alert the connected rack controller. The
38- # connected rack controller will drop the connection.
39- if (self.ident is not None and self.hostIsRemote):
40- yield deferToDatabase(
41- unregisterConnection, region_id, self.ident, self.host)
42+ except:
43+ # Ensure we're not hanging onto this connection.
44+ self.factory.service._removeConnectionFor(self.ident, self)
45+ # Tell the logs about it.
46 msg = (
47 "Failed to register rack controller '%s' into the "
48- "database. Connection has been dropped." % (
49- self.ident))
50- log.err(exc, msg)
51+ "database. Connection will be dropped." % self.ident)
52+ log.err(None, msg)
53+ # Finally, tell the callers.
54 raise exceptions.CannotRegisterRackController(msg)
55
56+ else:
57+ # Done registering the rack controller and connection.
58+ return {'system_id': self.ident}
59+
60 @inlineCallbacks
61 def performHandshake(self):
62 authenticated = yield self.authenticateCluster()
63
64=== modified file 'src/maasserver/rpc/tests/test_regionservice.py'
65--- src/maasserver/rpc/tests/test_regionservice.py 2016-10-28 15:58:32 +0000
66+++ src/maasserver/rpc/tests/test_regionservice.py 2016-11-14 07:34:58 +0000
67@@ -41,6 +41,7 @@
68 from maasserver.rpc import regionservice
69 from maasserver.rpc.regionservice import (
70 getRegionID,
71+ ignoreCancellation,
72 Region,
73 RegionAdvertising,
74 RegionAdvertisingService,
75@@ -569,7 +570,7 @@
76 CannotRegisterRackController)
77 self.assertEquals((
78 "Failed to register rack controller 'None' into the database. "
79- "Connection has been dropped.",), error.args)
80+ "Connection will be dropped.",), error.args)
81
82
83 class TestRegionService(MAASTestCase):
84@@ -777,6 +778,7 @@
85 def test_stopping_closes_connections_cleanly(self):
86 service = RegionService()
87 service.starting = Deferred()
88+ service.starting.addErrback(ignoreCancellation)
89 service.factory.protocol = HandshakingRegionServer
90 connections = {
91 service.factory.buildProtocol(None),
92@@ -801,6 +803,7 @@
93 def test_stopping_logs_errors_when_closing_connections(self):
94 service = RegionService()
95 service.starting = Deferred()
96+ service.starting.addErrback(ignoreCancellation)
97 service.factory.protocol = HandshakingRegionServer
98 connections = {
99 service.factory.buildProtocol(None),