Matt Riedemann | 27bdb05 | 2014-07-30 14:57:55 -0700 | [diff] [blame] | 1 | # 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 | |
| 15 | import mock |
Matthew Treinish | 411130a | 2014-08-28 19:21:40 -0400 | [diff] [blame] | 16 | from tempest_lib.cli import base as cli_base |
Matt Riedemann | 27bdb05 | 2014-07-30 14:57:55 -0700 | [diff] [blame] | 17 | import testtools |
| 18 | |
| 19 | from tempest import cli |
Matthew Treinish | 411130a | 2014-08-28 19:21:40 -0400 | [diff] [blame] | 20 | from tempest import config |
Matt Riedemann | 27bdb05 | 2014-07-30 14:57:55 -0700 | [diff] [blame] | 21 | from tempest import exceptions |
| 22 | from tempest.tests import base |
Matthew Treinish | 411130a | 2014-08-28 19:21:40 -0400 | [diff] [blame] | 23 | from tempest.tests import fake_config |
Matt Riedemann | 27bdb05 | 2014-07-30 14:57:55 -0700 | [diff] [blame] | 24 | |
| 25 | |
| 26 | class TestMinClientVersion(base.TestCase): |
| 27 | """Tests for the min_client_version decorator. |
| 28 | """ |
| 29 | |
Matthew Treinish | 411130a | 2014-08-28 19:21:40 -0400 | [diff] [blame] | 30 | 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 Riedemann | 27bdb05 | 2014-07-30 14:57:55 -0700 | [diff] [blame] | 35 | 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 Treinish | 411130a | 2014-08-28 19:21:40 -0400 | [diff] [blame] | 44 | with mock.patch.object(cli_base, 'execute', |
Matt Riedemann | 27bdb05 | 2014-07-30 14:57:55 -0700 | [diff] [blame] | 45 | 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 Treinish | 411130a | 2014-08-28 19:21:40 -0400 | [diff] [blame] | 52 | cli_dir='/usr/local/bin', |
Matt Riedemann | 27bdb05 | 2014-07-30 14:57:55 -0700 | [diff] [blame] | 53 | 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 Treinish | 411130a | 2014-08-28 19:21:40 -0400 | [diff] [blame] | 64 | @mock.patch.object(cli_base, 'execute', return_value=' ') |
Matt Riedemann | 27bdb05 | 2014-07-30 14:57:55 -0700 | [diff] [blame] | 65 | 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') |