summaryrefslogtreecommitdiffstats
path: root/test/cmdver
diff options
context:
space:
mode:
Diffstat (limited to 'test/cmdver')
-rw-r--r--test/cmdver/README.md1
-rw-r--r--test/cmdver/lmi/__init__.py27
-rw-r--r--test/cmdver/lmi/scripts/__init__.py27
-rw-r--r--test/cmdver/lmi/scripts/cmdver/__init__.py135
-rw-r--r--test/cmdver/lmi/scripts/cmdver/devel.py32
-rw-r--r--test/cmdver/lmi/scripts/cmdver/pre042.py32
-rw-r--r--test/cmdver/lmi/scripts/cmdver/swbase.py51
-rw-r--r--test/cmdver/lmi/scripts/cmdver/ver042.py32
-rw-r--r--test/cmdver/setup.py48
9 files changed, 385 insertions, 0 deletions
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',
+ ],
+ },
+ )