Blame test/cases/ostree.sh

Packit Service 509fd4
#!/bin/bash
Packit Service 509fd4
set -euo pipefail
Packit Service 509fd4
Packit Service 509fd4
OSBUILD_COMPOSER_TEST_DATA=/usr/share/tests/osbuild-composer/
Packit Service 509fd4
Packit Service 509fd4
# Get OS data.
Packit Service 509fd4
source /etc/os-release
Packit Service 509fd4
ARCH=$(uname -m)
Packit Service 509fd4
Packit Service 509fd4
# Provision the software under tet.
Packit Service 509fd4
/usr/libexec/osbuild-composer-test/provision.sh
Packit Service 509fd4
Packit Service 509fd4
# Set os-variant and boot location used by virt-install.
Packit Service 509fd4
case "${ID}-${VERSION_ID}" in
Packit Service 509fd4
    "fedora-32")
Packit Service 509fd4
        IMAGE_TYPE=fedora-iot-commit
Packit Service 509fd4
        OSTREE_REF="fedora/32/${ARCH}/iot"
Packit Service 509fd4
        OS_VARIANT="fedora32"
Packit Service 509fd4
        BOOT_LOCATION="https://mirrors.rit.edu/fedora/fedora/linux/releases/32/Everything/x86_64/os/";;
Packit Service 509fd4
    "fedora-33")
Packit Service 509fd4
        IMAGE_TYPE=fedora-iot-commit
Packit Service 509fd4
        OSTREE_REF="fedora/33/${ARCH}/iot"
Packit Service 509fd4
        OS_VARIANT="fedora33"
Packit Service 509fd4
        BOOT_LOCATION="https://mirrors.rit.edu/fedora/fedora/linux/releases/33/Everything/x86_64/os/";;
Packit Service 509fd4
    "rhel-8.3")
Packit Service 509fd4
        IMAGE_TYPE=rhel-edge-commit
Packit Service 509fd4
        OSTREE_REF="rhel/8/${ARCH}/edge"
Packit Service 509fd4
        OS_VARIANT="rhel8.3"
Packit Service 509fd4
        # When 8.3 was released, it wasn't available on all RH internal
Packit Service 509fd4
        # mirrors, therefore the Boston mirror is hardcoded.
Packit Service 509fd4
        BOOT_LOCATION="http://download.eng.bos.redhat.com/released/rhel-8/RHEL-8/8.3.0/BaseOS/x86_64/os/";;
Packit Service 509fd4
    "rhel-8.4")
Packit Service 509fd4
        IMAGE_TYPE=rhel-edge-commit
Packit Service 509fd4
        OSTREE_REF="rhel/8/${ARCH}/edge"
Packit Service 509fd4
        OS_VARIANT="rhel8-unknown"
Packit Service 509fd4
        BOOT_LOCATION="http://download.devel.redhat.com/nightly/rhel-8/RHEL-8/latest-RHEL-8.4/compose/BaseOS/x86_64/os/";;
Packit Service 509fd4
    *)
Packit Service 509fd4
        echo "unsupported distro: ${ID}-${VERSION_ID}"
Packit Service 509fd4
        exit 1;;
Packit Service 509fd4
esac
Packit Service 509fd4
Packit Service 509fd4
Packit Service 509fd4
# Colorful output.
Packit Service 509fd4
function greenprint {
Packit Service 509fd4
    echo -e "\033[1;32m${1}\033[0m"
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
# Start libvirtd and test it.
Packit Service 509fd4
greenprint "🚀 Starting libvirt daemon"
Packit Service 509fd4
sudo systemctl start libvirtd
Packit Service 509fd4
sudo virsh list --all > /dev/null
Packit Service 509fd4
Packit Service 509fd4
# Set a customized dnsmasq configuration for libvirt so we always get the
Packit Service 509fd4
# same address on bootup.
Packit Service 509fd4
sudo tee /tmp/integration.xml > /dev/null << EOF
Packit Service 509fd4
<network>
Packit Service 509fd4
  <name>integration</name>
Packit Service 509fd4
  <uuid>1c8fe98c-b53a-4ca4-bbdb-deb0f26b3579</uuid>
Packit Service 509fd4
  <forward mode='nat'>
Packit Service 509fd4
    <nat>
Packit Service 509fd4
      <port start='1024' end='65535'/>
Packit Service 509fd4
    </nat>
Packit Service 509fd4
  </forward>
Packit Service 509fd4
  <bridge name='integration' stp='on' delay='0'/>
Packit Service 509fd4
  <mac address='52:54:00:36:46:ef'/>
Packit Service 509fd4
  <ip address='192.168.100.1' netmask='255.255.255.0'>
Packit Service 509fd4
    <dhcp>
Packit Service 509fd4
      <range start='192.168.100.2' end='192.168.100.254'/>
Packit Service 509fd4
      <host mac='34:49:22:B0:83:30' name='vm' ip='192.168.100.50'/>
Packit Service 509fd4
    </dhcp>
Packit Service 509fd4
  </ip>
Packit Service 509fd4
</network>
Packit Service 509fd4
EOF
Packit Service 509fd4
if ! sudo virsh net-info integration > /dev/null 2>&1; then
Packit Service 509fd4
    sudo virsh net-define /tmp/integration.xml
Packit Service 509fd4
    sudo virsh net-start integration
Packit Service 509fd4
fi
Packit Service 509fd4
Packit Service 509fd4
# Allow anyone in the wheel group to talk to libvirt.
Packit Service 509fd4
greenprint "🚪 Allowing users in wheel group to talk to libvirt"
Packit Service 509fd4
WHEEL_GROUP=wheel
Packit Service 509fd4
if [[ $ID == rhel ]]; then
Packit Service 509fd4
    WHEEL_GROUP=adm
Packit Service 509fd4
fi
Packit Service 509fd4
sudo tee /etc/polkit-1/rules.d/50-libvirt.rules > /dev/null << EOF
Packit Service 509fd4
polkit.addRule(function(action, subject) {
Packit Service 509fd4
    if (action.id == "org.libvirt.unix.manage" &&
Packit Service 509fd4
        subject.isInGroup("${WHEEL_GROUP}")) {
Packit Service 509fd4
            return polkit.Result.YES;
Packit Service 509fd4
    }
Packit Service 509fd4
});
Packit Service 509fd4
EOF
Packit Service 509fd4
Packit Service 509fd4
# Set up variables.
Packit Service 509fd4
TEST_UUID=$(uuidgen)
Packit Service 509fd4
IMAGE_KEY="osbuild-composer-ostree-test-${TEST_UUID}"
Packit Service 509fd4
GUEST_ADDRESS=192.168.100.50
Packit Service 509fd4
Packit Service 509fd4
# Set up temporary files.
Packit Service 509fd4
TEMPDIR=$(mktemp -d)
Packit Service 509fd4
BLUEPRINT_FILE=${TEMPDIR}/blueprint.toml
Packit Service 509fd4
KS_FILE=${TEMPDIR}/ks.cfg
Packit Service 509fd4
COMPOSE_START=${TEMPDIR}/compose-start-${IMAGE_KEY}.json
Packit Service 509fd4
COMPOSE_INFO=${TEMPDIR}/compose-info-${IMAGE_KEY}.json
Packit Service 509fd4
Packit Service 509fd4
# SSH setup.
Packit Service 509fd4
SSH_OPTIONS=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5)
Packit Service 509fd4
SSH_KEY=${OSBUILD_COMPOSER_TEST_DATA}keyring/id_rsa
Packit Service 509fd4
Packit Service 509fd4
# Get the compose log.
Packit Service 509fd4
get_compose_log () {
Packit Service 509fd4
    COMPOSE_ID=$1
Packit Service 509fd4
    LOG_FILE=${WORKSPACE}/osbuild-${ID}-${VERSION_ID}-${COMPOSE_ID}.log
Packit Service 509fd4
Packit Service 509fd4
    # Download the logs.
Packit Service 509fd4
    sudo composer-cli compose log "$COMPOSE_ID" | tee "$LOG_FILE" > /dev/null
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
# Get the compose metadata.
Packit Service 509fd4
get_compose_metadata () {
Packit Service 509fd4
    COMPOSE_ID=$1
Packit Service 509fd4
    METADATA_FILE=${WORKSPACE}/osbuild-${ID}-${VERSION_ID}-${COMPOSE_ID}.json
Packit Service 509fd4
Packit Service 509fd4
    # Download the metadata.
Packit Service 509fd4
    sudo composer-cli compose metadata "$COMPOSE_ID" > /dev/null
Packit Service 509fd4
Packit Service 509fd4
    # Find the tarball and extract it.
Packit Service 509fd4
    TARBALL=$(basename "$(find . -maxdepth 1 -type f -name "*-metadata.tar")")
Packit Service 509fd4
    tar -xf "$TARBALL" -C "${TEMPDIR}"
Packit Service 509fd4
    rm -f "$TARBALL"
Packit Service 509fd4
Packit Service 509fd4
    # Move the JSON file into place.
Packit Service 509fd4
    cat "${TEMPDIR}"/"${COMPOSE_ID}".json | jq -M '.' | tee "$METADATA_FILE" > /dev/null
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
# Build ostree image.
Packit Service 509fd4
build_image() {
Packit Service 509fd4
    blueprint_file=$1
Packit Service 509fd4
    blueprint_name=$2
Packit Service 509fd4
Packit Service 509fd4
    # Prepare the blueprint for the compose.
Packit Service 509fd4
    greenprint "📋 Preparing blueprint"
Packit Service 509fd4
    sudo composer-cli blueprints push "$blueprint_file"
Packit Service 509fd4
    sudo composer-cli blueprints depsolve "$blueprint_name"
Packit Service 509fd4
Packit Service 509fd4
    # Get worker unit file so we can watch the journal.
Packit Service 509fd4
    WORKER_UNIT=$(sudo systemctl list-units | grep -o -E "osbuild.*worker.*\.service")
Packit Service 509fd4
    sudo journalctl -af -n 1 -u "${WORKER_UNIT}" &
Packit Service 509fd4
    WORKER_JOURNAL_PID=$!
Packit Service 509fd4
Packit Service 509fd4
    # Start the compose.
Packit Service 509fd4
    greenprint "🚀 Starting compose"
Packit Service 509fd4
    if [[ $blueprint_name == upgrade ]]; then
Packit Service 509fd4
        # composer-cli in Fedora 32 has a different start-ostree arguments
Packit Service 509fd4
        # see https://github.com/weldr/lorax/pull/1051
Packit Service 509fd4
        if [[ "${ID}-${VERSION_ID}" == fedora-32 ]]; then
Packit Service 509fd4
            sudo composer-cli --json compose start-ostree "$blueprint_name" $IMAGE_TYPE "$OSTREE_REF" "$COMMIT_HASH" | tee "$COMPOSE_START"
Packit Service 509fd4
        else
Packit Service 509fd4
            sudo composer-cli --json compose start-ostree --ref "$OSTREE_REF" --parent "$COMMIT_HASH" "$blueprint_name" $IMAGE_TYPE | tee "$COMPOSE_START"
Packit Service 509fd4
        fi
Packit Service 509fd4
    else
Packit Service 509fd4
        sudo composer-cli --json compose start "$blueprint_name" $IMAGE_TYPE | tee "$COMPOSE_START"
Packit Service 509fd4
    fi
Packit Service 509fd4
    COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START")
Packit Service 509fd4
Packit Service 509fd4
    # Wait for the compose to finish.
Packit Service 509fd4
    greenprint "⏱ Waiting for compose to finish: ${COMPOSE_ID}"
Packit Service 509fd4
    while true; do
Packit Service 509fd4
        sudo composer-cli --json compose info "${COMPOSE_ID}" | tee "$COMPOSE_INFO" > /dev/null
Packit Service 509fd4
        COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO")
Packit Service 509fd4
Packit Service 509fd4
        # Is the compose finished?
Packit Service 509fd4
        if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then
Packit Service 509fd4
            break
Packit Service 509fd4
        fi
Packit Service 509fd4
Packit Service 509fd4
        # Wait 30 seconds and try again.
Packit Service 509fd4
        sleep 5
Packit Service 509fd4
    done
Packit Service 509fd4
Packit Service 509fd4
    # Capture the compose logs from osbuild.
Packit Service 509fd4
    greenprint "💬 Getting compose log and metadata"
Packit Service 509fd4
    get_compose_log "$COMPOSE_ID"
Packit Service 509fd4
    get_compose_metadata "$COMPOSE_ID"
Packit Service 509fd4
Packit Service 509fd4
    # Did the compose finish with success?
Packit Service 509fd4
    if [[ $COMPOSE_STATUS != FINISHED ]]; then
Packit Service 509fd4
        echo "Something went wrong with the compose. 😢"
Packit Service 509fd4
        exit 1
Packit Service 509fd4
    fi
Packit Service 509fd4
Packit Service 509fd4
    # Stop watching the worker journal.
Packit Service 509fd4
    sudo kill ${WORKER_JOURNAL_PID}
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
# Wait for the ssh server up to be.
Packit Service 509fd4
wait_for_ssh_up () {
Packit Service 509fd4
    SSH_STATUS=$(sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@"${1}" '/bin/bash -c "echo -n READY"')
Packit Service 509fd4
    if [[ $SSH_STATUS == READY ]]; then
Packit Service 509fd4
        echo 1
Packit Service 509fd4
    else
Packit Service 509fd4
        echo 0
Packit Service 509fd4
    fi
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
# Clean up our mess.
Packit Service 509fd4
clean_up () {
Packit Service 509fd4
    greenprint "🧼 Cleaning up"
Packit Service 509fd4
    sudo virsh destroy "${IMAGE_KEY}"
Packit Service 509fd4
    if [[ $ARCH == aarch64 ]]; then
Packit Service 509fd4
        sudo virsh undefine "${IMAGE_KEY}" --nvram
Packit Service 509fd4
    else
Packit Service 509fd4
        sudo virsh undefine "${IMAGE_KEY}"
Packit Service 509fd4
    fi
Packit Service 509fd4
    # Remove qcow2 file.
Packit Service 509fd4
    sudo rm -f "$LIBVIRT_IMAGE_PATH"
Packit Service 509fd4
    # Remove extracted upgrade image-tar.
Packit Service 509fd4
    sudo rm -rf "$UPGRADE_PATH"
Packit Service 509fd4
    # Remove "remote" repo.
Packit Service 509fd4
    sudo rm -rf "${HTTPD_PATH}"/{repo,compose.json}
Packit Service 509fd4
    # Remomve tmp dir.
Packit Service 509fd4
    sudo rm -rf "$TEMPDIR"
Packit Service 509fd4
    # Stop httpd
Packit Service 509fd4
    sudo systemctl disable httpd --now
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
# Test result checking
Packit Service 509fd4
check_result () {
Packit Service 509fd4
    greenprint "Checking for test result"
Packit Service 509fd4
    if [[ $RESULTS == 1 ]]; then
Packit Service 509fd4
        greenprint "💚 Success"
Packit Service 509fd4
    else
Packit Service 509fd4
        greenprint "❌ Failed"
Packit Service 509fd4
        clean_up
Packit Service 509fd4
        exit 1
Packit Service 509fd4
    fi
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
##################################################
Packit Service 509fd4
##
Packit Service 509fd4
## ostree image/commit installation
Packit Service 509fd4
##
Packit Service 509fd4
##################################################
Packit Service 509fd4
Packit Service 509fd4
# Write a blueprint for ostree image.
Packit Service 509fd4
tee "$BLUEPRINT_FILE" > /dev/null << EOF
Packit Service 509fd4
name = "ostree"
Packit Service 509fd4
description = "A base ostree image"
Packit Service 509fd4
version = "0.0.1"
Packit Service 509fd4
modules = []
Packit Service 509fd4
groups = []
Packit Service 509fd4
Packit Service 509fd4
[[packages]]
Packit Service 509fd4
name = "python36"
Packit Service 509fd4
version = "*"
Packit Service 509fd4
EOF
Packit Service 509fd4
Packit Service 509fd4
# Build installation image.
Packit Service 509fd4
build_image "$BLUEPRINT_FILE" ostree
Packit Service 509fd4
Packit Service 509fd4
# Start httpd to serve ostree repo.
Packit Service 509fd4
greenprint "🚀 Starting httpd daemon"
Packit Service 509fd4
sudo systemctl start httpd
Packit Service 509fd4
Packit Service 509fd4
# Download the image and extract tar into web server root folder.
Packit Service 509fd4
greenprint "📥 Downloading and extracting the image"
Packit Service 509fd4
sudo composer-cli compose image "${COMPOSE_ID}" > /dev/null
Packit Service 509fd4
IMAGE_FILENAME="${COMPOSE_ID}-commit.tar"
Packit Service 509fd4
HTTPD_PATH="/var/www/html"
Packit Service 509fd4
sudo tar -xf "${IMAGE_FILENAME}" -C ${HTTPD_PATH}
Packit Service 509fd4
sudo rm -f "$IMAGE_FILENAME"
Packit Service 509fd4
Packit Service 509fd4
# Clean compose and blueprints.
Packit Service 509fd4
greenprint "Clean up osbuild-composer"
Packit Service 509fd4
sudo composer-cli compose delete "${COMPOSE_ID}" > /dev/null
Packit Service 509fd4
sudo composer-cli blueprints delete ostree > /dev/null
Packit Service 509fd4
Packit Service 509fd4
# Get ostree commit value.
Packit Service 509fd4
greenprint "Get ostree image commit value"
Packit Service 509fd4
COMMIT_HASH=$(jq -r '."ostree-commit"' < ${HTTPD_PATH}/compose.json)
Packit Service 509fd4
Packit Service 509fd4
# Ensure SELinux is happy with our new images.
Packit Service 509fd4
greenprint "👿 Running restorecon on image directory"
Packit Service 509fd4
sudo restorecon -Rv /var/lib/libvirt/images/
Packit Service 509fd4
Packit Service 509fd4
# Create qcow2 file for virt install.
Packit Service 509fd4
greenprint "Create qcow2 file for virt install"
Packit Service 509fd4
LIBVIRT_IMAGE_PATH=/var/lib/libvirt/images/${IMAGE_KEY}.qcow2
Packit Service 509fd4
sudo qemu-img create -f qcow2 "${LIBVIRT_IMAGE_PATH}" 20G
Packit Service 509fd4
Packit Service 509fd4
# Write kickstart file for ostree image installation.
Packit Service 509fd4
greenprint "Generate kickstart file"
Packit Service 509fd4
tee "$KS_FILE" > /dev/null << STOPHERE
Packit Service 509fd4
text
Packit Service 509fd4
lang en_US.UTF-8
Packit Service 509fd4
keyboard us
Packit Service 509fd4
timezone --utc Etc/UTC
Packit Service 509fd4
Packit Service 509fd4
selinux --enforcing
Packit Service 509fd4
rootpw --lock --iscrypted locked
Packit Service 509fd4
user --name=admin --groups=wheel --iscrypted --password=\$6\$1LgwKw9aOoAi/Zy9\$Pn3ErY1E8/yEanJ98evqKEW.DZp24HTuqXPJl6GYCm8uuobAmwxLv7rGCvTRZhxtcYdmC0.XnYRSR9Sh6de3p0
Packit Service 509fd4
sshkey --username=admin "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC61wMCjOSHwbVb4VfVyl5sn497qW4PsdQ7Ty7aD6wDNZ/QjjULkDV/yW5WjDlDQ7UqFH0Sr7vywjqDizUAqK7zM5FsUKsUXWHWwg/ehKg8j9xKcMv11AkFoUoujtfAujnKODkk58XSA9whPr7qcw3vPrmog680pnMSzf9LC7J6kXfs6lkoKfBh9VnlxusCrw2yg0qI1fHAZBLPx7mW6+me71QZsS6sVz8v8KXyrXsKTdnF50FjzHcK9HXDBtSJS5wA3fkcRYymJe0o6WMWNdgSRVpoSiWaHHmFgdMUJaYoCfhXzyl7LtNb3Q+Sveg+tJK7JaRXBLMUllOlJ6ll5Hod root@localhost"
Packit Service 509fd4
Packit Service 509fd4
bootloader --timeout=1 --append="net.ifnames=0 modprobe.blacklist=vc4"
Packit Service 509fd4
Packit Service 509fd4
network --bootproto=dhcp --device=link --activate --onboot=on
Packit Service 509fd4
Packit Service 509fd4
zerombr
Packit Service 509fd4
clearpart --all --initlabel --disklabel=msdos
Packit Service 509fd4
autopart --nohome --noswap --type=plain
Packit Service 509fd4
ostreesetup --nogpg --osname=${IMAGE_TYPE} --remote=${IMAGE_TYPE} --url=http://192.168.100.1/repo/ --ref=${OSTREE_REF}
Packit Service 509fd4
poweroff
Packit Service 509fd4
Packit Service 509fd4
%post --log=/var/log/anaconda/post-install.log --erroronfail
Packit Service 509fd4
Packit Service 509fd4
# no sudo password for user admin
Packit Service 509fd4
echo -e 'admin\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
Packit Service 509fd4
Packit Service 509fd4
# Remove any persistent NIC rules generated by udev
Packit Service 509fd4
rm -vf /etc/udev/rules.d/*persistent-net*.rules
Packit Service 509fd4
# And ensure that we will do DHCP on eth0 on startup
Packit Service 509fd4
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
Packit Service 509fd4
DEVICE="eth0"
Packit Service 509fd4
BOOTPROTO="dhcp"
Packit Service 509fd4
ONBOOT="yes"
Packit Service 509fd4
TYPE="Ethernet"
Packit Service 509fd4
PERSISTENT_DHCLIENT="yes"
Packit Service 509fd4
EOF
Packit Service 509fd4
Packit Service 509fd4
echo "Packages within this iot or edge image:"
Packit Service 509fd4
echo "-----------------------------------------------------------------------"
Packit Service 509fd4
rpm -qa | sort
Packit Service 509fd4
echo "-----------------------------------------------------------------------"
Packit Service 509fd4
# Note that running rpm recreates the rpm db files which aren't needed/wanted
Packit Service 509fd4
rm -f /var/lib/rpm/__db*
Packit Service 509fd4
Packit Service 509fd4
echo "Zeroing out empty space."
Packit Service 509fd4
# This forces the filesystem to reclaim space from deleted files
Packit Service 509fd4
dd bs=1M if=/dev/zero of=/var/tmp/zeros || :
Packit Service 509fd4
rm -f /var/tmp/zeros
Packit Service 509fd4
echo "(Don't worry -- that out-of-space error was expected.)"
Packit Service 509fd4
Packit Service 509fd4
%end
Packit Service 509fd4
STOPHERE
Packit Service 509fd4
Packit Service 509fd4
# Install ostree image via anaconda.
Packit Service 509fd4
greenprint "Install ostree image via anaconda"
Packit Service 509fd4
sudo virt-install  --initrd-inject="${KS_FILE}" \
Packit Service 509fd4
                   --extra-args="ks=file:/ks.cfg console=ttyS0,115200" \
Packit Service 509fd4
                   --name="${IMAGE_KEY}"\
Packit Service 509fd4
                   --disk path="${LIBVIRT_IMAGE_PATH}",format=qcow2 \
Packit Service 509fd4
                   --ram 3072 \
Packit Service 509fd4
                   --vcpus 2 \
Packit Service 509fd4
                   --network network=integration,mac=34:49:22:B0:83:30 \
Packit Service 509fd4
                   --os-type linux \
Packit Service 509fd4
                   --os-variant ${OS_VARIANT} \
Packit Service 509fd4
                   --location ${BOOT_LOCATION} \
Packit Service 509fd4
                   --nographics \
Packit Service 509fd4
                   --noautoconsole \
Packit Service 509fd4
                   --wait=-1 \
Packit Service 509fd4
                   --noreboot
Packit Service 509fd4
Packit Service 509fd4
# Start VM.
Packit Service 509fd4
greenprint "Start VM"
Packit Service 509fd4
sudo virsh start "${IMAGE_KEY}"
Packit Service 509fd4
Packit Service 509fd4
# Check for ssh ready to go.
Packit Service 509fd4
greenprint "🛃 Checking for SSH is ready to go"
Packit Service 509fd4
for LOOP_COUNTER in $(seq 0 30); do
Packit Service 509fd4
    RESULTS="$(wait_for_ssh_up $GUEST_ADDRESS)"
Packit Service 509fd4
    if [[ $RESULTS == 1 ]]; then
Packit Service 509fd4
        echo "SSH is ready now! 🥳"
Packit Service 509fd4
        break
Packit Service 509fd4
    fi
Packit Service 509fd4
    sleep 10
Packit Service 509fd4
done
Packit Service 509fd4
Packit Service 509fd4
# Check image installation result
Packit Service 509fd4
check_result
Packit Service 509fd4
Packit Service 509fd4
##################################################
Packit Service 509fd4
##
Packit Service 509fd4
## ostree image/commit upgrade
Packit Service 509fd4
##
Packit Service 509fd4
##################################################
Packit Service 509fd4
Packit Service 509fd4
# Write a blueprint for ostree image.
Packit Service 509fd4
tee "$BLUEPRINT_FILE" > /dev/null << EOF
Packit Service 509fd4
name = "upgrade"
Packit Service 509fd4
description = "An upgrade ostree image"
Packit Service 509fd4
version = "0.0.2"
Packit Service 509fd4
modules = []
Packit Service 509fd4
groups = []
Packit Service 509fd4
Packit Service 509fd4
[[packages]]
Packit Service 509fd4
name = "python36"
Packit Service 509fd4
version = "*"
Packit Service 509fd4
Packit Service 509fd4
[[packages]]
Packit Service 509fd4
name = "wget"
Packit Service 509fd4
version = "*"
Packit Service 509fd4
EOF
Packit Service 509fd4
Packit Service 509fd4
# Build upgrade image.
Packit Service 509fd4
build_image "$BLUEPRINT_FILE" upgrade
Packit Service 509fd4
Packit Service 509fd4
# Download the image and extract tar into web server root folder.
Packit Service 509fd4
greenprint "📥 Downloading and extracting the image"
Packit Service 509fd4
sudo composer-cli compose image "${COMPOSE_ID}" > /dev/null
Packit Service 509fd4
IMAGE_FILENAME="${COMPOSE_ID}-commit.tar"
Packit Service 509fd4
UPGRADE_PATH="$(pwd)/upgrade"
Packit Service 509fd4
mkdir -p "$UPGRADE_PATH"
Packit Service 509fd4
sudo tar -xf "$IMAGE_FILENAME" -C "$UPGRADE_PATH"
Packit Service 509fd4
sudo rm -f "$IMAGE_FILENAME"
Packit Service 509fd4
Packit Service 509fd4
# Clean compose and blueprints.
Packit Service 509fd4
greenprint "Clean up osbuild-composer again"
Packit Service 509fd4
sudo composer-cli compose delete "${COMPOSE_ID}" > /dev/null
Packit Service 509fd4
sudo composer-cli blueprints delete upgrade > /dev/null
Packit Service 509fd4
Packit Service 509fd4
# Introduce new ostree commit into repo.
Packit Service 509fd4
greenprint "Introduce new ostree commit into repo"
Packit Service 509fd4
sudo ostree pull-local --repo "${HTTPD_PATH}/repo" "${UPGRADE_PATH}/repo" "$OSTREE_REF"
Packit Service 509fd4
sudo ostree summary --update --repo "${HTTPD_PATH}/repo"
Packit Service 509fd4
Packit Service 509fd4
# Ensure SELinux is happy with all objects files.
Packit Service 509fd4
greenprint "👿 Running restorecon on web server root folder"
Packit Service 509fd4
sudo restorecon -Rv "${HTTPD_PATH}/repo" > /dev/null
Packit Service 509fd4
Packit Service 509fd4
# Get ostree commit value.
Packit Service 509fd4
greenprint "Get ostree image commit value"
Packit Service 509fd4
UPGRADE_HASH=$(jq -r '."ostree-commit"' < "${UPGRADE_PATH}"/compose.json)
Packit Service 509fd4
Packit Service 509fd4
# Upgrade image/commit.
Packit Service 509fd4
greenprint "Upgrade ostree image/commit"
Packit Service 509fd4
sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@${GUEST_ADDRESS} 'sudo rpm-ostree upgrade'
Packit Service 509fd4
sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@${GUEST_ADDRESS} 'nohup sudo systemctl reboot &>/dev/null & exit'
Packit Service 509fd4
Packit Service 509fd4
# Sleep 10 seconds here to make sure vm restarted already
Packit Service 509fd4
sleep 10
Packit Service 509fd4
Packit Service 509fd4
# Check for ssh ready to go.
Packit Service 509fd4
greenprint "🛃 Checking for SSH is ready to go"
Packit Service 509fd4
# shellcheck disable=SC2034  # Unused variables left for readability
Packit Service 509fd4
for LOOP_COUNTER in $(seq 0 30); do
Packit Service 509fd4
    RESULTS="$(wait_for_ssh_up $GUEST_ADDRESS)"
Packit Service 509fd4
    if [[ $RESULTS == 1 ]]; then
Packit Service 509fd4
        echo "SSH is ready now! 🥳"
Packit Service 509fd4
        break
Packit Service 509fd4
    fi
Packit Service 509fd4
    sleep 10
Packit Service 509fd4
done
Packit Service 509fd4
Packit Service 509fd4
# Check ostree upgrade result
Packit Service 509fd4
check_result
Packit Service 509fd4
Packit Service 509fd4
# Add instance IP address into /etc/ansible/hosts
Packit Service 509fd4
sudo tee "${TEMPDIR}"/inventory > /dev/null << EOF
Packit Service 509fd4
[ostree_guest]
Packit Service 509fd4
${GUEST_ADDRESS}
Packit Service 509fd4
Packit Service 509fd4
[ostree_guest:vars]
Packit Service 509fd4
ansible_python_interpreter=/usr/bin/python3
Packit Service 509fd4
ansible_user=admin
Packit Service 509fd4
ansible_private_key_file=${SSH_KEY}
Packit Service 509fd4
ansible_ssh_common_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
Packit Service 509fd4
EOF
Packit Service 509fd4
Packit Service 509fd4
# Test IoT/Edge OS
Packit Service 509fd4
sudo ansible-playbook -v -i "${TEMPDIR}"/inventory -e image_type=${IMAGE_TYPE} -e ostree_commit="${UPGRADE_HASH}" /usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0
Packit Service 509fd4
check_result
Packit Service 509fd4
Packit Service 509fd4
# Final success clean up
Packit Service 509fd4
clean_up
Packit Service 509fd4
Packit Service 509fd4
exit 0