Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Oct 17, 2024
1 parent 5bc451f commit c475d72
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 46 deletions.
8 changes: 7 additions & 1 deletion cloudinit/config/cc_ca_certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ def disable_default_ca_certs(distro_name, distro_cfg):
"""
if distro_name in ["rhel", "photon"]:
remove_default_ca_certs(distro_cfg)
elif distro_name in ["alpine", "aosc", "debian", "raspberry-pi-os", "ubuntu"]:
elif distro_name in [
"alpine",
"aosc",
"debian",
"raspberry-pi-os",
"ubuntu",
]:
disable_system_ca_certs(distro_cfg)

if distro_name in ["debian", "raspberry-pi-os", "ubuntu"]:
Expand Down
6 changes: 3 additions & 3 deletions cloudinit/config/cc_rpi_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#
# This file is part of cloud-init. See LICENSE file for license information.

import logging
from cloudinit import subp
from cloudinit.cloud import Cloud
from cloudinit.config import Config
from cloudinit.config.schema import MetaSchema
from cloudinit.settings import PER_INSTANCE
import logging


LOG = logging.getLogger(__name__)
Expand All @@ -31,7 +31,7 @@ def configure_rpi_connect(enable: bool) -> None:
try:
subp.subp(["/usr/bin/raspi-config", "do_rpi_connect", str(num)])
except subp.ProcessExecutionError as e:
LOG.error(f"Failed to configure rpi-connect: {e}")
LOG.error("Failed to configure rpi-connect: %s", e)


def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
Expand All @@ -43,5 +43,5 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
configure_rpi_connect(enable)
else:
LOG.warning(
f"Invalid value for {ENABLE_RPI_CONNECT_KEY}: " + str(enable)
"Invalid value for %s: %s", ENABLE_RPI_CONNECT_KEY, enable
)
33 changes: 20 additions & 13 deletions cloudinit/config/cc_rpi_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#
# This file is part of cloud-init. See LICENSE file for license information.

import logging
from cloudinit import subp
from cloudinit.cloud import Cloud
from cloudinit.config import Config
from cloudinit.config.schema import MetaSchema
from cloudinit.settings import PER_INSTANCE
import logging


LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -86,17 +86,17 @@ def configure_serial_interface(cfg: dict | bool, instCfg: Config) -> None:
]
)
except subp.ProcessExecutionError as e:
LOG.error(f"Failed to configure serial hardware: {e}")
LOG.error("Failed to configure serial hardware: %s", e)

require_reboot(instCfg)
except subp.ProcessExecutionError as e:
LOG.error(f"Failed to configure serial console: {e}")
LOG.error("Failed to configure serial console: %s", e)


def enable_ssh(cfg: Config, enable: bool) -> None:
if not enable:
return

try:
subp.subp(
[
Expand All @@ -106,7 +106,7 @@ def enable_ssh(cfg: Config, enable: bool) -> None:
)
require_reboot(cfg)
except subp.ProcessExecutionError as e:
LOG.error(f"Failed to enable ssh: {e}")
LOG.error("Failed to enable ssh: %s", e)


def configure_interface(iface: str, enable: bool) -> None:
Expand All @@ -124,42 +124,49 @@ def configure_interface(iface: str, enable: bool) -> None:
]
)
except subp.ProcessExecutionError as e:
LOG.error(f"Failed to configure {iface}: {e}")
LOG.error("Failed to configure %s: %s", iface, e)


def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
if RPI_INTERFACES_KEY not in cfg:
return
elif not isinstance(cfg[RPI_INTERFACES_KEY], dict):
LOG.warning(
f"Invalid value for {RPI_INTERFACES_KEY}: "
+ cfg[RPI_INTERFACES_KEY]
"Invalid value for %s: %s",
RPI_INTERFACES_KEY,
cfg[RPI_INTERFACES_KEY],
)
return
elif not cfg[RPI_INTERFACES_KEY]:
LOG.debug(f"Empty value for {RPI_INTERFACES_KEY}. Skipping...")
LOG.debug("Empty value for %s. Skipping...", RPI_INTERFACES_KEY)
return

# check for supported ARM interfaces
for key in cfg[RPI_INTERFACES_KEY]:
if key not in SUPPORTED_INTERFACES.keys():
LOG.warning(f"Invalid key for {RPI_INTERFACES_KEY}: {key}")
LOG.warning("Invalid key for %s: %s", RPI_INTERFACES_KEY, key)
continue

enable = cfg[RPI_INTERFACES_KEY][key]

if key == "serial":
if not isinstance(enable, dict) and not isinstance(enable, bool):
LOG.warning(
f"Invalid value for {RPI_INTERFACES_KEY}.{key}: {enable}"
"Invalid value for %s.%s: %s",
RPI_INTERFACES_KEY,
key,
enable,
)
else:
configure_serial_interface(enable, cfg)
continue
elif key == "ssh":
if not isinstance(enable, bool):
LOG.warning(
f"Invalid value for {RPI_INTERFACES_KEY}.{key}: {enable}"
"Invalid value for %s.%s: %s",
RPI_INTERFACES_KEY,
key,
enable,
)
else:
enable_ssh(cfg, enable)
Expand All @@ -169,5 +176,5 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
configure_interface(key, enable)
else:
LOG.warning(
f"Invalid value for {RPI_INTERFACES_KEY}.{key}: {enable}"
"Invalid value for %s.%s: %s", RPI_INTERFACES_KEY, key, enable
)
47 changes: 24 additions & 23 deletions cloudinit/config/cc_rpi_userdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
#
# This file is part of cloud-init. See LICENSE file for license information.

import logging
import os
import time
import subprocess
from cloudinit import subp
from cloudinit.cloud import Cloud
from cloudinit.config import Config
from cloudinit.config.schema import MetaSchema
from cloudinit.settings import PER_ALWAYS

import logging
import os
import subprocess
import time

LOG = logging.getLogger(__name__)
DISABLE_PIWIZ_KEY = "disable_piwiz"
Expand Down Expand Up @@ -101,7 +100,7 @@ def run_userconf_service(
LOG.error("Userconf service timed out.")
return False
except Exception as e:
LOG.error(f"Error running service: {e}")
LOG.warning("Error running service: %s", e)
if base:
try:
os.remove(f"{base}/userconf.txt")
Expand All @@ -116,17 +115,17 @@ def run_service(
# Ensure the TTY exists before trying to open it
if not os.path.exists(USERCONF_SERVICE_TTY):
if not passwd_override:
LOG.error(f"TTY device {USERCONF_SERVICE_TTY} does not exist.")
return
LOG.error("TTY device %s does not exist.", USERCONF_SERVICE_TTY)
return False
else:
LOG.debug(f"TTY device {USERCONF_SERVICE_TTY} does not exist.")
LOG.debug("TTY device %s does not exist.", USERCONF_SERVICE_TTY)

# should never happen and not solvable by the user
assert (passwd_override is None and user_override is None) or (
passwd_override is not None and user_override is not None
), (
"Internal error: User override is required when password "
+ "override is provided."
"Internal error: User override is required when password " \
"override is provided."
)

base: str | None = None
Expand All @@ -138,7 +137,7 @@ def run_service(
assert base, "Internal error: Failed to get firmware location."
with open(f"{base}/userconf.txt", "w") as f:
f.write(f"{user_override}:{passwd_override}")
LOG.debug(f"Userconf override file written to {base}/userconf.txt")
LOG.debug("Userconf override file written to %s/userconf.txt", base)

LOG.debug("Start running userconf-pi service loop...")
while True:
Expand All @@ -158,11 +157,11 @@ def configure_pizwiz(
user_override: str | None = None,
) -> None:
LOG.debug(
"Configuring piwiz with disable_piwiz=%s, passwd_override=%s, "
+ "user_override=%s",
"Configuring piwiz with disable_piwiz=%s, passwd_override=%s, " \
"user_override=%s",
bool_to_str(disable),
bool_to_str(passwd_override != None),
bool_to_str(user_override != None),
bool_to_str(passwd_override is not None),
bool_to_str(user_override is not None),
)

if disable:
Expand Down Expand Up @@ -192,8 +191,8 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
"/usr/lib/userconf-pi"
):
LOG.debug(
"Userconf-Pi: deactivation file detected or userconf-pi "
+ "not installed. Skipping..."
"Userconf-Pi: deactivation file detected or userconf-pi " \
"not installed. Skipping..."
)
return

Expand All @@ -207,19 +206,21 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
# user key is optional with default to pi
user_override = userconf.get("user", "pi")
LOG.debug(
f"Userconf override: user={user_override}, "
+ "password=<REDACTED>"
"Userconf override: user=%s, " \
"password=<REDACTED>",
user_override
)
else:
LOG.error(f"Invalid userconf-pi configuration: {userconf}")
LOG.error("Invalid userconf-pi configuration: %s", userconf)

if not password_override and DISABLE_PIWIZ_KEY in cfg:
if isinstance(cfg[DISABLE_PIWIZ_KEY], bool):
disable_piwiz = cfg[DISABLE_PIWIZ_KEY]
else:
LOG.error(
f"Invalid {DISABLE_PIWIZ_KEY} configuration: "
+ cfg[DISABLE_PIWIZ_KEY]
"Invalid %s configuration: %s",
str(cfg[DISABLE_PIWIZ_KEY]),
DISABLE_PIWIZ_KEY
)

configure_pizwiz(cfg, disable_piwiz, password_override, user_override)
7 changes: 5 additions & 2 deletions tests/unittests/config/test_cc_rpi_connect.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# This file is part of cloud-init. See LICENSE file for license information.

from cloudinit.config.cc_rpi_connect import ENABLE_RPI_CONNECT_KEY
from cloudinit.config.schema import validate_cloudconfig_schema, get_schema
from cloudinit.config.schema import SchemaValidationError
from cloudinit.config.schema import (
SchemaValidationError,
get_schema,
validate_cloudconfig_schema,
)
from tests.unittests.helpers import skipUnlessJsonSchema
import pytest

Expand Down
7 changes: 5 additions & 2 deletions tests/unittests/config/test_cc_rpi_interfaces.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# This file is part of cloud-init. See LICENSE file for license information.

from cloudinit.config.cc_rpi_interfaces import RPI_INTERFACES_KEY
from cloudinit.config.schema import validate_cloudconfig_schema, get_schema
from cloudinit.config.schema import SchemaValidationError
from cloudinit.config.schema import (
SchemaValidationError,
get_schema,
validate_cloudconfig_schema,
)
from tests.unittests.helpers import skipUnlessJsonSchema
import pytest

Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/config/test_cc_rpi_userdata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# This file is part of cloud-init. See LICENSE file for license information.

import pytest
from cloudinit.config.cc_rpi_userdata import (
DISABLE_PIWIZ_KEY,
RPI_USERCONF_KEY,
Expand All @@ -10,6 +9,7 @@
get_schema,
validate_cloudconfig_schema,
)
import pytest
from tests.unittests.helpers import skipUnlessJsonSchema

"""
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_render_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_variant_sets_default_user_in_cloud_cfg(self, variant, tmpdir):
("openbsd", ["openbsd"]),
("ubuntu", ["netplan", "eni", "sysconfig"]),
(
"raspberry-pi-os",
"raspberry-pi-os",
["netplan", "network-manager", "networkd", "eni"]
)
),
Expand Down

0 comments on commit c475d72

Please sign in to comment.