From 5836237221a61d7873087b4f0bb80b9a5ef2959f Mon Sep 17 00:00:00 2001 From: Patrick Uiterwijk Date: Tue, 7 Apr 2020 10:27:52 +0200 Subject: [PATCH] Add 'flags' for netboot, with noboot Signed-off-by: Patrick Uiterwijk --- tests/test_views_netboot.py | 26 ++++++++++++++++++++++++++ zezere/runreqs.py | 2 -- zezere/templates/netboot/grubcfg | 3 +++ zezere/templates/netboot/grubcfg_debug | 2 +- zezere/urls.py | 10 +++++----- zezere/views_netboot.py | 19 ++++++++++++++----- 6 files changed, 49 insertions(+), 13 deletions(-) diff --git a/tests/test_views_netboot.py b/tests/test_views_netboot.py index 31f1987..e262f6f 100644 --- a/tests/test_views_netboot.py +++ b/tests/test_views_netboot.py @@ -19,6 +19,7 @@ def test_static_grub_cfg(self): # Changing this URL is a solid API break. self.assertEqual(resp.status_code, 200) self.assertContains(resp, 'configfile "') + self.assertNotContains(resp, "set debug=all") def test_static_grub_cfg_head(self): resp = self.client.head("/netboot/x86_64/grub.cfg") @@ -42,6 +43,19 @@ def test_dynamic_grub_cfg_ok(self): resp = self.client.get(devurl) self.assertTemplateUsed(resp, "netboot/grubcfg") self.assertIsNotNone(resp.context["device"]) + self.assertContains(resp, "\nboot") + self.assertNotContains(resp, "set debug=all") + + def test_dynamic_grub_noboot_cfg_ok(self): + with self.loggedin_as(): + with self.claimed_device(self.DEVICE_1) as dev: + with self.device_with_runreq(dev, self.RUNREQ_RAWHIDE): + devurl = "/netboot/noboot/x86_64/grubcfg/%s" % self.DEVICE_1 + resp = self.client.get(devurl) + self.assertTemplateUsed(resp, "netboot/grubcfg") + self.assertIsNotNone(resp.context["device"]) + self.assertNotContains(resp, "\nboot") + self.assertNotContains(resp, "set debug=all") def test_dynamic_grub_debug_cfg_ok(self): with self.loggedin_as(): @@ -51,6 +65,18 @@ def test_dynamic_grub_debug_cfg_ok(self): resp = self.client.get(devurl) self.assertTemplateUsed(resp, "netboot/grubcfg") self.assertIsNotNone(resp.context["device"]) + self.assertContains(resp, "\nboot") + self.assertContains(resp, "set debug=all") + + def test_dynamic_grub_debug_noboot_cfg_ok(self): + with self.loggedin_as(): + with self.claimed_device(self.DEVICE_1) as dev: + with self.device_with_runreq(dev, self.RUNREQ_RAWHIDE): + devurl = "/netboot/debug+noboot/x86_64/grubcfg/%s" % self.DEVICE_1 + resp = self.client.get(devurl) + self.assertTemplateUsed(resp, "netboot/grubcfg") + self.assertIsNotNone(resp.context["device"]) + self.assertNotContains(resp, "\nboot") self.assertContains(resp, "set debug=all") def test_dynamic_grub_cfg_ok_ip_change(self): diff --git a/zezere/runreqs.py b/zezere/runreqs.py index d5c1ffd..fc089f8 100644 --- a/zezere/runreqs.py +++ b/zezere/runreqs.py @@ -103,7 +103,6 @@ def generate_runreq_grubcfg(request, device, runreq): return f""" linux {proxy_kernel_url} {runreq.kernel_cmd} initrd {proxy_initrd_url} -boot """ elif runreq.type == models.RunRequest.TYPE_EFI: @@ -112,7 +111,6 @@ def generate_runreq_grubcfg(request, device, runreq): insmod chain set root='(hd0,gpt1)' chainloader {runreq.settings.efi_path} -boot """ else: diff --git a/zezere/templates/netboot/grubcfg b/zezere/templates/netboot/grubcfg index f0846a8..155408a 100644 --- a/zezere/templates/netboot/grubcfg +++ b/zezere/templates/netboot/grubcfg @@ -6,6 +6,9 @@ {% if device.run_request %} {% render_runreq_grubcfg device %} +{% if 'noboot' not in flags %} +boot +{% endif %} {% elif device.owner is not None %} diff --git a/zezere/templates/netboot/grubcfg_debug b/zezere/templates/netboot/grubcfg_debug index 28ddbec..e7466e6 100644 --- a/zezere/templates/netboot/grubcfg_debug +++ b/zezere/templates/netboot/grubcfg_debug @@ -1,3 +1,3 @@ -{% if debug %} +{% if 'debug' in flags %} set debug=all {% endif %} diff --git a/zezere/urls.py b/zezere/urls.py index 8561150..370eb4e 100644 --- a/zezere/urls.py +++ b/zezere/urls.py @@ -89,24 +89,24 @@ views_netboot.arch_file, name="netboot_arch_file_double_slash", ), - # Netboot debug + # Netboot with different options path( - "netboot/debug//grub.cfg", + "netboot///grub.cfg", views_netboot.static_grub_cfg, name="netboot_grubcfg_static", ), path( - "netboot/debug//grubcfg/", + "netboot///grubcfg/", views_netboot.dynamic_grub_cfg, name="netboot_grubcfg_dynamic", ), path( - "netboot/debug//", + "netboot///", views_netboot.arch_file, name="netboot_arch_file", ), path( - "netboot/debug///", + "netboot////", views_netboot.arch_file, name="netboot_arch_file_double_slash", ), diff --git a/zezere/views_netboot.py b/zezere/views_netboot.py index 3b0e65a..b52e226 100644 --- a/zezere/views_netboot.py +++ b/zezere/views_netboot.py @@ -59,7 +59,7 @@ def index(request): return render_for_device(None, request, "netboot/index.html", context) -def arch_file(request, arch, filetype): +def arch_file(request, arch, filetype, flags=None): archfiles = ARCHES.get(arch) if not archfiles: raise Http404("Architecture not found") @@ -75,9 +75,14 @@ def arch_file(request, arch, filetype): return FileResponse(open(path, "rb"), content_type="application/efi") -def static_grub_cfg(request, arch): +def static_grub_cfg(request, arch, flags=None): + if flags: + flags = flags.split("+") + else: + flags = [] + contents = 'configfile "${http_path}/grubcfg/${net_default_mac}"' - if "debug" in request.path: + if "debug" in flags: contents += "\nset debug=all" content_len = len(contents) if request.method == "HEAD": @@ -107,10 +112,14 @@ def get_or_create_device(request, arch, mac_addr): return device -def dynamic_grub_cfg(request, arch, mac_addr): +def dynamic_grub_cfg(request, arch, mac_addr, flags=None): + if flags: + flags = flags.split("+") + else: + flags = [] context = { "service_url": request.build_absolute_uri("/"), - "debug": "debug" in request.path, + "flags": flags, } try: