Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 56 additions & 7 deletions cloudinit/distros/raspberry_pi_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,73 @@

import logging

from cloudinit import subp
from cloudinit import subp, util
from cloudinit.distros import debian

LOG = logging.getLogger(__name__)


class Distro(debian.Distro):
def set_keymap(self, layout: str, model: str, variant: str, options: str):
"""Currently Raspberry Pi OS sys-mods only supports
setting the layout"""
contents = "\n".join(
[
"# This file was generated by cloud-init",
"",
f'XKBMODEL="{model}"',
f'XKBLAYOUT="{layout}"',
f'XKBVARIANT="{variant}"',
f'XKBOPTIONS="{options}"',
"",
'BACKSPACE="guess"', # This is provided on default installs
"",
]
)
util.write_file(
filename="/etc/default/keyboard",
content=contents,
mode=0o644,
omode="w",
)

subp.subp(
[
"/usr/lib/raspberrypi-sys-mods/imager_custom",
"set_keymap",
layout,
]
"/usr/bin/raspi-config",
"nonint",
"update_labwc_keyboard",
],
rcs=[0],
)
subp.subp(
[
"/usr/bin/raspi-config",
"nonint",
"update_squeekboard",
"restart",
],
rcs=[0],
)
self.manage_service("restart", "keyboard-setup")

if subp.which("setupcon") and subp.which("setsid"):
subp.subp(
[
"/usr/bin/setsid",
"/bin/sh",
"-c",
"exec setupcon --save -k --force <> /dev/tty1 >&0 2>&1",
],
rcs=[0],
)
if subp.which("udevadm"):
subp.subp(
[
"udevadm",
"trigger",
"--subsystem-match=input",
"--action=change",
],
rcs=[0],
)

def apply_locale(self, locale, out_fn=None, keyname="LANG"):
try:
Expand Down
9 changes: 0 additions & 9 deletions tests/unittests/distros/test_raspberry_pi_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@


class TestRaspberryPiOS:
@mock.patch(M_PATH + "subp.subp")
def test_set_keymap_calls_imager_custom(self, m_subp):
cls = fetch("raspberry_pi_os")
distro = cls("raspberry-pi-os", {}, None)
distro.set_keymap("us", "pc105", "basic", "")
m_subp.assert_called_once_with(
["/usr/lib/raspberrypi-sys-mods/imager_custom", "set_keymap", "us"]
)

@mock.patch(M_PATH + "subp.subp")
def test_apply_locale_happy_path(self, m_subp):
cls = fetch("raspberry_pi_os")
Expand Down