Merge lp:~jtv/maas/bug-1058313 into lp:~maas-committers/maas/trunk

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 1114
Proposed branch: lp:~jtv/maas/bug-1058313
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 59 lines (+21/-3)
2 files modified
src/metadataserver/api.py (+8/-1)
src/metadataserver/tests/test_api.py (+13/-2)
To merge this branch: bzr merge lp:~jtv/maas/bug-1058313
Reviewer Review Type Date Requested Status
John A Meinel (community) Approve
Review via email: mp+127190@code.launchpad.net

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.

Description of the change

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

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

Are there any times other than during enlistment where public-keys are requested and it would be better to put something in the log?
if
22 + if item == 'public-keys':
23 + return HttpResponseNotFound("No SSH keys available for this node.")

is only in the 'enlistment' codepath, then it seems perfectly reasonable. And I certainly agree that not logging errors when there aren't any is a good thing.

review: Approve
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

I should have explained. The bug, and my code change, are in a separate anonymous-access metadata view that is documented as being only for enlistment. It otherwise mimicks the regular metadata view in a minimal way.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
2222
23from django.conf import settings23from django.conf import settings
24from django.core.exceptions import PermissionDenied24from django.core.exceptions import PermissionDenied
25from django.http import HttpResponse25from django.http import (
26 HttpResponse,
27 HttpResponseNotFound,
28 )
26from django.shortcuts import get_object_or_40429from django.shortcuts import get_object_or_404
27from maasserver.api import (30from maasserver.api import (
28 api_exported,31 api_exported,
@@ -372,6 +375,10 @@
372 if item is None or len(item) == 0:375 if item is None or len(item) == 0:
373 return make_list_response(sorted(self.data.keys()))376 return make_list_response(sorted(self.data.keys()))
374377
378 # Enlistment asks for SSH keys. We don't give it any, but it's
379 # not an error either.
380 if item == 'public-keys':
381 return HttpResponseNotFound("No SSH keys available for this node.")
375 if item not in self.data:382 if item not in self.data:
376 raise MAASAPINotFound("Unknown metadata attribute: %s" % item)383 raise MAASAPINotFound("Unknown metadata attribute: %s" % item)
377384
378385
=== 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 @@
663663
664 def test_get_hostname(self):664 def test_get_hostname(self):
665 # instance-id must be available665 # instance-id must be available
666 md_url = reverse('enlist-metadata-meta-data',666 md_url = reverse(
667 args=['latest', 'local-hostname'])667 'enlist-metadata-meta-data', args=['latest', 'local-hostname'])
668 response = self.client.get(md_url)668 response = self.client.get(md_url)
669 self.assertEqual(669 self.assertEqual(
670 (httplib.OK, "text/plain"),670 (httplib.OK, "text/plain"),
@@ -672,6 +672,17 @@
672 # just insist content is non-empty. It doesn't matter what it is.672 # just insist content is non-empty. It doesn't matter what it is.
673 self.assertTrue(response.content)673 self.assertTrue(response.content)
674674
675 def test_public_keys_returns_404_but_does_not_raise_exception(self):
676 # An enlisting node has no SSH keys, but it does request them
677 # (bug 1058313). The request should fail, but without the log
678 # noise of an exception.
679 md_url = reverse(
680 'enlist-metadata-meta-data', args=['latest', 'public-keys'])
681 response = self.client.get(md_url)
682 self.assertEqual(
683 (httplib.NOT_FOUND, "No SSH keys available for this node."),
684 (response.status_code, response.content))
685
675 def test_metadata_bogus_is_404(self):686 def test_metadata_bogus_is_404(self):
676 md_url = reverse('enlist-metadata-meta-data',687 md_url = reverse('enlist-metadata-meta-data',
677 args=['latest', 'BOGUS'])688 args=['latest', 'BOGUS'])