1#!/bin/bash -xe 2############################################################################### 3# 4# This script is for starting QEMU against the input build and running the 5# robot CI test suite against it.(ROBOT CI TEST CURRENTLY WIP) 6# 7############################################################################### 8# 9# Parameters used by the script: 10# UPSTREAM_WORKSPACE = The directory from which the QEMU components are being 11# imported from. Generally, this is the build directory 12# that is generated by the OpenBMC build-setup.sh script 13# when run with "target=qemu". 14# Example: /home/builder/workspace/openbmc-build/build. 15# 16# Optional Variables: 17# 18# WORKSPACE = Path of the workspace directory where some intermediate 19# files will be saved to. 20# QEMU_RUN_TIMER = Defaults to 300, a timer for the QEMU container. 21# DOCKER_IMG_NAME = Defaults to openbmc/ubuntu-robot-qemu, the name the 22# Docker image will be tagged with when built. 23# OBMC_BUILD_DIR = Defaults to /tmp/openbmc/build, the path to the 24# directory where the UPSTREAM_WORKSPACE build files will 25# be mounted to. Since the build containers have been 26# changed to use /tmp as the parent directory for their 27# builds, move the mounting location to be the same to 28# resolve issues with file links or referrals to exact 29# paths in the original build directory. If the build 30# directory was changed in the build-setup.sh run, this 31# variable should also be changed. Otherwise, the default 32# should be used. 33# LAUNCH = Used to determine how to launch the qemu robot test 34# containers. The options are "local", and "k8s". It will 35# default to local which will launch a single container 36# to do the runs. If specified k8s will launch a group of 37# containers into a kubernetes cluster using the helper 38# script. 39# 40############################################################################### 41 42set -uo pipefail 43 44QEMU_RUN_TIMER=${QEMU_RUN_TIMER:-300} 45WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} 46DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-openbmc/ubuntu-robot-qemu} 47OBMC_BUILD_DIR=${OBMC_BUILD_DIR:-/tmp/openbmc/build} 48UPSTREAM_WORKSPACE=${UPSTREAM_WORKSPACE:-${1}} 49LAUNCH=${LAUNCH:-local} 50 51# Determine the architecture 52ARCH=$(uname -m) 53 54# Determine the prefix of the Dockerfile's base image and the QEMU_ARCH variable 55case ${ARCH} in 56 "ppc64le") 57 DOCKER_BASE="ppc64le/" 58 QEMU_ARCH="ppc64le-linux" 59 ;; 60 "x86_64") 61 DOCKER_BASE="" 62 QEMU_ARCH="x86_64-linux" 63 ;; 64 *) 65 echo "Unsupported system architecture(${ARCH}) found for docker image" 66 exit 1 67esac 68 69# Get the base directory of the openbmc-build-scripts repo so we can return 70DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 71 72# Create the base Docker image for QEMU and Robot 73. "$DIR/scripts/build-qemu-robot-docker.sh" "$DOCKER_IMG_NAME" 74 75# Copy the scripts to start and verify QEMU in the workspace 76cp $DIR/scripts/boot-qemu* ${UPSTREAM_WORKSPACE} 77 78################################################################################ 79 80if [[ ${LAUNCH} == "local" ]]; then 81 82 # Start QEMU docker instance 83 # root in docker required to open up the https/ssh ports 84 obmc_qemu_docker=$(docker run --detach \ 85 --user root \ 86 --env HOME=${OBMC_BUILD_DIR} \ 87 --env QEMU_RUN_TIMER=${QEMU_RUN_TIMER} \ 88 --env QEMU_ARCH=${QEMU_ARCH} \ 89 --workdir "${OBMC_BUILD_DIR}" \ 90 --volume "${UPSTREAM_WORKSPACE}":"${OBMC_BUILD_DIR}" \ 91 --tty \ 92 ${DOCKER_IMG_NAME} ${OBMC_BUILD_DIR}/boot-qemu-test.exp) 93 94 # We can use default ports because we're going to have the 2 95 # docker instances talk over their private network 96 DOCKER_SSH_PORT=22 97 DOCKER_HTTPS_PORT=443 98 DOCKER_QEMU_IP_ADDR="$(docker inspect $obmc_qemu_docker | \ 99 grep -m 1 "IPAddress\":" | cut -d '"' -f 4)" 100 101 #Now wait for the OpenBMC QEMU Docker instance to get to standby 102 attempt=60 103 while [ $attempt -gt 0 ]; do 104 attempt=$(( $attempt - 1 )) 105 echo "Waiting for qemu to get to standby (attempt: $attempt)..." 106 result=$(docker logs $obmc_qemu_docker) 107 if grep -q 'OPENBMC-READY' <<< $result ; then 108 echo "QEMU is ready!" 109 # Give QEMU a few secs to stablize 110 sleep 5 111 break 112 fi 113 sleep 2 114 done 115 116 if [ "$attempt" -eq 0 ]; then 117 echo "Timed out waiting for QEMU, exiting" 118 exit 1 119 fi 120 121 # Now run the Robot test (Tests commented out until they are working again) 122 123 # Timestamp for job 124 #echo "Robot Test started, $(date)" 125 126 #mkdir -p ${WORKSPACE} 127 #cd ${WORKSPACE} 128 129 # Copy in the script which will execute the Robot tests 130 #cp $DIR/scripts/run-robot.sh ${WORKSPACE} 131 132 # Run the Docker container to execute the Robot test cases 133 # The test results will be put in ${WORKSPACE} 134 #docker run --rm \ 135 # --user root \ 136 # --env HOME=${HOME} \ 137 # --env IP_ADDR=${DOCKER_QEMU_IP_ADDR} \ 138 # --env SSH_PORT=${DOCKER_SSH_PORT} \ 139 # --env HTTPS_PORT=${DOCKER_HTTPS_PORT} \ 140 # --workdir ${HOME} \ 141 # --volume ${WORKSPACE}:${HOME} \ 142 # --tty \ 143 # ${DOCKER_IMG_NAME} ${HOME}/run-robot.sh 144 145 # Now stop the QEMU Docker image 146 docker stop $obmc_qemu_docker 147 148elif [[ ${LAUNCH} == "k8s" ]]; then 149 # Package the Upstream into an image based off the one created by the build-qemu-robot.sh 150 # Dockerfile = $( cat << EOF 151 imgname=$DOCKER_IMG_NAME 152 cd $DIR 153 source ./kubernetes/kubernetes-launch.sh QEMU-launch false false deployment 154 155 # Xcat Launch (NYI) 156 157 # source ./kubernetes/kubernetes-launch.sh XCAT-launch true true 158 159else 160 echo "LAUNCH variable invalid, Exiting" 161 exit 1 162fi 163