Skip to content

Commit

Permalink
Add 'flags' for netboot, with noboot
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Uiterwijk <[email protected]>
  • Loading branch information
puiterwijk authored and mergify[bot] committed Apr 7, 2020
1 parent 42a1775 commit 5836237
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
26 changes: 26 additions & 0 deletions tests/test_views_netboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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():
Expand All @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions zezere/runreqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -112,7 +111,6 @@ def generate_runreq_grubcfg(request, device, runreq):
insmod chain
set root='(hd0,gpt1)'
chainloader {runreq.settings.efi_path}
boot
"""

else:
Expand Down
3 changes: 3 additions & 0 deletions zezere/templates/netboot/grubcfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down
2 changes: 1 addition & 1 deletion zezere/templates/netboot/grubcfg_debug
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% if debug %}
{% if 'debug' in flags %}
set debug=all
{% endif %}
10 changes: 5 additions & 5 deletions zezere/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,24 @@
views_netboot.arch_file,
name="netboot_arch_file_double_slash",
),
# Netboot debug
# Netboot with different options
path(
"netboot/debug/<str:arch>/grub.cfg",
"netboot/<str:flags>/<str:arch>/grub.cfg",
views_netboot.static_grub_cfg,
name="netboot_grubcfg_static",
),
path(
"netboot/debug/<str:arch>/grubcfg/<str:mac_addr>",
"netboot/<str:flags>/<str:arch>/grubcfg/<str:mac_addr>",
views_netboot.dynamic_grub_cfg,
name="netboot_grubcfg_dynamic",
),
path(
"netboot/debug/<str:arch>/<str:filetype>",
"netboot/<str:flags>/<str:arch>/<str:filetype>",
views_netboot.arch_file,
name="netboot_arch_file",
),
path(
"netboot/debug/<str:arch>//<str:filetype>",
"netboot/<str:flags>/<str:arch>//<str:filetype>",
views_netboot.arch_file,
name="netboot_arch_file_double_slash",
),
Expand Down
19 changes: 14 additions & 5 deletions zezere/views_netboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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":
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 5836237

Please sign in to comment.