summaryrefslogtreecommitdiffstats
path: root/src/yum/test/yum_package.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/yum/test/yum_package.sh')
-rwxr-xr-xsrc/yum/test/yum_package.sh236
1 files changed, 236 insertions, 0 deletions
diff --git a/src/yum/test/yum_package.sh b/src/yum/test/yum_package.sh
new file mode 100755
index 0000000..c13cbe4
--- /dev/null
+++ b/src/yum/test/yum_package.sh
@@ -0,0 +1,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
+