Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 1 | #!/bin/bash -xe |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 2 | ############################################################################### |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 3 | # |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 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. |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 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. |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 39 | # |
| 40 | ############################################################################### |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 41 | |
| 42 | set -uo pipefail |
| 43 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 44 | QEMU_RUN_TIMER=${QEMU_RUN_TIMER:-300} |
Andrew Geissler | 1df680a | 2016-08-22 14:37:39 -0500 | [diff] [blame] | 45 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 46 | DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-openbmc/ubuntu-robot-qemu} |
| 47 | OBMC_BUILD_DIR=${OBMC_BUILD_DIR:-/tmp/openbmc/build} |
| 48 | UPSTREAM_WORKSPACE=${UPSTREAM_WORKSPACE:-${1}} |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 49 | LAUNCH=${LAUNCH:-local} |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 50 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 51 | # Determine the architecture |
| 52 | ARCH=$(uname -m) |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 53 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 54 | # Determine the prefix of the Dockerfile's base image and the QEMU_ARCH variable |
| 55 | case ${ARCH} in |
| 56 | "ppc64le") |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 57 | DOCKER_BASE="ppc64le/" |
| 58 | QEMU_ARCH="ppc64le-linux" |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 59 | ;; |
| 60 | "x86_64") |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 61 | DOCKER_BASE="" |
| 62 | QEMU_ARCH="x86_64-linux" |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 63 | ;; |
| 64 | *) |
| 65 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 66 | exit 1 |
| 67 | esac |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 68 | |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 69 | # Get the base directory of the openbmc-build-scripts repo so we can return |
| 70 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 71 | |
| 72 | # Create the base Docker image for QEMU and Robot |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 73 | . "$DIR/scripts/build-qemu-robot-docker.sh" "$DOCKER_IMG_NAME" |
| 74 | |
| 75 | # Copy the scripts to start and verify QEMU in the workspace |
| 76 | cp $DIR/scripts/boot-qemu* ${UPSTREAM_WORKSPACE} |
| 77 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 78 | ################################################################################ |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 79 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 80 | if [[ ${LAUNCH} == "local" ]]; then |
Alanny Lopez | 74d2aba | 2017-07-27 10:23:47 -0500 | [diff] [blame] | 81 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 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) |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 93 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 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)" |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 100 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 101 | #Now wait for the OpenBMC QEMU Docker instance to get to standby |
| 102 | attempt=60 |
| 103 | while [ $attempt -gt 0 ]; do |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 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 |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 108 | echo "QEMU is ready!" |
| 109 | # Give QEMU a few secs to stablize |
| 110 | sleep 5 |
| 111 | break |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 112 | fi |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 113 | sleep 2 |
| 114 | done |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 115 | |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 116 | if [ "$attempt" -eq 0 ]; then |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 117 | echo "Timed out waiting for QEMU, exiting" |
| 118 | exit 1 |
Alanny Lopez | 07b4d5b | 2017-08-01 16:24:07 -0500 | [diff] [blame] | 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 | |
| 148 | elif [[ ${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 | |
| 159 | else |
| 160 | echo "LAUNCH variable invalid, Exiting" |
| 161 | exit 1 |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 162 | fi |