Skip to content

Commit

Permalink
ci: move edge test to testing-farm
Browse files Browse the repository at this point in the history
  • Loading branch information
Yi He committed Jul 29, 2024
1 parent 7cd5abd commit 149a0bc
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 157 deletions.
1 change: 1 addition & 0 deletions .fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
308 changes: 158 additions & 150 deletions test/cases/ostree-simplified-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ set -euo pipefail
source /etc/os-release
ARCH=$(uname -m)

# In case port 8081 is already in use
sudo dnf install -y lsof
if lsof -nP -iTCP -sTCP:LISTEN|grep 8081; then
sudo fuser -k 8081/tcp
fi

# Provision the software under test.
/usr/libexec/osbuild-composer-test/provision.sh none

Expand Down Expand Up @@ -478,7 +484,7 @@ build_image simplified_iso_without_fdo "${INSTALLER_TYPE}" "${PROD_REPO_URL}/"
greenprint "📥 Downloading the simplified_iso_without_fdo image"
sudo composer-cli compose image "${COMPOSE_ID}" > /dev/null
ISO_FILENAME="${COMPOSE_ID}-${INSTALLER_FILENAME}"
sudo cp "${ISO_FILENAME}" /var/lib/libvirt/images
sudo mv "${ISO_FILENAME}" /var/lib/libvirt/images

# Clean compose and blueprints.
greenprint "🧹 Clean up simplified_iso_without_fdo blueprint and compose"
Expand Down Expand Up @@ -578,6 +584,7 @@ if [[ $(sudo virsh domstate "${IMAGE_KEY}-simplified_iso_without_fdo") == "runni
fi
sudo virsh undefine "${IMAGE_KEY}-simplified_iso_without_fdo" --nvram
sudo virsh vol-delete --pool images "$LIBVIRT_IMAGE_PATH"
sudo rm -fr /var/lib/libvirt/images/${ISO_FILENAME}

########################################################################
##
Expand Down Expand Up @@ -829,7 +836,7 @@ build_image fdosshkey "${INSTALLER_TYPE}" "${PROD_REPO_URL}"
greenprint "📥 Downloading the fdosshkey image"
sudo composer-cli compose image "${COMPOSE_ID}" > /dev/null
ISO_FILENAME="${COMPOSE_ID}-${INSTALLER_FILENAME}"
sudo cp "${ISO_FILENAME}" /var/lib/libvirt/images
sudo mv "${ISO_FILENAME}" /var/lib/libvirt/images

# Clean compose and blueprints.
greenprint "🧹 Clean up fdosshkey blueprint and compose"
Expand Down Expand Up @@ -946,145 +953,145 @@ sudo ansible-playbook -v -i "${TEMPDIR}"/inventory \
/usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0
check_result

##################################################################
##
## Build rebased ostree repo
##
##################################################################
tee "$BLUEPRINT_FILE" > /dev/null << EOF
name = "rebase"
description = "An rebase rhel-edge container image"
version = "0.0.2"
modules = []
groups = []
[[packages]]
name = "python3"
version = "*"
[[packages]]
name = "sssd"
version = "*"
[[packages]]
name = "wget"
version = "*"
[customizations.kernel]
name = "${KERNEL_RT_PKG}"
[[customizations.user]]
name = "admin"
description = "Administrator account"
password = "${EDGE_USER_PASSWORD_SHA512}"
home = "/home/admin/"
groups = ["wheel"]
EOF

greenprint "📄 rebase blueprint"
cat "$BLUEPRINT_FILE"

# Prepare the blueprint for the compose.
greenprint "📋 Preparing rebase blueprint"
sudo composer-cli blueprints push "$BLUEPRINT_FILE"
sudo composer-cli blueprints depsolve rebase

# Build upgrade image.
OSTREE_REF="test/redhat/x/${ARCH}/edge"
build_image rebase "$CONTAINER_TYPE" "$PROD_REPO_URL" "$PARENT_REF"

# Download the image
greenprint "📥 Downloading the rebase image"
sudo composer-cli compose image "${COMPOSE_ID}" > /dev/null

# Delete installation rhel-edge container and its image
greenprint "🧹 Delete installation rhel-edge container and its image"
# Remove rhel-edge container if exists
sudo podman ps -q --filter name=rhel-edge --format "{{.ID}}" | sudo xargs --no-run-if-empty podman rm -f
# Remove container image if exists
sudo podman images --filter "dangling=true" --format "{{.ID}}" | sudo xargs --no-run-if-empty podman rmi -f

# Deal with stage repo container
greenprint "🗜 Extracting image"
IMAGE_FILENAME="${COMPOSE_ID}-${CONTAINER_FILENAME}"
sudo podman pull "oci-archive:${IMAGE_FILENAME}"
sudo podman images
# Clear image file
sudo rm -f "$IMAGE_FILENAME"

# Run edge stage repo
greenprint "🛰 Running edge stage repo"
# Get image id to run image
EDGE_IMAGE_ID=$(sudo podman images --filter "dangling=true" --format "{{.ID}}")
sudo podman run -d --name rhel-edge --network edge --ip "$STAGE_REPO_ADDRESS" "$EDGE_IMAGE_ID"
# Wait for container to be running
until [ "$(sudo podman inspect -f '{{.State.Running}}' rhel-edge)" == "true" ]; do
sleep 1;
done;

# Pull rebase commit to prod mirror
greenprint "⛓ Pull rebase commit to prod mirror"
sudo ostree --repo="$PROD_REPO" pull --mirror edge-stage "$OSTREE_REF"

# Get ostree commit value.
greenprint "🕹 Get ostree rebase commit value"
REBASE_HASH=$(curl "${PROD_REPO_URL}/refs/heads/${OSTREE_REF}")

# Clean compose and blueprints.
greenprint "🧽 Clean up rebase blueprint and compose"
sudo composer-cli compose delete "${COMPOSE_ID}" > /dev/null
sudo composer-cli blueprints delete rebase > /dev/null

greenprint "🗳 Rebase ostree image/commit"
sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@${EDGE_GUEST_ADDRESS} "echo '${EDGE_USER_PASSWORD}' |sudo -S rpm-ostree rebase ${REF_PREFIX}:${OSTREE_REF}"
sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@${EDGE_GUEST_ADDRESS} "echo '${EDGE_USER_PASSWORD}' |nohup sudo -S systemctl reboot &>/dev/null & exit"

# Sleep 10 seconds here to make sure vm restarted already
sleep 10

# Check for ssh ready to go.
greenprint "🛃 Checking for SSH is ready to go"
# shellcheck disable=SC2034 # Unused variables left for readability
for _ in $(seq 0 30); do
RESULTS="$(wait_for_ssh_up $EDGE_GUEST_ADDRESS)"
if [[ $RESULTS == 1 ]]; then
echo "SSH is ready now! 🥳"
break
fi
sleep 10
done

# Check ostree rebase result
check_result

# Add instance IP address into /etc/ansible/hosts
sudo tee "${TEMPDIR}"/inventory > /dev/null << EOF
[ostree_guest]
${EDGE_GUEST_ADDRESS}
[ostree_guest:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_user=${ANSIBLE_USER}
ansible_private_key_file=${SSH_KEY}
ansible_ssh_common_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
ansible_become=yes
ansible_become_method=sudo
ansible_become_pass=${EDGE_USER_PASSWORD}
EOF

# Test IoT/Edge OS
sudo ansible-playbook -v -i "${TEMPDIR}"/inventory \
-e image_type=rhel-edge \
-e ostree_commit="${REBASE_HASH}" \
-e skip_rollback_test="true" \
-e edge_type=edge-simplified-installer \
-e fdo_credential="true" \
-e sysroot_ro="$SYSROOT_RO" \
-e mfg_guest_int_name="${MFG_GUEST_INT_NAME}" \
-e fips="${FIPS}" \
/usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0

check_result
# ##################################################################
# ##
# ## Build rebased ostree repo
# ##
# ##################################################################
# tee "$BLUEPRINT_FILE" > /dev/null << EOF
# name = "rebase"
# description = "An rebase rhel-edge container image"
# version = "0.0.2"
# modules = []
# groups = []

# [[packages]]
# name = "python3"
# version = "*"

# [[packages]]
# name = "sssd"
# version = "*"

# [[packages]]
# name = "wget"
# version = "*"

# [customizations.kernel]
# name = "${KERNEL_RT_PKG}"

# [[customizations.user]]
# name = "admin"
# description = "Administrator account"
# password = "${EDGE_USER_PASSWORD_SHA512}"
# home = "/home/admin/"
# groups = ["wheel"]
# EOF

# greenprint "📄 rebase blueprint"
# cat "$BLUEPRINT_FILE"

# # Prepare the blueprint for the compose.
# greenprint "📋 Preparing rebase blueprint"
# sudo composer-cli blueprints push "$BLUEPRINT_FILE"
# sudo composer-cli blueprints depsolve rebase

# # Build upgrade image.
# OSTREE_REF="test/redhat/x/${ARCH}/edge"
# build_image rebase "$CONTAINER_TYPE" "$PROD_REPO_URL" "$PARENT_REF"

# # Download the image
# greenprint "📥 Downloading the rebase image"
# sudo composer-cli compose image "${COMPOSE_ID}" > /dev/null

# # Delete installation rhel-edge container and its image
# greenprint "🧹 Delete installation rhel-edge container and its image"
# # Remove rhel-edge container if exists
# sudo podman ps -q --filter name=rhel-edge --format "{{.ID}}" | sudo xargs --no-run-if-empty podman rm -f
# # Remove container image if exists
# sudo podman images --filter "dangling=true" --format "{{.ID}}" | sudo xargs --no-run-if-empty podman rmi -f

# # Deal with stage repo container
# greenprint "🗜 Extracting image"
# IMAGE_FILENAME="${COMPOSE_ID}-${CONTAINER_FILENAME}"
# sudo podman pull "oci-archive:${IMAGE_FILENAME}"
# sudo podman images
# # Clear image file
# sudo rm -f "$IMAGE_FILENAME"

# # Run edge stage repo
# greenprint "🛰 Running edge stage repo"
# # Get image id to run image
# EDGE_IMAGE_ID=$(sudo podman images --filter "dangling=true" --format "{{.ID}}")
# sudo podman run -d --name rhel-edge --network edge --ip "$STAGE_REPO_ADDRESS" "$EDGE_IMAGE_ID"
# # Wait for container to be running
# until [ "$(sudo podman inspect -f '{{.State.Running}}' rhel-edge)" == "true" ]; do
# sleep 1;
# done;

# # Pull rebase commit to prod mirror
# greenprint "⛓ Pull rebase commit to prod mirror"
# sudo ostree --repo="$PROD_REPO" pull --mirror edge-stage "$OSTREE_REF"

# # Get ostree commit value.
# greenprint "🕹 Get ostree rebase commit value"
# REBASE_HASH=$(curl "${PROD_REPO_URL}/refs/heads/${OSTREE_REF}")

# # Clean compose and blueprints.
# greenprint "🧽 Clean up rebase blueprint and compose"
# sudo composer-cli compose delete "${COMPOSE_ID}" > /dev/null
# sudo composer-cli blueprints delete rebase > /dev/null

# greenprint "🗳 Rebase ostree image/commit"
# sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@${EDGE_GUEST_ADDRESS} "echo '${EDGE_USER_PASSWORD}' |sudo -S rpm-ostree rebase ${REF_PREFIX}:${OSTREE_REF}"
# sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@${EDGE_GUEST_ADDRESS} "echo '${EDGE_USER_PASSWORD}' |nohup sudo -S systemctl reboot &>/dev/null & exit"

# # Sleep 10 seconds here to make sure vm restarted already
# sleep 10

# # Check for ssh ready to go.
# greenprint "🛃 Checking for SSH is ready to go"
# # shellcheck disable=SC2034 # Unused variables left for readability
# for _ in $(seq 0 30); do
# RESULTS="$(wait_for_ssh_up $EDGE_GUEST_ADDRESS)"
# if [[ $RESULTS == 1 ]]; then
# echo "SSH is ready now! 🥳"
# break
# fi
# sleep 10
# done

# # Check ostree rebase result
# check_result

# # Add instance IP address into /etc/ansible/hosts
# sudo tee "${TEMPDIR}"/inventory > /dev/null << EOF
# [ostree_guest]
# ${EDGE_GUEST_ADDRESS}

# [ostree_guest:vars]
# ansible_python_interpreter=/usr/bin/python3
# ansible_user=${ANSIBLE_USER}
# ansible_private_key_file=${SSH_KEY}
# ansible_ssh_common_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
# ansible_become=yes
# ansible_become_method=sudo
# ansible_become_pass=${EDGE_USER_PASSWORD}
# EOF

# # Test IoT/Edge OS
# sudo ansible-playbook -v -i "${TEMPDIR}"/inventory \
# -e image_type=rhel-edge \
# -e ostree_commit="${REBASE_HASH}" \
# -e skip_rollback_test="true" \
# -e edge_type=edge-simplified-installer \
# -e fdo_credential="true" \
# -e sysroot_ro="$SYSROOT_RO" \
# -e mfg_guest_int_name="${MFG_GUEST_INT_NAME}" \
# -e fips="${FIPS}" \
# /usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0

# check_result

# Clean up VM
greenprint "🧹 Clean up VM"
Expand All @@ -1093,15 +1100,16 @@ if [[ $(sudo virsh domstate "${IMAGE_KEY}-fdosshkey") == "running" ]]; then
fi
sudo virsh undefine "${IMAGE_KEY}-fdosshkey" --nvram
sudo virsh vol-delete --pool images "$LIBVIRT_IMAGE_PATH"
sudo rm -fr /var/lib/libvirt/images/${ISO_FILENAME}

# Re configure OSTREE_REF because it's change to "test/redhat/x/${ARCH}/edge" by above rebase test
if [[ "$ID" == fedora ]]; then
OSTREE_REF="${ID}/${VERSION_ID}/${ARCH}/iot"
elif [[ "$VERSION_ID" == 8* ]]; then
OSTREE_REF="${ID}/8/${ARCH}/edge"
else
OSTREE_REF="${ID}/9/${ARCH}/edge"
fi
# # Re configure OSTREE_REF because it's change to "test/redhat/x/${ARCH}/edge" by above rebase test
# if [[ "$ID" == fedora ]]; then
# OSTREE_REF="${ID}/${VERSION_ID}/${ARCH}/iot"
# elif [[ "$VERSION_ID" == 8* ]]; then
# OSTREE_REF="${ID}/8/${ARCH}/edge"
# else
# OSTREE_REF="${ID}/9/${ARCH}/edge"
# fi

##################################################################
##
Expand Down Expand Up @@ -1162,7 +1170,7 @@ build_image fdorootcert "${INSTALLER_TYPE}" "${PROD_REPO_URL}/"
greenprint "📥 Downloading the fdorootcert image"
sudo composer-cli compose image "${COMPOSE_ID}" > /dev/null
ISO_FILENAME="${COMPOSE_ID}-${INSTALLER_FILENAME}"
sudo cp "${ISO_FILENAME}" /var/lib/libvirt/images
sudo mv "${ISO_FILENAME}" /var/lib/libvirt/images

# Clean compose and blueprints.
greenprint "🧹 Clean up fdorootcert blueprint and compose"
Expand Down
2 changes: 1 addition & 1 deletion test/cases/ostree-vsphere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ EDGE_USER_PASSWORD_SHA512=$(openssl passwd -6 -stdin <<< "${EDGE_USER_PASSWORD}"

DATACENTER_70="Datacenter7.0"
DATASTORE_70="datastore-80"
DATACENTER_70_POOL="/Datacenter7.0/host/Automation/Resources"
DATACENTER_70_POOL="/Datacenter7.0/host/Edge/Resources"
# Workdaround for creating rhel9 and centos9 on dc67, change guest_id to 8
case "${ID}-${VERSION_ID}" in
"rhel-9"* )
Expand Down
Loading

0 comments on commit 149a0bc

Please sign in to comment.