Skip to content

Commit

Permalink
Merge pull request #2518 from ggiguash/branch-microshift-origin-2513
Browse files Browse the repository at this point in the history
USHIFT-1804: Implement VM creation procedure for no-NIC scenario
  • Loading branch information
openshift-ci[bot] authored Oct 30, 2023
2 parents a3d9c8e + 1a96e6d commit 14f8ddb
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 36 deletions.
2 changes: 1 addition & 1 deletion test/bin/build_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ while getopts "iIg:st:h" opt; do
BUILD_INSTALLER=false
;;
g)
GROUP="${OPTARG}"
GROUP="$(realpath "${OPTARG}")"
;;
s)
BUILD_INSTALLER=false
Expand Down
14 changes: 13 additions & 1 deletion test/bin/ci_phase_iso_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ MAX_WORKERS=$(find "${ROOTDIR}/test/image-blueprints" -name \*.toml | wc -l)
CUR_WORKERS="$( [ "${CPU_CORES}" -lt $(( MAX_WORKERS * 2 )) ] && echo $(( CPU_CORES / 2 )) || echo "${MAX_WORKERS}" )"

bash -x ./bin/start_osbuild_workers.sh "${CUR_WORKERS}"
bash -x ./bin/build_images.sh

# Image build can be optimized in CI based on the job type
if [ -v CI_JOB_NAME ] ; then
bash -x ./bin/build_images.sh -g ./image-blueprints/group1
bash -x ./bin/build_images.sh -g ./image-blueprints/group2
# Group 3 only contains images used in periodic CI jobs
if [[ "${CI_JOB_NAME}" =~ .*periodic.* ]]; then
bash -x ./bin/build_images.sh -g ./image-blueprints/group3
fi
else
# Fall back to full build when not running in CI
bash -x ./bin/build_images.sh
fi

echo "Build phase complete"
102 changes: 68 additions & 34 deletions test/bin/scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ sos_report() {
continue
fi
ip=$(cat "${vmdir}/ip")
if [ -z "${ip}" ] ; then
# skip hosts without NICs
# FIXME: use virsh to copy sos report files
continue
fi
# Copy the sos helper for compatibility, it is only available in 4.14 RPMs
scp "${ROOTDIR}/scripts/microshift-sos-report.sh" "redhat@${ip}":/tmp
ssh "redhat@${ip}" \
Expand Down Expand Up @@ -252,13 +257,30 @@ launch_vm() {
sudo virsh pool-autostart "${vm_pool_name}"
fi

# Prepare network arguments for the VM creation depending on
# Prepare network and extra arguments for the VM creation depending on
# the number of requested NICs
local vm_network_args
local vm_extra_args
local vm_initrd_inject
vm_network_args=""
vm_extra_args="console=tty0 console=ttyS0,115200n8 inst.notmux"
vm_initrd_inject=""

for _ in $(seq "${vm_nics}") ; do
vm_network_args+="--network network=${network_name},model=virtio "
done
if [ -z "${vm_network_args}" ] ; then
vm_network_args="--network none"

# Kickstart should be downloaded and injected into the ISO
local -r kickstart_file=$(mktemp /tmp/kickstart.XXXXXXXX.ks)
curl -s "${kickstart_url}" > "${kickstart_file}"

vm_extra_args+=" inst.ks=file:/$(basename "${kickstart_file}")"
vm_initrd_inject="--initrd-inject ${kickstart_file}"
else
vm_extra_args+=" inst.ks=${kickstart_url}"
fi

# Implement retries on VM creation until the problem is fixed
# See https://github.com/virt-manager/virt-manager/issues/498
Expand Down Expand Up @@ -289,7 +311,8 @@ launch_vm() {
--events on_reboot=restart \
--noreboot \
--location "${VM_DISK_BASEDIR}/${boot_blueprint}.iso" \
--extra-args "inst.ks=${kickstart_url} console=tty0 console=ttyS0,115200n8 inst.notmux" \
--extra-args "${vm_extra_args}" \
${vm_initrd_inject} \
--wait ${vm_wait_timeout} ; then

# Check if the command exited within 15s due to a failure
Expand Down Expand Up @@ -317,42 +340,53 @@ launch_vm() {
fi
sudo virsh start "${full_vmname}"

# Wait for an IP to be assigned
echo "Waiting for VM ${full_vmname} to have an IP"
local -r ip=$(get_vm_ip "${full_vmname}")
echo "VM ${full_vmname} has IP ${ip}"
record_junit "${vmname}" "ip-assignment" "OK"
# If there is at least 1 NIC attached, wait for an IP to be assigned and poll for SSH access
if [ "${vm_nics}" -gt 0 ]; then
# Wait for an IP to be assigned
echo "Waiting for VM ${full_vmname} to have an IP"
local -r ip=$(get_vm_ip "${full_vmname}")
echo "VM ${full_vmname} has IP ${ip}"
record_junit "${vmname}" "ip-assignment" "OK"

# Remove any previous key info for the host
if [ -f "${HOME}/.ssh/known_hosts" ]; then
echo "Clearing known_hosts entry for ${ip}"
ssh-keygen -R "${ip}"
fi

# Remove any previous key info for the host
if [ -f "${HOME}/.ssh/known_hosts" ]; then
echo "Clearing known_hosts entry for ${ip}"
ssh-keygen -R "${ip}"
fi
# Record the IP of this VM so our caller can use it to configure
# port forwarding and the firewall.
mkdir -p "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}"
echo "${ip}" > "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/ip"
# Record the _public_ IP of the VM so the test suite can use it to
# access the host. This is useful when the public IP is the
# hypervisor forwarding connections. If we have no PUBLIC_IP, use
# the VM IP and assume a local connection.
if [ -n "${PUBLIC_IP}" ]; then
echo "${PUBLIC_IP}" > "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/public_ip"
else
echo "${ip}" > "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/public_ip"
# Set the defaults for the various ports so that connections
# from the hypervisor to the VM work.
echo "22" > "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/ssh_port"
echo "6443" > "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/api_port"
echo "5678" > "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/lb_port"
fi

# Record the IP of this VM so our caller can use it to configure
# port forwarding and the firewall.
mkdir -p "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}"
echo "${ip}" > "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/ip"
# Record the _public_ IP of the VM so the test suite can use it to
# access the host. This is useful when the public IP is the
# hypervisor forwarding connections. If we have no PUBLIC_IP, use
# the VM IP and assume a local connection.
if [ -n "${PUBLIC_IP}" ]; then
echo "${PUBLIC_IP}" > "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/public_ip"
if wait_for_ssh "${ip}"; then
record_junit "${vmname}" "ssh-access" "OK"
else
record_junit "${vmname}" "ssh-access" "FAILED"
return 1
fi
else
echo "${ip}" > "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/public_ip"
# Set the defaults for the various ports so that connections
# from the hypervisor to the VM work.
echo "22" > "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/ssh_port"
echo "6443" > "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/api_port"
echo "5678" > "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/lb_port"
fi
# Record no-IP for offline VMs to signal special sos report collection technique
mkdir -p "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}"
touch "${SCENARIO_INFO_DIR}/${SCENARIO}/vms/${vmname}/ip"

if wait_for_ssh "${ip}"; then
record_junit "${vmname}" "ssh-access" "OK"
else
record_junit "${vmname}" "ssh-access" "FAILED"
return 1
echo "VM ${full_vmname} has no NICs, skipping IP assignment and ssh polling"
record_junit "${vmname}" "ip-assignment" "SKIPPED"
record_junit "${vmname}" "ssh-access" "SKIPPED"
fi

echo "${full_vmname} is up and ready"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rhel-9.2-microshift-source-isolated
66 changes: 66 additions & 0 deletions test/kickstart-templates/kickstart-offline.ks.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
lang en_US.UTF-8
keyboard us
timezone UTC
text
reboot

# Do not enable a network device
network --no-activate --nodefroute --hostname=REPLACE_HOST_NAME

# Partition disk with a 1GB boot XFS partition and an LVM volume containing a 10GB+ system root
# The remainder of the volume will be used by the CSI driver for storing data
#
# For example, a 20GB disk would be partitioned in the following way:
#
# NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
# sda 8:0 0 20G 0 disk
# ├─sda1 8:1 0 200M 0 part /boot/efi
# ├─sda1 8:1 0 800M 0 part /boot
# └─sda2 8:2 0 19G 0 part
# └─rhel-root 253:0 0 10G 0 lvm /sysroot
#
zerombr
clearpart --all --initlabel
part /boot/efi --fstype=efi --size=200
part /boot --fstype=xfs --asprimary --size=800
# Uncomment this line to add a SWAP partition of the recommended size
#part swap --fstype=swap --recommended
part pv.01 --grow
volgroup rhel pv.01
logvol / --vgname=rhel --fstype=xfs --size=REPLACE_LVM_SYSROOT_SIZE --name=root

# Lock root user account
rootpw --lock

# Configure non-ostree filesystem
liveimg --url file:///run/install/repo/liveimg.tar.gz

%post --log=/var/log/anaconda/post-install.log --erroronfail

# Create a default redhat user, allowing it to run sudo commands without password
useradd -m -d /home/redhat -p \$5\$XDVQ6DxT8S5YWLV7\$8f2om5JfjK56v9ofUkUAwZXTxJl3Sqnc9yPnza4xoJ0 redhat
echo -e 'redhat\tALL=(ALL)\tNOPASSWD: ALL' > /etc/sudoers.d/microshift

# Make sure redhat user directory contents ownership is correct
chown -R redhat:redhat /home/redhat/

# Make the KUBECONFIG from MicroShift directly available for the root user
echo -e 'export KUBECONFIG=/var/lib/microshift/resources/kubeadmin/kubeconfig' >> /root/.profile

# Configure systemd journal service to persist logs between boots and limit their size to 1G
sudo mkdir -p /etc/systemd/journald.conf.d
cat > /etc/systemd/journald.conf.d/microshift.conf <<EOF
[Journal]
Storage=persistent
SystemMaxUse=1G
RuntimeMaxUse=1G
EOF

# Disable a timer that sets boot_success to 1 after two minutes from a user login.
# It impacts greenboot checks because grub script decrementing boot_counter works
# only if boot_success is 0 (see /etc/grub.d/08_fallback_counting). In case of a
# user login, this results in more than requested amount of red-boot-induced reboots
# and system needing much more time to roll back.
ln -sf /dev/null /etc/systemd/user/grub-boot-success.timer

%end
File renamed without changes.
18 changes: 18 additions & 0 deletions test/scenarios-periodics/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Sourced from scenario.sh and uses functions defined there.

scenario_create_vms() {
prepare_kickstart host1 kickstart-offline.ks.template ""
# Create a VM with embedded container images and 0 NICs
launch_vm host1 rhel-9.2-microshift-source-isolated "" "" "" "" 0
}

scenario_remove_vms() {
remove_vm host1
}

scenario_run_tests() {
# FIXME: Run the tests when the MicroShift offline configuration is fixed
echo run_tests host1 suites/standard/
}

0 comments on commit 14f8ddb

Please sign in to comment.