#!/bin/bash # $HeadURL$ $LastChangedRevision$ PROGNAME=`basename $0` SANDPIT=`pwd` . $(ade-config ade_share_prefix)/include/adetestsupport.sh ############################################################################## # # Purpose of test: to verify correct behaviour during long operations and # when long operations are interrupted. # # Bug id: # ############################################################################## # Ensure dates are consistently formatted export LC_ALL=C # Start of support functions filter_variant_text() { # Note how the variable *width* of a hostname - and therefore of the padding # that follows it in column-aligned output - means that we can't change # just to VARIANT-HOSTNAME but *with* padding to # VARIANT-HOSTNAME with fixed width padding. eval "$@" 2>&1 | sed -e 's/[A-Z][a-z][a-z] [A-Z][a-z][a-z] [1-3 ][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [A-Z][A-Z]* [1-2][0-9][0-9][0-9] *$/Fri Dec 31 23:59:59 GMT 1999/g' \ -e 's/^\(pub\)\( *\)\([^ ]*\)\( *\)\([^ ]*\)$/\1\2VARIANT-KEY-ID\4VARIANT-DATE/' \ -e "s@$SANDPIT@VARIANT-SANDPIT@g" \ -e "s/$UNAMEN */VARIANT-HOSTNAME /g" \ -e "s/$UNAMEN\([^ \t]\)/VARIANT-HOSTNAME\1/g" \ -e "s/20[1-9][0-9][0-1][0-9][0-3][0-9][0-2][0-9][0-5][0-9][0-5][0-9]/VARIANT-TIMESTAMP/g" \ -e "s/^\(.*\) \( [1-9]\| [1-9][0-9]\| [1-9][0-9][0-9]\| [1-9][0-9][0-9][0-9]\|[1-9][0-9][0-9][0-9][0-9]\)/\\1 XXXXX/" \ -e "s/locked ([1-9][0-9]*/locked (XXXXX/" # return the passed command's return code, not sed's. return ${PIPESTATUS[0]} } launch_shell() { PS1="$PROGNAME> " bash --norc || true } # End of support functions # Set up environment echo "$PROGNAME: setting up environment ..." # Ensure DB is created in sandpit export PAA_RCDIR=$SANDPIT/.paa # Ensure effects on OS (modiying the *OS*'s idea of repos, restarting apache, etc) are not real export PAA_ROOTDIR=$SANDPIT # Force use of non-interactive editor cat > /tmp/write-debian-config.$$ < \$1 <<'EOF2' # I need to put *all* releases here because this is a test # and we want to ensure this repo gets installed. Same goes # for the ports. _RELEASES="lenny squeeze wheezy" _PORTS="i386 amd64" _SECTIONS="main contrib non-free main/debian-installer" for _RELEASE in \$_RELEASES; do release \$_RELEASE for _PORT in \$_PORTS; do port \$_RELEASE \$_PORT done for _SECTION in \$_SECTIONS; do section \$_RELEASE \$_SECTION done done distro debian url "http://install.pasta.net/./" mirror_dir "$SANDPIT/mirrors/" freeze_dir "$SANDPIT/freezes/." indirect_dir "$SANDPIT/indirects/." mirror_cmd "touch \\\$(ls | wc -l)" EOF2 EOF chmod 755 /tmp/write-debian-config.$$ export EDITOR=/tmp/write-debian-config.$$ mkdir $SANDPIT/bin mkdir -p $SANDPIT/etc/init.d echo -e '#!/bin/sh\n\necho -n "Reloading web server config: apache2."\nsleep 2\necho' > $SANDPIT/etc/init.d/apache2 chmod 755 $SANDPIT/etc/init.d/apache2 # Use a test-specific gpg configuration export GNUPGHOME=$SANDPIT/.gpupg # Don't use any running gpg-agent unset GPG_AGENT_INFO # Don't put the apache config files in $MODROOT/var 'cos they'll contaminate it. export PAA_STATE_PREFIX=$SANDPIT/var # Misc UNAMEN=$(uname -n) echo STEPS=(host register configure access unaccess mirror freeze indirect share unshare unindirect unfreeze unmirror unregister unhost) CMDLINE_host="paa host $UNAMEN deb debian squeeze amd64" CMDLINE_unhost="paa unhost $UNAMEN" CMDLINE_register="paa repo myrepo deb mirrored true" CMDLINE_unregister="paa unrepo myrepo" CMDLINE_configure="paa editrepo myrepo" CMDLINE_mirror="paa mirror myrepo" CMDLINE_unmirror="paa unmirror myrepo" CMDLINE_freeze="paa freeze myrepo" CMDLINE_unfreeze="paa unfreeze myrepo NEWEST-FREEZE" CMDLINE_indirect="paa indirect myrepo $UNAMEN NEWEST-FREEZE" CMDLINE_unindirect="paa unindirect myrepo $UNAMEN" ## This host must be registered else 'paa share' won't know how to restart apache. #CMDLINE_thishost="paa host $UNAMEN deb debian squeeze amd64" CMDLINE_share="paa share myrepo $UNAMEN" CMDLINE_unshare="paa unshare myrepo $UNAMEN" CMDLINE_access="paa access myrepo" CMDLINE_unaccess="paa unaccess myrepo" CMDLINE_LIST_host="paa listhosts" CMDLINE_LIST_unhost="$CMDLINE_LIST_host" CMDLINE_LIST_register="paa listrepos" CMDLINE_LIST_unregister="$CMDLINE_LIST_register" CMDLINE_LIST_configure="paa listrepos" CMDLINE_LIST_mirror="paa listmirrors" CMDLINE_LIST_unmirror="$CMDLINE_LIST_mirror" CMDLINE_LIST_freeze="paa listfreezes" CMDLINE_LIST_unfreeze="$CMDLINE_LIST_freeze" CMDLINE_LIST_indirect="paa listindirects" CMDLINE_LIST_unindirect="$CMDLINE_LIST_indirect" #CMDLINE_LIST_thishost="$CMDLINE_LIST_host" CMDLINE_LIST_unshare="$CMDLINE_LIST_share" CMDLINE_LIST_share="paa listshares" CMDLINE_LIST_unshare="$CMDLINE_LIST_share" CMDLINE_LIST_access="paa listaccesses" CMDLINE_LIST_unaccess="$CMDLINE_LIST_access" LONG_SLEEP=300 SHORT_SLEEP=40 for ((I=0; I<${#STEPS[*]}; I++)); do echo "$PROGNAME: running $STEP, backgrounded, concurrently, killed, resumed ..." # Sanity checks and derivations STEP=${STEPS[$I]} eval "LIST=\"\$CMDLINE_LIST_${STEP}\"" eval "CMDLINE=\"\$CMDLINE_$STEP\"" [ "X$STEP" != X ] || adetestsupport_error "STEP: not set" [ "X$LIST" != X ] || adetestsupport_error "LIST: not set" [ "X$CMDLINE" != X ] || adetestsupport_error "CMDLINE: not set" echo "$PROGNAME: executing '$STEP' running slowly in background ..." SLEEP=$LONG_SLEEP $CMDLINE & PAA_PID=$! echo "$PROGNAME: sleeping $SHORT_SLEEP seconds before listing ..." sleep $SHORT_SLEEP echo "$PROGNAME: listing ..." filter_variant_text "$LIST" echo "$PROGNAME: trying to run a second one in parallel ..." adetestsupport_invert_rc "filter_variant_text \"$CMDLINE\"" echo "$PROGNAME: listing ..." filter_variant_text "$LIST" echo "$PROGNAME: killing the backgrounded step ..." kill $PAA_PID wait $PAA_PID 2> /dev/null || true filter_variant_text "$LIST" echo "$PROGNAME: re-executing '$STEP' step normally ..." # Re-executing generates a warning about fostering, and the # text of this warning, in the case of freezing and unfreezing, # contains variant text. filter_variant_text "$CMDLINE" filter_variant_text "$LIST" echo done echo "end"