Last active
March 17, 2020 09:09
-
-
Save mine260309/cd1455096a419829471155bdc5f1f9ce to your computer and use it in GitHub Desktop.
Run OpenBMC Jenkins jobs in Shanghai Lab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Environment to be set in Jenkins | |
# BIG_ENDIAN_SYSTEM_IP=<IP> | |
# USER=<USER> (setup by ssh-copy-id) | |
#!/bin/bash | |
set -xe | |
BRANCH_LOCAL=local_test | |
TMP_LOCAL_REPO=/tmp/test_pldm | |
rm -rf ${TMP_LOCAL_REPO} | |
# Store a path to the image so we can find it later | |
echo "Triggered by ${GERRIT_PROJECT}" | |
mkdir ${TMP_LOCAL_REPO} | |
cd ${TMP_LOCAL_REPO} | |
git clone "http://gerrit.openbmc-project.xyz/openbmc/pldm" || exit 100 | |
(cd pldm && git fetch --tags --progress -- "http://gerrit.openbmc-project.xyz/openbmc/pldm" ${GERRIT_REFSPEC} && git checkout FETCH_HEAD -b local_test) || exit 100 | |
cd ${TMP_LOCAL_REPO}/pldm | |
git bundle create pldm.bundle ${BRANCH_LOCAL} | |
ssh ${USER}@${BIG_ENDIAN_SYSTEM_IP} "mkdir -p ${TMP_LOCAL_REPO}" | |
scp pldm.bundle ${USER}@${BIG_ENDIAN_SYSTEM_IP}:${TMP_LOCAL_REPO} | |
ssh ${USER}@${BIG_ENDIAN_SYSTEM_IP}<<'ENDSSH' | |
set -xe | |
BRANCH_LOCAL=local_test | |
TMP_LOCAL_REPO=/tmp/test_pldm | |
rm -rf ${TMP_LOCAL_REPO}/pldm | |
mkdir -p ${TMP_LOCAL_REPO} | |
cd ${TMP_LOCAL_REPO} | |
git clone -b ${BRANCH_LOCAL} pldm.bundle pldm | |
cd pldm | |
meson -Dlibpldm-only=enabled -Doem-ibm=enabled build | |
ninja -C build/ test || (cat build/meson-logs/testlog.txt && exit 1) | |
ENDSSH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -xe | |
# Precondition: | |
# Fork openbmc/pldm | |
# Enable travis on your forked pldm repo | |
# This script will create a branch `${GERRIT_REFSPEC}` on each Verified +1, | |
# trigger the traivs on the github branch, and wait for the travis result. | |
echo "Triggered by ${GERRIT_PROJECT}" | |
rm -rf * | |
# Setup a docker container with hub tool | |
cat >Dockerfile <<EOF | |
FROM ubuntu:eoan | |
RUN apt update && apt -yq install git hub | |
ADD . /root | |
EOF | |
docker build -t libpldm_ci . | |
## Environments | |
REPO=git@github.com:$USERNAME/pldm.git | |
TMP_LOCAL_REPO=/tmp/test_pldm | |
cat >test.sh <<EOF | |
#!/bin/bash | |
set -x | |
HUB_TOOL=hub | |
GERRIT_REFSPEC=${GERRIT_REFSPEC} | |
rm -rf ${TMP_LOCAL_REPO} | |
mkdir ${TMP_LOCAL_REPO} | |
cd ${TMP_LOCAL_REPO} | |
git clone ${REPO} || exit 100 | |
(cd pldm && git fetch --tags --progress -- "http://gerrit.openbmc-project.xyz/openbmc/pldm" \${GERRIT_REFSPEC} && git checkout FETCH_HEAD -b \${GERRIT_REFSPEC}) || exit 100 | |
cd ${TMP_LOCAL_REPO}/pldm | |
\${HUB_TOOL} push origin \${GERRIT_REFSPEC} # Need .ssh for auto login | |
# Now check the Travis CI result | |
n=0 | |
until [ \$n -ge 6 ] | |
do | |
sleep 10 | |
result=\$(\${HUB_TOOL} ci-status \${GERRIT_REFSPEC}) # Need .config/hub for hub | |
rc=\$? | |
if [ "\$result" == "success" ]; then | |
break | |
fi | |
if [ "\$result" == "no status" ]; then | |
exit 100 | |
fi | |
n=\$[\$n+1] | |
done | |
echo Result: \${result} | |
exit \${rc} | |
EOF | |
chmod +x test.sh | |
WORKSPACE=`pwd` | |
DOCKER_IMG_NAME=libpldm_ci | |
WORKING_DIR=/tmp/pldm_ci | |
docker container run \ | |
--name libpldm_test \ | |
--rm --network host \ | |
--volume ${WORKSPACE}:/${WORKING_DIR}/ \ | |
--volume ${HOME}/.ssh:/root/.ssh:ro \ | |
--volume ${HOME}/.config:/root/.config:ro \ | |
${DOCKER_IMG_NAME} ${WORKING_DIR}/test.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Environment to be set in Jenkins | |
# MACHINE=romulus | |
# BMC_IP=<BMC> | |
# BMC_USERNAME=root | |
# BMC_PASSWORD=0penBmc | |
# SSH_PORT=22 | |
# HTTPS_PORT=443 | |
# OBMC_JENKINS_USERNAME = <USER> | |
# OBMC_JENKINS_TOKEN = <TOKEN> | |
#!/bin/bash | |
set -xe | |
rm -rf * | |
# Check if BMC is alive | |
# By ping we got permission issue in docker | |
# ping $BMC_IP -c 1 || (echo "Failed to ping BMC!"; exit 100) | |
# So let's use curl | |
curl -k https://$BMC_IP >/dev/null 2>&1 || (echo "Failed to connect to BMC!"; exit 100) | |
WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} | |
mkdir -p ${WORKSPACE} | |
cd ${WORKSPACE} | |
# Store a path to the image so we can find it later | |
echo "Triggered by ${GERRIT_PROJECT}" | |
# Support both openbmc/openbmc and the new meta layers | |
if [[ "${GERRIT_PROJECT}" == "openbmc/openbmc" ]]; then | |
GERRIT_PATH="run-openbmc-ci" | |
deploy="openbmc/build/tmp/deploy/" | |
else | |
GERRIT_PATH="run-meta-ci" | |
deploy="openbmc/build/tmp/deploy/" | |
fi | |
# Get a crumb so we don't have CSRF issues | |
wget --user ${OBMC_JENKINS_USERNAME}:${OBMC_JENKINS_TOKEN} --output-document ${WORKSPACE}/crumb 'https://openpower.xyz/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)' | |
url=$(curl --header $(cat ${WORKSPACE}/crumb) -G -s "https://openpower.xyz/job/$GERRIT_PATH/api/xml" --data-urlencode "tree=builds[number,url,actions[parameters[name,value]]]" --data-urlencode "xpath=/matrixProject/build[action/parameter[name='GERRIT_REFSPEC' and value='${GERRIT_REFSPEC}']][1]/url") | |
url=${url#"<url>"} | |
url=${url%"</url>"} | |
filename=$(curl --header $(cat ${WORKSPACE}/crumb) -G -s "https://openpower.xyz/job/$GERRIT_PATH/distro=ubuntu,label=builder,target=${MACHINE}/api/xml" --data-urlencode "tree=builds[actions[parameters[name,value]],artifacts[fileName]]" --data-urlencode "xpath=(matrixConfiguration/build[action[parameter[name='GERRIT_REFSPEC' and value='${GERRIT_REFSPEC}']]]/artifact/fileName[contains(text(),\"obmc-phosphor-image-${MACHINE}.static.mtd.tar\")])[1]") | |
filename=${filename#"<fileName>"} | |
filename=${filename%"</fileName>"} | |
if [[ $filename == *"XPath (matrixConfiguration/build[action[parameter[name"* ]]; then | |
echo "We did not find a .mtd.tar BMC image" | |
exit 100 | |
fi | |
fullpath=$url"distro=ubuntu,label=builder,target=${MACHINE}/artifact/$deploy/images/${MACHINE}/"$filename | |
printf "BmcImage=$fullpath" > generated-params.txt | |
echo $fullpath | |
export USER=$(whoami) # Necessary due to Jenkins container does not set USER env | |
DOCKER_IMG_NAME=openbmc/ubuntu-robot-qemu | |
BMC_IMAGE=$fullpath | |
delay=1 | |
# Get the build script, one can use from the gerrit directly | |
# https://gerrit.openbmc-project.xyz/openbmc/openbmc-build-scripts | |
# Due to recent flaky gerrit server, using github instead. | |
git clone https://github.com/openbmc/openbmc-build-scripts | |
cd openbmc-build-scripts | |
# Build the docker image required to execute the robot tests. | |
. "./scripts/build-qemu-robot-docker.sh" | |
if [ $? -ne 0 ]; then exit 100; fi | |
# Now pull in test scripts | |
cd ${WORKSPACE} | |
retries=5 | |
count=0 | |
while [ $count -lt $retries ]; do | |
git clone https://github.com/openbmc/openbmc-test-automation.git | |
if [ $? -eq 0 ]; then | |
break | |
fi | |
let count=$count+1 | |
sleep $delay | |
done | |
if [ $count -eq $retries ]; then exit 100; fi | |
# Hacked by LeiYU: | |
# The code update does a reboot and wait for up to 8 minutes | |
# it works for Witherspoon which does the flash erase/write in activating, | |
# but does not work for static layout systems like Romulus, which does | |
# the flash erase/write during reboot. | |
# Change it to 30 minutes so that it has enough time to do the code update | |
sed -i "s/8 mins/30 mins/" ${WORKSPACE}/openbmc-test-automation/lib/state.py | |
# Download BMC image if supplied. | |
if [ ! -z ${BMC_IMAGE+x} ]; then | |
# Get the short name for the image | |
SHORT_BMC_IMG_NAME=${BMC_IMAGE##*/} | |
# Retrieve the .tar | |
rm -f ./$SHORT_BMC_IMG_NAME | |
if [ ! -f ./$SHORT_BMC_IMG_NAME ]; then | |
# check if we were given a local file or https | |
# Example : /esw/san5/images/xyz*.ubi.mtd.tar | |
if [ -f ${BMC_IMAGE} ]; then | |
echo "Local file so copy into workspace" | |
cp ${BMC_IMAGE} ./ | |
else | |
echo "Remote file so wget it" | |
wget --no-check-certificate ${BMC_IMAGE} | |
fi | |
if [ $? -ne 0 ]; then exit 100; fi | |
else | |
echo "Already have downloaded $SHORT_BMC_IMG_NAME" | |
fi | |
# Trigger firmware update for BMC. | |
DEFAULT_UPDATE=0 | |
# Run the docker container to execute the code update | |
# The test results will be put in ${WORKSPACE} | |
# UBI format BMC firmware update. | |
docker run --user ${USER} \ | |
--env HOME=${HOME} \ | |
--workdir ${HOME} \ | |
--volume ${WORKSPACE}:${HOME} \ | |
--tty \ | |
${DOCKER_IMG_NAME} python3 -m robot \ | |
-v quiet:0 \ | |
-v OPENBMC_HOST:${BMC_IP} \ | |
-v OPENBMC_USERNAME:${BMC_USERNAME} \ | |
-v OPENBMC_PASSWORD:${BMC_PASSWORD} \ | |
-v REST_PASSWORD:${BMC_PASSWORD} \ | |
-v IMAGE_FILE_PATH:${HOME}/${SHORT_BMC_IMG_NAME} \ | |
-v SKIP_UPDATE_IF_ACTIVE:true \ | |
--include REST_BMC_Code_Update \ | |
${HOME}/openbmc-test-automation/extended/code_update/bmc_code_update.robot | |
if [ $? -ne 0 ]; then exit 100; fi | |
fi | |
ROBOT_CMD="--argumentfile test_lists/HW_CI -v LOOP_COUNT:1 --exclude Verify_Redfish_Host_PowerOn --include Verify_Redfish_BMC_PowerOn_With_OCC_State redfish tests" | |
# Run the docker container to execute the robot test cases | |
# The test results will be put in ${WORKSPACE} | |
docker run --user "${USER}" \ | |
--env HOME=${HOME} \ | |
--env IP_ADDR=${BMC_IP} \ | |
--env SSH_PORT=${SSH_PORT} \ | |
--env HTTPS_PORT=${HTTPS_PORT} \ | |
--env DELETE_OLD_GUARD_FILE=true \ | |
--env ROBOT_TEST_CMD="python3 -m robot -v OPENBMC_HOST:${BMC_IP} -v OPENBMC_USERNAME:${BMC_USERNAME} -v OPENBMC_PASSWORD:${BMC_PASSWORD} -v REST_PASSWORD:${BMC_PASSWORD} -v IPMI_PASSWORD:${BMC_PASSWORD} ${ROBOT_CMD}" \ | |
--workdir ${HOME} \ | |
--volume ${WORKSPACE}:${HOME} \ | |
--tty \ | |
${DOCKER_IMG_NAME} ${HOME}/openbmc-build-scripts/scripts/run-robot.sh | |
if [ $? -ne 0 ]; then exit 1; fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment