Merge lp:~jtv/maas/1.2-bug-1084507 into lp:maas/1.2

Proposed by Jeroen T. Vermeulen
Status: Merged
Merged at revision: 1335
Proposed branch: lp:~jtv/maas/1.2-bug-1084507
Merge into: lp:maas/1.2
Diff against target: 143 lines (+41/-3)
4 files modified
src/maasserver/api.py (+15/-1)
src/maasserver/tests/test_api.py (+16/-2)
src/provisioningserver/tests/test_tftp.py (+5/-0)
src/provisioningserver/tftp.py (+5/-0)
To merge this branch: bzr merge lp:~jtv/maas/1.2-bug-1084507
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+139273@code.launchpad.net

Commit message

Backport trunk r1391: Pass cluster uuid to pxeconfig API call, so it knows which cluster a request comes from.

To post a comment you must log in.
Revision history for this message
Julian Edwards (julian-edwards) :
review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/maas-merger-quantal/305/console reported an error when processing this lp:~jtv/maas/1.2-bug-1084507 branch.
Not merging it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api.py'
2--- src/maasserver/api.py 2012-12-04 10:17:17 +0000
3+++ src/maasserver/api.py 2012-12-11 17:51:26 +0000
4@@ -1822,6 +1822,16 @@
5 return macaddress.node if macaddress else None
6
7
8+def find_nodegroup_for_pxeconfig_request(request):
9+ """Find the nodegroup responsible for a `pxeconfig` request.
10+
11+ Looks for the `cluster_uuid` parameter in the request. If there is
12+ none, figures it out based on the requesting IP as a compatibility
13+ measure. In that case, the result may be incorrect.
14+ """
15+ return find_nodegroup(request)
16+
17+
18 def pxeconfig(request):
19 """Get the PXE configuration given a node's details.
20
21@@ -1845,6 +1855,10 @@
22 :param subarch: Subarchitecture name (in the pxelinux namespace).
23 :param local: The IP address of the cluster controller.
24 :param remote: The IP address of the booting node.
25+ :param cluster_uuid: UUID of the cluster responsible for this node.
26+ If omitted, the call will attempt to figure it out based on the
27+ requesting IP address, for compatibility. Passing `cluster_uuid`
28+ is preferred.
29 """
30 node = get_node_from_mac_string(request.GET.get('mac', None))
31
32@@ -1889,7 +1903,7 @@
33 # 1-1 mapping.
34 subarch = pxelinux_subarch
35
36- nodegroup = find_nodegroup(request)
37+ nodegroup = find_nodegroup_for_pxeconfig_request(request)
38 preseed_url = compose_enlistment_preseed_url(nodegroup=nodegroup)
39 hostname = 'maas-enlist'
40 domain = Config.objects.get_config('enlistment_domain')
41
42=== modified file 'src/maasserver/tests/test_api.py'
43--- src/maasserver/tests/test_api.py 2012-12-04 10:17:17 +0000
44+++ src/maasserver/tests/test_api.py 2012-12-11 17:51:26 +0000
45@@ -59,6 +59,7 @@
46 extract_constraints,
47 extract_oauth_key,
48 extract_oauth_key_from_auth_header,
49+ find_nodegroup_for_pxeconfig_request,
50 get_oauth_token,
51 get_overrided_query_dict,
52 store_node_power_parameters,
53@@ -3436,7 +3437,7 @@
54 self.get_pxeconfig(),
55 ContainsAll(KernelParameters._fields))
56
57- def test_pxeconfig_returns_data_for_known_node(self):
58+ def test_pxeconfig_returns_success_for_known_node(self):
59 params = self.get_mac_params()
60 response = self.client.get(reverse('pxeconfig'), params)
61 self.assertEqual(httplib.OK, response.status_code)
62@@ -3446,7 +3447,7 @@
63 response = self.client.get(reverse('pxeconfig'), params)
64 self.assertEqual(httplib.NO_CONTENT, response.status_code)
65
66- def test_pxeconfig_returns_data_for_detailed_but_unknown_node(self):
67+ def test_pxeconfig_returns_success_for_detailed_but_unknown_node(self):
68 architecture = factory.getRandomEnum(ARCHITECTURE)
69 arch, subarch = architecture.split('/')
70 params = dict(
71@@ -3559,6 +3560,19 @@
72 compose_preseed_url(node),
73 json.loads(response.content)["preseed_url"])
74
75+ def find_nodegroup_for_pxeconfig_request_uses_cluster_uuid(self):
76+ # find_nodegroup_for_pxeconfig_request returns the nodegroup
77+ # identified by the cluster_uuid parameter, if given. It
78+ # completely ignores the other node or request details, as shown
79+ # here by passing a uuid for a different cluster.
80+ params = self.get_mac_params()
81+ nodegroup = factory.make_node_group()
82+ params['cluster_uuid'] = nodegroup.uuid
83+ request = RequestFactory.get(reverse('pxeconfig'), **params)
84+ self.assertEqual(
85+ nodegroup,
86+ find_nodegroup_for_pxeconfig_request(request))
87+
88 def test_preseed_url_for_known_node_uses_nodegroup_maas_url(self):
89 ng_url = 'http://%s' % factory.make_name('host')
90 network = IPNetwork("10.1.1/24")
91
92=== modified file 'src/provisioningserver/tests/test_tftp.py'
93--- src/provisioningserver/tests/test_tftp.py 2012-10-30 10:25:55 +0000
94+++ src/provisioningserver/tests/test_tftp.py 2012-12-11 17:51:26 +0000
95@@ -23,6 +23,7 @@
96
97 from maastesting.factory import factory
98 from maastesting.testcase import TestCase
99+from provisioningserver import tftp as tftp_module
100 from provisioningserver.pxe.tftppath import compose_config_path
101 from provisioningserver.tests.test_kernel_opts import make_kernel_parameters
102 from provisioningserver.tftp import (
103@@ -211,6 +212,9 @@
104 def test_get_reader_config_file(self):
105 # For paths matching re_config_file, TFTPBackend.get_reader() returns
106 # a Deferred that will yield a BytesReader.
107+ cluster_uuid = factory.getRandomUUID()
108+ self.patch(tftp_module, 'get_cluster_uuid').return_value = (
109+ cluster_uuid)
110 mac = factory.getRandomMACAddress(b"-")
111 config_path = compose_config_path(mac)
112 backend = TFTPBackend(self.make_dir(), b"http://example.com/")
113@@ -240,6 +244,7 @@
114 "mac": mac,
115 "local": call_context["local"][0], # address only.
116 "remote": call_context["remote"][0], # address only.
117+ "cluster_uuid": cluster_uuid,
118 }
119 observed_params = json.loads(output)
120 self.assertEqual(expected_params, observed_params)
121
122=== modified file 'src/provisioningserver/tftp.py'
123--- src/provisioningserver/tftp.py 2012-10-30 10:25:55 +0000
124+++ src/provisioningserver/tftp.py 2012-12-11 17:51:26 +0000
125@@ -28,6 +28,7 @@
126 from provisioningserver.enum import ARP_HTYPE
127 from provisioningserver.kernel_opts import KernelParameters
128 from provisioningserver.pxe.config import render_pxe_config
129+from provisioningserver.start_cluster_controller import get_cluster_uuid
130 from provisioningserver.utils import deferred
131 from tftp.backend import (
132 FilesystemSynchronousBackend,
133@@ -217,6 +218,10 @@
134 params["local"] = local_host
135 remote_host, remote_port = get("remote", (None, None))
136 params["remote"] = remote_host
137+ # XXX 2012-12-04 JeroenVermeulen bug=1086239: move
138+ # get_cluster_uuid to a properly reusable location, and
139+ # implement it without the celery import (and side effects).
140+ params["cluster_uuid"] = get_cluster_uuid()
141 d = self.get_config_reader(params)
142 d.addErrback(self.get_page_errback, file_name)
143 return d

Subscribers

People subscribed via source and target branches

to status/vote changes: