Merge ~blake-rouse/maas:fix-1841807 into maas:master

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: ee25f48bffd2a7f9a71c0631f65c25af47059c0b
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~blake-rouse/maas:fix-1841807
Merge into: maas:master
Diff against target: 67 lines (+20/-4)
2 files modified
src/maasserver/models/node.py (+6/-3)
src/maasserver/models/tests/test_node.py (+14/-1)
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
MAAS Lander Approve
Review via email: mp+372546@code.launchpad.net

Commit message

Fixes LP: #1841807 - Handle the case where the RPC connection can be lost in a list-boot-images API call.

There is a case where the RPC connection can be lost for multiple reasons during an RPC call to a rack controller. The error path was not handling this case, but was handling other cases. This updates that error path to handle the connection lost case so the API output is consistent and not an improper error or API return code.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix-1841807 lp:~blake-rouse/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: ee25f48bffd2a7f9a71c0631f65c25af47059c0b

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

LGTM, +1

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/models/node.py b/src/maasserver/models/node.py
2index d8fa3d9..c4fe307 100644
3--- a/src/maasserver/models/node.py
4+++ b/src/maasserver/models/node.py
5@@ -256,7 +256,10 @@ from twisted.internet.defer import (
6 inlineCallbacks,
7 succeed,
8 )
9-from twisted.internet.error import ConnectionDone
10+from twisted.internet.error import (
11+ ConnectionClosed,
12+ ConnectionDone,
13+)
14 from twisted.internet.threads import deferToThread
15 from twisted.python.failure import Failure
16 from twisted.python.threadable import isInIOThread
17@@ -6370,7 +6373,7 @@ class RackController(Controller):
18 status = "syncing"
19 else:
20 status = "out-of-sync"
21- except (NoConnectionsAvailable, TimeoutError):
22+ except (NoConnectionsAvailable, TimeoutError, ConnectionClosed):
23 status = 'unknown'
24 return status
25
26@@ -6401,7 +6404,7 @@ class RackController(Controller):
27 } for (name, arch), subarches in downloaded_boot_images.items()]
28 status = self.get_image_sync_status(boot_images)
29 return {'images': images, 'connected': True, 'status': status}
30- except (NoConnectionsAvailable, TimeoutError):
31+ except (NoConnectionsAvailable, ConnectionClosed, TimeoutError):
32 return {'images': [], 'connected': False, 'status': 'unknown'}
33
34 def is_import_boot_images_running(self):
35diff --git a/src/maasserver/models/tests/test_node.py b/src/maasserver/models/tests/test_node.py
36index 66b7374..0765582 100644
37--- a/src/maasserver/models/tests/test_node.py
38+++ b/src/maasserver/models/tests/test_node.py
39@@ -251,7 +251,10 @@ from testtools.matchers import (
40 Not,
41 )
42 from twisted.internet import defer
43-from twisted.internet.error import ConnectionDone
44+from twisted.internet.error import (
45+ ConnectionClosed,
46+ ConnectionDone,
47+)
48 import yaml
49
50
51@@ -11727,6 +11730,16 @@ class TestRackController(MAASTransactionServerTestCase):
52 self.assertEquals('unknown', images['status'])
53 self.assertEquals('unknown', rack_controller.get_image_sync_status())
54
55+ def test_list_boot_images_when_connection_closed(self):
56+ rack_controller = factory.make_RackController()
57+ self.patch(
58+ boot_images, 'get_boot_images').side_effect = ConnectionClosed()
59+ images = rack_controller.list_boot_images()
60+ self.assertEquals(False, images['connected'])
61+ self.assertItemsEqual([], images['images'])
62+ self.assertEquals('unknown', images['status'])
63+ self.assertEquals('unknown', rack_controller.get_image_sync_status())
64+
65 def test_list_boot_images_region_importing(self):
66 rack_controller = factory.make_RackController()
67 self.patch(

Subscribers

People subscribed via source and target branches