summaryrefslogtreecommitdiffstats
path: root/pst
diff options
context:
space:
mode:
Diffstat (limited to 'pst')
-rwxr-xr-xpst201
1 files changed, 201 insertions, 0 deletions
diff --git a/pst b/pst
new file mode 100755
index 0000000..f151d9f
--- /dev/null
+++ b/pst
@@ -0,0 +1,201 @@
+#!/bin/bash
+# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Description: Package Sanity test
+# Author: Petr Splichal <psplicha@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Copyright (c) 2009 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing
+# to use, modify, copy, or redistribute it subject to the terms
+# and conditions of the GNU General Public License version 2.
+#
+# This program is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+# Include BeakerLib environment
+. /usr/lib/beakerlib/beakerlib.sh
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# BeakerLib Stuff
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+TEST="PackageSanityTest"
+PACKAGE="AnyPackage"
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# Help Message
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+HelpMessage() {
+ cat <<-EOF
+
+ Usage:
+ pst --rpm /path/to/package [/path/to/package...]
+ pst --yum package-nvr [package-nvr...]
+
+ Options:
+ -r --rpm test local update (provide packages with full path)
+ -y --yum update from the updates-testing repo (nvrs only)
+ -d --dry do nothing, just print what would be done
+ -h --help display this help message
+
+EOF
+}
+
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# Parse Options
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ParseOptions() {
+ local getopt=`getopt -q -o rydh -l rpm,yum,dry,help -- "$@"`
+ eval set -- "$getopt"
+
+ OptionDry="false"
+ OptionRpm="false"
+ OptionYum="false"
+
+ while true ; do
+ case "$1" in
+ -h|--help)
+ HelpMessage
+ exit 0;;
+ -d|--dry)
+ OptionDry="true"
+ shift;;
+ -r|--rpm)
+ OptionRpm="true"
+ shift;;
+ -y|--yum)
+ OptionYum="true"
+ shift;;
+ --)
+ shift;
+ break;;
+ *)
+ shift;;
+ esac
+ done
+
+ OptionPackages="$@"
+
+ # check that the mode is specified
+ if ! $OptionRpm && ! $OptionYum; then
+ echo "Need to choose either --rpm or --yum mode"
+ exit 1
+ fi
+
+ # we need at least one package
+ if [ -z "$OptionPackages" ]; then
+ echo "No packages specified"
+ exit 2
+ fi
+}
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# Checking package presence
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+# Make sure all the packages from the list are not installed on the system
+CheckMissingPackages() {
+ for package in $@; do
+ rlAssertNotRpm $package
+ done
+}
+
+# Make sure all the packages from the list are installed on the system
+CheckInstalledPackages() {
+ for package in $@; do
+ rlAssertRpm $package
+ done
+}
+
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# Main
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+# Parse command line options
+ParseOptions "$@"
+
+exit 0
+
+rlJournalStart
+ # setup
+ rlPhaseStartSetup
+ rlAssertRpm "yum"
+ rlRun "set -o pipefail"
+ rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory"
+ rlRun "pushd $TmpDir"
+ rlAssertExists "$OldPackages"
+ rlAssertExists "$NewPackages"
+ CheckInstalledPackages $OldPackages
+ rlPhaseEnd
+
+ # update
+ rlPhaseStartTest "Update"
+ rlRun "yum --enablerepo=updates-testing update -y $NewPackages" \
+ 0 "Updating to the new packages"
+ CheckInstalledPackages $NewPackages
+ CheckMissingPackages $OldPackages
+ rlPhaseEnd
+
+ # verify
+ rlPhaseStartTest "Verify"
+ for package in $NewPackages; do
+ rlRun "rpm -V $package" 0 "Verifying package $package"
+ done
+ rlPhaseEnd
+
+ # delete
+ rlPhaseStartTest "Delete"
+ if rlRun "rpm -e $NewPackages 2>&1 | tee output" \
+ 0,2 "Removing the new packages"; then
+ InstallTest=true
+ CheckMissingPackages $OldPackages $NewPackages
+ else
+ InstallTest=false
+ rlRun "grep -q 'Failed dependencies' output" \
+ 0 "Removing packages refused because of dependencies"
+ fi
+ rlPhaseEnd
+
+ # install (run only if delete was successful)
+ if $InstallTest; then
+ rlPhaseStartTest "Install"
+ rlRun "yum --enablerepo=updates-testing install -y $NewPackages" \
+ 0 "Installing the new packages"
+ CheckInstalledPackages $NewPackages
+ CheckMissingPackages $OldPackages
+ rlPhaseEnd
+ fi
+
+ # downgrade
+ rlPhaseStartTest "Downgrade"
+ rlRun "yum downgrade -y $OldPackages" \
+ 0 "Downgrading to the old packages"
+ CheckInstalledPackages $OldPackages
+ CheckMissingPackages $NewPackages
+ rlPhaseEnd
+
+ # cleanup
+ rlPhaseStartCleanup
+ CheckInstalledPackages $OldPackages
+ rlRun "popd"
+ rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
+ rlPhaseEnd
+rlJournalPrintText
+rlJournalEnd