← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/maas/bug-1058313 into lp:maas

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/bug-1058313 into lp:maas.

Commit message:
Return, not raise, a 404 when an enlisting node asks for public-keys on the metadata service.  It still doesn't have any (and as per the bug report things work just fine without) but this will suppress useless tracebacks in the log.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1058313 in MAAS: "MAASAPINotFound: Unknown metadata attribute: public-keys  during commissioning"
  https://bugs.launchpad.net/maas/+bug/1058313

For more details, see:
https://code.launchpad.net/~jtv/maas/bug-1058313/+merge/127190

Discussed with Julian.  No changes in cloud-init; it has no conception of enlistment so we have no good way to stop it from asking.  But we can make the server not take it so badly.


Jeroen
-- 
https://code.launchpad.net/~jtv/maas/bug-1058313/+merge/127190
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/bug-1058313 into lp:maas.
=== modified file 'src/metadataserver/api.py'
--- src/metadataserver/api.py	2012-09-29 21:27:52 +0000
+++ src/metadataserver/api.py	2012-10-01 05:30:28 +0000
@@ -22,7 +22,10 @@
 
 from django.conf import settings
 from django.core.exceptions import PermissionDenied
-from django.http import HttpResponse
+from django.http import (
+    HttpResponse,
+    HttpResponseNotFound,
+    )
 from django.shortcuts import get_object_or_404
 from maasserver.api import (
     api_exported,
@@ -372,6 +375,10 @@
         if item is None or len(item) == 0:
             return make_list_response(sorted(self.data.keys()))
 
+        # Enlistment asks for SSH keys.  We don't give it any, but it's
+        # not an error either.
+        if item == 'public-keys':
+            return HttpResponseNotFound("No SSH keys available for this node.")
         if item not in self.data:
             raise MAASAPINotFound("Unknown metadata attribute: %s" % item)
 

=== modified file 'src/metadataserver/tests/test_api.py'
--- src/metadataserver/tests/test_api.py	2012-09-27 09:59:53 +0000
+++ src/metadataserver/tests/test_api.py	2012-10-01 05:30:28 +0000
@@ -663,8 +663,8 @@
 
     def test_get_hostname(self):
         # instance-id must be available
-        md_url = reverse('enlist-metadata-meta-data',
-            args=['latest', 'local-hostname'])
+        md_url = reverse(
+            'enlist-metadata-meta-data', args=['latest', 'local-hostname'])
         response = self.client.get(md_url)
         self.assertEqual(
             (httplib.OK, "text/plain"),
@@ -672,6 +672,17 @@
         # just insist content is non-empty. It doesn't matter what it is.
         self.assertTrue(response.content)
 
+    def test_public_keys_returns_404_but_does_not_raise_exception(self):
+        # An enlisting node has no SSH keys, but it does request them
+        # (bug 1058313).  The request should fail, but without the log
+        # noise of an exception.
+        md_url = reverse(
+            'enlist-metadata-meta-data', args=['latest', 'public-keys'])
+        response = self.client.get(md_url)
+        self.assertEqual(
+            (httplib.NOT_FOUND, "No SSH keys available for this node."),
+            (response.status_code, response.content))
+
     def test_metadata_bogus_is_404(self):
         md_url = reverse('enlist-metadata-meta-data',
             args=['latest', 'BOGUS'])