Merge lp:~jtv/maas/no-public-keys-is-not-an-error 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: 1166
Proposed branch: lp:~jtv/maas/no-public-keys-is-not-an-error
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 95 lines (+18/-20)
2 files modified
src/metadataserver/api.py (+10/-13)
src/metadataserver/tests/test_api.py (+8/-7)
To merge this branch: bzr merge lp:~jtv/maas/no-public-keys-is-not-an-error
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+127969@code.launchpad.net

Commit message

If a node requests its public-keys but there are none, just return a success response without any keys. The tracebacks were distracting, and may or may not have affected commissioning.

Description of the change

Julian ran into the traceback when commissioning. Commissioning was broken for apparently unrelated reasons, but we might as well eliminate the error from our list of suspects.

Jeroen

To post a comment you must log in.
Revision history for this message
Dave Walker (davewalker) wrote :

This has annoyed me for ages! Thanks for tackling this. lgtm

Revision history for this message
Raphaël Badin (rvb) wrote :

Looks good.

[0]

85 + # (bug 1058313). If the node insists, we give it the empty

Why keep the reference to that bug? The bug is about a MAASAPINotFound being raised and it looks to me like this fixes the problem.

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

Fair enough. I removed the bug reference.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/metadataserver/api.py'
2--- src/metadataserver/api.py 2012-10-04 00:01:47 +0000
3+++ src/metadataserver/api.py 2012-10-04 11:22:25 +0000
4@@ -22,10 +22,7 @@
5
6 from django.conf import settings
7 from django.core.exceptions import PermissionDenied
8-from django.http import (
9- HttpResponse,
10- HttpResponseNotFound,
11- )
12+from django.http import HttpResponse
13 from django.shortcuts import get_object_or_404
14 from maasserver.api import (
15 extract_oauth_key,
16@@ -337,10 +334,8 @@
17
18 def public_keys(self, node, version, item):
19 """ Produce public-keys attribute."""
20- keys = SSHKey.objects.get_keys_for_user(user=node.owner)
21- if not keys:
22- raise MAASAPINotFound("No registered public keys")
23- return make_list_response(keys)
24+ return make_list_response(
25+ SSHKey.objects.get_keys_for_user(user=node.owner))
26
27
28 class UserDataHandler(MetadataViewHandler):
29@@ -367,6 +362,7 @@
30 data = {
31 'instance-id': 'i-maas-enlistment',
32 'local-hostname': "maas-enlisting-node",
33+ 'public-keys': "",
34 }
35
36 def read(self, request, version, item=None):
37@@ -374,12 +370,13 @@
38
39 # Requesting the list of attributes, not any particular attribute.
40 if item is None or len(item) == 0:
41- return make_list_response(sorted(self.data.keys()))
42+ keys = sorted(self.data.keys())
43+ # There's nothing in public-keys, so we don't advertise it.
44+ # But cloud-init does ask for it and it's not worth logging
45+ # a traceback for.
46+ keys.remove('public-keys')
47+ return make_list_response(keys)
48
49- # Enlistment asks for SSH keys. We don't give it any, but it's
50- # not an error either.
51- if item == 'public-keys':
52- return HttpResponseNotFound("No SSH keys available for this node.")
53 if item not in self.data:
54 raise MAASAPINotFound("Unknown metadata attribute: %s" % item)
55
56
57=== modified file 'src/metadataserver/tests/test_api.py'
58--- src/metadataserver/tests/test_api.py 2012-10-04 00:01:47 +0000
59+++ src/metadataserver/tests/test_api.py 2012-10-04 11:22:25 +0000
60@@ -272,11 +272,13 @@
61 self.assertIn(
62 'public-keys', response.content.decode('ascii').split('\n'))
63
64- def test_public_keys_for_node_without_public_keys_returns_not_found(self):
65+ def test_public_keys_for_node_without_public_keys_returns_empty(self):
66 url = reverse('metadata-meta-data', args=['latest', 'public-keys'])
67 client = self.make_node_client()
68 response = client.get(url)
69- self.assertEqual(httplib.NOT_FOUND, response.status_code)
70+ self.assertEqual(
71+ (httplib.OK, ''),
72+ (response.status_code, response.content))
73
74 def test_public_keys_for_node_returns_list_of_keys(self):
75 user, _ = factory.make_user_with_keys(n_keys=2, username='my-user')
76@@ -675,15 +677,14 @@
77 # just insist content is non-empty. It doesn't matter what it is.
78 self.assertTrue(response.content)
79
80- def test_public_keys_returns_404_but_does_not_raise_exception(self):
81- # An enlisting node has no SSH keys, but it does request them
82- # (bug 1058313). The request should fail, but without the log
83- # noise of an exception.
84+ def test_public_keys_returns_empty(self):
85+ # An enlisting node has no SSH keys, but it does request them.
86+ # If the node insists, we give it the empty list.
87 md_url = reverse(
88 'enlist-metadata-meta-data', args=['latest', 'public-keys'])
89 response = self.client.get(md_url)
90 self.assertEqual(
91- (httplib.NOT_FOUND, "No SSH keys available for this node."),
92+ (httplib.OK, ""),
93 (response.status_code, response.content))
94
95 def test_metadata_bogus_is_404(self):