← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~julian-edwards/maas/boot_image_messages into lp:maas

 

Julian Edwards has proposed merging lp:~julian-edwards/maas/boot_image_messages into lp:maas.

Commit message:
Fix the persistent errors for missing boot images so that a message appears if any of the nodegroups are missing images.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~julian-edwards/maas/boot_image_messages/+merge/131409
-- 
https://code.launchpad.net/~julian-edwards/maas/boot_image_messages/+merge/131409
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~julian-edwards/maas/boot_image_messages into lp:maas.
=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py	2012-10-25 11:09:54 +0000
+++ src/maasserver/api.py	2012-10-25 13:41:28 +0000
@@ -1884,13 +1884,20 @@
                 release=image['release'],
                 purpose=image['purpose'])
 
-        if len(images) == 0:
+        # Work out if any nodegroups are missing images.
+        nodegroup_ids_with_images = BootImage.objects.values_list(
+            "nodegroup_id", flat=True)
+        nodegroups_missing_images = NodeGroup.objects.exclude(
+            id__in=nodegroup_ids_with_images).filter(
+                status=NODEGROUP_STATUS.ACCEPTED)
+        if nodegroups_missing_images.exists():
             warning = dedent("""\
-                No boot images have been imported yet.  Either the
+                Some cluster controllers are missing boot images.  Either the
                 maas-import-pxe-files script has not run yet, or it failed.
 
-                Try running it manually.  If it succeeds, this message will
-                go away within 5 minutes.
+                Try running it manually on the affected
+                <a href="/settings/#accepted-clusters">cluster controllers.</a>
+                If it succeeds, this message will go away within 5 minutes.
                 """)
             register_persistent_error(COMPONENT.IMPORT_PXE_FILES, warning)
         else:

=== modified file 'src/maasserver/components.py'
--- src/maasserver/components.py	2012-09-28 18:42:16 +0000
+++ src/maasserver/components.py	2012-10-25 13:41:28 +0000
@@ -17,6 +17,7 @@
     "register_persistent_error",
     ]
 
+from django.utils.safestring import mark_safe
 from maasserver.models import ComponentError
 from maasserver.utils.orm import get_one
 
@@ -50,4 +51,5 @@
 
 def get_persistent_errors():
     """Return list of current persistent error messages."""
-    return sorted(err.error for err in ComponentError.objects.all())
+    return sorted(
+        mark_safe(err.error) for err in ComponentError.objects.all())

=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py	2012-10-25 11:09:54 +0000
+++ src/maasserver/tests/test_api.py	2012-10-25 13:41:28 +0000
@@ -4124,6 +4124,7 @@
 
     def test_report_boot_images_warns_if_no_images_found(self):
         nodegroup = NodeGroup.objects.ensure_master()
+        factory.make_node_group()  # Second nodegroup with no images.
         recorder = self.patch(api, 'register_persistent_error')
         client = make_worker_client(nodegroup)
         response = self.report_images(nodegroup, [], client=client)
@@ -4135,6 +4136,32 @@
             COMPONENT.IMPORT_PXE_FILES,
             [args[0][0] for args in recorder.call_args_list])
 
+    def test_report_boot_images_warns_if_any_nodegroup_has_no_images(self):
+        nodegroup = NodeGroup.objects.ensure_master()
+        # Second nodegroup with no images.
+        factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED)
+        recorder = self.patch(api, 'register_persistent_error')
+        client = make_worker_client(nodegroup)
+        image = make_boot_image_params()
+        response = self.report_images(nodegroup, [image], client=client)
+        self.assertEqual(
+            (httplib.OK, "OK"),
+            (response.status_code, response.content))
+
+        self.assertIn(
+            COMPONENT.IMPORT_PXE_FILES,
+            [args[0][0] for args in recorder.call_args_list])
+
+    def test_report_boot_images_ignores_non_accepted_groups(self):
+        nodegroup = factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED)
+        factory.make_node_group(status=NODEGROUP_STATUS.PENDING)
+        factory.make_node_group(status=NODEGROUP_STATUS.REJECTED)
+        recorder = self.patch(api, 'register_persistent_error')
+        client = make_worker_client(nodegroup)
+        image = make_boot_image_params()
+        response = self.report_images(nodegroup, [image], client=client)
+        self.assertEqual(0, recorder.call_count)
+
     def test_report_boot_images_removes_warning_if_images_found(self):
         self.patch(api, 'register_persistent_error')
         self.patch(api, 'discard_persistent_error')