1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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
|