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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
#!/bin/bash
dir=`dirname $0`
[ -z "$dir" ] && dir=.
CLASS_NAME="LMI_YumPackage"
. $dir/test_common.sh
declare -A pkg1 pkg2
if [[ "$fedora_release" = 16 ]]; then
pkg1=( \
[name]=python-xlib-doc
[epoch]=0 \
[ver]=0.15 \
[rel]=0.6.rc1.fc16 \
[arch]=noarch \
[updatable]=0 \
)
pkg2=( \
[name]=ruby-ri \
[epoch]=0 \
[ver]=1.8.7.352 \
[rel]=1.fc16 \
[arch]=x86_64 \
[updatable]=1 \
[up_epoch]=0 \
[up_ver]=1.8.7.358 \
[up_rel]=2.fc16 \
)
elif [[ "$fedora_release" = 17 ]]; then
pkg1=( \
[name]=python-xlib-doc
[epoch]=0 \
[ver]=0.15 \
[rel]=0.6.rc1.fc17 \
[arch]=noarch \
[updatable]=0 \
)
pkg2=( \
[name]=slv2 \
[epoch]=0 \
[ver]=0.6.6 \
[rel]=8.fc17 \
[arch]=x86_64 \
[updatable]=1 \
[up_epoch]=0 \
[up_ver]=0.6.6 \
[up_rel]=9.fc17 \
)
elif [[ -z "$fedora_release" ]]; then
echo "failed to get Fedora release number!" 2>&1
exit 1
else
echo "no packages defined for Fedora release $fedora_release" 2>&1
exit 1
fi
keys=(name epoch ver rel arch updatable up_epoch up_ver up_rel)
make_inst_keys() {
# accepts arguments: name, epoch, ver, rel, arch
# in this order
local path='Name="%s",SoftwareElementID="%s",SoftwareElementState="%s",'
path+='TargetOperatingSystem="%s",Version="%s"'
printf $path $1 `make_nevra "$@"` 2 36 $3
}
test_install() {
local name epoch ver rel arch updatable up_epoch up_ver up_rel;
read name epoch ver rel arch updatable \
up_epoch up_ver up_rel <<< "$@"
echo "********************************************************************"
echo " * TEST INSTALL"
nevra_arr=($name $epoch $ver $rel $arch)
nevra=`make_nevra ${nevra_arr[@]}`
echo -n "$nevra is "
[ "$updatable" == 0 ] && echo -n "not "
echo -n "updatable and "
is_installed $name || echo -n "not "
echo "installed"
if is_installed $name; then
echo "removing package \"${nevra}\" with rpm"
remove $name
fi
local keys=`make_inst_keys ${nevra_arr[@]}`
local url="$url/$op.${keys}"
echo "trying to get instance"
if ! wbemerr gi "$url" |& \
grep -q '\<SoftwareElementState="\?1"\?'; then
echo "wrong SoftwareElementState"
exit 1
fi
echo "installing $CLASS_NAME: $url"
if ! wbemerr cm "$url" Install |& \
grep -q '\<Install:\s*1\s\+Installed'; then
echo "wrong return code"
exit 1
fi
if is_installed $name; then
echo "successful installation"
else
echo "package not installed"
exit 1
fi
echo "checking get instance"
if ! wbemerr gi "$url" |& \
grep -q '\<SoftwareElementState="\?2"\?'; then
echo "wrong SoftwareElementState"
exit 1
fi
echo "testing installation of already installed package"
if ! wbemcli cm "${url}" Install |& \
grep -q '\<Install:\s*0\s\+Installed'; then
echo "wrong return code"
exit 1
fi
}
test_update() {
read name epoch ver rel arch updatable \
up_epoch up_ver up_rel <<< "$@"
echo "********************************************************************"
echo " * TEST UPDATE"
if [ "$updatable" == 0 ]; then
echo "package not updatable"
exit 1
fi
nevra_arr=($name $epoch $ver $rel $arch)
nevra=`make_nevra ${nevra_arr[@]}`
echo -n "$nevra is "
[ "$updatable" == 0 ] && echo -n "not "
echo -n "updatable and "
is_installed $name || echo -n "not "
echo "installed"
if is_installed $name; then
echo "removing package \"${name}\" with rpm"
remove $name
fi
local keys=`make_inst_keys ${nevra_arr[@]}`
local package_url="$url/$op.$keys"
echo "intalling older package with $CLASS_NAME: $package_url"
wbemerr cm "$package_url" Install
if is_installed $name; then
echo "successful installation"
else
echo "package not installed"
exit 1
fi
echo "updating with LMI_YumInstalledPackage.Update()"
local installed_keys="Software=$op.$keys,System=$computer_system_op"
local installed_url="$url/`make_op LMI_YumInstalledPackage $installed_keys`"
if ! wbemerr cm "$installed_url" "Update" | \
grep -q '\<Update:\s*1\s\+Installed'; then
echo "wrong return code"
exit 1
fi
if is_installed_nevra $name $up_epoch $up_ver $up_rel $arch; then
echo "successful update"
else
echo "update failed"
exit 1
fi
keys=`make_inst_keys $name $up_epoch $up_ver $up_rel $arch`
installed_keys="Software=$op.$keys,System=$computer_system_op"
local installed_url2="$url/`make_op LMI_YumInstalledPackage $installed_keys`"
echo "trying to update once more to: $installed_url2"
if ! wbemerr cm "$installed_url2" "Update" | \
grep -q '\<Update:\s*0\s\+Installed'; then
echo "wrong return code"
exit 1
fi
echo "removing updated package"
wbemerr di "$installed_url2"
if is_installed $name; then
echo "failed to remove ${name}"
exit 1
else
echo "success"
fi
echo "installing older package"
install_pkg "$@" || exit 1
echo "trying to update to not existing version-release"
wbemerr cm "$installed_url" "Update.Version=\"not-existing-version\"" |&
grep -q CIM_ERR_NOT_FOUND && echo "ok" || echo "failed"
echo "trying to update to the same version-release"
wbemerr cm "$installed_url" \
"Update.Version=\"${ver}\",Release=\"${rel}\"" | \
grep -q '\<Update:\s*0\s\+Installed' || \
echo "wrong return code"
if is_installed_nevra $name $epoch $ver $rel $arch; then
echo "success"
else
echo "failed"
exit 1
fi
echo "trying to update to the specific version"
wbemerr cm "$installed_url" \
"Update.Version=\"${up_ver}\",Release=\"${up_rel}\"" |
grep -q '\<Update:\s*1\s\+Installed' || \
echo "wrong return code"
if is_installed_nevra $name $up_epoch $up_ver $up_rel $arch; then
echo "success"
else
echo "failed"
exit 1
fi
}
test_remove() {
read name epoch ver rel arch updatable \
up_epoch up_ver up_rel <<< "$@"
echo "********************************************************************"
echo " * TEST REMOVE"
nevra_arr=($name $epoch $ver $rel $arch)
nevra=`make_nevra ${nevra_arr[@]}`
if ! is_installed $name; then
echo "installing package \"${nevra}\" with yum"
install_pkg "$@" || exit 1
fi
local keys=`make_inst_keys ${nevra_arr[@]}`
local installed_keys="Software=$op.$keys,System=$computer_system_op"
local installed_url="$url/`make_op LMI_YumInstalledPackage $installed_keys`"
wbemerr di "$installed_url"
if is_installed $name; then
echo "failed to remove ${name}"
exit 1
else
echo "success"
fi
local url="$url/$op.$keys"
if ! wbemerr gi "$url" |& \
grep -q '\<SoftwareElementState="\?1"\?'; then
echo "wrong SoftwareElementState"
exit 1
fi
}
for p in 1 2
do
declare -a args
for ((i=0; i < ${#keys[@]}; i++)) do
key=${keys[$i]}
eval "args[\$i]=\${pkg${p}[\$key]}"
done
test_install "${args[@]}"
test_remove "${args[@]}"
eval "updatable=\${pkg${p}[updatable]}"
[ "$updatable" == 1 ] && test_update "${args[@]}"
done
|