Merge pull request #26771 from YHNdnzj/machinectl-edit

machinectl: add verb edit and cat to operate on .nspawn files
This commit is contained in:
Yu Watanabe
2023-03-16 04:02:11 +09:00
committed by GitHub
4 changed files with 228 additions and 4 deletions
+4
View File
@@ -7,4 +7,8 @@ TEST_DESCRIPTION="Tests for auxiliary utilities"
# shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions"
test_append_files() (
image_install script
)
do_test "$@"
+43
View File
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
# shellcheck disable=SC2016
set -eux
set -o pipefail
# shellcheck source=test/units/assert.sh
. "$(dirname "$0")"/assert.sh
: >/failed
at_exit() {
if [[ -v NSPAWN_NAME && -e "/var/lib/machines/$NSPAWN_NAME" ]]; then
rm -fvr "/var/lib/machines/$NSPAWN_NAME" "/etc/systemd/nspawn/$NSPAWN_NAME" "new"
fi
return 0
}
trap at_exit EXIT
export NSPAWN_NAME="machinectl-test-$RANDOM.nspawn"
cat >"/var/lib/machines/$NSPAWN_NAME" <<\EOF
[Exec]
Boot=true
EOF
EDITOR='true' script -ec 'machinectl edit "$NSPAWN_NAME"' /dev/null
[ -f "/etc/systemd/nspawn/$NSPAWN_NAME" ]
cmp "/var/lib/machines/$NSPAWN_NAME" "/etc/systemd/nspawn/$NSPAWN_NAME"
cat >new <<\EOF
[Exec]
Boot=false
EOF
script -ec 'machinectl cat "$PWD/new"' /dev/null
EDITOR='mv new' script -ec 'machinectl edit "$NSPAWN_NAME"' /dev/null
printf '%s\n' '[Exec]' 'Boot=false' | cmp - "/etc/systemd/nspawn/$NSPAWN_NAME"
touch /testok
rm /failed