From 5c4c55a970a0b165a6cf35339af8fee96221ef16 Mon Sep 17 00:00:00 2001 From: Rohan Kanade Date: Tue, 1 Jul 2014 12:56:54 +0200 Subject: [PATCH] Check python>=2.7 before running tempest * Tempest requires python>=2.7 * Check python version >=2.7 before installing virtualenv for tempest Change-Id: I89048652d879fd3907f1628887dd6cc1e6e3ba3e Closes-Bug: #1336209 --- rally/exceptions.py | 5 +++++ rally/verification/verifiers/tempest/tempest.py | 11 +++++++++++ tests/verification/verifiers/test_tempest.py | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/rally/exceptions.py b/rally/exceptions.py index c499ef5652..dbe3947d07 100644 --- a/rally/exceptions.py +++ b/rally/exceptions.py @@ -246,3 +246,8 @@ class UnknownRelease(RallyException): class ImageCleanUpException(RallyException): msg_fmt = _("Image Deletion Failed") + + +class IncompatiblePythonVersion(RallyException): + msg_fmt = _("Incompatible python version found '%(version)s', " + "required at least python>=2.7.x") diff --git a/rally/verification/verifiers/tempest/tempest.py b/rally/verification/verifiers/tempest/tempest.py index 13a829d760..9bded40757 100644 --- a/rally/verification/verifiers/tempest/tempest.py +++ b/rally/verification/verifiers/tempest/tempest.py @@ -18,6 +18,7 @@ import logging import os import shutil import subprocess +import sys from rally import exceptions from rally.openstack.common.gettextutils import _ @@ -63,6 +64,8 @@ class Tempest(object): def _install_venv(self): if not os.path.isdir(os.path.join(self.tempest_path, '.venv')): + LOG.info('Validating python environment') + self.validate_env() LOG.info("No virtual environment found...Install the virtualenv.") LOG.debug("Virtual environment directory: %s" % os.path.join(self.tempest_path, ".venv")) @@ -230,6 +233,14 @@ class Tempest(object): self.verification.finish_verification(total=total, test_cases=test_cases) + def validate_env(self): + """Validate environment parameters required for running tempest + eg: python>2.7 + """ + if sys.version_info < (2, 7): + raise exceptions.IncompatiblePythonVersion( + version=sys.version_info) + def verify(self, set_name, regex): self._prepare_and_run(set_name, regex) self._save_results() diff --git a/tests/verification/verifiers/test_tempest.py b/tests/verification/verifiers/test_tempest.py index f0e54bf977..2e45894940 100644 --- a/tests/verification/verifiers/test_tempest.py +++ b/tests/verification/verifiers/test_tempest.py @@ -14,9 +14,12 @@ # under the License. import os +import sys import mock +import testtools +from rally import exceptions from rally.openstack.common import jsonutils from rally.verification.verifiers.tempest import subunit2json from rally.verification.verifiers.tempest import tempest @@ -125,6 +128,7 @@ class TempestTestCase(test.TestCase): @mock.patch('os.path.isdir') @mock.patch(TEMPEST_PATH + '.tempest.subprocess') + @testtools.skipIf(sys.version_info < (2, 7), "Incompatible Python Version") def test__venv_install_when_venv_exists(self, mock_sp, mock_isdir): mock_isdir.return_value = True self.verifier._install_venv() @@ -135,6 +139,7 @@ class TempestTestCase(test.TestCase): @mock.patch('os.path.isdir') @mock.patch(TEMPEST_PATH + '.tempest.subprocess.check_call') + @testtools.skipIf(sys.version_info < (2, 7), "Incompatible Python Version") def test__venv_install_when_venv_not_exist(self, mock_sp, mock_isdir): mock_isdir.return_value = False self.verifier._install_venv() @@ -148,6 +153,17 @@ class TempestTestCase(test.TestCase): self.verifier.venv_wrapper, shell=True, cwd=self.verifier.tempest_path)]) + @mock.patch('os.path.isdir') + @testtools.skipIf(sys.version_info >= (2, 7), + "Incompatible Python Version") + def test__venv_install_for_py26_fails(self, mock_isdir): + mock_isdir.return_value = False + self.assertRaises(exceptions.IncompatiblePythonVersion, + self.verifier._install_venv) + + mock_isdir.assert_called_once_with( + os.path.join(self.verifier.tempest_path, '.venv')) + @mock.patch('os.path.isdir') @mock.patch(TEMPEST_PATH + '.tempest.subprocess') def test__initialize_testr_when_testr_already_initialized(