← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/ephe-exceptions into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/ephe-exceptions into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~rvb/maas/ephe-exceptions/+merge/118572

This cleanup branch adds a specific exception raised when the compose_kernel_command_line() tries to generate the kernel options and fails at finding the ephemeral info.  Other things could go wrong (the info file could be badly formed for instance) but I choose to focus on the more probable cause of error: if the import script has failed to run.
-- 
https://code.launchpad.net/~rvb/maas/ephe-exceptions/+merge/118572
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/ephe-exceptions into lp:maas.
=== modified file 'src/maasserver/exceptions.py'
--- src/maasserver/exceptions.py	2012-04-25 16:19:07 +0000
+++ src/maasserver/exceptions.py	2012-08-07 15:01:19 +0000
@@ -40,6 +40,10 @@
     """Could not reach RabbitMQ."""
 
 
+class EphemeralImagesDirectoryNotFound(MAASException):
+    """The ephemeral images directory cannot be found."""
+
+
 class MAASAPIException(Exception):
     """Base class for MAAS' API exceptions.
 

=== modified file 'src/maasserver/kernel_opts.py'
--- src/maasserver/kernel_opts.py	2012-08-07 12:22:26 +0000
+++ src/maasserver/kernel_opts.py	2012-08-07 15:01:19 +0000
@@ -17,6 +17,7 @@
 import os
 
 from django.conf import settings
+from maasserver.exceptions import EphemeralImagesDirectoryNotFound
 from maasserver.server_address import get_maas_facing_server_address
 from maasserver.utils import absolute_reverse
 from provisioningserver.pxe.tftppath import compose_image_path
@@ -115,7 +116,13 @@
     /var/lib/maas/ephemeral/precise/ephemeral/i386/20120424/info
     """
     root = os.path.join(settings.EPHEMERAL_ROOT, release, 'ephemeral', arch)
-    filename = os.path.join(get_last_directory(root), 'info')
+    try:
+        filename = os.path.join(get_last_directory(root), 'info')
+    except OSError:
+        raise EphemeralImagesDirectoryNotFound(
+            "The directory containing the ephemeral images/info is missing "
+            "('%s').  Make sure to run the script "
+            "'maas-import-ephemerals'." % root)
     name = parse_key_value_file(filename, separator="=")['name']
     return name
 

=== modified file 'src/maasserver/tests/test_kernel_opts.py'
--- src/maasserver/tests/test_kernel_opts.py	2012-08-07 07:19:45 +0000
+++ src/maasserver/tests/test_kernel_opts.py	2012-08-07 15:01:19 +0000
@@ -17,6 +17,7 @@
 
 from django.conf import settings
 from maasserver.api import get_boot_purpose
+from maasserver.exceptions import EphemeralImagesDirectoryNotFound
 from maasserver.kernel_opts import (
     compose_enlistment_preseed_url,
     compose_kernel_command_line,
@@ -186,6 +187,15 @@
                 "iscsi_target_ip=%s" % get_maas_facing_server_address(),
                 ]))
 
+    def test_compose_kernel_command_line_reports_error_about_missing_dir(self):
+        self.patch(
+            settings, 'EPHEMERAL_ROOT', factory.make_name('missing-dir'))
+        node = factory.make_node()
+        self.assertRaises(
+            EphemeralImagesDirectoryNotFound,
+            compose_kernel_command_line, node, factory.make_name('arch'),
+            factory.make_name('subarch'), purpose="commissioning")
+
     def test_compose_enlistment_preseed_url_links_to_enlistment_preseed(self):
         response = self.client.get(compose_enlistment_preseed_url())
         self.assertEqual(