From bcfb092e49ec8f77513d6567d3f609ca545118d6 Mon Sep 17 00:00:00 2001 From: Petr Splichal Date: Mon, 29 Mar 2010 11:25:20 +0200 Subject: added options parsing, some cleanup --- Makefile | 63 ------------------- PURPOSE | 2 +- pst | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ runtest.sh | 121 ------------------------------------- 4 files changed, 202 insertions(+), 185 deletions(-) delete mode 100644 Makefile create mode 100755 pst delete mode 100755 runtest.sh diff --git a/Makefile b/Makefile deleted file mode 100644 index 23c1284..0000000 --- a/Makefile +++ /dev/null @@ -1,63 +0,0 @@ -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# Makefile of /distribution/all/Sanity/tps -# Description: Test packages sanity -# Author: Petr Splichal -# -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# 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. -# -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -export TEST=/distribution/all/Sanity/tps -export TESTVERSION=1.0 - -BUILT_FILES= - -FILES=$(METADATA) runtest.sh Makefile PURPOSE - -.PHONY: all install download clean - -run: $(FILES) build - ./runtest.sh - -build: $(BUILT_FILES) - chmod a+x runtest.sh - -clean: - rm -f *~ $(BUILT_FILES) - - -include /usr/share/rhts/lib/rhts-make.include - -$(METADATA): Makefile - @echo "Owner: Petr Splichal " > $(METADATA) - @echo "Name: $(TEST)" >> $(METADATA) - @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) - @echo "Path: $(TEST_DIR)" >> $(METADATA) - @echo "Description: Test packages sanity" >> $(METADATA) - @echo "Type: Sanity" >> $(METADATA) - @echo "TestTime: 30m" >> $(METADATA) - @echo "RunFor: all" >> $(METADATA) - @echo "Requires: yum" >> $(METADATA) - @echo "Priority: Normal" >> $(METADATA) - @echo "License: GPLv2" >> $(METADATA) - @echo "Confidential: no" >> $(METADATA) - @echo "Destructive: no" >> $(METADATA) - - rhts-lint $(METADATA) diff --git a/PURPOSE b/PURPOSE index 2ec4d96..4bba34a 100644 --- a/PURPOSE +++ b/PURPOSE @@ -13,4 +13,4 @@ package tasks such as: verify, delete, install or downgrade as well. For more details see the Test Package Sanity page: -https://fedoraproject.org/wiki/Test_Package_Sanity +https://fedoraproject.org/wiki/QA:Package_Sanity_Test_Plan 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 +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# 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 diff --git a/runtest.sh b/runtest.sh deleted file mode 100755 index 5530e3e..0000000 --- a/runtest.sh +++ /dev/null @@ -1,121 +0,0 @@ -#!/bin/bash -# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# runtest.sh of /distribution/all/Sanity/tps -# Description: Test packages sanity -# Author: Petr Splichal -# -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# 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 rhts environment -. /usr/bin/rhts-environment.sh -. /usr/lib/beakerlib/beakerlib.sh - -PACKAGE="all" - -UpdatesRepo="updates-testing" - -OldPackages="vsftpd-2.0.7-2.fc10" -NewPackages="vsftpd-2.0.7-3.fc10" - -#OldPackages="phonon-4.3.1-6.fc10.1.i386 phonon-backend-gstreamer-4.3.1-6.fc10.1.i386" -#NewPackages="phonon-4.3.1-102.fc10.i386 phonon-backend-gstreamer-4.3.1-102.fc10.i386" - - -# Make sure all the packages from the list are not installed on the system -CheckMissingPackages() { - for package in $@; do - rlRun "rpm -q --quiet $package" 1 "Check missing: $package" - done -} - -# Make sure all the packages from the list are installed on the system -CheckInstalledPackages() { - for package in $@; do - rlRun "rpm -q --quiet $package" 0 "Check installed: $package" - done -} - -rlJournalStart - # setup - rlPhaseStartSetup - rlAssertRpm "yum" - rlRun "set -o pipefail" - rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory" - rlRun "pushd $TmpDir" - CheckInstalledPackages $OldPackages - rlPhaseEnd - - # update - rlPhaseStartTest "Update" - rlRun "yum --enablerepo=$UpdatesRepo 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=$UpdatesRepo 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 -- cgit