Merge ~cgrabowski/maas:use-maas-run-scripts-instead-of-host-info into maas:master

Proposed by Christian Grabowski
Status: Merged
Approved by: Christian Grabowski
Approved revision: e0cf6bd87f39171c9a1dc149b2d9833123212fa8
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~cgrabowski/maas:use-maas-run-scripts-instead-of-host-info
Merge into: maas:master
Diff against target: 308 lines (+35/-73)
12 files modified
Makefile (+0/-2)
debian/maas-common.install (+0/-6)
debian/rules (+0/-3)
dev/null (+0/-32)
src/host-info/Makefile (+2/-3)
src/maasserver/urls.py (+0/-10)
src/maasserver/webapp.py (+0/-4)
src/metadataserver/templates/hardware_sync_service.template (+8/-3)
src/metadataserver/tests/test_vendor_data.py (+6/-1)
src/metadataserver/vendor_data.py (+19/-2)
src/provisioningserver/rackdservices/http.py (+0/-1)
src/provisioningserver/templates/http/rackd.nginx.conf.template (+0/-6)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Alexsander de Souza Approve
Review via email: mp+416552@code.launchpad.net

Commit message

use maas-run-scripts instead of hardware sync

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b use-maas-run-scripts-instead-of-host-info lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/12041/console
COMMIT: 99a2f6722c5e07951131e37ed726810ac9973a34

review: Needs Fixing
e0cf6bd... by Christian Grabowski

remove old redirect handler from urls

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b use-maas-run-scripts-instead-of-host-info lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/12044/console
COMMIT: c9e5038d2925911763ccab154676bb378f5b902d

review: Needs Fixing
Revision history for this message
Alexsander de Souza (alexsander-souza) wrote :

+1

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b use-maas-run-scripts-instead-of-host-info lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/12046/console
COMMIT: 6536a47b44eec29a68fde4fcfdc025404f58b75d

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b use-maas-run-scripts-instead-of-host-info lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: e0cf6bd87f39171c9a1dc149b2d9833123212fa8

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/Makefile b/Makefile
2index 334c5ed..35923f5 100644
3--- a/Makefile
4+++ b/Makefile
5@@ -450,6 +450,4 @@ sync-dev-snap: $(UI_BUILD) $(DEV_SNAP_PRIME_MARKER)
6 $(RSYNC) snap/local/tree/ $(DEV_SNAP_PRIME_DIR)/
7 $(RSYNC) src/host-info/bin/machine-resources/ \
8 $(DEV_SNAP_PRIME_DIR)/usr/share/maas/machine-resources/
9- $(RSYNC) src/host-info/bin/hardware-sync/ \
10- $(DEV_SNAP_PRIME_DIR)/usr/share/maas/hardware-sync/
11 .PHONY: sync-dev-snap
12diff --git a/debian/maas-common.install b/debian/maas-common.install
13index 8e2ac95..48e970a 100644
14--- a/debian/maas-common.install
15+++ b/debian/maas-common.install
16@@ -19,12 +19,6 @@ debian/tmp/usr/share/maas/machine-resources/armhf usr/share/maas/machine-resourc
17 debian/tmp/usr/share/maas/machine-resources/i386 usr/share/maas/machine-resources
18 debian/tmp/usr/share/maas/machine-resources/ppc64el usr/share/maas/machine-resources
19 debian/tmp/usr/share/maas/machine-resources/s390x usr/share/maas/machine-resources
20-debian/tmp/usr/share/maas/hardware-sync/amd64 usr/share/maas/hardware-sync
21-debian/tmp/usr/share/maas/hardware-sync/arm64 usr/share/maas/hardware-sync
22-debian/tmp/usr/share/maas/hardware-sync/armhf usr/share/maas/hardware-sync
23-debian/tmp/usr/share/maas/hardware-sync/i386 usr/share/maas/hardware-sync
24-debian/tmp/usr/share/maas/hardware-sync/ppc64el usr/share/maas/hardware-sync
25-debian/tmp/usr/share/maas/hardware-sync/s390x usr/share/maas/hardware-sync
26
27 usr/bin/maas-common /usr/lib/maas
28 etc/maas/certificates
29diff --git a/debian/rules b/debian/rules
30index d5842f7..104dcd7 100755
31--- a/debian/rules
32+++ b/debian/rules
33@@ -38,12 +38,9 @@ override_dh_auto_install:
34
35 # Build and move lxd commissioning binaries
36 install -d -m 755 $(CURDIR)/debian/tmp/usr/share/maas/machine-resources
37- install -d -m 755 $(CURDIR)/debian/tmp/usr/share/maas/hardware-sync
38 make -C $(CURDIR)/src/host-info build
39 mv $(CURDIR)/src/host-info/bin/machine-resources/* \
40 $(CURDIR)/debian/tmp/usr/share/maas/machine-resources/
41- mv $(CURDIR)/src/host-info/bin/hardware-sync/* \
42- $(CURDIR)/debian/tmp/usr/share/maas/hardware-sync/
43
44 # install the apparmor profile
45 install -d -m 755 $(CURDIR)/debian/tmp/etc/apparmor.d/dhcpd.d
46diff --git a/src/host-info/Makefile b/src/host-info/Makefile
47index d3a2b66..fe91c33 100644
48--- a/src/host-info/Makefile
49+++ b/src/host-info/Makefile
50@@ -30,7 +30,7 @@ $(MACHINE_RESOURCES_BINARIES): vendor
51 $(HARDWARE_SYNC_BINARIES): vendor
52 GOCACHE=$(GO_CACHE_DIR) GOARCH=$(DEB_GO_ARCH_$(notdir $@)) go build -mod vendor -ldflags '-s -w' -o $@ $(HARDWARE_SYNC_DIR)
53
54-build: $(MACHINE_RESOURCES_BINARIES) $(HARDWARE_SYNC_BINARIES)
55+build: $(MACHINE_RESOURCES_BINARIES)
56 .PHONY: build
57
58 clean:
59@@ -41,9 +41,8 @@ format:
60 @go fmt $(PACKAGE_DIR)
61 .PHONY: format
62
63-install: $(MACHINE_RESOURCES_BINARIES) $(HARDWARE_SYNC_BINARIES)
64+install: $(MACHINE_RESOURCES_BINARIES)
65 install -t $(DESTDIR)/usr/share/maas/machine-resources -D $(MACHINE_RESOURCES_BINARIES)
66- install -t $(DESTDIR)/usr/share/maas/hardware-sync -D $(HARDWARE_SYNC_BINARIES)
67 .PHONY: install
68
69 vendor:
70diff --git a/src/maasserver/api/maas_run_scripts.py b/src/maasserver/api/maas_run_scripts.py
71deleted file mode 100644
72index cb9986b..0000000
73--- a/src/maasserver/api/maas_run_scripts.py
74+++ /dev/null
75@@ -1,11 +0,0 @@
76-# Copyright 2022 Canonical Ltd. This software is licensed under the
77-# GNU Affero General Public License version 3 (see the file LICENSE).
78-
79-from django.shortcuts import redirect
80-
81-from maasserver.api.support import AnonymousOperationsHandler
82-
83-
84-class MAASRunScriptHandler(AnonymousOperationsHandler):
85- def read(self, request, architecture):
86- return redirect(f"/MAAS/hardware-sync/{architecture}")
87diff --git a/src/maasserver/api/tests/test_maas_run_scripts.py b/src/maasserver/api/tests/test_maas_run_scripts.py
88deleted file mode 100644
89index bd8b2eb..0000000
90--- a/src/maasserver/api/tests/test_maas_run_scripts.py
91+++ /dev/null
92@@ -1,32 +0,0 @@
93-# Copyright 2022 Canonical Ltd. This software is licensed under the
94-# GNU Affero General Public License version 3 (see the file LICENSE).
95-
96-import http.client
97-
98-from django.urls import reverse
99-
100-from maasserver.testing.api import APITestCase
101-from maasserver.testing.factory import factory
102-
103-
104-class TestMAASRunScriptHandlerFor(APITestCase.ForAnonymous):
105- def _get_maas_run_scripts_url(self, arch=None):
106- if arch is None:
107- return reverse("maas-run-scripts")
108- return reverse("maas-run-scripts-bin", args=[arch])
109-
110- def test_read_no_architecture_arg_serves_scripts(self):
111- response = self.client.get(self._get_maas_run_scripts_url())
112- self.assertEqual(http.client.OK, response.status_code)
113- self.assertEqual("text/x-python", response["Content-Type"])
114- self.assertIn(b"#!/usr/bin/env python3", response.content)
115-
116- def test_read_architecture_serves_binary(self):
117- node = factory.make_Node()
118- response = self.client.get(
119- self._get_maas_run_scripts_url(arch=node.architecture)
120- )
121- self.assertEqual(http.client.FOUND, response.status_code)
122- self.assertEqual(
123- f"/MAAS/hardware-sync/{node.architecture}", response.url
124- )
125diff --git a/src/maasserver/urls.py b/src/maasserver/urls.py
126index 328d0f5..536033e 100644
127--- a/src/maasserver/urls.py
128+++ b/src/maasserver/urls.py
129@@ -9,8 +9,6 @@ from django.http import HttpResponse
130 from django.views.generic import TemplateView
131
132 from maasserver import urls_api
133-from maasserver.api.maas_run_scripts import MAASRunScriptHandler
134-from maasserver.api.support import OperationsResource
135 from maasserver.bootresources import (
136 simplestreams_file_handler,
137 simplestreams_stream_handler,
138@@ -22,9 +20,6 @@ from maasserver.views.account import authenticate, csrf, login, logout
139 from maasserver.views.rpc import info
140 from maasserver.views.vmhost import vmhost_certificate_handler
141
142-maas_run_script_handler = OperationsResource(MAASRunScriptHandler)
143-
144-
145 # Anonymous views.
146 urlpatterns = [
147 url(r"^accounts/login/$", login, name="login"),
148@@ -53,11 +48,6 @@ urlpatterns = [
149 ),
150 name="maas-run-scripts",
151 ),
152- url(
153- r"^maas-run-scripts/(?P<architecture>.*)$",
154- maas_run_script_handler,
155- name="maas-run-scripts-bin",
156- ),
157 url(r"^metrics$", prometheus_stats_handler, name="metrics"),
158 url(
159 r"^metrics/endpoints$",
160diff --git a/src/maasserver/webapp.py b/src/maasserver/webapp.py
161index 1aed785..4eec5a8 100644
162--- a/src/maasserver/webapp.py
163+++ b/src/maasserver/webapp.py
164@@ -273,10 +273,6 @@ class WebApplicationService(StreamServerEndpointService):
165 get_root_path() / "usr/share/maas/machine-resources"
166 ),
167 )
168- maas.putChild(
169- b"hardware-sync",
170- NoListingFile(get_root_path() / "usr/share/maas/hardware-sync"),
171- )
172
173 # Setup static docs
174 maas.putChild(
175diff --git a/src/metadataserver/templates/hardware_sync_service.template b/src/metadataserver/templates/hardware_sync_service.template
176index 806bd42..3855d9f 100644
177--- a/src/metadataserver/templates/hardware_sync_service.template
178+++ b/src/metadataserver/templates/hardware_sync_service.template
179@@ -6,6 +6,11 @@ After=network.target
180
181 [Service]
182 type=oneshot
183-ExecStartPre=/usr/bin/wget -O /usr/bin/maas-hardware-sync {{ maas_url }}/hardware-sync/{{ architecture }}
184-ExecStartPre=/bin/chmod 0755 /usr/bin/maas-hardware-sync
185-ExecStart=/bin/echo "TODO run hardware-sync commands"
186+ExecStartPre=/usr/bin/wget -O /usr/bin/maas-run-scripts {{ maas_url }}/maas-run-scripts
187+ExecStartPre=/bin/chmod 0755 /usr/bin/maas-run-scripts
188+ExecStartPre=/usr/bin/maas-run-scripts get-machine-token\
189+ --maas-url='{{ maas_url }}'\
190+ --admin_toke='{{ admin_token }}'\
191+ {{ system_id }}\
192+ {{ token_file_path }}
193+ExecStart=/usr/bin/maas-run-scripts report-results --config {{ token_file_path }}
194diff --git a/src/metadataserver/tests/test_vendor_data.py b/src/metadataserver/tests/test_vendor_data.py
195index 6c4000a..7936ed3 100644
196--- a/src/metadataserver/tests/test_vendor_data.py
197+++ b/src/metadataserver/tests/test_vendor_data.py
198@@ -29,6 +29,7 @@ from maastesting.matchers import MockNotCalled
199 from metadataserver import vendor_data
200 from metadataserver.vendor_data import (
201 _get_metadataserver_template,
202+ _get_node_admin_token,
203 generate_ephemeral_deployment_network_configuration,
204 generate_ephemeral_netplan_lock_removal,
205 generate_hardware_sync_systemd_configuration,
206@@ -39,6 +40,7 @@ from metadataserver.vendor_data import (
207 generate_system_info,
208 get_node_maas_url,
209 get_vendor_data,
210+ HARDWARE_SYNC_MACHINE_TOKEN_PATH,
211 HARDWARE_SYNC_SERVICE_TEMPLATE,
212 HARDWARE_SYNC_TIMER_TEMPLATE,
213 )
214@@ -732,7 +734,10 @@ class TestGenerateHardwareSyncSystemdConfiguration(MAASServerTestCase):
215 },
216 {
217 "content": self._get_service_template().substitute(
218- maas_url=maas_url, architecture=node.architecture
219+ admin_token=_get_node_admin_token(node),
220+ maas_url=maas_url,
221+ system_id=node.system_id,
222+ token_file_path=HARDWARE_SYNC_MACHINE_TOKEN_PATH,
223 ),
224 "path": "/lib/systemd/system/maas_hardware_sync.service",
225 },
226diff --git a/src/metadataserver/vendor_data.py b/src/metadataserver/vendor_data.py
227index 2d17e6a..58b5be6 100644
228--- a/src/metadataserver/vendor_data.py
229+++ b/src/metadataserver/vendor_data.py
230@@ -18,6 +18,7 @@ import yaml
231 from maasserver import ntp
232 from maasserver.models import Config, NodeMetadata
233 from maasserver.models.controllerinfo import get_target_version
234+from maasserver.models.user import get_auth_tokens
235 from maasserver.node_status import COMMISSIONING_LIKE_STATUSES
236 from maasserver.permissions import NodePermission
237 from maasserver.preseed import get_network_yaml_settings
238@@ -31,8 +32,9 @@ from provisioningserver.utils.text import make_gecos_field
239 LXD_CERTIFICATE_METADATA_KEY = "lxd_certificate"
240 VIRSH_PASSWORD_METADATA_KEY = "virsh_password"
241
242-HARDWARE_SYNC_TIMER_TEMPLATE = "hardware_sync_timer.template"
243+HARDWARE_SYNC_MACHINE_TOKEN_PATH = "/tmp/maas-machine-creds.yml"
244 HARDWARE_SYNC_SERVICE_TEMPLATE = "hardware_sync_service.template"
245+HARDWARE_SYNC_TIMER_TEMPLATE = "hardware_sync_timer.template"
246
247
248 def get_vendor_data(node, proxy):
249@@ -369,6 +371,17 @@ def _get_metadataserver_template(template_name):
250 ).decode("utf-8")
251
252
253+def _get_node_admin_token(node):
254+ admin_token = ""
255+ if node.owner:
256+ token = get_auth_tokens(node.owner).first()
257+ if token:
258+ admin_token = ":".join(token.consumer.key, token.key, token.secret)
259+ if token.consumer.secret:
260+ admin_token = f"{admin_token}:{token.consumer.secret}"
261+ return admin_token
262+
263+
264 def generate_hardware_sync_systemd_configuration(node):
265 """generate systemd unit files for hardware sync"""
266 if not node.enable_hw_sync:
267@@ -389,8 +402,12 @@ def generate_hardware_sync_systemd_configuration(node):
268 hardware_sync_timer = hardware_sync_timer_tmpl.substitute(
269 hardware_sync_interval=hardware_sync_interval
270 )
271+
272 hardware_sync_service = hardware_sync_service_tmpl.substitute(
273- maas_url=maas_url, architecture=node.architecture
274+ admin_token=_get_node_admin_token(node),
275+ maas_url=maas_url,
276+ system_id=node.system_id,
277+ token_file_path=HARDWARE_SYNC_MACHINE_TOKEN_PATH,
278 )
279
280 yield "write_files", [
281diff --git a/src/provisioningserver/rackdservices/http.py b/src/provisioningserver/rackdservices/http.py
282index bb0672d..9ca4583 100644
283--- a/src/provisioningserver/rackdservices/http.py
284+++ b/src/provisioningserver/rackdservices/http.py
285@@ -177,7 +177,6 @@ class RackHTTPService(TimerService):
286 "upstream_http": list(sorted(upstream_http)),
287 "resource_root": self._resource_root,
288 "machine_resources": str(root_prefix / "usr/share/maas"),
289- "hardware_sync": str(root_prefix / "usr/share/maas"),
290 }
291 )
292 except NameError as error:
293diff --git a/src/provisioningserver/templates/http/rackd.nginx.conf.template b/src/provisioningserver/templates/http/rackd.nginx.conf.template
294index a0cfca0..f73a7be 100644
295--- a/src/provisioningserver/templates/http/rackd.nginx.conf.template
296+++ b/src/provisioningserver/templates/http/rackd.nginx.conf.template
297@@ -30,12 +30,6 @@ server {
298 gzip on;
299 }
300
301- location /hardware-sync/ {
302- root {{hardware_sync}};
303- autoindex on;
304- gzip on;
305- }
306-
307 location /images/ {
308 auth_request /log;
309

Subscribers

People subscribed via source and target branches