Skip to content

Commit

Permalink
Merge pull request #2294 from ggiguash/add_multi_nic_support
Browse files Browse the repository at this point in the history
USHIFT-1605: Add multi nic scenario support and robot test
  • Loading branch information
openshift-merge-robot authored Sep 7, 2023
2 parents 526612f + 642eefd commit 8f21a8d
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 64 deletions.
32 changes: 23 additions & 9 deletions test/bin/scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ function get_vm_ip {
local -r vmname="${1}"
local -r start=$(date +%s)
local ip
ip=$("${ROOTDIR}/scripts/devenv-builder/manage-vm.sh" ip -n "${vmname}")
ip=$("${ROOTDIR}/scripts/devenv-builder/manage-vm.sh" ip -n "${vmname}" | head -1)
while [ "${ip}" = "" ]; do
now=$(date +%s)
if [ $(( now - start )) -ge ${VM_BOOT_TIMEOUT} ]; then
echo "Timed out while waiting for IP retrieval"
exit 1
fi
sleep 1
ip=$("${ROOTDIR}/scripts/devenv-builder/manage-vm.sh" ip -n "${vmname}")
ip=$("${ROOTDIR}/scripts/devenv-builder/manage-vm.sh" ip -n "${vmname}" | head -1)
done
echo "${ip}"
}
Expand Down Expand Up @@ -200,10 +200,18 @@ EOF
# necessarily the image to be installed (see
# prepare_kickstart).
# network_name -- The name of the network used when creating the VM.
# vm_vcpus -- Number of vCPUs for the VM.
# vm_memory -- Size of RAM in MB for the VM.
# vm_disksize -- Size of disk in GB for the VM.
# vm_nics -- Number of network interfaces for the VM.
launch_vm() {
local -r vmname="$1"
local -r boot_blueprint="${2:-${DEFAULT_BOOT_BLUEPRINT}}"
local -r network_name="${3:-default}"
local -r vm_vcpus="${4:-2}"
local -r vm_memory="${5:-4096}"
local -r vm_disksize="${6:-20}"
local -r vm_nics="${7:-1}"

local -r full_vmname="$(full_vm_name "${vmname}")"
local -r kickstart_url="${WEB_SERVER_URL}/scenario-info/${SCENARIO}/vms/${vmname}/kickstart.ks"
Expand All @@ -230,15 +238,20 @@ launch_vm() {
sudo virsh pool-autostart "${vm_pool_name}"
fi

# Prepare network arguments for the VM creation depending on
# the number of requested NICs
local vm_network_args
vm_network_args=""
for _ in $(seq "${vm_nics}") ; do
vm_network_args+="--network network=${network_name},model=virtio "
done

# Implement retries on VM creation until the problem is fixed
# See https://github.com/virt-manager/virt-manager/issues/498
local vm_created=false
for attempt in $(seq 5) ; do
local vm_create_start
vm_create_start=$(date +%s)
# FIXME: variable for vcpus?
# FIXME: variable for memory?
# FIXME: variable for ISO

local graphics_args
graphics_args="none"
Expand All @@ -250,14 +263,15 @@ launch_vm() {
# the bg job does not get its own TTY.
# If the TTY is not provided, virt-install refuses
# to attach to the console. `unbuffer` provides the TTY.
# shellcheck disable=SC2086
if ! sudo unbuffer virt-install \
--autoconsole text \
--graphics "${graphics_args}" \
--name "${full_vmname}" \
--vcpus 2 \
--memory 4092 \
--disk "pool=${vm_pool_name},size=20" \
--network network="${network_name}",model=virtio \
--vcpus "${vm_vcpus}" \
--memory "${vm_memory}" \
--disk "pool=${vm_pool_name},size=${vm_disksize}" \
${vm_network_args} \
--events on_reboot=restart \
--noreboot \
--location "${VM_DISK_BASEDIR}/${boot_blueprint}.iso" \
Expand Down
8 changes: 5 additions & 3 deletions test/kickstart-templates/kickstart-liveimg.ks.template
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ apiServer:
subjectAltNames:
EOF

DEFAULT_ROUTE_IP="$(ip route show default 2>/dev/null | head -1 | awk '{print $9}')"
if [ -n "${DEFAULT_ROUTE_IP}" ] ; then
echo " - ${DEFAULT_ROUTE_IP}" >>/etc/microshift/config.yaml
DEFAULT_ROUTE_IPS="$(ip route show default 2>/dev/null | awk '{print $9}')"
if [ -n "${DEFAULT_ROUTE_IPS}" ] ; then
for r in ${DEFAULT_ROUTE_IPS} ; do
echo " - ${r}" >>/etc/microshift/config.yaml
done
else
MAIN_HOST_IP="$(hostname -I | awk '{print $1}')"
echo " - ${MAIN_HOST_IP}" >>/etc/microshift/config.yaml
Expand Down
8 changes: 5 additions & 3 deletions test/kickstart-templates/kickstart.ks.template
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ apiServer:
subjectAltNames:
EOF

DEFAULT_ROUTE_IP="$(ip route show default 2>/dev/null | head -1 | awk '{print $9}')"
if [ -n "${DEFAULT_ROUTE_IP}" ] ; then
echo " - ${DEFAULT_ROUTE_IP}" >>/etc/microshift/config.yaml
DEFAULT_ROUTE_IPS="$(ip route show default 2>/dev/null | awk '{print $9}')"
if [ -n "${DEFAULT_ROUTE_IPS}" ] ; then
for r in ${DEFAULT_ROUTE_IPS} ; do
echo " - ${r}" >>/etc/microshift/config.yaml
done
else
MAIN_HOST_IP="$(hostname -I | awk '{print $1}')"
echo " - ${MAIN_HOST_IP}" >>/etc/microshift/config.yaml
Expand Down
58 changes: 58 additions & 0 deletions test/resources/microshift-network.resource
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
*** Settings ***
Documentation Keywords for testing the MicroShift network
Resource common.resource
Library SSHLibrary


*** Variables ***
${HELLO_USHIFT} ./assets/hello-microshift.yaml
${LB_PORT} 5678
${NP_PORT} 32222
${HTTP_PORT} 80


*** Keywords ***
Create Hello MicroShift Pod
[Documentation] Create a pod running the "hello microshift" application
Oc Create -f ${HELLO_USHIFT} -n ${NAMESPACE}
Oc Wait For pods -l app=hello-microshift condition\=Ready timeout=300s

Expose Hello MicroShift Pod Via LB
[Documentation] Expose the "hello microshift" application through the load balancer
Run With Kubeconfig oc create service loadbalancer hello-microshift --tcp=${LB_PORT}:8080 -n ${NAMESPACE}

Expose Hello MicroShift Pod Via NodePort
[Documentation] Expose the "hello microshift" application through the NodePort
Run With Kubeconfig
... oc create service nodeport hello-microshift --node-port=${NP_PORT} --tcp=8080 -n ${NAMESPACE}

Access Hello Microshift
[Documentation] Try to retrieve data from the "hello microshift" service end point
[Arguments] ${ushift_port} ${ushift_ip}=${USHIFT_HOST}

${connect_to}= Set Variable "hello-microshift.cluster.local:${HTTP_PORT}:${ushift_ip}:${ushift_port}"

${result}= Run Process
... curl -i http://hello-microshift.cluster.local --connect-to ${connect_to}
... shell=True
... timeout=15s
Log Many ${result.rc} ${result.stdout} ${result.stderr}
Should Be Equal As Integers ${result.rc} 0
Should Match Regexp ${result.stdout} HTTP.*200
Should Match ${result.stdout} *Hello MicroShift*

Verify Hello MicroShift LB
[Documentation] Run Hello MicroShift Load Balancer verification
Create Hello MicroShift Pod
Expose Hello MicroShift Pod Via LB
Wait Until Keyword Succeeds 30x 10s
... Access Hello Microshift ${LB_PORT}

[Teardown] Run Keywords
... Delete Hello MicroShift Pod And Service

Delete Hello MicroShift Pod And Service
[Documentation] Delete service and pod for cleanup.
Oc Delete service/hello-microshift -n ${NAMESPACE}
Oc Delete -f ${HELLO_USHIFT} -n ${NAMESPACE}
33 changes: 31 additions & 2 deletions test/resources/microshift-process.resource
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ Wait For MicroShift
# greenboot check script to let us use it even when not on a
# greenboot host?

MicroShift Process ID
[Documentation] Return the current MicroShift process ID
${stdout} ${stderr} ${rc}= Execute Command
... pidof microshift
... return_stdout=True return_stderr=True return_rc=True
Log ${stderr}
RETURN ${stdout}

MicroShift Process ID Changed
[Documentation] Compare the specified and current MicroShift process ID
[Arguments] ${old_pid}
${cur_pid}= MicroShift Process ID
IF "${cur_pid}"=="${old_pid}"
RETURN False
ELSE
RETURN True
END

Wait Until MicroShift Process ID Changes
[Documentation] Wait until the current MicroShift process ID changes
[Arguments] ${old_pid}

Wait Until Keyword Succeeds 30x 10s
... MicroShift Process ID Changed ${old_pid}

MicroShift Service Is Active
[Documentation] Check if microshift.service is active
... (process announced readiness)
Expand All @@ -63,15 +88,19 @@ Restart MicroShift
# expect without worrying about the race. Any test that modifies
# the MicroShift configuration file will be more reliable as a
# result.
Systemctl With Retry stop microshift.service
Stop MicroShift
Sleep 10 seconds
Systemctl With Retry start microshift.service
Start MicroShift
Wait For MicroShift

Stop MicroShift
[Documentation] Stop the MicroShift service
Systemctl With Retry stop microshift.service

Start MicroShift
[Documentation] Start the MicroShift service
Systemctl With Retry start microshift.service

Enable MicroShift
[Documentation] Enable the MicroShift service
Systemctl enable microshift.service
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ scenario_remove_vms() {
}

scenario_run_tests() {
run_tests host1 suites/isolated-net/isolated-network.robot
run_tests host1 suites/network/isolated-network.robot
}
24 changes: 24 additions & 0 deletions test/scenarios/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

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

scenario_create_vms() {
prepare_kickstart host1 kickstart.ks.template rhel-9.2-microshift-source
# Create a VM with 2 NICs
launch_vm host1 "" "" "" "" "" 2
}

scenario_remove_vms() {
remove_vm host1
}

scenario_run_tests() {
local -r vmname=$(full_vm_name host1)
local -r vm_ip1=$("${ROOTDIR}/scripts/devenv-builder/manage-vm.sh" ip -n "${vmname}" | head -1)
local -r vm_ip2=$("${ROOTDIR}/scripts/devenv-builder/manage-vm.sh" ip -n "${vmname}" | tail -1)

run_tests host1 \
--variable "USHIFT_HOST_IP1:${vm_ip1}" \
--variable "USHIFT_HOST_IP2:${vm_ip2}" \
suites/network/multi-nic.robot
}
File renamed without changes.
Loading

0 comments on commit 8f21a8d

Please sign in to comment.