Skip to content

Commit

Permalink
CASMTRIAGE-6885 - fix etc/resolv.conf resolution for broken symlinks.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlaine-hpe-2 committed Apr 18, 2024
1 parent 9535415 commit 06558a3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.13.1] - 2024-04-12
### Changed
- CASMTRIAGE-6885 - fix etc/resolv.conf resolution when it is a broken symlink.

## [2.13.0] - 2024-03-01
### Added
- CASMCMS-8821 - add support for remote build jobs.
Expand Down
22 changes: 14 additions & 8 deletions scripts/buildenv-sidecar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ setup_user_shell() {
chmod 600 /etc/cray/ims

# Change signal location if user if jailed and not running on remote
if [ "$SSH_JAIL" = "True" -a "$REMOTE_BUILD_NODE" = ""]
if [ "$SSH_JAIL" = "True" -a -z "$REMOTE_BUILD_NODE"]
then
SIGNAL_FILE_COMPLETE=$IMAGE_ROOT_PARENT/image-root/tmp/complete
SIGNAL_FILE_FAILED=$IMAGE_ROOT_PARENT/image-root/tmp/failed
Expand Down Expand Up @@ -158,10 +158,10 @@ setup_resolv() {
local IMAGE_ROOT_DIR=$1
local IMAGE_ROOT_RESOLV=$IMAGE_ROOT_DIR/etc/resolv.conf
local TMP_RESOLV=$IMAGE_ROOT_DIR/tmp/resolv.conf
if [ -f "$IMAGE_ROOT_RESOLV" ]; then
if [ -f "$IMAGE_ROOT_RESOLV" -o -L "$IMAGE_ROOT_RESOLV" ]; then
mv "$IMAGE_ROOT_RESOLV" "$TMP_RESOLV"
fi
cp /etc/resolv.conf "$IMAGE_ROOT_RESOLV"
cp --remove-destination /etc/resolv.conf "$IMAGE_ROOT_RESOLV"
}

restore_resolv() {
Expand All @@ -170,7 +170,7 @@ restore_resolv() {
local IMAGE_ROOT_RESOLV=$IMAGE_ROOT_DIR/etc/resolv.conf
local TMP_RESOLV=$IMAGE_ROOT_DIR/tmp/resolv.conf
rm "$IMAGE_ROOT_RESOLV"
if [ -f "$TMP_RESOLV" ]; then
if [ -f "$TMP_RESOLV" -o -L "$TMP_RESOLV" ]; then
mv "$TMP_RESOLV" "$IMAGE_ROOT_RESOLV"
fi
}
Expand Down Expand Up @@ -200,13 +200,19 @@ case "$IMS_ACTION" in
fi
;;
customize)
# copy ca root key into the image before user shell
copy_ca_root_key "$IMAGE_ROOT_PARENT/image-root"
setup_resolv "$IMAGE_ROOT_PARENT/image-root"
# copy ca root key into the image before user shell if running locally
if [[ -z "${REMOTE_BUILD_NODE}" ]]; then
copy_ca_root_key "$IMAGE_ROOT_PARENT/image-root"
setup_resolv "$IMAGE_ROOT_PARENT/image-root"
fi

echo "Running user shell for customize action"
setup_user_shell
restore_resolv "$IMAGE_ROOT_PARENT/image-root"

# only restore the resolv file if running locally
if [[ -z "${REMOTE_BUILD_NODE}" ]]; then
restore_resolv "$IMAGE_ROOT_PARENT/image-root"
fi

if [ -f "$SIGNAL_FILE_FAILED" ]; then
echo "Customization of image root marked as failed. A new IMS image will not be created."
Expand Down
23 changes: 17 additions & 6 deletions scripts/remote_customize_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ setup_resolv() {
# Copy the container's /etc/resolv.conf to the image root for customization
local IMAGE_ROOT_RESOLV=$IMAGE_ROOT_DIR/etc/resolv.conf
local TMP_RESOLV=$IMAGE_ROOT_DIR/tmp/resolv.conf
if [ -f "$IMAGE_ROOT_RESOLV" ]; then
if [ -f "$IMAGE_ROOT_RESOLV" -o -L "$IMAGE_ROOT_RESOLV" ]; then
mv "$IMAGE_ROOT_RESOLV" "$TMP_RESOLV"
else
echo "Did not find an existing /etc/resolv.conf file"
fi
cp /etc/resolv.conf "$IMAGE_ROOT_RESOLV"
cp --remove-destination /etc/resolv.conf "$IMAGE_ROOT_RESOLV"
}

restore_resolv() {
# Restore the image root's old /etc/resolv.conf after customization
local IMAGE_ROOT_RESOLV=$IMAGE_ROOT_DIR/etc/resolv.conf
local TMP_RESOLV=$IMAGE_ROOT_DIR/tmp/resolv.conf
rm "$IMAGE_ROOT_RESOLV"
if [ -f "$TMP_RESOLV" ]; then
if [ -f "$TMP_RESOLV" -o -L "$TMP_RESOLV" ]; then
mv "$TMP_RESOLV" "$IMAGE_ROOT_RESOLV"
fi
}
Expand Down Expand Up @@ -109,6 +111,10 @@ fi
mkdir -p $IMAGE_ROOT_PARENT
unsquashfs -f -d $IMAGE_ROOT_DIR /data/image.sqsh

# clear any signal flags that were left in the image
rm $USER_SIGNAL_FILE_FAILED
rm $USER_SIGNAL_FILE_COMPLETE

# Copy cray certs into image
copy_ca_root_key

Expand Down Expand Up @@ -196,10 +202,11 @@ fi
restore_resolv

# if successful, package up the results into a squashfs file to transfer back to worker node
if [ ! -f "$USER_SIGNAL_FILE_FAILED" ]; then
# Remove the successful signal file and put failed flag in place in case squash fails
if [ -f "$USER_SIGNAL_FILE_COMPLETE" ]; then
# Remove the signal flags before squash and put failed flag in place in case squash fails
# NOTE: the sshd entrypoint script will be waiting for $SIGNAL_FILE_REMOTE_EXITING
rm $SIGNAL_FILE_COMPLETE
rm $USER_SIGNAL_FILE_FAILED
rm $USER_SIGNAL_FILE_COMPLETE
touch $SIGNAL_FILE_FAILED

# Make the squashfs formatted archive to transfer results back to job
Expand All @@ -215,6 +222,10 @@ if [ ! -f "$USER_SIGNAL_FILE_FAILED" ]; then
rm $SIGNAL_FILE_FAILED
touch $SIGNAL_FILE_COMPLETE
fi
else
# failed so set the correct signal files
rm $USER_SIGNAL_FILE_FAILED
touch $SIGNAL_FILE_FAILED
fi

# Signal that this is finished
Expand Down

0 comments on commit 06558a3

Please sign in to comment.