From d46ea13d48a365c3c7bd2292b54717b0a1758299 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Sat, 8 Apr 2017 15:56:31 +0200 Subject: review jenkins scripts Change-Id: I420910bd2d30e96605ecf3acb779ce726c75d912 --- contrib/jenkins-openbsc-build.sh | 142 ------------------------------------- contrib/jenkins-osmo-bts-octphy.sh | 141 +++++++++++++++--------------------- contrib/jenkins-osmo-bts-sysmo.sh | 30 ++++---- contrib/jenkins-osmo-bts-trx.sh | 13 ++-- contrib/jenkins-osmo-nitb.sh | 63 ++++++++++++++++ contrib/jenkins-remote-update.sh | 24 +++++++ contrib/jenkins-run.sh | 36 ++++++++++ contrib/trials-cleanup.sh | 30 ++++++++ contrib/ts-dir-cleanup.sh | 30 -------- 9 files changed, 234 insertions(+), 275 deletions(-) delete mode 100755 contrib/jenkins-openbsc-build.sh create mode 100755 contrib/jenkins-osmo-nitb.sh create mode 100755 contrib/jenkins-remote-update.sh create mode 100755 contrib/jenkins-run.sh create mode 100755 contrib/trials-cleanup.sh delete mode 100755 contrib/ts-dir-cleanup.sh (limited to 'contrib') diff --git a/contrib/jenkins-openbsc-build.sh b/contrib/jenkins-openbsc-build.sh deleted file mode 100755 index f2be853..0000000 --- a/contrib/jenkins-openbsc-build.sh +++ /dev/null @@ -1,142 +0,0 @@ -set -e -x - -prefix_base="`pwd`" -prefix_dirname="inst-openbsc" -prefix="$prefix_base/$prefix_dirname" - -reposes=" -libosmocore -libosmo-abis -libosmo-netif -openggsn -libsmpp34 -libosmo-sccp -openbsc/openbsc -" - -osmo_gsm_tester_host=root@10.9.1.190 -osmo_gsm_tester_dir="/var/tmp/osmo-gsm-tester" -tmp_dir="/var/tmp/prep-osmo-gsm-tester" -arch="x86_64" -archive_name="openbsc.$arch-build-$BUILD_NUMBER" -archive="$archive_name.tgz" -manifest="checksums.md5" -test_report="test-report.xml" -test_timeout_sec=120 - -rm -rf $prefix -mkdir -p $prefix - -opt_prefix="" -if [ -n "$prefix" ]; then - export LD_LIBRARY_PATH="$prefix"/lib - export PKG_CONFIG_PATH="$prefix"/lib/pkgconfig - opt_prefix="--prefix=$prefix" -fi - -for r in $reposes; do - make -C "$r" clean || true -done - -for r in $reposes; do - - cd "$r" - - echo "$(git rev-parse HEAD) $r" >> "$prefix/openbsc_git_hashes.txt" - - autoreconf -fi - - opt_enable="" - if [ "$r" = 'openbsc/openbsc' ]; then - opt_enable="--enable-smpp --enable-osmo-bsc --enable-nat" - fi - - ./configure "$opt_prefix" $opt_enable - - make -j || make || make - if [ "$r" != asn1c ]; then - if [ "$r" = 'libosmo-netif' ]; then - # skip clock dependent test in libosmo-netif - make check TESTSUITEFLAGS='-k !osmux_test' - else - make check - fi - fi - make install - cd .. -done - -# create test session directory, archive and manifest - -cd $prefix_base - -ts_name="$NODE_NAME-$BUILD_TAG" -local_ts_base="./compose_ts" -local_ts_dir="$local_ts_base/$ts_name" - -rm -rf "$local_ts_base" || true -mkdir -p "$local_ts_dir" - -# create archive of openbsc build -cd "$prefix_dirname" -tar czf "../$local_ts_dir/$archive" * -cd .. -# move archived bts builds into test session directory -mv $WORKSPACE/osmo-bts-*.tgz "$local_ts_dir" -cd "$local_ts_dir" -md5sum *.tgz > $manifest -cd - - -# transfer test session directory to temporary dir on osmo-gsm-tester host -# when transfer is complete, move the directory to its final location (where -# the osmo-gsm-tester will recognize the session directory and start the session - -ssh $osmo_gsm_tester_host "mkdir -p $tmp_dir" -scp -r "$local_ts_dir" $osmo_gsm_tester_host:$tmp_dir/ -ssh $osmo_gsm_tester_host "mv $tmp_dir/$ts_name $osmo_gsm_tester_dir" - -# poll for test status -ts_dir="$osmo_gsm_tester_dir/$ts_name" - -set +x -ts_log=$ts_dir/test-session.log -echo "Waiting for test session log to be created" -while /bin/true; do - if ssh $osmo_gsm_tester_host "test -e $ts_log"; then - break - fi - sleep 1 -done - -echo "Following test session log" -# NOTE this will leave dead ssh session with tail running -ssh $osmo_gsm_tester_host "tail -f $ts_log" & - -echo "Waiting for test session to complete" -while /bin/true; do -# if [ "$test_timeout_sec" = "0" ]; then -# echo "TIMEOUT test execution timeout ($test_timeout_sec seconds) exceeded!" -# exit 1 -# fi - if ssh $osmo_gsm_tester_host "test -e $ts_dir/$test_report"; then - break - fi - sleep 1 -# test_timeout_sec="$(($test_timeout_sec - 1))" -done -set -x - -# use pgrep to terminate the ssh/tail (if it still exists) -remote_tail_pid=`ssh $osmo_gsm_tester_host "pgrep -fx 'tail -f $ts_log'"` -echo "remote_tail_pid = $remote_tail_pid" -ssh $osmo_gsm_tester_host "kill $remote_tail_pid" - -# copy contents of test session directory back and remove it from the osmo-gsm-tester host - -rsync -av -e ssh --exclude='inst-*' --exclude='tmp*' $osmo_gsm_tester_host:$ts_dir/ "$local_ts_dir/" - -ssh $osmo_gsm_tester_host "/usr/local/src/osmo-gsm-tester/contrib/ts-dir-cleanup.sh" - -# touch test-report.xml (to make up for clock drift between jenkins and build slave) - -touch "$local_ts_dir/$test_report" diff --git a/contrib/jenkins-osmo-bts-octphy.sh b/contrib/jenkins-osmo-bts-octphy.sh index 0a5a88c..4284262 100755 --- a/contrib/jenkins-osmo-bts-octphy.sh +++ b/contrib/jenkins-osmo-bts-octphy.sh @@ -1,94 +1,65 @@ #!/bin/sh +set -x -e -set -e +base="$PWD" +prefix="$base/inst-osmo-bts-octphy" -OPTION_DO_CLONE=0 -OPTION_DO_CLEAN=0 -OPTION_DO_TEST=1 +rm -f "$base/osmo-bts-octphy*.tgz" -PREFIX=`pwd`/inst-osmo-bts-octphy - -# NOTE Make sure either 'octphy-2g-headers' (prefered) or -# 'octsdr-2g' is listed among the repositories - -octbts_repos="libosmocore +deps=" +libosmocore libosmo-abis -openbsc/openbsc -octphy-2g-headers -osmo-bts" - -clone_repos() { - repos="$1" - for repo in $repos; do - if [ -e $repo ]; then - continue - fi - if [ "$repo" = "libosmocore" ]; then - url="git://git.osmocom.org/libosmocore.git" - elif [ "$repo" = "libosmo-abis" ]; then - url="git://git.osmocom.org/libosmo-abis.git" - elif [ "$repo" = "libosmo-netif" ]; then - url="git://git.osmocom.org/libosmo-netif.git" - elif [ "$repo" = "openbsc/openbsc" ]; then - url="git://git.osmocom.org/openbsc" - elif [ "$repo" = "octphy-2g-headers" ]; then - url="git://git.osmocom.org/octphy-2g-headers" - elif [ "$repo" = "octsdr-2g" ]; then - # NOTE acutally we only need the headers from the octphy-2g-headers - # repository but this (private) repository contains more recent versions - url="ssh://git@git.admin.sysmocom.de/octasic/octsdr-2g" - elif [ "$repo" = "osmo-bts" ]; then - url="git://git.osmocom.org/osmo-bts.git" - else - exit 2 - fi - git clone $url - done -} +osmo-bts +" -main() { - repos="$1" - if [ $OPTION_DO_CLONE -eq 1 ]; then clone_repos "$repos"; fi - rm -rf $PREFIX - mkdir -p $PREFIX - for repo in $repos; do - if [ "$repo" = "openbsc/openbsc" ]; then - continue - fi - if [ "$repo" = "octphy-2g-headers" ]; then - OCTPHY_INCDIR=`pwd`/octphy-2g-headers - continue - fi - if [ "$repo" = "octsdr-2g" ]; then - cd $repo - git checkout 5c7166bab0a0f2d8a9664213d18642ae305e7004 - cd - - OCTPHY_INCDIR=`pwd`/octsdr-2g/software/include - continue - fi - cd $repo - if [ $OPTION_DO_CLEAN -eq 1 ]; then git clean -dxf; fi - echo "$(git rev-parse HEAD) $repo" >> "$PREFIX/osmo-bts-octphy_git_hashes.txt" - autoreconf -fi - if [ "$repo" != "libosmocore" ]; then - export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig - export LD_LIBRARY_PATH=$PREFIX/lib:/usr/local/lib - fi - config_opts="" - case "$repo" in - 'osmo-bts') config_opts="$config_opts --enable-octphy --with-octsdr-2g=$OCTPHY_INCDIR" - esac - ./configure --prefix=$PREFIX $config_opts - make -j8 - if [ $OPTION_DO_TEST -eq 1 ]; then make check; fi - make install - cd .. - done +have_repo() { + repo="$1" + cd "$base" + if [ ! -e "$repo" ]; then + set +x + echo "MISSING REPOSITORY: $repo" + echo "should be provided by the jenkins workspace" + exit 1 + fi + cd "$repo" + git clean -dxf + cd "$base" } -set -x -main "$octbts_repos" +# for gsm_data_shared.* +have_repo openbsc + +# octphy headers +have_repo octphy-2g-headers + + +rm -rf "$prefix" +mkdir -p "$prefix" + +export PKG_CONFIG_PATH="$prefix/lib/pkgconfig" +export LD_LIBRARY_PATH="$prefix/lib" + +for dep in $deps; do + have_repo "$dep" + cd "$dep" + rm -rf * + git checkout . + + echo "$(git rev-parse HEAD) $dep" >> "$prefix/osmo-bts-octphy_git_hashes.txt" + + autoreconf -fi + + config_opts="" + + case "$repo" in + 'osmo-bts') config_opts="$config_opts --enable-octphy --with-octsdr-2g=$base/octphy-2g-headers" ;; + esac + + ./configure --prefix="$prefix" $config_opts + make -j8 + make install +done -# build the archive that is going to be copied to the tester and then to the BTS -rm -f $WORKSPACE/osmo-bts-octphy*.tgz -tar czf $WORKSPACE/osmo-bts-octphy.build-$BUILD_NUMBER.tgz inst-osmo-bts-octphy +# build the archive that is going to be copied to the tester +cd "$prefix" +tar czf "$base/osmo-bts-octphy.build-${BUILD_NUMBER}.tgz" * diff --git a/contrib/jenkins-osmo-bts-sysmo.sh b/contrib/jenkins-osmo-bts-sysmo.sh index 6edb7d3..7870259 100755 --- a/contrib/jenkins-osmo-bts-sysmo.sh +++ b/contrib/jenkins-osmo-bts-sysmo.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -e -x deps=" @@ -7,6 +8,7 @@ osmo-bts " base="$PWD" +rm -f "$base/osmo-bts-sysmo.*.tgz" have_repo() { repo="$1" @@ -31,6 +33,7 @@ have_repo openbsc . /opt/poky/1.5.4/environment-setup-armv5te-poky-linux-gnueabi +# Cross-compilation: all installations need to be put in the sysmo SDK sysroot export DESTDIR=/opt/poky/1.5.4/sysroots/armv5te-poky-linux-gnueabi prefix_base="/usr/local/jenkins-build" @@ -42,24 +45,25 @@ prefix_real="$DESTDIR$prefix" mkdir -p "$prefix_real" for dep in $deps; do - cd "$base/$dep" + cd "$base/$dep" + rm -rf * + git checkout . - echo "$(git rev-parse HEAD) $dep" >> "$prefix_real/osmo-bts-sysmo_git_hashes.txt" + echo "$(git rev-parse HEAD) $dep" >> "$prefix_real/osmo-bts-sysmo_git_hashes.txt" - autoreconf -fi + autoreconf -fi - config_opts="" - case "$dep" in - 'libosmocore') config_opts="--disable-pcsc" ;; - 'osmo-bts') config_opts="--enable-sysmocom-bts --with-openbsc=$base/openbsc/openbsc/include" ;; - esac + config_opts="" + case "$dep" in + 'libosmocore') config_opts="--disable-pcsc" ;; + 'osmo-bts') config_opts="--enable-sysmocom-bts --with-openbsc=$base/openbsc/openbsc/include" ;; + esac - ./configure --prefix="$prefix" $CONFIGURE_FLAGS $config_opts - make -j8 - make install + ./configure --prefix="$prefix" $CONFIGURE_FLAGS $config_opts + make -j8 + make install done # build the archive that is going to be copied to the tester and then to the BTS -rm -f "$base/osmo-bts-sysmo.*.tgz" -cd "$prefix_base_real" +cd "$prefix_real" tar cvzf "$base/osmo-bts-sysmo.build-${BUILD_NUMBER}.tgz" * diff --git a/contrib/jenkins-osmo-bts-trx.sh b/contrib/jenkins-osmo-bts-trx.sh index 713f974..acdcc89 100755 --- a/contrib/jenkins-osmo-bts-trx.sh +++ b/contrib/jenkins-osmo-bts-trx.sh @@ -1,8 +1,10 @@ +#!/bin/sh set -x -e base="$PWD" -inst="inst-osmo-bts-trx" -prefix="$base/$inst" +prefix="$base/inst-osmo-bts-trx" + +rm -f "$base/osmo-bts-trx*.tgz" deps=" libosmocore @@ -38,6 +40,8 @@ export LD_LIBRARY_PATH="$prefix/lib" for dep in $deps; do have_repo "$dep" cd "$dep" + rm -rf * + git checkout . echo "$(git rev-parse HEAD) $dep" >> "$prefix/osmo-bts-trx_osmo-trx_git_hashes.txt" @@ -56,6 +60,5 @@ for dep in $deps; do done # build the archive that is going to be copied to the tester -rm -f "$base/osmo-bts-trx*.tgz" -cd "$base" -tar czf "osmo-bts-trx.build-${BUILD_NUMBER}.tgz" "$inst" +cd "$prefix" +tar czf "$base/osmo-bts-trx.build-${BUILD_NUMBER}.tgz" * diff --git a/contrib/jenkins-osmo-nitb.sh b/contrib/jenkins-osmo-nitb.sh new file mode 100755 index 0000000..e655082 --- /dev/null +++ b/contrib/jenkins-osmo-nitb.sh @@ -0,0 +1,63 @@ +set -e -x + +base="$PWD" +prefix="$base/inst-osmo-nitb" + +rm -f "$base/osmo-nitb*.tgz" + +deps=" +libosmocore +libosmo-abis +libosmo-netif +openggsn +libsmpp34 +libosmo-sccp +openbsc +" + +have_repo() { + repo="$1" + cd "$base" + if [ ! -e "$repo" ]; then + set +x + echo "MISSING REPOSITORY: $repo" + echo "should be provided by the jenkins workspace" + exit 1 + fi + cd "$repo" + git clean -dxf + cd "$base" +} + +rm -rf "$prefix" +mkdir -p "$prefix" + +export PKG_CONFIG_PATH="$prefix/lib/pkgconfig" +export LD_LIBRARY_PATH="$prefix/lib" + +for dep in $deps; do + have_repo "$dep" + cd "$dep" + rm -rf * + git checkout . + + echo "$(git rev-parse HEAD) $dep" >> "$prefix/osmo-nitb_git_hashes.txt" + + config_opts="" + + case "$dep" in + 'openbsc') + config_opts="$config_opts --enable-smpp --enable-osmo-bsc --enable-nat" + cd openbsc/ + ;; + esac + + autoreconf -fi + ./configure --prefix="$prefix" $config_opts + make -j8 || make # libsmpp34 can't build in parallel + make install +done + +# build the archive that is going to be copied to the tester +cd "$prefix" +tar czf "$base/osmo-nitb.build-${BUILD_NUMBER}.tgz" * diff --git a/contrib/jenkins-remote-update.sh b/contrib/jenkins-remote-update.sh new file mode 100755 index 0000000..3b4fc74 --- /dev/null +++ b/contrib/jenkins-remote-update.sh @@ -0,0 +1,24 @@ +#!/bin/sh +set -e -x + +if [ -z "$OSMO_GSM_TESTER_REMOTE_MAIN_UNIT" ]; then + echo "To run the tests from jenkins, a main unit host must be defined." + echo "e.g. OSMO_GSM_TESTER_REMOTE_MAIN_UNIT=\"user@10.9.8.7\"" +fi + +osmo_gsm_tester_host="$OSMO_GSM_TESTER_REMOTE_MAIN_UNIT" +osmo_gsm_tester_src="${OSMO_GSM_TESTER_REMOTE_SRC:-/usr/local/src/osmo-gsm-tester}" + +if ssh "$osmo_gsm_tester_host" "test -d \"$osmo_gsm_tester_src\"" ; then + # exists + status="$(ssh "$osmo_gsm_tester_host" "git -C \"$osmo_gsm_tester_src\" status --porcelain")" + if [ "x$status" != "x" ]; then + echo "Remote osmo-gsm-tester is not clean: $osmo_gsm_tester_host:$osmo_gsm_tester_src" + echo "$status" + exit 1 + fi + ssh "$osmo_gsm_tester_host" "cd \"$osmo_gsm_tester_src\"; git clean -fdx; git pull" +else + osmo_gsm_tester_src_dirname="$(dirname "$osmo_gsm_tester_src")" + ssh "$osmo_gsm_tester_host" "git clone git://git.osmocom.org/osmo-gsm-tester.git \"$osmo_gsm_tester_src\"" +fi diff --git a/contrib/jenkins-run.sh b/contrib/jenkins-run.sh new file mode 100755 index 0000000..62394d1 --- /dev/null +++ b/contrib/jenkins-run.sh @@ -0,0 +1,36 @@ +#!/bin/sh +set -e -x + +if [ -z "$OSMO_GSM_TESTER_REMOTE_MAIN_UNIT" ]; then + echo "To run the tests from jenkins, a main unit host must be defined." + echo "e.g. OSMO_GSM_TESTER_REMOTE_MAIN_UNIT=\"user@10.9.8.7\"" +fi + +osmo_gsm_tester_host="$OSMO_GSM_TESTER_REMOTE_MAIN_UNIT" +osmo_gsm_tester_src="${OSMO_GSM_TESTER_REMOTE_SRC:-/usr/local/src/osmo-gsm-tester}" +osmo_gsm_tester_dir="/var/tmp/osmo-gsm-tester" +tmp_dir="/var/tmp/prep-osmo-gsm-tester" + +trial_name="$NODE_NAME-$BUILD_TAG" +local_trial_base="./compose_trial" +local_trial_dir="$local_trial_base/$trial_name" + +rm -rf "$local_trial_base" || true +mkdir -p "$local_trial_dir" + +# Add archives from other jenkins builds. +# This jenkins job must be configured to copy *.tgz artifacts to the +# workspace from the various jenkins*bts*.sh runs. +mv $WORKSPACE/*.tgz "$local_trial_dir" +cd "$local_trial_dir" +md5sum *.tgz > checksums.md5 +cd - + +ssh "$osmo_gsm_tester_host" "$osmo_gsm_tester_src/contrib/trials-cleanup.sh" + +ssh "$osmo_gsm_tester_host" "mkdir -p $tmp_dir" +scp -r "$local_trial_dir" $osmo_gsm_tester_host:$tmp_dir/ +ssh "$osmo_gsm_tester_host" "mv $tmp_dir/$trial_name $osmo_gsm_tester_dir" +trial_dir="$osmo_gsm_tester_dir/$trial_name" + +ssh "$osmo_gsm_tester_host" "$osmo_gsm_tester_src/src/osmo-gsm-tester.py $trial_dir" diff --git a/contrib/trials-cleanup.sh b/contrib/trials-cleanup.sh new file mode 100755 index 0000000..2ad8c93 --- /dev/null +++ b/contrib/trials-cleanup.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Remove all but the N newest test run dirs (that have been started) + +trial_rx_dir="$1" +trial_prep_dir="$2" +if [ -z "$trial_rx_dir" ]; then + trial_rx_dir="/var/tmp/osmo-gsm-tester" +fi +if [ -z "$trial_prep_dir" ]; then + trial_prep_dir="/var/tmp/prep-osmo-gsm-tester" +fi + +mkdir -p "$trial_prep_dir" + +rm_trial() { + trial_dir="$1" + trial_name="$(basename "$trial_dir")" + echo "Removing: $(ls -ld "$trial_dir")" + # ensure atomic removal, so that the gsm-tester doesn't take it as a + # newly added dir (can happen when the 'SEEN' marker is removed first). + mv "$trial_dir" "$trial_prep_dir/" + rm -rf "$trial_prep_dir/$trial_name" +} + +# keep the N newest test session dirs that have been started: find all that +# have been started sorted by time, then discard all but the N newest ones. + +for seen in $(ls -1t "$trial_rx_dir"/*/SEEN | tail -n +31); do + rm_trial "$(dirname "$seen")" +done diff --git a/contrib/ts-dir-cleanup.sh b/contrib/ts-dir-cleanup.sh deleted file mode 100755 index ae5ea04..0000000 --- a/contrib/ts-dir-cleanup.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -# Remove all but the N newest test run dirs (that have been started) - -ts_rx_dir="$1" -ts_prep_dir="$2" -if [ -z "$ts_rx_dir" ]; then - ts_rx_dir="/var/tmp/osmo-gsm-tester" -fi -if [ -z "$ts_prep_dir" ]; then - ts_prep_dir="/var/tmp/prep-osmo-gsm-tester" -fi - -mkdir -p "$ts_prep_dir" - -rm_ts() { - ts_dir="$1" - ts_name="$(basename "$ts_dir")" - echo "Removing: $(ls -ld "$ts_dir")" - # ensure atomic removal, so that the gsm-tester doesn't take it as a - # newly added dir (can happen when the 'SEEN' marker is removed first). - mv "$ts_dir" "$ts_prep_dir/" - rm -rf "$ts_prep_dir/$ts_name" -} - -# keep the N newest test session dirs that have been started: find all that -# have been started sorted by time, then discard all but the N newest ones. - -for seen in $(ls -1t "$ts_rx_dir"/*/SEEN | tail -n +31); do - rm_ts "$(dirname "$seen")" -done -- cgit v1.2.3