diff --git a/tempest_lib/cli/base.py b/tempest_lib/cli/base.py index ce18734..3b7a5bf 100644 --- a/tempest_lib/cli/base.py +++ b/tempest_lib/cli/base.py @@ -13,18 +13,14 @@ # License for the specific language governing permissions and limitations # under the License. -import functools import logging import os import shlex import subprocess -import testtools - from tempest_lib import base import tempest_lib.cli.output_parser from tempest_lib import exceptions -from tempest_lib.openstack.common import versionutils LOG = logging.getLogger(__name__) @@ -51,44 +47,6 @@ def execute(cmd, action, flags='', params='', fail_ok=False, return result -def check_client_version(client, version): - """Checks if the client's version is compatible with the given version - - @param client: The client to check. - @param version: The version to compare against. - @return: True if the client version is compatible with the given version - parameter, False otherwise. - """ - current_version = execute(client, '', params='--version', - merge_stderr=True) - - if not current_version.strip(): - raise exceptions.TempestException('"%s --version" output was empty' % - client) - - return versionutils.is_compatible(version, current_version, - same_major=False) - - -def min_client_version(*args, **kwargs): - """A decorator to skip tests if the client used isn't of the right version. - - @param client: The client command to run. For python-novaclient, this is - 'nova', for python-cinderclient this is 'cinder', etc. - @param version: The minimum version required to run the CLI test. - """ - def decorator(func): - @functools.wraps(func) - def wrapper(*func_args, **func_kwargs): - if not check_client_version(kwargs['client'], kwargs['version']): - msg = "requires %s client version >= %s" % (kwargs['client'], - kwargs['version']) - raise testtools.TestCase.skipException(msg) - return func(*func_args, **func_kwargs) - return wrapper - return decorator - - class CLIClientBase(object): def __init__(self, username='', password='', tenant_name='', uri='', cli_dir='', *args, **kwargs): diff --git a/tempest_lib/tests/cli/test_cli.py b/tempest_lib/tests/cli/test_cli.py deleted file mode 100644 index 9d24b0e..0000000 --- a/tempest_lib/tests/cli/test_cli.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2014 IBM Corp. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -import testtools - -from tempest_lib.cli import base as cli -from tempest_lib import exceptions -from tempest_lib.tests import base - - -class TestMinClientVersion(base.TestCase): - """Tests for the min_client_version decorator.""" - - def _test_min_version(self, required, installed, expect_skip): - - @cli.min_client_version(client='nova', version=required) - def fake(self, expect_skip): - if expect_skip: - # If we got here, the decorator didn't raise a skipException as - # expected so we need to fail. - self.fail('Should not have gotten past the decorator.') - - with mock.patch.object(cli, 'execute', - return_value=installed) as mock_cmd: - if expect_skip: - self.assertRaises(testtools.TestCase.skipException, fake, - self, expect_skip) - else: - fake(self, expect_skip) - mock_cmd.assert_called_once_with('nova', '', params='--version', - merge_stderr=True) - - def test_min_client_version(self): - # required, installed, expect_skip - cases = (('2.17.0', '2.17.0', False), - ('2.17.0', '2.18.0', False), - ('2.18.0', '2.17.0', True)) - - for case in cases: - self._test_min_version(*case) - - @mock.patch.object(cli, 'execute', return_value=' ') - def test_check_client_version_empty_output(self, mock_execute): - # Tests that an exception is raised if the command output is empty. - self.assertRaises(exceptions.TempestException, - cli.check_client_version, 'nova', '2.18.0')