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
21 changes: 7 additions & 14 deletions .github/workflows/ci-check-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ defaults:
shell: sh -ex {0}

jobs:
check_format:
check_linters:
strategy:
fail-fast: false
matrix:
env: [ruff, mypy, pylint, black, isort]
env: [check_format]
name: Check ${{ matrix.env }}
runs-on: ubuntu-latest
env:
Expand All @@ -30,6 +30,7 @@ jobs:
run: |
sudo DEBIAN_FRONTEND=noninteractive apt-get -qy update
sudo DEBIAN_FRONTEND=noninteractive apt-get -qy install tox
sudo snap install shfmt

- name: Print version
run: python3 --version
Expand All @@ -39,20 +40,12 @@ jobs:
# matrix env: not to be confused w/environment variables or testenv
TOXENV: ${{ matrix.env }}
run: tox
schema-format:
strategy:
fail-fast: false
name: Check json format
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Test format
- name: Formatting check failed
if: failure()
run: |
tools/check_json_format.sh cloudinit/config/schemas/schema-cloud-config-v1.json
tools/check_json_format.sh cloudinit/config/schemas/schema-network-config-v1.json
tools/check_json_format.sh cloudinit/config/schemas/versions.schema.cloud-config.json
echo "[31mResolve formatting errors with `tox -e do_format` (requires shfmt to format shell).\e[0m"
echo "[31mFor mypy and pylint failures see the warnings above.\e[0m"

doc:
strategy:
Expand Down
33 changes: 2 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,18 @@ distro ?= redhat

GENERATOR_F=./systemd/cloud-init-generator
DS_IDENTIFY=./tools/ds-identify
BENCHMARK=./tools/benchmark.sh


all: check

check: test

style-check: lint

lint:
@$(CWD)/tools/run-lint

unittest: clean_pyc
$(PYTHON) -m pytest -v tests/unittests cloudinit

render-template:
$(PYTHON) ./tools/render-template --variant=$(VARIANT) $(FILE) $(subst .tmpl,,$(FILE))

# from systemd-generator(7) regarding generators:
# "We do recommend C code however, since generators are executed
# synchronously and hence delay the entire boot if they are slow."
#
# Our generator is a shell script. Make it easy to measure the
# generator. This should be monitored for performance regressions
benchmark-generator: FILE=$(GENERATOR_F).tmpl
benchmark-generator: VARIANT="benchmark"
benchmark-generator: export ITER=$(NUM_ITER)
benchmark-generator: render-template
$(BENCHMARK) $(GENERATOR_F)

benchmark-ds-identify: export ITER=$(NUM_ITER)
benchmark-ds-identify:
$(BENCHMARK) $(DS_IDENTIFY)

ci-deps-ubuntu:
@$(PYTHON) $(CWD)/tools/read-dependencies --distro ubuntu --test-distro

Expand Down Expand Up @@ -103,13 +81,6 @@ deb-src:
doc:
tox -e doc

fmt:
tox -e do_format && tox -e check_format

fmt-tip:
tox -e do_format_tip && tox -e check_format_tip


.PHONY: all check test lint clean rpm srpm deb deb-src clean_pyc
.PHONY: unittest style-check render-template benchmark-generator
.PHONY: all check test clean rpm srpm deb deb-src clean_pyc
.PHONY: unittest render-template
.PHONY: clean_pytest clean_packaging clean_release doc
11 changes: 6 additions & 5 deletions tools/Z99-cloud-locale-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
# (c) 2012, Canonical Group, Ltd.
#
# This file is part of cloud-init. See LICENSE file for license information.

# Purpose: Detect invalid locale settings and inform the user
# of how to fix them.

locale_warn() {
command -v local >/dev/null && local _local="local" ||
command -v local > /dev/null && local _local="local" ||
typeset _local="typeset"

$_local bad_names="" bad_lcs="" key="" val="" var="" vars="" bad_kv=""
Expand All @@ -27,13 +27,14 @@ locale_warn() {
# locale: Cannot set LC_SOMETHING to default locale
while read -r w1 w2 w3 w4 remain; do
case "$w1" in
locale:) bad_names="${bad_names} ${w4}";;
locale:) bad_names="${bad_names} ${w4}" ;;
*)
key=${w1%%=*}
val=${w1#*=}
val=${val#\"}
val=${val%\"}
vars="${vars} $key=$val";;
vars="${vars} $key=$val"
;;
esac
done
for bad in $bad_names; do
Expand Down Expand Up @@ -93,7 +94,7 @@ locale_warn() {
printf "_____________________________________________________________________\n\n"

# only show the message once
: > ~/.cloud-locale-test.skip 2>/dev/null || :
: > ~/.cloud-locale-test.skip 2> /dev/null || :
}

[ -f ~/.cloud-locale-test.skip -o -f /var/lib/cloud/instance/locale-check.skip ] ||
Expand Down
4 changes: 2 additions & 2 deletions tools/Z99-cloudinit-warnings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Purpose: show user warnings on login.

cloud_init_warnings() {
command -v local >/dev/null && local _local="local" ||
command -v local > /dev/null && local _local="local" ||
typeset _local="typeset"
$_local warning="" idir="/var/lib/cloud/instance" n=0
$_local warndir="$idir/warnings"
Expand All @@ -16,7 +16,7 @@ cloud_init_warnings() {
for warning in "$warndir"/*; do
[ -f "$warning" ] || continue
cat "$warning"
n=$((n+1))
n=$((n + 1))
done
[ $n -eq 0 ] && return 0
echo ""
Expand Down
8 changes: 0 additions & 8 deletions tools/benchmark.sh

This file was deleted.

5 changes: 4 additions & 1 deletion tools/build-on-freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

set -eux

fail() { echo "FAILED:" "$@" 1>&2; exit 1; }
fail() {
echo "FAILED:" "$@" 1>&2
exit 1
}

PYTHON="${PYTHON:-python3}"
if [ ! $(which ${PYTHON}) ]; then
Expand Down
5 changes: 4 additions & 1 deletion tools/build-on-netbsd
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/sh

fail() { echo "FAILED:" "$@" 1>&2; exit 1; }
fail() {
echo "FAILED:" "$@" 1>&2
exit 1
}

PYTHON="${PYTHON:-python3}"
if [ ! $(which ${PYTHON}) ]; then
Expand Down
13 changes: 8 additions & 5 deletions tools/build-on-openbsd
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/sh

fail() { echo "FAILED:" "$@" 1>&2; exit 1; }
fail() {
echo "FAILED:" "$@" 1>&2
exit 1
}

PYTHON=${PYTHON:-python3}
if ! command -v ${PYTHON} >/dev/null 2>&1; then
if ! command -v ${PYTHON} > /dev/null 2>&1; then
echo "Please install python first."
exit 1
fi
Expand All @@ -27,10 +30,10 @@ pkgs="
wget
"

[ -f $depschecked ] || echo "Installing the following packages: $pkgs"; output=$(pkg_add -zI $pkgs 2>&1)

[ -f $depschecked ] || echo "Installing the following packages: $pkgs"
output=$(pkg_add -zI $pkgs 2>&1)

if echo "$output" | grep -q -e "Can't find" -e "Ambiguous"; then
if echo "$output" | grep -q -e "Can't find" -e "Ambiguous"; then
echo "Failed to find or install one or more packages"
echo "Failed Package(s):"
echo "$output"
Expand Down
11 changes: 0 additions & 11 deletions tools/check_json_format.sh

This file was deleted.

10 changes: 5 additions & 5 deletions tools/cloud-init-hotplugd
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ PIPE="/run/cloud-init/share/hook-hotplug-cmd"
[ -p $PIPE ] || mkfifo -m700 $PIPE

while true; do
# shellcheck disable=SC2162
if read args < $PIPE; then
# shellcheck disable=SC2086
/usr/bin/cloud-init devel hotplug-hook $args
fi
# shellcheck disable=SC2162
if read args < $PIPE; then
# shellcheck disable=SC2086
/usr/bin/cloud-init devel hotplug-hook $args
fi
done
49 changes: 31 additions & 18 deletions tools/cloud-init-per
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DATA_PRE="/var/lib/cloud/sem/bootper"
INST_PRE="/var/lib/cloud/instance/sem/bootper"

Usage() {
cat <<EOF
cat << EOF
Usage: ${0##*/} frequency name cmd [ arg1 [ arg2 [ ... ] ]
run cmd with arguments provided.

Expand All @@ -20,38 +20,51 @@ Usage: ${0##*/} frequency name cmd [ arg1 [ arg2 [ ... ] ]
EOF
}
error() { echo "$@" 1>&2; }
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
fail() {
[ $# -eq 0 ] || error "$@"
exit 1
}

# support the old 'cloud-init-run-module freq name "execute" cmd arg1'
# if < 3 arguments, it will fail below on usage.
if [ "${0##*/}" = "cloud-init-run-module" ]; then
if [ $# -le 2 -o "$3" = "execute" ]; then
error "Warning: ${0##*/} is deprecated. Please use cloud-init-per."
freq=$1; name=$2;
[ $# -le 2 ] || shift 3;
set -- "$freq" "$name" "$@"
else
fail "legacy cloud-init-run-module only supported with module 'execute'"
fi
if [ $# -le 2 -o "$3" = "execute" ]; then
error "Warning: ${0##*/} is deprecated. Please use cloud-init-per."
freq=$1
name=$2
[ $# -le 2 ] || shift 3
set -- "$freq" "$name" "$@"
else
fail "legacy cloud-init-run-module only supported with module 'execute'"
fi
fi

[ "$1" = "-h" -o "$1" = "--help" ] && { Usage ; exit 0; }
[ $# -ge 3 ] || { Usage 1>&2; exit 1; }
[ "$1" = "-h" -o "$1" = "--help" ] && {
Usage
exit 0
}
[ $# -ge 3 ] || {
Usage 1>&2
exit 1
}
freq=$1
name=$(echo $2 | sed 's/-/_/g')
shift 2;
shift 2

[ "${name#*/}" = "${name}" ] || fail "name cannot contain a /"
[ "$(id -u)" = "0" ] || fail "must be root"

case "$freq" in
once|always) sem="${DATA_PRE}.$name.$freq";;
instance) sem="${INST_PRE}.$name.$freq";;
*) Usage 1>&2; fail "invalid frequency: $freq";;
once | always) sem="${DATA_PRE}.$name.$freq" ;;
instance) sem="${INST_PRE}.$name.$freq" ;;
*)
Usage 1>&2
fail "invalid frequency: $freq"
;;
esac

[ -d "${sem%/*}" ] || mkdir -p "${sem%/*}" ||
fail "failed to make directory for ${sem}"
fail "failed to make directory for ${sem}"

# Rename legacy sem files with dashes in their names. Do not overwrite existing
# sem files to prevent clobbering those which may have been created from calls
Expand All @@ -63,5 +76,5 @@ sem_legacy=$(echo $sem | sed 's/_/-/g')
"$@"
ret=$?
printf "%s\t%s\n" "$ret" "$(date +%s)" > "$sem" ||
fail "failed to write to $sem"
fail "failed to write to $sem"
exit $ret
Loading