summaryrefslogtreecommitdiffstats
path: root/src/yum/test/yum_package.sh
blob: c13cbe4fdef80a7d0b674b9c339c3e5634592d8f (plain)
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
#!/bin/bash

dir=`dirname $0`
[ -z "$dir" ] && dir=.

CLASS_NAME="LMI_YumPackage"

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="$op.${keys}"
    echo "creating instance of $CLASS_NAME: $url"
    wbemerr ci "$url" "${keys},Release=\"$rel\""
    
    if is_installed $name; then
        echo "successful installation"
    else
        echo "package not installed"
        exit 1
    fi

    echo "testing installation of already installed package"
    wbemcli ci "${url}" "${keys},Release=\"rel\"" |& \
        grep -q CIM_ERR_ALREADY_EXISTS &&
        echo "success" || echo "failed"
}

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 url="$op.${keys}"
    echo "intalling older package with $CLASS_NAME: $url"
    wbemerr ci "$url" "${keys},Release=\"$rel\""
    
    if is_installed $name; then
        echo "successful installation"
    else
        echo "package not installed"
        exit 1
    fi

    echo "updating with ${CLASS_NAME}.Update()"
    wbemerr cm "$url" "Update" | 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 "successful update"
    else
        echo "update failed"
        exit 1
    fi

    keys=`make_inst_keys $name $up_epoch $up_ver $up_rel $arch`
    url2="${op}.${keys}"
    echo "trying to update once more to: $url2"
    wbemerr cm "$url2" "Update" | grep -q '\<Update:\s*0\s\+Installed' || \
        echo "wrong return code"

    echo "removing updated package"
    wbemerr di "$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 "$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 "$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 "$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 url="$op.${keys}"
    wbemerr di "$url"
    if is_installed $name; then
        echo "failed to remove ${name}"
    else
        echo "success"
    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