blob: 8f18dfccb736dcbf69f7bd2f767cebb44c33eb38 [file] [log] [blame]
Matt Riedemann27bdb052014-07-30 14:57:55 -07001# Copyright 2014 IBM Corp.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import mock
Matthew Treinish411130a2014-08-28 19:21:40 -040016from tempest_lib.cli import base as cli_base
Matt Riedemann27bdb052014-07-30 14:57:55 -070017import testtools
18
19from tempest import cli
Matthew Treinish411130a2014-08-28 19:21:40 -040020from tempest import config
Matt Riedemann27bdb052014-07-30 14:57:55 -070021from tempest import exceptions
22from tempest.tests import base
Matthew Treinish411130a2014-08-28 19:21:40 -040023from tempest.tests import fake_config
Matt Riedemann27bdb052014-07-30 14:57:55 -070024
25
26class TestMinClientVersion(base.TestCase):
27 """Tests for the min_client_version decorator.
28 """
29
Matthew Treinish411130a2014-08-28 19:21:40 -040030 def setUp(self):
31 super(TestMinClientVersion, self).setUp()
32 self.useFixture(fake_config.ConfigFixture())
33 self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
34
Matt Riedemann27bdb052014-07-30 14:57:55 -070035 def _test_min_version(self, required, installed, expect_skip):
36
37 @cli.min_client_version(client='nova', version=required)
38 def fake(self, expect_skip):
39 if expect_skip:
40 # If we got here, the decorator didn't raise a skipException as
41 # expected so we need to fail.
42 self.fail('Should not have gotten past the decorator.')
43
Matthew Treinish411130a2014-08-28 19:21:40 -040044 with mock.patch.object(cli_base, 'execute',
Matt Riedemann27bdb052014-07-30 14:57:55 -070045 return_value=installed) as mock_cmd:
46 if expect_skip:
47 self.assertRaises(testtools.TestCase.skipException, fake,
48 self, expect_skip)
49 else:
50 fake(self, expect_skip)
51 mock_cmd.assert_called_once_with('nova', '', params='--version',
Matthew Treinish411130a2014-08-28 19:21:40 -040052 cli_dir='/usr/local/bin',
Matt Riedemann27bdb052014-07-30 14:57:55 -070053 merge_stderr=True)
54
55 def test_min_client_version(self):
56 # required, installed, expect_skip
57 cases = (('2.17.0', '2.17.0', False),
58 ('2.17.0', '2.18.0', False),
59 ('2.18.0', '2.17.0', True))
60
61 for case in cases:
62 self._test_min_version(*case)
63
Matthew Treinish411130a2014-08-28 19:21:40 -040064 @mock.patch.object(cli_base, 'execute', return_value=' ')
Matt Riedemann27bdb052014-07-30 14:57:55 -070065 def test_check_client_version_empty_output(self, mock_execute):
66 # Tests that an exception is raised if the command output is empty.
67 self.assertRaises(exceptions.TempestException,
68 cli.check_client_version, 'nova', '2.18.0')