#!/bin/bash # $HeadURL$ $LastChangedRevision$ PROGNAME=`basename $0` SANDPIT=`pwd` . $(ade-config ade_share_prefix)/include/adetestsupport.sh ############################################################################## # # Purpose of test: to verify basic paa functions # # Bug id: # ############################################################################## # Make quotes of a consistent style (all other references to LC_ALL - e.g. # from before 'sort' commands has been removed). 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. Another padding issues comes # from that summer and winter timezones have different widths and therefore # different paddings. Although the timezone is devarianted the spacing is # not. This only seems to be a problem on the end of the line because dates # are always in the last column. eval "$@" | 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/ *\$//" # return the passed command's return code, not sed's. return ${PIPESTATUS[0]} } launch_shell() { PS1="$PROGNAME> " bash --norc || true } inspect_repos() { echo "$PROGNAME: listing repos ($1) ..." filter_variant_text "paa listrepos" echo "$PROGNAME: inspecting repos ($1) ..." filter_variant_text "( cd $SANDPIT && find repos 2>&1 | sort )" } inspect_mirrors() { echo "$PROGNAME: listing mirrors ($1) ..." filter_variant_text "paa listmirrors" echo "$PROGNAME: inspecting mirrors ($1)..." filter_variant_text "( cd $SANDPIT && find mirrors 2>&1 | sort )" } inspect_freezes() { echo "$PROGNAME: listing freezes ($1) ..." filter_variant_text "paa listfreezes" echo "$PROGNAME: inspecting freezes ($1)..." filter_variant_text "( cd $SANDPIT && find freezes ! -type l 2>&1 | sort )" } inspect_indirects() { echo "$PROGNAME: listing indirects ($1) ..." filter_variant_text "paa listindirects" echo "$PROGNAME: inspecting indirects ($1)..." filter_variant_text "( cd $SANDPIT && find indirects -type l -printf \"%p -> %l\\n\" 2>&1 | sort )" } inspect_shares() { echo "$PROGNAME: listing shares ($1) ..." filter_variant_text "paa listshares" echo "$PROGNAME: inspecting shares ($1)..." filter_variant_text "( cd $SANDPIT && find var 2>&1 | sort )" } inspect_accesses() { echo "$PROGNAME: listing accesses ($1) ..." filter_variant_text "paa listaccesses" echo "$PROGNAME: inspecting accesses ($1) ..." filter_variant_text "( cd $SANDPIT && find etc -name init.d -prune -o -print 2>&1 | sort )" } inspect_hosts() { echo "$PROGNAME: listing hosts ($1) ..." filter_variant_text "paa listhosts" } # End of support functions # Set variables used in this test # 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 export EDITOR=$SANDPIT/bin/caton # 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) ## rngd is needed to prevent 'gpg --gen-key' from blocking on insufficent entropy. #echo "$PROGNAME: checking rngd is running ..." #pidof rngd > /dev/null || { echo "rngd is not running"; false; } echo "$PROGNAME: creating non-interactive editor ..." mkdir -p $SANDPIT/{bin,etc/init.d} echo -e '#!/bin/sh\n\ncat > $1' > $SANDPIT/bin/caton chmod 755 $SANDPIT/bin/caton echo "$PROGNAME: generating a gpg key ..." # Generate a key without a password and without communicating with my agent mkdir $GNUPGHOME chmod 700 $GNUPGHOME #gpg --quiet --batch --gen-key 2> /dev/null <./" mirror_dir "$SANDPIT/mirrors/" freeze_dir "$SANDPIT/freezes/." indirect_dir "$SANDPIT/indirects/." mirror_cmd "touch \\\$(ls | wc -l)" EOF paa -v editrepo mirrored-rpm-repo <./" mirror_dir "$SANDPIT/mirrors/" freeze_dir "$SANDPIT/freezes/." indirect_dir "$SANDPIT/indirects/." mirror_cmd "touch \\\$(ls | wc -l)" EOF inspect_repos "after configuring repos properly" echo # Inserts inspect_repos "before inserting" inspect_repos "after inserting" echo # Control inspect_repos "before controlling" inspect_repos "after controlling" echo # Hosts inspect_hosts "before hosting" echo "$PROGNAME: adding some hosts ..." HOSTNAME_PKGTYPE_DISTRO_RELEASE_PORT_TUPLES="dsx:deb:debian:squeeze:amd64 f13i:rpm:fedora:13:i386" for HOSTNAME_PKGTYPE_DISTRO_RELEASE_PORT_TUPLE in $HOSTNAME_PKGTYPE_DISTRO_RELEASE_PORT_TUPLES; do [[ $HOSTNAME_PKGTYPE_DISTRO_RELEASE_PORT_TUPLE =~ (.*):(.*):(.*):(.*):(.*) ]] HOSTNAME=${BASH_REMATCH[1]} PKGTYPE=${BASH_REMATCH[2]} DISTRO=${BASH_REMATCH[3]} RELEASE=${BASH_REMATCH[4]} PORT=${BASH_REMATCH[5]} paa -v host $HOSTNAME $PKGTYPE $DISTRO $RELEASE $PORT done echo "$PROGNAME: adding some strange hosts ..." # This is bad because it contains an unknown package type adetestsupport_invert_rc "paa -v host a badpkgtype debian squeeze amd64" # But it has left an orphaned host, which will spoil all # later output, so we need to clean up. paa unhost a # An unknown distro, release or port are all ok! It just # means that paa hasn't yet been acquainted with that # distro, release or port. paa -v host b deb baddistro squeeze amd64 paa -v host c deb debian badrelease amd64 paa -v host d deb debian squeeze badport inspect_hosts "after adding strange entries" echo "$PROGNAME: removing strange entries ..." paa -v unhost b paa -v unhost c paa -v unhost d #inspect_hosts "after removing strange entries, before adding this host" inspect_hosts "after removing strange entries" # We do need to add this host because we'll set up accesses for it # later. But I'm going to have to filter this better: currently the # hostname is filtered but it also needs the pkgtype filtered (imagine # running the test on an RPM-based system). #echo "$PROGNAME: adding this host ..." #paa host THIS-HOST ## The host gets de-varianted but there are plenty of other variant fields ## on the same line; so we replace all of them here. #inspect_hosts "after adding this host" | sed -e 's/\(VARIANT-HOSTNAME *available *\).*/\1VARIANT-OTHER-TEXT/' echo # Mirrors inspect_mirrors "before mirroring" echo "$PROGNAME: mirroring repos ..." paa -v mirror ALL-REPOS inspect_mirrors "after mirroring" echo # Freezes inspect_freezes "before freezing" echo "$PROGNAME: freezing repos ..." filter_variant_text "paa -v freeze ALL-REPOS 2>&1" inspect_freezes "after freezing" echo # Directs inspect_indirects "before indirecting" echo "$PROGNAME: indirecting ..." # Some hosts can use some repos, but we're not going to bother trying to work that # out in advance here just to see what repo/freezes are applicable to which hosts. # We just try all and filter away errors. filter_variant_text "paa listfreezes | sed -e '1,2d' -e '\$d' | while read R F JUNK; do paa -v indirect \$R ALL-HOSTS \$F 2>&1 | grep -v 'nothing indirected' || true; done | sort" inspect_indirects "after indirecting" echo # Shares inspect_shares "before sharing" echo "$PROGNAME: sharing ..." # This will complain because (1) it doesn't know if this host where # Apache is running is deb or rpm, (2) because /etc/init.d/apache2 and the # 'service' command don't exist. # # adetestsupport_invert_rc "filter_variant_text \"paa -v share ALL-REPOS ALL-HOSTS 2>&1\"" # # Unfortunately, that creates the shares but just fails at the last moment # which means - were we to try again - it would complain that stuff was # already shared. This means we can't be so clever as to test this function # bit by bit. We can only go for success first time. # # We tell paa it's a debian machine, even if it isn't. paa host $(uname -n) deb debian lenny i386 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 filter_variant_text "paa -v share ALL-REPOS ALL-HOSTS 2>&1" inspect_shares "after sharing" echo ## Accesses #inspect_accesses "before accessing" #echo "$PROGNAME: accessing ..." #paa -v access ALL-REPOS #inspect_accesses "after accessing" #echo # ## Unaccesses #inspect_accesses "before unaccessing" #echo "$PROGNAME: unaccessing ..." #adetestsupport_invert_rc "paa -v unaccess ALL-REPOS" #echo "$PROGNAME: trying again with force ..." #paa -v --force unaccess ALL-REPOS #inspect_accesses "after unaccessing" #echo # Unshares inspect_shares "before unsharing" echo "$PROGNAME: unsharing ..." adetestsupport_invert_rc "paa -v unshare ALL-REPOS ALL-HOSTS" echo "$PROGNAME: trying again with force ..." filter_variant_text "paa -v --force unshare ALL-REPOS ALL-HOSTS 2>&1" inspect_shares "after unsharing" echo # Unindirects inspect_indirects "before unindirecting" echo "$PROGNAME: unindirecting ..." adetestsupport_invert_rc "paa -v unindirect ALL-REPOS ALL-HOSTS" echo "$PROGNAME: trying again with force ..." filter_variant_text "paa -v --force unindirect ALL-REPOS ALL-HOSTS 2>&1" inspect_indirects "after unindirecting" echo # Unfreezes inspect_freezes "before unfreezing" echo "$PROGNAME: unfreezing repos ..." adetestsupport_invert_rc "filter_variant_text \"paa -v unfreeze ALL-REPOS ALL-FREEZES 2>&1\"" echo "$PROGNAME: trying again with force ..." filter_variant_text "paa -v --force unfreeze ALL-REPOS ALL-FREEZES 2>&1" inspect_freezes "after unfreezing" echo # Unmirrors inspect_mirrors "before unmirroring" echo "$PROGNAME: unmirroring repos ..." adetestsupport_invert_rc "paa -v unmirror ALL-REPOS" echo "$PROGNAME: trying again with force ..." paa -v --force unmirror ALL-REPOS inspect_mirrors "after unmirroring" echo # Unrepo inspect_repos "before unrepoing" echo "$PROGNAME: unrepoing ..." adetestsupport_invert_rc "paa -v unrepo ALL-REPOS" echo "$PROGNAME: trying again with force ..." filter_variant_text "paa -v --force unrepo ALL-REPOS 2>&1" inspect_repos "after unrepoing" echo "$PROGNAME: manually cleaning up ..." inspect_repos "after manual cleanup" echo echo "$PROGNAME: done"