Hello community, here is the log from the commit of package crmsh for openSUSE:Factory checked in at 2014-02-11 11:03:14 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/crmsh (Old) and /work/SRC/openSUSE:Factory/.crmsh.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "crmsh" Changes: -------- --- /work/SRC/openSUSE:Factory/crmsh/crmsh.changes 2014-02-03 16:12:05.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.crmsh.new/crmsh.changes 2014-02-11 11:03:15.000000000 +0100 @@ -1,0 +2,18 @@ +Mon Feb 10 08:16:12 UTC 2014 - [email protected] + +- tests: run CIB tests with regression test suite +- upstream cs: 49572fb0f7bb + +------------------------------------------------------------------- +Thu Feb 6 14:34:20 UTC 2014 - [email protected] + +- high: parse: Fix sequential=true for resource sets (bnc#862334) +- medium: corosync: Allow tabs in corosync.conf (bnc#862577) +- low: cibconfig: fencing_topology warning with stonith templates (savannah#41414) +- spec: update description of crmsh package +- tests: split regression tests into separate -test package +- tests: use python-nose as unit test runner +- tests: improved unit test coverage +- upstream cs: cc52dc69ceb1 + +------------------------------------------------------------------- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ crmsh.spec ++++++ --- /var/tmp/diff_new_pack.5KHNen/_old 2014-02-11 11:03:15.000000000 +0100 +++ /var/tmp/diff_new_pack.5KHNen/_new 2014-02-11 11:03:15.000000000 +0100 @@ -38,7 +38,7 @@ %{!?py_sitedir: %{expand: %%global py_sitedir %%{expand:%%%%{py_libdir}/site-packages}}} Name: crmsh -Summary: Pacemaker command line interface +Summary: High Availability cluster command-line interface License: GPL-2.0+ Group: %{pkg_group} Version: 2.0 @@ -86,20 +86,32 @@ BuildRequires: libxslt-tools %endif +%description +The crm shell is a command-line interface for High-Availability +cluster management on GNU/Linux systems. It simplifies the +configuration, management and troubleshooting of Pacemaker-based +clusters, by providing a powerful and intuitive set of features. + +Authors: Dejan Muhamedagic <[email protected]> and many others + +%package test +Summary: Test package for crmsh +Group: %{pkg_group} +Requires: crmsh %if 0%{?with_regression_tests} BuildRequires: corosync BuildRequires: procps BuildRequires: python-dateutil +BuildRequires: python-nose BuildRequires: vim Requires: pacemaker Requires: pssh %endif - -%description -crm shell, a Pacemaker command line interface. - -Pacemaker is an advanced, scalable High-Availability cluster resource -manager for Heartbeat and/or Corosync. +%description test +The crm shell is a command-line interface for High-Availability +cluster management on GNU/Linux systems. It simplifies the +configuration, management and troubleshooting of Pacemaker-based +clusters, by providing a powerful and intuitive set of features. Authors: Dejan Muhamedagic <[email protected]> and many others @@ -140,8 +152,9 @@ make %{_smp_mflags} docdir=%{crmsh_docdir} %if 0%{?with_regression_tests} - if ! test/unittests/testrunner.py ; then - echo "Shell unit tests failed." + ./test/unit-tests.sh --quiet + if [ ! $? ]; then + echo "Unit tests failed." exit 1 fi %endif @@ -159,14 +172,19 @@ # Run regression tests after installing the package # NB: this is called twice by OBS, that's why we touch the file %if 0%{?with_regression_tests} -%post +%post test if [ ! -e /tmp/.crmsh_regression_tests_ran ]; then touch /tmp/.crmsh_regression_tests_ran if ! %{_datadir}/%{name}/tests/regression.sh ; then - echo "Shell tests failed." + echo "Regression tests failed." cat crmtestout/regression.out exit 1 fi + cd %{_datadir}/%{name}/tests + if ! ./cib-tests.sh ; then + echo "CIB tests failed." + exit 1 + fi fi %endif @@ -178,6 +196,7 @@ %{py_sitedir}/crmsh %{_datadir}/%{name} +%exclude %{_datadir}/%{name}/tests %doc %{_mandir}/man8/* %{crmsh_docdir}/COPYING @@ -195,4 +214,8 @@ %dir %attr (770, %{uname}, %{gname}) %{_var}/cache/crm %config %{_sysconfdir}/bash_completion.d/crm.sh +%files test +%defattr(-,root,root) +%{_datadir}/%{name}/tests + %changelog ++++++ crmsh.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/.hg_archival.txt new/crmsh/.hg_archival.txt --- old/crmsh/.hg_archival.txt 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/.hg_archival.txt 2014-02-10 08:37:44.000000000 +0100 @@ -1,5 +1,5 @@ repo: 13c3bd69e935090cd25213c474cafc3f01b5910b -node: 170f0ff108dfe5d186092d023f389bf813490bfe +node: 49572fb0f7bbf6fce9cf3df967799c2132f109bb branch: default latesttag: 1.2.6-rc1 -latesttagdistance: 400 +latesttagdistance: 415 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/.travis.yml new/crmsh/.travis.yml --- old/crmsh/.travis.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/.travis.yml 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,9 @@ +--- +language: python +python: + - "2.6" + - "2.7" +install: + - "pip install -r requirements.txt" +script: ./test/unit-tests.sh --with-coverage + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/configure.ac new/crmsh/configure.ac --- old/crmsh/configure.ac 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/configure.ac 2014-02-10 08:37:44.000000000 +0100 @@ -260,6 +260,7 @@ scripts/remove/Makefile \ test/Makefile \ test/testcases/Makefile \ +test/cibtests/Makefile \ modules/Makefile \ hb_report/Makefile \ hb_report/hb_report \ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/crmsh.spec new/crmsh/crmsh.spec --- old/crmsh/crmsh.spec 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/crmsh.spec 2014-02-10 08:37:44.000000000 +0100 @@ -38,7 +38,7 @@ %{!?py_sitedir: %{expand: %%global py_sitedir %%{expand:%%%%{py_libdir}/site-packages}}} Name: crmsh -Summary: Pacemaker command line interface +Summary: High Availability cluster command-line interface License: GPL-2.0+ Group: %{pkg_group} Version: 2.0 @@ -86,20 +86,32 @@ BuildRequires: libxslt-tools %endif +%description +The crm shell is a command-line interface for High-Availability +cluster management on GNU/Linux systems. It simplifies the +configuration, management and troubleshooting of Pacemaker-based +clusters, by providing a powerful and intuitive set of features. + +Authors: Dejan Muhamedagic <[email protected]> and many others + +%package test +Summary: Test package for crmsh +Group: %{pkg_group} +Requires: crmsh %if 0%{?with_regression_tests} BuildRequires: corosync BuildRequires: procps BuildRequires: python-dateutil +BuildRequires: python-nose BuildRequires: vim Requires: pacemaker Requires: pssh %endif - -%description -crm shell, a Pacemaker command line interface. - -Pacemaker is an advanced, scalable High-Availability cluster resource -manager for Heartbeat and/or Corosync. +%description test +The crm shell is a command-line interface for High-Availability +cluster management on GNU/Linux systems. It simplifies the +configuration, management and troubleshooting of Pacemaker-based +clusters, by providing a powerful and intuitive set of features. Authors: Dejan Muhamedagic <[email protected]> and many others @@ -140,8 +152,9 @@ make %{_smp_mflags} docdir=%{crmsh_docdir} %if 0%{?with_regression_tests} - if ! test/unittests/testrunner.py ; then - echo "Shell unit tests failed." + ./test/unit-tests.sh --quiet + if [ ! $? ]; then + echo "Unit tests failed." exit 1 fi %endif @@ -159,14 +172,19 @@ # Run regression tests after installing the package # NB: this is called twice by OBS, that's why we touch the file %if 0%{?with_regression_tests} -%post +%post test if [ ! -e /tmp/.crmsh_regression_tests_ran ]; then touch /tmp/.crmsh_regression_tests_ran if ! %{_datadir}/%{name}/tests/regression.sh ; then - echo "Shell tests failed." + echo "Regression tests failed." cat crmtestout/regression.out exit 1 fi + cd %{_datadir}/%{name}/tests + if ! ./cib-tests.sh ; then + echo "CIB tests failed." + exit 1 + fi fi %endif @@ -178,6 +196,7 @@ %{py_sitedir}/crmsh %{_datadir}/%{name} +%exclude %{_datadir}/%{name}/tests %doc %{_mandir}/man8/* %{crmsh_docdir}/COPYING @@ -195,4 +214,8 @@ %dir %attr (770, %{uname}, %{gname}) %{_var}/cache/crm %config %{_sysconfdir}/bash_completion.d/crm.sh +%files test +%defattr(-,root,root) +%{_datadir}/%{name}/tests + %changelog diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/doc/development.txt new/crmsh/doc/development.txt --- old/crmsh/doc/development.txt 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/doc/development.txt 2014-02-10 08:37:44.000000000 +0100 @@ -41,11 +41,14 @@ === Unit tests === +The test suite uses nose. On most distributions, this can be installed +by installing the package +python-nose+, or using +pip+. + To run the unit test suite, go to the source code directory of `crmsh` and call: ---- -./test/unittests/testrunner.py +./test/unit-tests.sh ---- === Regression tests === diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/modules/cibconfig.py new/crmsh/modules/cibconfig.py --- old/crmsh/modules/cibconfig.py 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/modules/cibconfig.py 2014-02-10 08:37:44.000000000 +0100 @@ -1970,6 +1970,15 @@ return rc +def is_stonith_rsc(xmlnode): + ''' + True if resource is stonith or derived from stonith template. + ''' + if xmlnode.get('template'): + xmlnode = reduce_primitive(xmlnode) + return xmlnode.get('class') == 'stonith' + + class CibFencingOrder(CibObject): ''' Fencing order (fencing-topology). @@ -2068,7 +2077,7 @@ rc = 1 stonith_rsc_l = [x.obj_id for x in cib_factory.get_elems_on_type("type:primitive") - if x.node.get("class") == "stonith"] + if is_stonith_rsc(x.node)] for devices in [x.get("devices") for x in nl]: for dev in devices.split(","): if not cib_factory.find_object(dev): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/modules/corosync.py new/crmsh/modules/corosync.py --- old/crmsh/modules/corosync.py 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/modules/corosync.py 2014-02-10 08:37:44.000000000 +0100 @@ -68,8 +68,8 @@ def corosync_tokenizer(stream): """Parses the corosync config file into a token stream""" - section_re = re.compile(r'(\w+) {') - value_re = re.compile(r'(\w+): (\S+)') + section_re = re.compile(r'(\w+)\s*{') + value_re = re.compile(r'(\w+):\s*(\S+)') path = [] while stream: stream = stream.lstrip() @@ -100,7 +100,7 @@ stream = stream[m.end():] yield t continue - raise ValueError("Parse error at ...%s" % (stream)) + raise ValueError("Parse error at [..%s..]" % (stream[:16])) def make_section(path, contents=None): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/modules/parse.py new/crmsh/modules/parse.py --- old/crmsh/modules/parse.py 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/modules/parse.py 2014-02-10 08:37:44.000000000 +0100 @@ -974,6 +974,8 @@ self.set_pl.insert(0, [self.curr_attr, self.prev_q]) if not self.sequential: self.set_pl.insert(0, ["sequential", "false"]) + elif not self.require_all: + self.set_pl.insert(0, ["sequential", "true"]) if not self.require_all: self.set_pl.insert(0, ["require-all", "false"]) self.cli_list.append(["resource_set", self.set_pl]) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/requirements.txt new/crmsh/requirements.txt --- old/crmsh/requirements.txt 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/requirements.txt 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,3 @@ +lxml +PyYAML +nosexcover diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/001.exp.xml new/crmsh/test/001.exp.xml --- old/crmsh/test/001.exp.xml 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/001.exp.xml 1970-01-01 01:00:00.000000000 +0100 @@ -1,15 +0,0 @@ -<cib epoch="1" num_updates="1" admin_epoch="0" validate-with="pacemaker-1.0" cib-last-written="Tue Mar 31 15:06:01 2009"> - <configuration> - <crm_config/> - <nodes/> - <resources> - <primitive class="ocf" id="rsc_dummy" provider="heartbeat" type="Dummy"> - <operations> - <op id="rsc_dummy-monitor-30" interval="30" name="monitor"/> - </operations> - </primitive> - </resources> - <constraints/> - </configuration> - <status/> -</cib> \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/001.input new/crmsh/test/001.input --- old/crmsh/test/001.input 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/001.input 1970-01-01 01:00:00.000000000 +0100 @@ -1,5 +0,0 @@ -configure -primitive rsc_dummy ocf:heartbeat:Dummy -monitor rsc_dummy 30 -commit -quit diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/002.exp.xml new/crmsh/test/002.exp.xml --- old/crmsh/test/002.exp.xml 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/002.exp.xml 1970-01-01 01:00:00.000000000 +0100 @@ -1,28 +0,0 @@ -<cib epoch="2" num_updates="1" admin_epoch="0" validate-with="pacemaker-1.0" cib-last-written="Tue Mar 31 15:06:02 2009"> - <configuration> - <crm_config/> - <nodes/> - <resources> - <primitive class="ocf" id="rsc_dummy" provider="heartbeat" type="Dummy"> - <operations> - <op id="rsc_dummy-monitor-30" interval="30" name="monitor"/> - </operations> - </primitive> - <clone id="testfs-clone"> - <meta_attributes id="testfs-clone-meta_attributes"> - <nvpair id="testfs-clone-meta_attributes-ordered" name="ordered" value="true"/> - <nvpair id="testfs-clone-meta_attributes-interleave" name="interleave" value="true"/> - </meta_attributes> - <primitive class="ocf" id="testfs" provider="heartbeat" type="Filesystem"> - <instance_attributes id="testfs-instance_attributes"> - <nvpair id="testfs-instance_attributes-directory" name="directory" value="/mnt"/> - <nvpair id="testfs-instance_attributes-fstype" name="fstype" value="ocfs2"/> - <nvpair id="testfs-instance_attributes-device" name="device" value="/dev/sda1"/> - </instance_attributes> - </primitive> - </clone> - </resources> - <constraints/> - </configuration> - <status/> -</cib> \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/002.input new/crmsh/test/002.input --- old/crmsh/test/002.input 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/002.input 1970-01-01 01:00:00.000000000 +0100 @@ -1,7 +0,0 @@ -configure -primitive testfs ocf:heartbeat:Filesystem \ - params directory="/mnt" fstype="ocfs2" device="/dev/sda1" -clone testfs-clone testfs \ - meta ordered="true" interleave="true" -commit -quit diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/003.exp.xml new/crmsh/test/003.exp.xml --- old/crmsh/test/003.exp.xml 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/003.exp.xml 1970-01-01 01:00:00.000000000 +0100 @@ -1,29 +0,0 @@ -<cib epoch="3" num_updates="1" admin_epoch="0" validate-with="pacemaker-1.0" cib-last-written="Tue Mar 31 15:06:56 2009"> - <configuration> - <crm_config/> - <nodes/> - <resources> - <primitive class="ocf" id="rsc_dummy" provider="heartbeat" type="Dummy"> - <operations> - <op id="rsc_dummy-monitor-30" interval="30" name="monitor"/> - </operations> - </primitive> - <clone id="testfs-clone"> - <meta_attributes id="testfs-clone-meta_attributes"> - <nvpair id="testfs-clone-meta_attributes-ordered" name="ordered" value="true"/> - <nvpair id="testfs-clone-meta_attributes-interleave" name="interleave" value="true"/> - <nvpair id="testfs-clone-meta_attributes-target-role" name="target-role" value="Stopped"/> - </meta_attributes> - <primitive class="ocf" id="testfs" provider="heartbeat" type="Filesystem"> - <instance_attributes id="testfs-instance_attributes"> - <nvpair id="testfs-instance_attributes-directory" name="directory" value="/mnt"/> - <nvpair id="testfs-instance_attributes-fstype" name="fstype" value="ocfs2"/> - <nvpair id="testfs-instance_attributes-device" name="device" value="/dev/sda1"/> - </instance_attributes> - </primitive> - </clone> - </resources> - <constraints/> - </configuration> - <status/> -</cib> \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/003.input new/crmsh/test/003.input --- old/crmsh/test/003.input 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/003.input 1970-01-01 01:00:00.000000000 +0100 @@ -1,2 +0,0 @@ -resource stop testfs-clone - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/004.exp.xml new/crmsh/test/004.exp.xml --- old/crmsh/test/004.exp.xml 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/004.exp.xml 1970-01-01 01:00:00.000000000 +0100 @@ -1,29 +0,0 @@ -<cib epoch="4" num_updates="1" admin_epoch="0" validate-with="pacemaker-1.0" cib-last-written="Tue Mar 31 15:07:27 2009"> - <configuration> - <crm_config/> - <nodes/> - <resources> - <primitive class="ocf" id="rsc_dummy" provider="heartbeat" type="Dummy"> - <operations> - <op id="rsc_dummy-monitor-30" interval="30" name="monitor"/> - </operations> - </primitive> - <clone id="testfs-clone"> - <meta_attributes id="testfs-clone-meta_attributes"> - <nvpair id="testfs-clone-meta_attributes-ordered" name="ordered" value="true"/> - <nvpair id="testfs-clone-meta_attributes-interleave" name="interleave" value="true"/> - <nvpair id="testfs-clone-meta_attributes-target-role" name="target-role" value="Started"/> - </meta_attributes> - <primitive class="ocf" id="testfs" provider="heartbeat" type="Filesystem"> - <instance_attributes id="testfs-instance_attributes"> - <nvpair id="testfs-instance_attributes-directory" name="directory" value="/mnt"/> - <nvpair id="testfs-instance_attributes-fstype" name="fstype" value="ocfs2"/> - <nvpair id="testfs-instance_attributes-device" name="device" value="/dev/sda1"/> - </instance_attributes> - </primitive> - </clone> - </resources> - <constraints/> - </configuration> - <status/> -</cib> \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/004.input new/crmsh/test/004.input --- old/crmsh/test/004.input 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/004.input 1970-01-01 01:00:00.000000000 +0100 @@ -1,2 +0,0 @@ -resource start testfs-clone - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/Makefile.am new/crmsh/test/Makefile.am --- old/crmsh/test/Makefile.am 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/Makefile.am 2014-02-10 08:37:44.000000000 +0100 @@ -18,10 +18,10 @@ # MAINTAINERCLEANFILES = Makefile.in -SUBDIRS = testcases +SUBDIRS = testcases cibtests testdir = $(datadir)/$(PACKAGE)/tests -test_SCRIPTS = regression.sh evaltest.sh +test_SCRIPTS = regression.sh evaltest.sh cib-tests.sh test_DATA = README.regression defaults descriptions \ crm-interface history-test.tar.bz2 # shouldn't need this, but we do for some versions of autofoo tools diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/cib-tests.sh new/crmsh/test/cib-tests.sh --- old/crmsh/test/cib-tests.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/cib-tests.sh 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,98 @@ +#!/bin/bash + +# Copyright (C) 2009 Lars Marowsky-Bree <[email protected]> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This software 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 library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +BASE=${1:-`pwd`}/cibtests +AUTOCREATE=1 + +logt() { + local msg="$1" + echo $(date) "$msg" >>$LOGF + echo "$msg" +} + +difft() { + crm_diff -V --filter -o $1 -n $2 +} + +run() { + local cmd="$1" + local erc="$2" + local msg="$3" + local rc + local out + + echo $(date) "$1" >>$LOGF + $1 >>$LOGF 2>&1 ; rc=$? + echo $(date) "Returned: $rc (expected $erc)" >>$LOGF + if [ $erc != "I" ]; then + if [ $rc -ne $erc ]; then + logt "$msg: FAILED ($erc != $rc)" + cat $LOGF + return 1 + fi + fi + echo "$msg: ok" + return 0 +} + +runt() { + local T="$1" + local CIBE="$BASE/$(basename $T .input).exp.xml" + cp $BASE/shadow.base $CIB_file + run "crm" 0 "Running testcase: $T" <$T + local rc + if [ ! -e $CIBE ]; then + if [ "$AUTOCREATE" = "1" ]; then + logt "Creating new expected output for $T." + cp $CIB_file $CIBE + return 0 + else + logt "$T: No expected output." + return 0 + fi + fi + + if ! crm_diff --filter -o $CIBE -n $CIB_file >/dev/null 2>&1 ; then + logt "$T: XML: $CIBE does not match $CIB_file" + difft $CIBE $CIB_file + return 1 + fi + return 0 +} + +LOGF=$(mktemp) +export PATH=/usr/sbin:$PATH + +export CIB_file=$BASE/shadow.test + +failed=0 +for T in $(ls $BASE/*.input) ; do + runt $T + failed=$(($? + $failed)) +done + +if [ $failed -gt 0 ]; then + logt "$failed tests failed!" + exit 1 +fi + +logt "All tests passed!" +rm $LOGF $CIB_file +exit 0 + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/cibtests/001.exp.xml new/crmsh/test/cibtests/001.exp.xml --- old/crmsh/test/cibtests/001.exp.xml 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/cibtests/001.exp.xml 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,19 @@ +<cib epoch="2" num_updates="1" admin_epoch="0" validate-with="pacemaker-1.0" cib-last-written="Tue Mar 31 15:06:01 2009"> + <configuration> + <crm_config> + <cluster_property_set id="cib-bootstrap-options"> + <nvpair name="stonith-enabled" value="false" id="cib-bootstrap-options-stonith-enabled"/> + </cluster_property_set> + </crm_config> + <nodes/> + <resources> + <primitive class="ocf" id="rsc_dummy" provider="heartbeat" type="Dummy"> + <operations> + <op id="rsc_dummy-monitor-30" interval="30" name="monitor"/> + </operations> + </primitive> + </resources> + <constraints/> + </configuration> + <status/> +</cib> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/cibtests/001.input new/crmsh/test/cibtests/001.input --- old/crmsh/test/cibtests/001.input 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/cibtests/001.input 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,6 @@ +configure +property stonith-enabled=false +primitive rsc_dummy ocf:heartbeat:Dummy +monitor rsc_dummy 30 +commit +quit diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/cibtests/002.exp.xml new/crmsh/test/cibtests/002.exp.xml --- old/crmsh/test/cibtests/002.exp.xml 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/cibtests/002.exp.xml 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,27 @@ +<cib epoch="2" num_updates="1" admin_epoch="0" validate-with="pacemaker-1.0" cib-last-written="Tue Mar 31 14:52:24 2009"> + <configuration> + <crm_config> + <cluster_property_set id="cib-bootstrap-options"> + <nvpair name="stonith-enabled" value="false" id="cib-bootstrap-options-stonith-enabled"/> + </cluster_property_set> + </crm_config> + <nodes/> + <resources> + <clone id="testfs-clone"> + <meta_attributes id="testfs-clone-meta_attributes"> + <nvpair name="ordered" value="true" id="testfs-clone-meta_attributes-ordered"/> + <nvpair name="interleave" value="true" id="testfs-clone-meta_attributes-interleave"/> + </meta_attributes> + <primitive id="testfs" class="ocf" provider="heartbeat" type="Filesystem"> + <instance_attributes id="testfs-instance_attributes"> + <nvpair name="directory" value="/mnt" id="testfs-instance_attributes-directory"/> + <nvpair name="fstype" value="ocfs2" id="testfs-instance_attributes-fstype"/> + <nvpair name="device" value="/dev/sda1" id="testfs-instance_attributes-device"/> + </instance_attributes> + </primitive> + </clone> + </resources> + <constraints/> + </configuration> + <status/> +</cib> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/cibtests/002.input new/crmsh/test/cibtests/002.input --- old/crmsh/test/cibtests/002.input 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/cibtests/002.input 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,8 @@ +configure +property stonith-enabled=false +primitive testfs ocf:heartbeat:Filesystem \ + params directory="/mnt" fstype="ocfs2" device="/dev/sda1" +clone testfs-clone testfs \ + meta ordered="true" interleave="true" +commit +quit diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/cibtests/003.exp.xml new/crmsh/test/cibtests/003.exp.xml --- old/crmsh/test/cibtests/003.exp.xml 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/cibtests/003.exp.xml 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,28 @@ +<cib epoch="3" num_updates="1" admin_epoch="0" validate-with="pacemaker-1.0" cib-last-written="Tue Mar 31 14:52:24 2009"> + <configuration> + <crm_config> + <cluster_property_set id="cib-bootstrap-options"> + <nvpair name="stonith-enabled" value="false" id="cib-bootstrap-options-stonith-enabled"/> + </cluster_property_set> + </crm_config> + <nodes/> + <resources> + <clone id="testfs-clone"> + <meta_attributes id="testfs-clone-meta_attributes"> + <nvpair name="ordered" value="true" id="testfs-clone-meta_attributes-ordered"/> + <nvpair name="interleave" value="true" id="testfs-clone-meta_attributes-interleave"/> + <nvpair id="testfs-clone-meta_attributes-target-role" name="target-role" value="Stopped"/> + </meta_attributes> + <primitive id="testfs" class="ocf" provider="heartbeat" type="Filesystem"> + <instance_attributes id="testfs-instance_attributes"> + <nvpair name="directory" value="/mnt" id="testfs-instance_attributes-directory"/> + <nvpair name="fstype" value="ocfs2" id="testfs-instance_attributes-fstype"/> + <nvpair name="device" value="/dev/sda1" id="testfs-instance_attributes-device"/> + </instance_attributes> + </primitive> + </clone> + </resources> + <constraints/> + </configuration> + <status/> +</cib> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/cibtests/003.input new/crmsh/test/cibtests/003.input --- old/crmsh/test/cibtests/003.input 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/cibtests/003.input 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,11 @@ +configure +property stonith-enabled=false +primitive testfs ocf:heartbeat:Filesystem \ + params directory="/mnt" fstype="ocfs2" device="/dev/sda1" +clone testfs-clone testfs \ + meta ordered="true" interleave="true" +commit +up +resource stop testfs-clone +quit + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/cibtests/004.exp.xml new/crmsh/test/cibtests/004.exp.xml --- old/crmsh/test/cibtests/004.exp.xml 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/cibtests/004.exp.xml 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,28 @@ +<cib epoch="3" num_updates="1" admin_epoch="0" validate-with="pacemaker-1.0" cib-last-written="Tue Mar 31 14:52:24 2009"> + <configuration> + <crm_config> + <cluster_property_set id="cib-bootstrap-options"> + <nvpair name="stonith-enabled" value="false" id="cib-bootstrap-options-stonith-enabled"/> + </cluster_property_set> + </crm_config> + <nodes/> + <resources> + <clone id="testfs-clone"> + <meta_attributes id="testfs-clone-meta_attributes"> + <nvpair name="ordered" value="true" id="testfs-clone-meta_attributes-ordered"/> + <nvpair name="interleave" value="true" id="testfs-clone-meta_attributes-interleave"/> + <nvpair id="testfs-clone-meta_attributes-target-role" name="target-role" value="Started"/> + </meta_attributes> + <primitive id="testfs" class="ocf" provider="heartbeat" type="Filesystem"> + <instance_attributes id="testfs-instance_attributes"> + <nvpair name="directory" value="/mnt" id="testfs-instance_attributes-directory"/> + <nvpair name="fstype" value="ocfs2" id="testfs-instance_attributes-fstype"/> + <nvpair name="device" value="/dev/sda1" id="testfs-instance_attributes-device"/> + </instance_attributes> + </primitive> + </clone> + </resources> + <constraints/> + </configuration> + <status/> +</cib> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/cibtests/004.input new/crmsh/test/cibtests/004.input --- old/crmsh/test/cibtests/004.input 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/cibtests/004.input 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,11 @@ +configure +property stonith-enabled=false +primitive testfs ocf:heartbeat:Filesystem \ + params directory="/mnt" fstype="ocfs2" device="/dev/sda1" +clone testfs-clone testfs \ + meta ordered="true" interleave="true" +commit +up +resource start testfs-clone +quit + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/cibtests/Makefile.am new/crmsh/test/cibtests/Makefile.am --- old/crmsh/test/cibtests/Makefile.am 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/cibtests/Makefile.am 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,29 @@ +# +# Author: Sun Jiang Dong <[email protected]> +# Copyright (c) 2004 International Business Machines +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +MAINTAINERCLEANFILES = Makefile.in + +cibtestsdir = $(datadir)/$(PACKAGE)/tests/cibtests +cibtests_DATA = shadow.base \ + 001.exp.xml 001.input \ + 002.exp.xml 002.input \ + 003.exp.xml 003.input \ + 004.exp.xml 004.input + +# shouldn't need this next line... +EXTRA_DIST = $(cibtests_DATA) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/cibtests/shadow.base new/crmsh/test/cibtests/shadow.base --- old/crmsh/test/cibtests/shadow.base 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/cibtests/shadow.base 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,10 @@ +<cib epoch="0" num_updates="0" admin_epoch="0" validate-with="pacemaker-1.0" cib-last-written="Tue Mar 31 14:52:24 2009"> + <configuration> + <crm_config/> + <nodes/> + <resources/> + <constraints/> + </configuration> + <status/> +</cib> + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/crm_regression.sh new/crmsh/test/crm_regression.sh --- old/crmsh/test/crm_regression.sh 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/crm_regression.sh 1970-01-01 01:00:00.000000000 +0100 @@ -1,84 +0,0 @@ -#!/bin/bash - -# Copyright (C) 2009 Lars Marowsky-Bree <[email protected]> -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This software 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 library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# - -BASE=${1:-`pwd`} -AUTOCREATE=1 - -logt() { - local msg="$1" - echo $(date) "$msg" >>$LOGF - echo "$msg" -} - -run() { - local cmd="$1" - local erc="$2" - local msg="$3" - local rc - local out - - echo $(date) "$1" >>$LOGF - $1 >>$LOGF 2>&1 ; rc=$? - echo $(date) "Returned: $rc (expected $erc)" >>$LOGF - if [ $erc != "I" ]; then - if [ $rc -ne $erc ]; then - logt "$msg: FAILED ($erc != $rc)" - logt "See $LOGF for details." - exit 1 - fi - fi - echo "$msg: ok" -} - -runt() { - local T="$1" - local CIBE="$BASE/$(basename $T .input).exp.xml" - run "crm" 0 "Running testcase: $T" <$T - local rc - if [ ! -e $CIBE ]; then - if [ "$AUTOCREATE" = "1" ]; then - logt "Creating new expected output for $T." - cp $CIB_file $CIBE - return 0 - else - logt "$T: No expected output." - return 0 - fi - fi - - if ! crm_diff -o $CIBE -n $CIB_file >/dev/null 2>&1 ; then - logt "$T: XML: $CIBE does not match $CIB_file" - exit 1 - fi -} - -LOGF=$(mktemp) -export PATH=/usr/sbin:$PATH - -export CIB_file=$BASE/shadow.test -cp $BASE/shadow.base $CIB_file - -for T in $(ls $BASE/*.input) ; do - runt $T -done - -logt "All tests passed!" -rm $LOGF $CIB_file -exit 0 - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/shadow.base new/crmsh/test/shadow.base --- old/crmsh/test/shadow.base 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/shadow.base 1970-01-01 01:00:00.000000000 +0100 @@ -1,9 +0,0 @@ -<cib epoch="0" num_updates="0" admin_epoch="0" validate-with="pacemaker-1.0" cib-last-written="Tue Mar 31 14:52:24 2009"> - <configuration> - <crm_config/> - <nodes/> - <resources/> - <constraints/> - </configuration> - <status/> -</cib> \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/unit-tests.sh new/crmsh/test/unit-tests.sh --- old/crmsh/test/unit-tests.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/unit-tests.sh 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,13 @@ +#!/bin/sh +case `pwd` in + */test/unittests) + PYTHONPATH=../../modules nosetests -w . "$@" + ;; + */test) + PYTHONPATH=../modules nosetests -w unittests "$@" + ;; + *) + PYTHONPATH=modules nosetests -w test/unittests "$@" + ;; +esac + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/unittests/bug-862577_corosync.conf new/crmsh/test/unittests/bug-862577_corosync.conf --- old/crmsh/test/unittests/bug-862577_corosync.conf 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/unittests/bug-862577_corosync.conf 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,51 @@ +# Please read the corosync.conf.5 manual page + +service { + ver: 1 + name: pacemaker +} +totem { + version: 2 + secauth: off + cluster_name: hacluster + clear_node_high_bit: yes + +# Following are old corosync 1.4.x defaults from SLES +# token: 5000 +# token_retransmits_before_loss_const: 10 +# join: 60 +# consensus: 6000 +# vsftype: none +# max_messages: 20 +# threads: 0 + + crypto_cipher: none + crypto_hash: none + + interface { + ringnumber: 0 + bindnetaddr: 10.122.2.13 + mcastaddr: 239.91.185.71 + mcastport: 5405 + ttl: 1 + } +} +logging { + fileline: off + to_stderr: no + to_logfile: yes + logfile: /var/log/cluster/corosync.log + to_syslog: yes + debug: off + timestamp: on + logger_subsys { + subsys: QUORUM + debug: off + } +} +quorum { + # Enable and configure quorum subsystem (default: off) + # see also corosync.conf.5 and votequorum.5 + provider: corosync_votequorum + expected_votes: 2 +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/unittests/test_corosync.py new/crmsh/test/unittests/test_corosync.py --- old/crmsh/test/unittests/test_corosync.py 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/unittests/test_corosync.py 2014-02-10 08:37:44.000000000 +0100 @@ -23,6 +23,7 @@ F1 = open('corosync.conf.1').read() F2 = open('corosync.conf.2').read() +F3 = open('bug-862577_corosync.conf').read() def _valid(parser): @@ -94,5 +95,10 @@ self.assertEqual(p.get_all('nodelist.node.nodeid'), ['1']) + def test_bnc862577(self): + p = Parser(F3) + _valid(p) + self.assertEqual(p.count('service.ver'), 1) + if __name__ == '__main__': unittest.main() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/unittests/test_parse.py new/crmsh/test/unittests/test_parse.py --- old/crmsh/test/unittests/test_parse.py 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/unittests/test_parse.py 2014-02-10 08:37:44.000000000 +0100 @@ -179,7 +179,7 @@ self.assertEqual(len(out.children), 0) self.assertTrue('a' in out.params) - def test_constraints(self): + def test_location(self): out = self.parser.parse('location loc-1 resource inf: foo') self.assertEqual(out.id, 'loc-1') self.assertEqual(out.resource, 'resource') @@ -203,6 +203,7 @@ self.assertEqual(out.node, 'bar') #print out.to_list() + def test_colocation(self): out = self.parser.parse('colocation col-1 inf: foo:master ( bar wiz sequential=yes )') self.assertEqual(out.id, 'col-1') self.assertEqual(2, sum(1 for s in out.resources if s[0] == 'resource_set')) @@ -227,7 +228,27 @@ out = self.parser.parse('colocation col-1 10: ( bar wiz ]') self.assertFalse(out) + def test_order(self): out = self.parser.parse('order o1 Mandatory: [ A B sequential=true ] C') + self.assertEqual(out.resources[0][0], 'resource_set') + self.assertTrue(['require-all', 'false'] in out.resources[0][1]) + self.assertTrue(['sequential', 'true'] in out.resources[0][1]) + self.assertEqual(out.id, 'o1') + + out = self.parser.parse('order o1 Mandatory: [ A B sequential=false ] C') + self.assertEqual(out.resources[0][0], 'resource_set') + self.assertTrue(['require-all', 'false'] in out.resources[0][1]) + self.assertTrue(['sequential', 'false'] in out.resources[0][1]) + self.assertEqual(out.id, 'o1') + + out = self.parser.parse('order o1 Mandatory: A B C sequential=false') + self.assertEqual(out.resources[0][0], 'resource_set') + self.assertTrue(['sequential', 'false'] in out.resources[0][1]) + self.assertEqual(out.id, 'o1') + + out = self.parser.parse('order o1 Mandatory: A B C sequential=true') + self.assertEqual(out.resources[0][0], 'resource_set') + self.assertTrue(['sequential', 'true'] not in out.resources[0][1]) self.assertEqual(out.id, 'o1') out = self.parser.parse('order c_apache_1 Mandatory: apache:start ip_1') @@ -244,6 +265,7 @@ self.assertEqual(out.id, 'order-1') self.assertEqual(out.to_list(), [['order', [['id', 'order-1'], ['kind', 'Optional'], ['first', 'group1'], ['first-action', 'stop'], ['then', 'group2'], ['then-action', 'start']]]]) + def test_ticket(self): out = self.parser.parse('rsc_ticket ticket-A_public-ip ticket-A: public-ip') self.assertEqual(out.id, 'ticket-A_public-ip') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/unittests/test_utils.py new/crmsh/test/unittests/test_utils.py --- old/crmsh/test/unittests/test_utils.py 1970-01-01 01:00:00.000000000 +0100 +++ new/crmsh/test/unittests/test_utils.py 2014-02-10 08:37:44.000000000 +0100 @@ -0,0 +1,137 @@ +# Copyright (C) 2014 Kristoffer Gronlund <[email protected]> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This software 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 library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# unit tests for utils.py + +import os +from itertools import chain +import utils +import config + + +def test_systeminfo(): + assert utils.getuser() is not None + assert utils.gethomedir() is not None + assert utils.get_tempdir() is not None + + +def test_shadowcib(): + assert utils.get_cib_in_use() == "" + utils.set_cib_in_use("foo") + assert utils.get_cib_in_use() == "foo" + utils.clear_cib_in_use() + assert utils.get_cib_in_use() == "" + + +def test_booleans(): + truthy = ['yes', 'Yes', 'True', 'true', 'TRUE', + 'YES', 'on', 'On', 'ON'] + falsy = ['no', 'false', 'off', 'OFF', 'FALSE', 'nO'] + not_truthy = ['', 'not', 'ONN', 'TRUETH', 'yess'] + for case in chain(truthy, falsy): + assert utils.verify_boolean(case) is True + for case in truthy: + assert utils.is_boolean_true(case) is True + assert utils.is_boolean_false(case) is False + assert utils.get_boolean(case) is True + for case in falsy: + assert utils.is_boolean_true(case) is False + assert utils.is_boolean_false(case) is True + assert utils.get_boolean(case, dflt=True) is False + for case in not_truthy: + assert utils.verify_boolean(case) is False + assert utils.is_boolean_true(case) is False + assert utils.is_boolean_false(case) is False + assert utils.get_boolean(case) is False + + +def test_olist(): + lst = utils.olist(['B', 'C', 'A']) + lst.append('f') + lst.append('aA') + lst.append('_') + assert 'aa' in lst + assert 'a' in lst + assert list(lst) == ['b', 'c', 'a', 'f', 'aa', '_'] + + +def test_add_sudo(): + tmpuser = config.core.user + try: + config.core.user = 'root' + assert utils.add_sudo('ls').startswith('sudo') + config.core.user = '' + assert utils.add_sudo('ls') == 'ls' + finally: + config.core.user = tmpuser + + +def test_str2tmp(): + txt = "This is a test string" + filename = utils.str2tmp(txt) + assert os.path.isfile(filename) + assert open(filename).read() == txt + "\n" + assert utils.file2str(filename) == txt + # TODO: should this really return + # an empty line at the end? + assert utils.file2list(filename) == [txt, ''] + os.unlink(filename) + + +def test_sanity(): + sane_paths = ['foo/bar', 'foo', '/foo/bar', 'foo0', + 'foo_bar', 'foo-bar', '0foo', '.foo', + 'foo.bar'] + insane_paths = ['#foo', 'foo?', 'foo*', 'foo$', 'foo[bar]', + 'foo`', "foo'", 'foo/*'] + for p in sane_paths: + assert utils.is_path_sane(p) + for p in insane_paths: + assert not utils.is_path_sane(p) + sane_filenames = ['foo', '0foo', '0', '.foo'] + insane_filenames = ['foo/bar'] + for p in sane_filenames: + assert utils.is_filename_sane(p) + for p in insane_filenames: + assert not utils.is_filename_sane(p) + sane_names = ['foo'] + insane_names = ["f'o"] + for n in sane_names: + assert utils.is_name_sane(n) + assert utils.is_value_sane(n) + for n in insane_names: + assert not utils.is_name_sane(n) + assert not utils.is_value_sane(n) + + +def test_nvpairs2dict(): + assert utils.nvpairs2dict(['a=b', 'c=d']) == {'a': 'b', 'c': 'd'} + assert utils.nvpairs2dict(['a=b=c', 'c=d']) == {'a': 'b=c', 'c': 'd'} + assert utils.nvpairs2dict(['a']) == {'a': None} + + +def test_validity(): + assert utils.is_id_valid('foo0') + assert not utils.is_id_valid('0foo') + + +def test_msec(): + assert utils.crm_msec('1ms') == 1 + assert utils.crm_msec('1s') == 1000 + assert utils.crm_msec('1us') == 0 + assert utils.crm_msec('1') == 1000 + assert utils.crm_msec('1m') == 60*1000 + assert utils.crm_msec('1h') == 60*60*1000 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/crmsh/test/unittests/testrunner.py new/crmsh/test/unittests/testrunner.py --- old/crmsh/test/unittests/testrunner.py 2014-02-01 00:11:56.000000000 +0100 +++ new/crmsh/test/unittests/testrunner.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,49 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2013 Kristoffer Gronlund <[email protected]> -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This software 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 library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# -# simple unit test testrunner - -import os -import sys -import re -import subprocess - -os.chdir(os.path.dirname(os.path.abspath(sys.modules[__name__].__file__))) - - -def test_info(f): - m = re.match(r'^test_(.+)\.py$', os.path.basename(f)) - if m: - return (m.group(1), f) - return None -tests = [test_info(f) for f in os.listdir('.') if test_info(f)] - - -def run_test(name, testfile): - print "%s" % (name.capitalize()) - cmd = 'PYTHONPATH=%s CRM_CONFIG_FILE=%s python -B %s' % ( - '../../modules', - 'test.conf', - testfile - ) - ret = subprocess.call(cmd, shell=True) - return ret == 0 - -results = [run_test(name, test) for name, test in tests] - -sys.exit(False in results) -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
