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
This commit is contained in:
Rohan Kanade
2014-07-01 12:56:54 +02:00
parent 5b7b9b343f
commit 5c4c55a970
3 changed files with 32 additions and 0 deletions

View File

@@ -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")

View File

@@ -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()

View File

@@ -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(