blob: be8757516197652f16219d7927fd920ee41c94a4 [file] [log] [blame]
Andrew Geissler0205e8d2016-08-10 07:46:19 -05001#!/bin/bash -xe
Alanny Lopez74d2aba2017-07-27 10:23:47 -05002###############################################################################
Andrew Geissler0205e8d2016-08-10 07:46:19 -05003#
Alanny Lopez74d2aba2017-07-27 10:23:47 -05004# 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.
Alanny Lopez07b4d5b2017-08-01 16:24:07 -050033# 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.
Alanny Lopez74d2aba2017-07-27 10:23:47 -050039#
40###############################################################################
Andrew Geissler0205e8d2016-08-10 07:46:19 -050041
42set -uo pipefail
43
Alanny Lopez74d2aba2017-07-27 10:23:47 -050044QEMU_RUN_TIMER=${QEMU_RUN_TIMER:-300}
Andrew Geissler1df680a2016-08-22 14:37:39 -050045WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Alanny Lopez74d2aba2017-07-27 10:23:47 -050046DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-openbmc/ubuntu-robot-qemu}
47OBMC_BUILD_DIR=${OBMC_BUILD_DIR:-/tmp/openbmc/build}
48UPSTREAM_WORKSPACE=${UPSTREAM_WORKSPACE:-${1}}
Alanny Lopez07b4d5b2017-08-01 16:24:07 -050049LAUNCH=${LAUNCH:-local}
Andrew Geissler0205e8d2016-08-10 07:46:19 -050050
Alanny Lopez74d2aba2017-07-27 10:23:47 -050051# Determine the architecture
52ARCH=$(uname -m)
Andrew Geissler0205e8d2016-08-10 07:46:19 -050053
Alanny Lopez74d2aba2017-07-27 10:23:47 -050054# Determine the prefix of the Dockerfile's base image and the QEMU_ARCH variable
55case ${ARCH} in
56 "ppc64le")
Andrew Geissler0205e8d2016-08-10 07:46:19 -050057 DOCKER_BASE="ppc64le/"
58 QEMU_ARCH="ppc64le-linux"
Alanny Lopez74d2aba2017-07-27 10:23:47 -050059 ;;
60 "x86_64")
Andrew Geissler0205e8d2016-08-10 07:46:19 -050061 DOCKER_BASE=""
62 QEMU_ARCH="x86_64-linux"
Alanny Lopez74d2aba2017-07-27 10:23:47 -050063 ;;
64 *)
65 echo "Unsupported system architecture(${ARCH}) found for docker image"
66 exit 1
67esac
Andrew Geissler0205e8d2016-08-10 07:46:19 -050068
Alanny Lopez74d2aba2017-07-27 10:23:47 -050069# 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
Andrew Geissler0205e8d2016-08-10 07:46:19 -050073. "$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
Alanny Lopez07b4d5b2017-08-01 16:24:07 -050078################################################################################
Alanny Lopez74d2aba2017-07-27 10:23:47 -050079
Alanny Lopez07b4d5b2017-08-01 16:24:07 -050080if [[ ${LAUNCH} == "local" ]]; then
Alanny Lopez74d2aba2017-07-27 10:23:47 -050081
Alanny Lopez07b4d5b2017-08-01 16:24:07 -050082 # 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)
Andrew Geissler0205e8d2016-08-10 07:46:19 -050093
Alanny Lopez07b4d5b2017-08-01 16:24:07 -050094 # 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)"
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500100
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500101 #Now wait for the OpenBMC QEMU Docker instance to get to standby
102 attempt=60
103 while [ $attempt -gt 0 ]; do
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500104 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
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500108 echo "QEMU is ready!"
109 # Give QEMU a few secs to stablize
110 sleep 5
111 break
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500112 fi
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500113 sleep 2
114 done
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500115
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500116 if [ "$attempt" -eq 0 ]; then
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500117 echo "Timed out waiting for QEMU, exiting"
118 exit 1
Alanny Lopez07b4d5b2017-08-01 16:24:07 -0500119 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
Andrew Geissler0205e8d2016-08-10 07:46:19 -0500162fi