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
diff --git a/src/maasserver/models/node.py b/src/maasserver/models/node.py
index d8fa3d9..c4fe307 100644
--- a/src/maasserver/models/node.py
+++ b/src/maasserver/models/node.py
@@ -256,7 +256,10 @@ from twisted.internet.defer import (
256 inlineCallbacks,256 inlineCallbacks,
257 succeed,257 succeed,
258)258)
259from twisted.internet.error import ConnectionDone259from twisted.internet.error import (
260 ConnectionClosed,
261 ConnectionDone,
262)
260from twisted.internet.threads import deferToThread263from twisted.internet.threads import deferToThread
261from twisted.python.failure import Failure264from twisted.python.failure import Failure
262from twisted.python.threadable import isInIOThread265from twisted.python.threadable import isInIOThread
@@ -6370,7 +6373,7 @@ class RackController(Controller):
6370 status = "syncing"6373 status = "syncing"
6371 else:6374 else:
6372 status = "out-of-sync"6375 status = "out-of-sync"
6373 except (NoConnectionsAvailable, TimeoutError):6376 except (NoConnectionsAvailable, TimeoutError, ConnectionClosed):
6374 status = 'unknown'6377 status = 'unknown'
6375 return status6378 return status
63766379
@@ -6401,7 +6404,7 @@ class RackController(Controller):
6401 } for (name, arch), subarches in downloaded_boot_images.items()]6404 } for (name, arch), subarches in downloaded_boot_images.items()]
6402 status = self.get_image_sync_status(boot_images)6405 status = self.get_image_sync_status(boot_images)
6403 return {'images': images, 'connected': True, 'status': status}6406 return {'images': images, 'connected': True, 'status': status}
6404 except (NoConnectionsAvailable, TimeoutError):6407 except (NoConnectionsAvailable, ConnectionClosed, TimeoutError):
6405 return {'images': [], 'connected': False, 'status': 'unknown'}6408 return {'images': [], 'connected': False, 'status': 'unknown'}
64066409
6407 def is_import_boot_images_running(self):6410 def is_import_boot_images_running(self):
diff --git a/src/maasserver/models/tests/test_node.py b/src/maasserver/models/tests/test_node.py
index 66b7374..0765582 100644
--- a/src/maasserver/models/tests/test_node.py
+++ b/src/maasserver/models/tests/test_node.py
@@ -251,7 +251,10 @@ from testtools.matchers import (
251 Not,251 Not,
252)252)
253from twisted.internet import defer253from twisted.internet import defer
254from twisted.internet.error import ConnectionDone254from twisted.internet.error import (
255 ConnectionClosed,
256 ConnectionDone,
257)
255import yaml258import yaml
256259
257260
@@ -11727,6 +11730,16 @@ class TestRackController(MAASTransactionServerTestCase):
11727 self.assertEquals('unknown', images['status'])11730 self.assertEquals('unknown', images['status'])
11728 self.assertEquals('unknown', rack_controller.get_image_sync_status())11731 self.assertEquals('unknown', rack_controller.get_image_sync_status())
1172911732
11733 def test_list_boot_images_when_connection_closed(self):
11734 rack_controller = factory.make_RackController()
11735 self.patch(
11736 boot_images, 'get_boot_images').side_effect = ConnectionClosed()
11737 images = rack_controller.list_boot_images()
11738 self.assertEquals(False, images['connected'])
11739 self.assertItemsEqual([], images['images'])
11740 self.assertEquals('unknown', images['status'])
11741 self.assertEquals('unknown', rack_controller.get_image_sync_status())
11742
11730 def test_list_boot_images_region_importing(self):11743 def test_list_boot_images_region_importing(self):
11731 rack_controller = factory.make_RackController()11744 rack_controller = factory.make_RackController()
11732 self.patch(11745 self.patch(

Subscribers

People subscribed via source and target branches