|
Packit Service |
bcdfb1 |
#!/bin/bash
|
|
Packit Service |
bcdfb1 |
set -euo pipefail
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
OSBUILD_COMPOSER_TEST_DATA=/usr/share/tests/osbuild-composer
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
source /etc/os-release
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Colorful output.
|
|
Packit Service |
bcdfb1 |
function greenprint {
|
|
Packit Service |
bcdfb1 |
echo -e "\033[1;32m${1}\033[0m"
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Provision the software under tet.
|
|
Packit Service |
bcdfb1 |
/usr/libexec/osbuild-composer-test/provision.sh
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Apply lorax patch to work around pytoml issues in RHEL 8.x.
|
|
Packit Service |
bcdfb1 |
# See BZ 1843704 or https://github.com/weldr/lorax/pull/1030 for more details.
|
|
Packit Service |
bcdfb1 |
if [[ $ID == rhel ]]; then
|
|
Packit Service |
bcdfb1 |
sudo sed -r -i 's#toml.load\(args\[3\]\)#toml.load(open(args[3]))#' \
|
|
Packit Service |
bcdfb1 |
/usr/lib/python3.6/site-packages/composer/cli/compose.py
|
|
Packit Service |
bcdfb1 |
sudo rm -f /usr/lib/python3.6/site-packages/composer/cli/compose.pyc
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
GOVC_CMD=/tmp/govc
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# shellcheck source=/dev/null
|
|
Packit Service |
bcdfb1 |
source "$VCENTER_CREDS"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# We need govc to talk to vSphere
|
|
Packit Service |
bcdfb1 |
if ! hash govc; then
|
|
Packit Service |
bcdfb1 |
greenprint "Installing govc"
|
|
Packit Service |
bcdfb1 |
pushd /tmp
|
|
Packit Service |
bcdfb1 |
curl -Ls --retry 5 --output govc.gz \
|
|
Packit Service |
bcdfb1 |
https://github.com/vmware/govmomi/releases/download/v0.24.0/govc_linux_amd64.gz
|
|
Packit Service |
bcdfb1 |
gunzip -f govc.gz
|
|
Packit Service |
bcdfb1 |
chmod +x /tmp/govc
|
|
Packit Service |
bcdfb1 |
$GOVC_CMD version
|
|
Packit Service |
bcdfb1 |
popd
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
TEST_UUID=$(uuidgen)
|
|
Packit Service |
bcdfb1 |
IMAGE_KEY=osbuild-composer-vmware-test-${TEST_UUID}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Jenkins sets WORKSPACE to the job workspace, but if this script runs
|
|
Packit Service |
bcdfb1 |
# outside of Jenkins, we can set up a temporary directory instead.
|
|
Packit Service |
bcdfb1 |
if [[ ${WORKSPACE:-empty} == empty ]]; then
|
|
Packit Service |
bcdfb1 |
WORKSPACE=$(mktemp -d)
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Set up temporary files
|
|
Packit Service |
bcdfb1 |
TEMPDIR=$(mktemp -d)
|
|
Packit Service |
bcdfb1 |
VMWARE_CONFIG=${TEMPDIR}/vmware.toml
|
|
Packit Service |
bcdfb1 |
BLUEPRINT_FILE=${TEMPDIR}/blueprint.toml
|
|
Packit Service |
bcdfb1 |
COMPOSE_START=${TEMPDIR}/compose-start-${IMAGE_KEY}.json
|
|
Packit Service |
bcdfb1 |
COMPOSE_INFO=${TEMPDIR}/compose-info-${IMAGE_KEY}.json
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Check that the system started and is running correctly
|
|
Packit Service |
bcdfb1 |
running_test_check () {
|
|
Packit Service |
bcdfb1 |
STATUS=$(sudo ssh -i $OSBUILD_COMPOSER_TEST_DATA/keyring/id_rsa redhat@"${1}" 'systemctl --wait is-system-running')
|
|
Packit Service |
bcdfb1 |
if [[ $STATUS == running || $STATUS == degraded ]]; then
|
|
Packit Service |
bcdfb1 |
echo 0
|
|
Packit Service |
bcdfb1 |
else
|
|
Packit Service |
bcdfb1 |
echo 1
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Get the compose log.
|
|
Packit Service |
bcdfb1 |
get_compose_log () {
|
|
Packit Service |
bcdfb1 |
COMPOSE_ID=$1
|
|
Packit Service |
bcdfb1 |
LOG_FILE=${WORKSPACE}/osbuild-${ID}-${VERSION_ID}-vmware.log
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Download the logs.
|
|
Packit Service |
bcdfb1 |
sudo composer-cli compose log "$COMPOSE_ID" | tee "$LOG_FILE" > /dev/null
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Get the compose metadata.
|
|
Packit Service |
bcdfb1 |
get_compose_metadata () {
|
|
Packit Service |
bcdfb1 |
COMPOSE_ID=$1
|
|
Packit Service |
bcdfb1 |
METADATA_FILE=${WORKSPACE}/osbuild-${ID}-${VERSION_ID}-vmware.json
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Download the metadata.
|
|
Packit Service |
bcdfb1 |
sudo composer-cli compose metadata "$COMPOSE_ID" > /dev/null
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Find the tarball and extract it.
|
|
Packit Service |
bcdfb1 |
TARBALL=$(basename "$(find . -maxdepth 1 -type f -name "*-metadata.tar")")
|
|
Packit Service |
bcdfb1 |
tar -xf "$TARBALL"
|
|
Packit Service |
bcdfb1 |
rm -f "$TARBALL"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Move the JSON file into place.
|
|
Packit Service |
bcdfb1 |
cat "${COMPOSE_ID}".json | jq -M '.' | tee "$METADATA_FILE" > /dev/null
|
|
Packit Service |
bcdfb1 |
}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Write an VMWare TOML file
|
|
Packit Service |
bcdfb1 |
tee "$VMWARE_CONFIG" > /dev/null << EOF
|
|
Packit Service |
bcdfb1 |
provider = "vmware"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
[settings]
|
|
Packit Service |
bcdfb1 |
host = "${GOVMOMI_URL}"
|
|
Packit Service |
bcdfb1 |
username = "${GOVMOMI_USERNAME}"
|
|
Packit Service |
bcdfb1 |
password = "${GOVMOMI_PASSWORD}"
|
|
Packit Service |
bcdfb1 |
cluster = "${GOVMOMI_CLUSTER}"
|
|
Packit Service |
bcdfb1 |
dataStore = "${GOVMOMI_DATASTORE}"
|
|
Packit Service |
bcdfb1 |
dataCenter = "${GOVMOMI_DATACENTER}"
|
|
Packit Service |
bcdfb1 |
EOF
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Write a basic blueprint for our image.
|
|
Packit Service |
bcdfb1 |
tee "$BLUEPRINT_FILE" > /dev/null << EOF
|
|
Packit Service |
bcdfb1 |
name = "bash"
|
|
Packit Service |
bcdfb1 |
description = "A base system with bash"
|
|
Packit Service |
bcdfb1 |
version = "0.0.1"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
[[packages]]
|
|
Packit Service |
bcdfb1 |
name = "bash"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
[customizations.services]
|
|
Packit Service |
bcdfb1 |
enabled = ["sshd"]
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
[[customizations.user]]
|
|
Packit Service |
bcdfb1 |
name = "redhat"
|
|
Packit Service |
bcdfb1 |
key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC61wMCjOSHwbVb4VfVyl5sn497qW4PsdQ7Ty7aD6wDNZ/QjjULkDV/yW5WjDlDQ7UqFH0Sr7vywjqDizUAqK7zM5FsUKsUXWHWwg/ehKg8j9xKcMv11AkFoUoujtfAujnKODkk58XSA9whPr7qcw3vPrmog680pnMSzf9LC7J6kXfs6lkoKfBh9VnlxusCrw2yg0qI1fHAZBLPx7mW6+me71QZsS6sVz8v8KXyrXsKTdnF50FjzHcK9HXDBtSJS5wA3fkcRYymJe0o6WMWNdgSRVpoSiWaHHmFgdMUJaYoCfhXzyl7LtNb3Q+Sveg+tJK7JaRXBLMUllOlJ6ll5Hod root@localhost"
|
|
Packit Service |
bcdfb1 |
EOF
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Prepare the blueprint for the compose.
|
|
Packit Service |
bcdfb1 |
greenprint "๐ Preparing blueprint"
|
|
Packit Service |
bcdfb1 |
sudo composer-cli blueprints push "$BLUEPRINT_FILE"
|
|
Packit Service |
bcdfb1 |
sudo composer-cli blueprints depsolve bash
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Get worker unit file so we can watch the journal.
|
|
Packit Service |
bcdfb1 |
WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service")
|
|
Packit Service |
bcdfb1 |
sudo journalctl -af -n 1 -u "${WORKER_UNIT}" &
|
|
Packit Service |
bcdfb1 |
WORKER_JOURNAL_PID=$!
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Start the compose and upload to VMWare.
|
|
Packit Service |
bcdfb1 |
greenprint "๐ Starting compose"
|
|
Packit Service |
bcdfb1 |
sudo composer-cli --json compose start bash vmdk "$IMAGE_KEY" "$VMWARE_CONFIG" | tee "$COMPOSE_START"
|
|
Packit Service |
bcdfb1 |
COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START")
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Wait for the compose to finish.
|
|
Packit Service |
bcdfb1 |
greenprint "โฑ Waiting for compose to finish: ${COMPOSE_ID}"
|
|
Packit Service |
bcdfb1 |
while true; do
|
|
Packit Service |
bcdfb1 |
sudo composer-cli --json compose info "${COMPOSE_ID}" | tee "$COMPOSE_INFO" > /dev/null
|
|
Packit Service |
bcdfb1 |
COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO")
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Is the compose finished?
|
|
Packit Service |
bcdfb1 |
if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then
|
|
Packit Service |
bcdfb1 |
break
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Wait 30 seconds and try again.
|
|
Packit Service |
bcdfb1 |
sleep 30
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
done
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Capture the compose logs from osbuild.
|
|
Packit Service |
bcdfb1 |
greenprint "๐ฌ Getting compose log and metadata"
|
|
Packit Service |
bcdfb1 |
get_compose_log "$COMPOSE_ID"
|
|
Packit Service |
bcdfb1 |
get_compose_metadata "$COMPOSE_ID"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Did the compose finish with success?
|
|
Packit Service |
bcdfb1 |
if [[ $COMPOSE_STATUS != FINISHED ]]; then
|
|
Packit Service |
bcdfb1 |
echo "Something went wrong with the compose. ๐ข"
|
|
Packit Service |
bcdfb1 |
exit 1
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Stop watching the worker journal.
|
|
Packit Service |
bcdfb1 |
sudo kill ${WORKER_JOURNAL_PID}
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
greenprint "๐ท๐ป Building VM in vSphere"
|
|
Packit Service |
bcdfb1 |
$GOVC_CMD vm.create -u "${GOVMOMI_USERNAME}":"${GOVMOMI_PASSWORD}"@"${GOVMOMI_URL}" \
|
|
Packit Service |
bcdfb1 |
-k=true \
|
|
Packit Service |
bcdfb1 |
-pool="${GOVMOMI_CLUSTER}"/Resources \
|
|
Packit Service |
bcdfb1 |
-dc="${GOVMOMI_DATACENTER}" \
|
|
Packit Service |
bcdfb1 |
-ds="${GOVMOMI_DATASTORE}" \
|
|
Packit Service |
bcdfb1 |
-folder="${GOVMOMI_FOLDER}" \
|
|
Packit Service |
bcdfb1 |
-net="${GOVMOMI_NETWORK}" \
|
|
Packit Service |
bcdfb1 |
-m=2048 -g=rhel8_64Guest -on=true -firmware=bios \
|
|
Packit Service |
bcdfb1 |
-disk="${IMAGE_KEY}"/"${IMAGE_KEY}".vmdk \
|
|
Packit Service |
bcdfb1 |
--disk.controller=ide \
|
|
Packit Service |
bcdfb1 |
"${IMAGE_KEY}"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
greenprint "Getting IP of created VM"
|
|
Packit Service |
bcdfb1 |
VM_IP=$($GOVC_CMD vm.ip -u "${GOVMOMI_USERNAME}":"${GOVMOMI_PASSWORD}"@"${GOVMOMI_URL}" -k=true "${IMAGE_KEY}")
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Wait for the node to come online.
|
|
Packit Service |
bcdfb1 |
greenprint "โฑ Waiting for VM to respond to ssh"
|
|
Packit Service |
bcdfb1 |
LOOP_COUNTER=1
|
|
Packit Service |
bcdfb1 |
while [ $LOOP_COUNTER -le 30 ]; do
|
|
Packit Service |
bcdfb1 |
if ssh-keyscan "$VM_IP" > /dev/null 2>&1; then
|
|
Packit Service |
bcdfb1 |
echo "SSH is up!"
|
|
Packit Service |
bcdfb1 |
ssh-keyscan "$VM_IP" | sudo tee -a /root/.ssh/known_hosts
|
|
Packit Service |
bcdfb1 |
break
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# ssh-keyscan has a 5 second timeout by default, so the pause per loop
|
|
Packit Service |
bcdfb1 |
# is 10 seconds when you include the following `sleep`.
|
|
Packit Service |
bcdfb1 |
echo "Retrying in 5 seconds..."
|
|
Packit Service |
bcdfb1 |
sleep 5
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
((LOOP_COUNTER++))
|
|
Packit Service |
bcdfb1 |
done
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
greenprint "๐ Checking that system is running"
|
|
Packit Service |
bcdfb1 |
for LOOP_COUNTER in {0..10}; do
|
|
Packit Service |
bcdfb1 |
RESULT="$(running_test_check "$VM_IP")"
|
|
Packit Service |
bcdfb1 |
if [[ $RESULT == 0 ]]; then
|
|
Packit Service |
bcdfb1 |
echo "System is running! ๐ฅณ"
|
|
Packit Service |
bcdfb1 |
break
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
sleep 5
|
|
Packit Service |
bcdfb1 |
done
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
# Clean up
|
|
Packit Service |
bcdfb1 |
greenprint "๐งผ Cleaning up"
|
|
Packit Service |
bcdfb1 |
$GOVC_CMD vm.destroy -u "${GOVMOMI_USERNAME}":"${GOVMOMI_PASSWORD}"@"${GOVMOMI_URL}" -k=true "${IMAGE_KEY}"
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
if [[ $RESULT != 0 ]]; then
|
|
Packit Service |
bcdfb1 |
greenprint "โ Failed"
|
|
Packit Service |
bcdfb1 |
exit 1
|
|
Packit Service |
bcdfb1 |
fi
|
|
Packit Service |
bcdfb1 |
|
|
Packit Service |
bcdfb1 |
greenprint "๐ Success"
|
|
Packit Service |
bcdfb1 |
exit 0
|