Test/ostree-raw-image: test dirs and files customizations

Extend the `ostree-raw-image.sh` to use the directories and files
customizations for the raw image and test their effect using the ansible
playbook.

Custom files and directories are currently tested only on Fedora,
because they are allowed by policy only there.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2023-02-13 12:40:11 +01:00 committed by Achilleas Koutsou
parent 956e3b9b69
commit bf377d81c1

View file

@ -90,6 +90,7 @@ KERNEL_RT_PKG="kernel-rt"
# Set up variables.
SYSROOT_RO="false"
CUSTOM_DIRS_FILES="false"
case "${ID}-${VERSION_ID}" in
"rhel-8.8")
@ -119,6 +120,7 @@ case "${ID}-${VERSION_ID}" in
OS_VARIANT="fedora-unknown"
OSTREE_OSNAME="fedora-iot"
SYSROOT_RO="true"
CUSTOM_DIRS_FILES="true"
;;
*)
echo "unsupported distro: ${ID}-${VERSION_ID}"
@ -507,6 +509,36 @@ groups = ["wheel"]
EOF
fi
# Add directory and files customization, and services customization for testing
if [[ "$CUSTOM_DIRS_FILES" == "true" ]]; then
tee -a "$BLUEPRINT_FILE" > /dev/null << EOF
[[customizations.directories]]
path = "/etc/custom_dir/dir1"
user = 1020
group = 1020
mode = "0770"
ensure_parents = true
[[customizations.files]]
path = "/etc/systemd/system/custom.service"
data = "[Unit]\nDescription=Custom service\n[Service]\nType=oneshot\nRemainAfterExit=yes\nExecStart=/usr/bin/false\n[Install]\nWantedBy=multi-user.target\n"
[[customizations.files]]
path = "/etc/custom_file.txt"
data = "image builder is the best\n"
[[customizations.directories]]
path = "/etc/systemd/system/custom.service.d"
[[customizations.files]]
path = "/etc/systemd/system/custom.service.d/override.conf"
data = "[Service]\nExecStart=\nExecStart=/usr/bin/cat /etc/custom_file.txt\n"
[customizations.services]
enabled = ["custom.service"]
EOF
fi
greenprint "📄 raw image blueprint"
cat "$BLUEPRINT_FILE"
@ -624,6 +656,7 @@ EOF
-e edge_type=edge-raw-image \
-e ostree_commit="${INSTALL_HASH}" \
-e sysroot_ro="$SYSROOT_RO" \
-e test_custom_dirs_files="$CUSTOM_DIRS_FILES" \
/usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0
check_result
@ -652,6 +685,7 @@ EOF
-e edge_type=edge-raw-image \
-e ostree_commit="${INSTALL_HASH}" \
-e sysroot_ro="$SYSROOT_RO" \
-e test_custom_dirs_files="$CUSTOM_DIRS_FILES" \
/usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0
check_result
fi
@ -753,6 +787,7 @@ sudo ansible-playbook -v -i "${TEMPDIR}"/inventory \
-e edge_type=edge-raw-image \
-e ostree_commit="${INSTALL_HASH}" \
-e sysroot_ro="$SYSROOT_RO" \
-e test_custom_dirs_files="$CUSTOM_DIRS_FILES" \
/usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0
check_result
@ -783,6 +818,7 @@ EOF
-e edge_type=edge-raw-image \
-e ostree_commit="${INSTALL_HASH}" \
-e sysroot_ro="$SYSROOT_RO" \
-e test_custom_dirs_files="$CUSTOM_DIRS_FILES" \
/usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0
check_result
fi
@ -836,6 +872,36 @@ groups = ["wheel"]
EOF
fi
# Add directory and files customization, and services customization for testing
if [[ "$CUSTOM_DIRS_FILES" == "true" ]]; then
tee -a "$BLUEPRINT_FILE" > /dev/null << EOF
[[customizations.directories]]
path = "/etc/custom_dir/dir1"
user = 1020
group = 1020
mode = "0770"
ensure_parents = true
[[customizations.files]]
path = "/etc/systemd/system/custom.service"
data = "[Unit]\nDescription=Custom service\n[Service]\nType=oneshot\nRemainAfterExit=yes\nExecStart=/usr/bin/false\n[Install]\nWantedBy=multi-user.target\n"
[[customizations.files]]
path = "/etc/custom_file.txt"
data = "image builder is the best\n"
[[customizations.directories]]
path = "/etc/systemd/system/custom.service.d"
[[customizations.files]]
path = "/etc/systemd/system/custom.service.d/override.conf"
data = "[Service]\nExecStart=\nExecStart=/usr/bin/cat /etc/custom_file.txt\n"
[customizations.services]
enabled = ["custom.service"]
EOF
fi
greenprint "📄 upgrade blueprint"
cat "$BLUEPRINT_FILE"
@ -945,6 +1011,7 @@ EOF
-e edge_type=edge-raw-image \
-e ostree_commit="${UPGRADE_HASH}" \
-e sysroot_ro="$SYSROOT_RO" \
-e test_custom_dirs_files="$CUSTOM_DIRS_FILES" \
/usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0
check_result
fi
@ -974,6 +1041,7 @@ sudo ansible-playbook -v -i "${TEMPDIR}"/inventory \
-e edge_type=edge-raw-image \
-e ostree_commit="${UPGRADE_HASH}" \
-e sysroot_ro="$SYSROOT_RO" \
-e test_custom_dirs_files="$CUSTOM_DIRS_FILES" \
/usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0
check_result