diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/README.md | 7 | ||||
-rw-r--r-- | test/cmdver/README.md | 1 | ||||
-rw-r--r-- | test/cmdver/lmi/__init__.py | 27 | ||||
-rw-r--r-- | test/cmdver/lmi/scripts/__init__.py | 27 | ||||
-rw-r--r-- | test/cmdver/lmi/scripts/cmdver/__init__.py | 135 | ||||
-rw-r--r-- | test/cmdver/lmi/scripts/cmdver/devel.py | 32 | ||||
-rw-r--r-- | test/cmdver/lmi/scripts/cmdver/pre042.py | 32 | ||||
-rw-r--r-- | test/cmdver/lmi/scripts/cmdver/swbase.py | 51 | ||||
-rw-r--r-- | test/cmdver/lmi/scripts/cmdver/ver042.py | 32 | ||||
-rw-r--r-- | test/cmdver/setup.py | 48 | ||||
-rw-r--r-- | test/test_unit.sh | 69 | ||||
-rw-r--r-- | test/test_versioning.sh | 236 | ||||
-rw-r--r-- | test/unit/test_common.py | 79 |
13 files changed, 776 insertions, 0 deletions
diff --git a/test/README.md b/test/README.md index 03219b3..cfcbbf7 100644 --- a/test/README.md +++ b/test/README.md @@ -11,6 +11,10 @@ Dependencies * openlmi-tools Openlmi scripts need not be installed. + +Remote host shall have `openlmi-software` and `openlmi-hardware` installed. If +not, `LMI_SOFTWARE_PROVIDER_VERSION` and `LMI_HARDWARE_PROVIDER_VERSION` needs +to be set to `none`. Run --- @@ -20,6 +24,9 @@ can connect to it. Export these variables: * LMI_CIMOM_URL * LMI_CIMOM_USERNAME * LMI_CIMOM_PASSWORD + * LMI_SOFTWARE_PROVIDER_VERSION - version of software provider registered + with CIMOM + * LMI_HARDWARE_PROVIDER_VERSION Execute: $ ./run.sh diff --git a/test/cmdver/README.md b/test/cmdver/README.md new file mode 100644 index 0000000..14c401e --- /dev/null +++ b/test/cmdver/README.md @@ -0,0 +1 @@ +Subcommand just for testing purposes. diff --git a/test/cmdver/lmi/__init__.py b/test/cmdver/lmi/__init__.py new file mode 100644 index 0000000..b1a2ff0 --- /dev/null +++ b/test/cmdver/lmi/__init__.py @@ -0,0 +1,27 @@ +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are +# those of the authors and should not be interpreted as representing official +# policies, either expressed or implied, of the FreeBSD Project. +__import__('pkg_resources').declare_namespace(__name__) diff --git a/test/cmdver/lmi/scripts/__init__.py b/test/cmdver/lmi/scripts/__init__.py new file mode 100644 index 0000000..b1a2ff0 --- /dev/null +++ b/test/cmdver/lmi/scripts/__init__.py @@ -0,0 +1,27 @@ +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are +# those of the authors and should not be interpreted as representing official +# policies, either expressed or implied, of the FreeBSD Project. +__import__('pkg_resources').declare_namespace(__name__) diff --git a/test/cmdver/lmi/scripts/cmdver/__init__.py b/test/cmdver/lmi/scripts/cmdver/__init__.py new file mode 100644 index 0000000..f9e0c8b --- /dev/null +++ b/test/cmdver/lmi/scripts/cmdver/__init__.py @@ -0,0 +1,135 @@ +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are +# those of the authors and should not be interpreted as representing official +# policies, either expressed or implied, of the FreeBSD Project. + +import pywbem +from lmi.scripts.common import command +from lmi.scripts.common import get_computer_system + +# 1st entry point +class CmdverSw(command.LmiSelectCommand): + """ + This is a short description for CmdverSw. + """ + SELECT = ( + ('OpenLMI-Software < 0.4.2', 'lmi.scripts.cmdver.pre042.Cmd'), + ('OpenLMI-Software == 0.4.2', 'lmi.scripts.cmdver.ver042.Cmd'), + ('OpenLMI-Software > 0.4.2', 'lmi.scripts.cmdver.devel.Cmd'), + ) + +def get_hw_profile_version(ns): + try: + return ns.connection.root.interop.wql('SELECT * FROM PG_RegisteredProfile' + ' WHERE RegisteredName="OpenLMI-Hardware"')[0].RegisteredVersion + except pywbem.CIMError, IndexError: + return None + +class SystemInfo(command.LmiLister): + COLUMNS = [] + PRE042 = False + + def execute(self, ns): + cls = ns.LMI_Chassis + inst = cls.first_instance() + verstr = get_hw_profile_version(ns) + if self.PRE042: + verstr += ' (PRE 0.4.2)' + return [('Prov version', verstr), + ('Chassis Type', cls.ChassisPackageTypeValues.value_name( + inst.ChassisPackageType))] + +class HostnameInfo(command.LmiLister): + COLUMNS = [] + PRE042 = False + + def execute(self, ns): + verstr = get_hw_profile_version(ns) + if self.PRE042: + verstr += ' (PRE 0.4.2)' + return [('Prov version', verstr), + ('Hostname', get_computer_system(ns).Name)] + +class PreSystemInfo(SystemInfo): + PRE042 = True + +class PreHostnameInfo(HostnameInfo): + PRE042 = True + +class HwCmd(command.LmiCommandMultiplexer): + """ + Hardware testing command. + + Usage: + %(cmd)s system + %(cmd)s hostname + """ + COMMANDS = { + 'system' : SystemInfo, + 'hostname' : HostnameInfo + } + OWN_USAGE = True + +class PreHwCmd(HwCmd): + COMMANDS = { + 'system' : PreSystemInfo, + 'hostname' : PreHostnameInfo + } + +class NoHwRegistered(command.LmiLister): + """ + Hardware testing command. + + Usage: %(cmd)s <cmd> + """ + COLUMNS = [] + OWN_USAGE = True + def execute(self, ns, cmd): + return [('Given command', cmd), ('Prov version', 'N/A')] + +# 2nd entry point +class CmdverHw(command.LmiSelectCommand): + """ + This is a short description for CmdverHw. + """ + SELECT = ( + ('OpenLMI-Hardware < 0.4.2', PreHwCmd), + ('OpenLMI-Hardware >= 0.4.2 & class LMI_Chassis == 0.3.0', HwCmd) + ) + DEFAULT = NoHwRegistered + +# 3rd entry point +class Cmdver(command.LmiCommandMultiplexer): + """ + Command for testing version dependencies. + + Usage: + %(cmd)s (sw|hw) [<args>...] + """ + COMMANDS = { + 'sw' : CmdverSw, + 'hw' : CmdverHw + } + OWN_USAGE = True diff --git a/test/cmdver/lmi/scripts/cmdver/devel.py b/test/cmdver/lmi/scripts/cmdver/devel.py new file mode 100644 index 0000000..624428e --- /dev/null +++ b/test/cmdver/lmi/scripts/cmdver/devel.py @@ -0,0 +1,32 @@ +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are +# those of the authors and should not be interpreted as representing official +# policies, either expressed or implied, of the FreeBSD Project. + +from lmi.scripts.common import command +from lmi.scripts.cmdver import swbase + +class Cmd(swbase.SwCmdBase): + ADDITIONAL_VERSION_INFO = ' (DEVEL)' diff --git a/test/cmdver/lmi/scripts/cmdver/pre042.py b/test/cmdver/lmi/scripts/cmdver/pre042.py new file mode 100644 index 0000000..e7565ae --- /dev/null +++ b/test/cmdver/lmi/scripts/cmdver/pre042.py @@ -0,0 +1,32 @@ +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are +# those of the authors and should not be interpreted as representing official +# policies, either expressed or implied, of the FreeBSD Project. + +from lmi.scripts.common import command +from lmi.scripts.cmdver import swbase + +class Cmd(swbase.SwCmdBase): + ADDITIONAL_VERSION_INFO = ' (PRE 0.4.2)' diff --git a/test/cmdver/lmi/scripts/cmdver/swbase.py b/test/cmdver/lmi/scripts/cmdver/swbase.py new file mode 100644 index 0000000..eed9dc2 --- /dev/null +++ b/test/cmdver/lmi/scripts/cmdver/swbase.py @@ -0,0 +1,51 @@ +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are +# those of the authors and should not be interpreted as representing official +# policies, either expressed or implied, of the FreeBSD Project. +""" +Software testing command. + +Usage: %(cmd)s +""" + +import pywbem +from lmi.scripts.common import command + +def get_sw_profile_version(ns): + try: + return ns.connection.root.interop.wql('SELECT * FROM PG_RegisteredProfile' + ' WHERE RegisteredName="OpenLMI-Software"')[0].RegisteredVersion + except pywbem.CIMError, IndexError: + return None + +class SwCmdBase(command.LmiLister): + OWN_USAGE = __doc__ + COLUMNS = [] + ADDITIONAL_VERSION_INFO = '' + + def execute(self, ns): + return [('Prov version', + get_sw_profile_version(ns) + self.ADDITIONAL_VERSION_INFO)] + diff --git a/test/cmdver/lmi/scripts/cmdver/ver042.py b/test/cmdver/lmi/scripts/cmdver/ver042.py new file mode 100644 index 0000000..433b539 --- /dev/null +++ b/test/cmdver/lmi/scripts/cmdver/ver042.py @@ -0,0 +1,32 @@ +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are +# those of the authors and should not be interpreted as representing official +# policies, either expressed or implied, of the FreeBSD Project. + +from lmi.scripts.common import command +from lmi.scripts.cmdver import swbase + +class Cmd(swbase.SwCmdBase): + ADDITIONAL_VERSION_INFO = ' (VER 0.4.2)' diff --git a/test/cmdver/setup.py b/test/cmdver/setup.py new file mode 100644 index 0000000..58ea463 --- /dev/null +++ b/test/cmdver/setup.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from setuptools import setup + +try: + long_description = open('README.md', 'rt').read() +except IOError: + long_description = '' + +setup( + name='openlmi-scripts-cmdver', + version='0.1.2', + description='Test command for versioning.', + long_description=long_description, + author=u'Michal Minar', + author_email='miminar@redhat.com', + url='https://github.com/openlmi/openlmi-cmdver', + download_url='https://github.com/openlmi/openlmi-cmdver/tarball/master', + platforms=['Any'], + license="BSD", + classifiers=[ + 'License :: OSI Approved :: BSD License', + 'Operating System :: POSIX :: Linux', + 'Topic :: System :: Systems Administration', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Intended Audience :: Developers', + 'Environment :: Console', + ], + + install_requires=['openlmi-scripts'], + + namespace_packages=['lmi', 'lmi.scripts'], + packages=['lmi', 'lmi.scripts', 'lmi.scripts.cmdver'], + include_package_data=True, + + entry_points={ + 'lmi.scripts.cmd': [ + # All subcommands of lmi command should go here. + # See http://pythonhosted.org/openlmi-scripts/script-development.html#writing-setup-py + 'ver-sw = lmi.scripts.cmdver:CmdverSw', + 'ver-hw = lmi.scripts.cmdver:CmdverHw', + 'ver = lmi.scripts.cmdver:Cmdver', + ], + }, + ) diff --git a/test/test_unit.sh b/test/test_unit.sh new file mode 100644 index 0000000..04fe17b --- /dev/null +++ b/test/test_unit.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# +# Copyright (c) 2014, Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are +# those of the authors and should not be interpreted as representing official +# policies, either expressed or implied, of the FreeBSD Project. +# +# Authors: Michal Minar <miminar@redhat.com> + +. ./base.sh + +# Set the full test name +TEST="openlmi-scripts/test/test_cmd.sh" + +PACKAGE="openlmi-scripts" + +rlJournalStart + +rlPhaseStartSetup + rlLogInfo "Creating temporary python sandbox" + sandbox=`mktemp -d` + export PYTHONPATH="$sandbox" + pushd .. + rlLogInfo "Installing lmi meta-command" + rlRun "python setup.py develop --install-dir=$sandbox" + popd + export "$sandbox:$PATH" +rlPhaseEnd + +rlPhaseStartTest + rlLogInfo "Running unittests" + + pushd unit + for i in test_*.py; do + rlRun "python $i" + done + popd # unit + +rlPhaseEnd + +rlPhaseStartCleanup + rlLogInfo "Removing temporary python sandbox" + rm -rf "$sandbox" +rlPhaseEnd + +rlJournalPrintText +rlJournalEnd diff --git a/test/test_versioning.sh b/test/test_versioning.sh new file mode 100644 index 0000000..0f7f5b6 --- /dev/null +++ b/test/test_versioning.sh @@ -0,0 +1,236 @@ +#!/bin/bash +# +# Copyright (c) 2014, Red Hat, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and documentation are +# those of the authors and should not be interpreted as representing official +# policies, either expressed or implied, of the FreeBSD Project. +# +# Authors: Michal Minar <miminar@redhat.com> + +. ./base.sh + +EXIT_CODE_UNSATISFIED=5 +DEFAULT_VERSION='0.4.2' + +# Set the full test name +TEST="openlmi-scripts/test/test_versioning" + +# Package being tested +PACKAGE="openlmi-scripts" + +function cmp2int() { + digits=( `echo $1 | tr '.' ' '` ) + result=0 + for i in `seq 0 $((${#digits[@]} - 1))`; do + result=$((result*100)) + result=$((result + ${digits[$i]})) + done + echo $result +} + +rlJournalStart + +if [[ -z "${LMI_SOFTWARE_PROVIDER_VERSION}" ]]; then + msg="No version specified for OpenLMI-Software. Defaulting to " + msg+="{$DEFAULT_VERSION}." + rlLogInfo "$msg" + LMI_SOFTWARE_PROVIDER_VERSION="${DEFAULT_VERSION}" +elif [[ "$LMI_SOFTWARE_PROVIDER_VERSION" == none ]]; then + LMI_SOFTWARE_PROVIDER_VERSION='' +fi +if [[ -z "${LMI_HARDWARE_PROVIDER_VERSION}" ]]; then + msg="No version specified for OpenLMI-Hardware Defaulting to " + msg+="{$DEFAULT_VERSION}." + rlLogInfo "$msg" + LMI_HARDWARE_PROVIDER_VERSION="${DEFAULT_VERSION}" +elif [[ "$LMI_SOFTWARE_PROVIDER_VERSION" == none ]]; then + LMI_HARDWARE_PROVIDER_VERSION='' +fi + +rlPhaseStartSetup + rlLogInfo "Creating temporary python sandbox" + sandbox=`mktemp -d` + export PYTHONPATH="$sandbox" + pushd .. + rlLogInfo "Installing lmi meta-command" + rlRun "python setup.py develop --install-dir=$sandbox" + popd + rlLogInfo "Installing testing command" + pushd cmdver + rlRun "python setup.py develop --install-dir=$sandbox" + popd + export "$sandbox:$PATH" +rlPhaseEnd + +rlPhaseStartTest + rlLogInfo "Test help on select command" + + rlRun -s "$LMI_ help" + rlAssertEquals "Check the number of subcommands available." \ + `grep '^\s\+[[:alnum:]-]\+\s\+-\s\+' $rlRun_LOG | wc -l` 4 + rlAssertGrep '\<ver\>\s\+-\s\+Command for testing version dependencies\.$' \ + $rlRun_LOG + rlAssertGrep '\<ver-hw\s\+-\s\+This is a short description for CmdverHw\.$' \ + $rlRun_LOG + rlAssertGrep '\<ver-sw\s\+-\s\+This is a short description for CmdverSw\.$' \ + $rlRun_LOG + rm $rlRun_LOG + + rlRun -s "$LMI help ver" + rlAssertGrep "^Command for testing version dependencies.$" $rlRun_LOG + rlAssertGrep "^Usage:$" $rlRun_LOG + rlAssertGrep "^\s\+lmi ver (sw\\|hw) \[<args>\.\.\.\]$'" $rlRun_LOG + rm $rlRun_LOG + + if [[ -z "$LMI_SOFTWARE_PROVIDER_VERSION" ]]; then + rlRun -s "$LMI help ver-sw" $EXIT_CODE_UNSATISFIED + rlAssertGrep "error\s*:\s\+Profile and class dependencies were not satisfied for" \ + $rlRun_LOG + rm $rlRun_LOG + + rlRun -s "$LMI help ver sw" $EXIT_CODE_UNSATISFIED + rlAssertGrep "error\s*:\s\+Profile and class dependencies were not satisfied for" \ + $rlRun_LOG + rm $rlRun_LOG + + else + rlRun -s "$LMI help ver-sw" + rlAssertGrep "^Software testing command.$" $rlRun_LOG + rlAssertGrep "Usage: lmi ver-sw" $rlRun_LOG + rm $rlRun_LOG + + rlRun -s "$LMI help ver sw" 0 + rlAssertGrep "^Software testing command.$" $rlRun_LOG + rlAssertGrep "Usage: lmi ver sw" $rlRun_LOG + rm $rlRun_LOG + fi + + if [[ -z "$LMI_HARDWARE_PROVIDER_VERSION" ]]; then + rlRun -s "$LMI help ver-hw" + rlAssertGrep "^Hardware testing command\.$" $rlRun_LOG + rlAssertGrep "^Usage: lmi ver-hw <cmd>$" $rlRun_LOG + rm $rlRun_LOG + + rlRun -s "$LMI help ver hw" + rlAssertGrep "^Hardware testing command\.$" $rlRun_LOG + rlAssertGrep "^Usage: lmi ver hw <cmd>$" $rlRun_LOG + rm $rlRun_LOG + + else + rlRun -s "$LMI help ver-hw" + rlAssertGrep "^Hardware testing command\.$" $rlRun_LOG + rlAssertGrep "^Usage:$" $rlRun_LOG + rlAssertGrep "^\s\+lmi ver-hw system$" $rlRun_LOG + rlAssertGrep "^\s\+lmi ver-hw hostname$" $rlRun_LOG + rm $rlRun_LOG + + rlRun -s "$LMI help ver hw" 0 + rlAssertGrep "^Hardware testing command.$" $rlRun_LOG + rlAssertGrep "^Usage:$" $rlRun_LOG + rlAssertGrep "^\s\+lmi ver hw system$" $rlRun_LOG + rlAssertGrep "^\s\+lmi ver hw hostname$" $rlRun_LOG + rm $rlRun_LOG + + rlRun -s "$LMI help ver hw system" 0 + rlAssertGrep "^Hardware testing command.$" $rlRun_LOG + rlAssertGrep "^Usage:$" $rlRun_LOG + rlAssertGrep "^\s\+lmi ver hw system$" $rlRun_LOG + rlAssertGrep "^\s\+lmi ver hw hostname$" $rlRun_LOG + rm $rlRun_LOG + fi + +rlPhaseEnd + +rlPhaseStartTest + rlLogInfo "Test software testing command" + + if [[ -z "$LMI_SOFTWARE_PROVIDER_VERSION" ]]; then + rlRun -s "$LMI ver-sw" $EXIT_CODE_UNSATISFIED + rlAssertGrep "Profile and class dependencies were not satisfied" \ + $rlRun_LOG + rm $rlRun_LOG + + elif [[ `cmp2int $LMI_SOFTWARE_PROVIDER_VERSION` -lt `cmp2int 0.4.2` ]]; then + + rlRun -s "$LMI ver-sw" + rlAssertGrep "Prov version.*${LMI_SOFTWARE_PROVIDER_VERSION} (PRE 0.4.2)" $rlRun_LOG + rm $rlRun_LOG + + elif [[ `cmp2int $LMI_SOFTWARE_PROVIDER_VERSION` == `cmp2int 0.4.2` ]]; then + rlRun -s "$LMI ver-sw" + rlAssertGrep "Prov version.*${LMI_SOFTWARE_PROVIDER_VERSION} (VER 0.4.2)" $rlRun_LOG + rm $rlRun_LOG + + else + rlRun -s "$LMI ver-sw" + rlAssertGrep "Prov version.*${LMI_SOFTWARE_PROVIDER_VERSION} (DEVEL)" $rlRun_LOG + rm $rlRun_LOG + fi + +rlPhaseEnd + +rlPhaseStartTest + rlLogInfo "Test hardware testing command" + + if [[ -z "$LMI_HARDWARE_PROVIDER_VERSION" ]]; then + for cmd in "system" "hostname"; do + rlRun -s "$LMI ver-hw $cmd" + rlAssertEquals "Printed table has just 2 rows" \ + `cat $rlRun_LOG | wc -l` 2 + rlAssertGrep "^Given command\s\+$cmd$" $rlRun_LOG + rlAssertGrep "^Prov version\s\+N/A" $rlRun_LOG + rm $rlRun_LOG + done + + else + if [[ `cmp2int $LMI_HARDWARE_PROVIDER_VERSION` -lt `cmp2int 0.4.2` ]]; then + ver_suffix=' (PRE 0.4.2)' + else + ver_suffix='' + fi + for cmd in "system" "hostname"; do + rlRun -s "$LMI ver-hw $cmd" + rlAssertEquals "Printed table has just 2 rows" \ + `cat $rlRun_LOG | wc -l` 2 + rlAssertGrep "^Prov version\s\+$LMI_SOFTWARE_PROVIDER_VERSION$ver_suffix\$" \ + $rlRun_LOG + if [[ $cmd == system ]]; then + reg="^Chassis Type\s\+.*" + else + reg="^Hostname\s\+$HOSTNAME" $rlRun_LOG + fi + rm $rlRun_LOG + done + fi + +rlPhaseEnd + +rlPhaseStartCleanup + rlLogInfo "Removing temporary python sandbox" + rm -rf "$sandbox" +rlPhaseEnd + +rlJournalPrintText +rlJournalEnd diff --git a/test/unit/test_common.py b/test/unit/test_common.py new file mode 100644 index 0000000..955d964 --- /dev/null +++ b/test/unit/test_common.py @@ -0,0 +1,79 @@ +import unittest + +from lmi.scripts.common.util import FilteredDict + +class FilteredDictTest(unittest.TestCase): + + def test_empty(self): + d = FilteredDict(tuple(), {}) + self.assertEqual(0, len(d)) + self.assertNotIn('key', d) + self.assertEqual(0, len(d.keys())) + self.assertEqual(0, len(d.values())) + self.assertEqual(0, len(d.items())) + self.assertRaises(KeyError, d.__getitem__, 'key') + self.assertRaises(KeyError, d.__setitem__, 'key', 'value') + + def test_empty_keys(self): + d = FilteredDict(tuple(), {'a': 1}) + self.assertEqual(0, len(d)) + self.assertNotIn('a', d) + self.assertEqual(0, len(d.keys())) + self.assertEqual(0, len(d.values())) + self.assertEqual(0, len(d.items())) + self.assertRaises(KeyError, d.__getitem__, 'a') + self.assertRaises(KeyError, d.__setitem__, 'a', 2) + + def test_empty_origin(self): + d = FilteredDict(tuple('a'), {}) + self.assertEqual(0, len(d)) + self.assertNotIn('a', d) + self.assertEqual(0, len(d.keys())) + self.assertEqual(0, len(d.values())) + self.assertEqual(0, len(d.items())) + self.assertRaises(KeyError, d.__getitem__, 'a') + d['a'] = 1 + self.assertEqual(1, len(d)) + self.assertEqual(1, d['a']) + self.assertIn('a', d) + self.assertEqual(['a',], d.keys()) + self.assertEqual([1], d.values()) + self.assertEqual([('a', 1)], d.items()) + di = d.iteritems() + self.assertEqual(('a', 1), di.next()) + self.assertRaises(StopIteration, di.next) + d['a'] = 2 + self.assertEqual(2, d['a']) + del d['a'] + self.assertEqual(0, len(d)) + + def test_filled(self): + original = {'b': 2, 'c': 3} + d = FilteredDict(('a', 'b'), original) + self.assertEqual(1, len(d)) + self.assertNotIn('a', d) + self.assertIn('b', d) + self.assertNotIn('c', d) + self.assertEqual(1, len(d.keys())) + self.assertEqual(1, len(d.values())) + self.assertEqual(1, len(d.items())) + self.assertRaises(KeyError, d.__getitem__, 'a') + self.assertEqual(2, d['b']) + di = d.iteritems() + self.assertEqual(('b', 2), di.next()) + self.assertRaises(StopIteration, di.next) + self.assertEqual(2, d.pop('b')) + self.assertEqual(0, len(d)) + self.assertEqual({'c': 3}, original) + d.update({'a': 1, 'b': 4}) + self.assertEqual({'a': 1, 'b': 4, 'c': 3}, original) + self.assertEqual(2, len(d)) + self.assertEqual(set((('a', 1), ('b', 4))), set(d.items())) + d.clear() + self.assertEqual(0, len(d)) + self.assertEqual({'c': 3}, original) + self.assertRaises(KeyError, d.__setitem__, 'c', 5) + self.assertRaises(KeyError, d.update, {'b': 2, 'c': 3}) + +if __name__ == '__main__': + unittest.main() |