client/debian/apt-spacewalk/test/Makefile | 11 +
client/debian/apt-spacewalk/test/PURPOSE | 21 ++
client/debian/apt-spacewalk/test/equivs-template | 7
client/debian/apt-spacewalk/test/library.sh | 26 +++
client/debian/apt-spacewalk/test/runtest.sh | 163 +++++++++++++++++++++++
client/debian/apt-spacewalk/test/settings.sh | 7
client/debian/apt-spacewalk/test/sw_deb.py | 101 ++++++++++++++
7 files changed, 336 insertions(+)
New commits:
commit 231e5865d93255a7db2ec89b2ad3bb32345cb056
Author: Simon Lukasik <slukasik(a)redhat.com>
Date: Thu Apr 28 23:28:11 2011 +0200
The Apt-Spacewalk sanity test
diff --git a/client/debian/apt-spacewalk/test/Makefile
b/client/debian/apt-spacewalk/test/Makefile
new file mode 100644
index 0000000..fb773e2
--- /dev/null
+++ b/client/debian/apt-spacewalk/test/Makefile
@@ -0,0 +1,11 @@
+
+.PHONY: run build
+
+SCRIPTS=runtest.sh library.sh settings.sh sw_deb.py
+FILES=$(SCRIPTS) equivs-template
+
+run: $(FILES) build
+ ./runtest.sh
+
+build:
+ chmod a+x $(SCRIPTS)
diff --git a/client/debian/apt-spacewalk/test/PURPOSE
b/client/debian/apt-spacewalk/test/PURPOSE
new file mode 100644
index 0000000..5a72dd0
--- /dev/null
+++ b/client/debian/apt-spacewalk/test/PURPOSE
@@ -0,0 +1,21 @@
+Name: apt-spacewalk/sanity
+Summary: Spacewalk Debian Client -- Sanity Test
+Author: Simon Lukasik
+License: GNU GPLv2
+Description:
+
+The test automates basic package management scenario for Debian clients.
+
+ * Creation of debian channels
+ * Creation of an activation key
+ * Registration with the activation key
+ * rhnpush of Debian packages
+ * rhn-profile-sync
+ * Download of the repository metadata from Spacewalk
+ * Installation of packages from Spacewalk
+ * Scheduling of remote action to install/update packages
+ * rhn_check
+ * Update against Spacewalk
+ * System deletion
+ * Child and base channels are used
+ * No-arch and arch-dependent packages are used
diff --git a/client/debian/apt-spacewalk/test/equivs-template
b/client/debian/apt-spacewalk/test/equivs-template
new file mode 100644
index 0000000..637feb5
--- /dev/null
+++ b/client/debian/apt-spacewalk/test/equivs-template
@@ -0,0 +1,7 @@
+Section: misc
+Priority: optional
+Standards-Version: 3.6.2
+Package: %name%
+Version: %version%
+Description: Dummy testing package
+Architecture: %arch%
diff --git a/client/debian/apt-spacewalk/test/library.sh
b/client/debian/apt-spacewalk/test/library.sh
new file mode 100755
index 0000000..8ae36df
--- /dev/null
+++ b/client/debian/apt-spacewalk/test/library.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# Workaround the bug 700525
+touch /etc/redhat-release
+
+. /usr/share/beakerlib/beakerlib.sh
+
+function rlAssertDpkg(){
+ local package=$1;
+ dpkg -l $package > /dev/null
+ __INTERNAL_ConditionalAssert "Checking for the presence of $package deb"
$?;
+}
+
+function rlGetArch(){
+ local arch=`uname -i`
+ # Overrife architecture name to be compliant with debian packages
+ case ${arch} in
+ i486|i566|i686)
+ arch=i386
+ ;;
+ x86_64)
+ arch=amd64
+ ;;
+ esac
+ echo $arch
+}
diff --git a/client/debian/apt-spacewalk/test/runtest.sh
b/client/debian/apt-spacewalk/test/runtest.sh
new file mode 100755
index 0000000..d93502c
--- /dev/null
+++ b/client/debian/apt-spacewalk/test/runtest.sh
@@ -0,0 +1,163 @@
+#!/bin/bash
+
+set -e
+set -o pipefail
+
+. library.sh
+. settings.sh
+
+
+rlJournalStart
+ rlPhaseStartSetup
+ for pkg in ${required_packages}; do
+ rlAssertDpkg ${pkg} || rlDie "Install ${pkg} first"
+ done
+
+ seed=$(date +%N | tr [:print:] a-z | fold -w5 | head -n1)
+ rlFileBackup /etc/sysconfig/rhn/
+ rlPhaseEnd
+
+
+
+ rlPhaseStartSetup 'Build packages'
+ old_pwd=`pwd`
+ build_dir="${old_pwd}/build/"
+ template="${old_pwd}/equivs-template"
+ rlRun "rm -rf ${build_dir}"
+
+ for arch in all `rlGetArch`; do
+ rlRun "mkdir -p ${build_dir}/${arch}"
+ cd ${build_dir}/${arch}
+ for i in `seq ${package_count}`; do
+ name="dum-${arch}-${i}-${seed}"
+ cp ${template} ${name}
+ sed -i s/%name%/${name}/g ${name}
+ sed -i s/%arch%/${arch}/g ${name}
+ sed -i s/%version%/1.1/g ${name}
+ rlRun "equivs-build ${name} &> /dev/null"
+ sed -i s/1.1/2.2/g ${name}
+ rlRun "equivs-build ${name} &> /dev/null"
+ rm -rf ${name}
+ package_list="${package_list} $name"
+ done
+ done
+ cd ${old_pwd}
+ rlPhaseEnd
+
+
+
+ rlPhaseStartSetup 'Create channels'
+ channel_name="debian_${seed}"
+ child_channel_name="child_${seed}"
+ rlRun "./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} \
+ create_channel ${channel_name} `rlGetArch`"
+ rlRun "./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} \
+ create_channel ${child_channel_name} `rlGetArch` ${channel_name}"
+ rlRun "rhnpush --server ${SW_SERVER} -u ${SW_USER} -p ${SW_PASS} \
+ -vvv -c ${channel_name} -d ${build_dir}/all"
+ rlRun "rhnpush --server ${SW_SERVER} -u ${SW_USER} -p ${SW_PASS} \
+ -vvv -c ${child_channel_name} -d ${build_dir}/`rlGetArch`"
+ ak=`./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} \
+ create_activationkey ${channel_name} ${child_channel_name}| head -n1`
+ rlPhaseEnd
+
+
+
+ rlPhaseStartSetup 'Register'
+ rlRun "wget -q -O /etc/sysconfig/rhn/RHN-ORG-TRUSTED-SSL-CERT \
+ https://${SW_SERVER}/pub/RHN-ORG-TRUSTED-SSL-CERT
--no-check-certificate"
+ rlRun "rhnreg_ks --sslCACert=/etc/sysconfig/rhn/RHN-ORG-TRUSTED-SSL-CERT -v
\
+ --serverUrl=https://${SW_SERVER}/XMLRPC --activationkey=${ak} --force"
+ rlPhaseEnd
+
+
+
+ rlPhaseStartTest 'rhn-profile-sync'
+ rlRun 'rhn-profile-sync -v'
+ rlPhaseEnd
+
+
+
+ rlPhaseStartTest 'Taskomatic'
+ rlRun "apt-get clean"
+ rlRun "apt-get update" 0,100
+ # Workaround for those who don't have Apt patched
+ rlRun "apt-get update" 0,100
+
+ rlRun "sleep 1m" 0 "Waiting for taskomatic to regenerate
metadata"
+ rlPhaseEnd
+
+
+
+ rlPhaseStartTest "apt-get update"
+ rlRun "apt-get update"
+ sources_list=/etc/apt/sources.list.d/spacewalk.list
+ rlAssertExists ${sources_list}
+ rlAssertGrep "deb spacewalk://${SW_SERVER} channels: main
${child_channel_name}" ${sources_list}
+ rlPhaseEnd
+
+
+
+ rlPhaseStartTest "Install packages"
+ for pkg in ${package_list}; do
+ rlRun "apt-get install ${pkg}=1.1 -y --force-yes"
+ done
+
+ tmp=`mktemp`
+ rlRun "./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} system_package_list \
+ ${channel_name} ${child_channel_name} > ${tmp}"
+ for pkg in ${package_list}; do
+ rlAssertGrep ${pkg}-1.1 ${tmp}
+ done
+ rm -rf $tmp
+ rlPhaseEnd
+
+
+
+ rlPhaseStartTest "Schedule actions"
+ pkg1_id=`./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} channel_package_list
${channel_name} | head -n1`
+ pkg2_id=`./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} channel_package_list
${child_channel_name} | head -n1`
+ rlRun "./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} package_install
${pkg1_id} ${pkg2_id}"
+ rlPhaseEnd
+
+
+
+ rlPhaseStartTest "Pick-up actions"
+ rlRun "rhn_check -vvv"
+
+ rlRun "./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} system_package_list \
+ ${channel_name} ${child_channel_name} | grep dum | grep ${seed} | grep
2.2"
+ rlPhaseEnd
+
+
+
+ rlPhaseStartTest "Update"
+ rlRun "apt-get install ${package_list} -y --force-yes"
+
+ tmp=`mktemp`
+ rlRun "./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} system_package_list \
+ ${channel_name} ${child_channel_name} > ${tmp}"
+ for pkg in ${package_list}; do
+ rlAssertGrep ${pkg}-2.2 ${tmp}
+ done
+ rm -rf $tmp
+ rlPhaseEnd
+
+
+
+ rlPhaseStartCleanup
+ for pkg in ${package_list}; do
+ dpkg -l ${pkg} &> /dev/null \
+ && rlRun "apt-get remove ${pkg} -y --force-yes
&>/dev/null"
+ done
+
+ rlRun "rm -rf ${build_dir}"
+ rlRun "./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} remove_activationkey
${ak}"
+ rlRun "./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} remove_channel
${child_channel_name}"
+ rlRun "./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} remove_channel
${channel_name}"
+ rlRun "./sw_deb.py ${SW_SERVER} ${SW_USER} ${SW_PASS} unregister"
+ rlFileRestore
+ rlPhaseEnd
+
+rlJournalEnd
+rlJournalPrintText
diff --git a/client/debian/apt-spacewalk/test/settings.sh
b/client/debian/apt-spacewalk/test/settings.sh
new file mode 100755
index 0000000..0deed98
--- /dev/null
+++ b/client/debian/apt-spacewalk/test/settings.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+export required_packages="python-rhn-client-tools python-rhnlib apt-spacewalk
rhnpush equivs"
+export package_count="3"
+export
SW_SERVER=spacewalk.example.com
+export SW_USER=admin
+export SW_PASS=admin
diff --git a/client/debian/apt-spacewalk/test/sw_deb.py
b/client/debian/apt-spacewalk/test/sw_deb.py
new file mode 100755
index 0000000..321644a
--- /dev/null
+++ b/client/debian/apt-spacewalk/test/sw_deb.py
@@ -0,0 +1,101 @@
+#!/usr/bin/python
+#
+# Summary: Support function for Debian Spacewalk Clients Tests
+# License: GNU GPLv2
+#
+
+import sys
+import re
+import xmlrpclib
+import xml.dom.minidom
+
+sys.path.append("/usr/share/rhn/")
+import up2date_client.config as up2dateConfig
+
+class sw_deb:
+ def __init__(self, fqdn, user, passwd):
+ self.uri = 'https://' + fqdn + '/rpc/api'
+ self.client = xmlrpclib.Server(self.uri, verbose=0)
+ self.key = self.client.auth.login(user, passwd)
+
+ def create_channel(self, params):
+ name = params[0]
+ arch = 'channel-' + params[1] + '-deb'
+ try:
+ parent = params[2]
+ except IndexError:
+ parent = ''
+ return self.client.channel.software.create(self.key, name, name, name, arch,
parent)
+
+ def remove_channel(self, params):
+ return self.client.channel.software.delete(self.key, params[0]) == 1
+
+ def create_activationkey(self, params):
+ channel = params[0]
+ ak = self.client.activationkey.create(self.key, channel, '', channel, [],
False)
+ print ak
+ if params[1:]:
+ return self.client.activationkey.addChildChannels(self.key, ak, params[1:])
+ return ak.endswith(channel)
+
+ def remove_activationkey(self, params):
+ ak = params[0]
+ return self.client.activationkey.delete(self.key, ak) == 1
+
+ def channel_package_list(self, params):
+ channel = params[0]
+ for pkg in self.client.channel.software.listAllPackages(self.key, channel):
+ print pkg['id']
+ return True
+
+ def system_package_list(self, params=None):
+ systemid = self.__get_systemid()
+ for pkg in self.client.system.listPackages(self.key, systemid):
+ print '%s-%s' % (pkg['name'], pkg['version'])
+ return True
+
+ def package_install(self, params):
+ systemid = self.__get_systemid()
+ for i in range(len(params)):
+ params[i] = int(params[i])
+ time =
self.client.system.searchByName(self.key,'\w')[0]['last_checkin']
+ return self.client.system.schedulePackageInstall(self.key, systemid, params,
time) == 1
+
+ def unregister(self, params=None):
+ systemid = self.__get_systemid()
+ return self.client.system.deleteSystems(self.key, (systemid,)) == 1
+
+ def dispatch(self, func, param):
+ method = getattr(self, func)
+ result = method(param)
+ print "Running %s ..." % func,
+ if result:
+ print 'Pass'
+ else:
+ print 'Fail'
+ return not result
+
+ def __get_systemid(self):
+ cfg = up2dateConfig.initUp2dateConfig()
+ doc = xml.dom.minidom.parse(cfg['systemIdPath'])
+ for membernode in doc.getElementsByTagName("member"):
+ found = False
+ for node in membernode.childNodes:
+ if node.nodeName == "name":
+ data = node.firstChild.data
+ if data == "system_id": found = True
+ if node.nodeName == "value" and found:
+ system_id_raw = (node.firstChild.firstChild).data
+ system_id = re.match('ID-([0-9]*).*',
system_id_raw).group(1)
+ return int(system_id)
+
+
+if __name__ == '__main__':
+ fqdn = sys.argv[1]
+ user = sys.argv[2]
+ passwd = sys.argv[3]
+ func = sys.argv[4]
+ params = sys.argv[5:]
+
+ s = sw_deb(fqdn, user, passwd)
+ sys.exit(s.dispatch(func, params))