
Class `verification.verifiers.tempest.Tempest` contains next changes: Output from installation of virtual environment is not useful for users, so visibility of this output was changed and now only in debug mode it will be printed. The status of verification will be changed to 'FAILED' if something will go wrong in subproccess.call Two variables contain word 'tempest' in their names. This is redundant, so they were renamed: Tempest.tempest_base_path => Tempest.base_repo Tempest.tempest_path => Tempest._path Construction "os.path.join(Tempest.path, some_path)" was moved to method `Tempest.path`, since it used in many places. Method `Tempest.parse_results` should not be static, because it needed inner variable `Tempest.log_file_raw`, so this was fixed. "git remote update" is not needed in Tempest installation, so we can remove this call and decrease time of installation. In `rally.cmd.commands.verify.start` command, several issues were fixed: First function argument changed to "set_name" instead of "deploy_id". Reason: "deploy_id" have default value, so it should be the first in arguments. It will simplify command for end-users(launch 'rally verify start <set_name>' instead of 'rally verify start --set <set_name>'). Task commands have cool feature: save task_id in global variables, so results cmd can print the last task, without setting it id. This feature is ported in verification. Tests for verification contains a lot of tests, so they are splitted to separate classes(TempestVerifyTestCase, TempestInstallAndUninstallTestCase and etc). Also, new tests were added. Change-Id: I08a52a1e3ceb468ba619049573bcfe642aecbcaf
120 lines
4.9 KiB
Python
120 lines
4.9 KiB
Python
# Copyright 2014: Mirantis Inc.
|
|
# All Rights Reserved.
|
|
#
|
|
# 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 subprocess
|
|
|
|
import mock
|
|
|
|
from rally.benchmark.context import tempest
|
|
from rally import exceptions
|
|
from rally.verification.verifiers.tempest import config
|
|
from rally.verification.verifiers.tempest import tempest as tempest_verifier
|
|
from tests.unit import test
|
|
|
|
|
|
CONTEXT = "rally.benchmark.context.tempest"
|
|
TEMPEST = "rally.verification.verifiers.tempest.tempest"
|
|
|
|
|
|
class TempestContextTestCase(test.TestCase):
|
|
|
|
def setUp(self):
|
|
super(TempestContextTestCase, self).setUp()
|
|
task = mock.MagicMock()
|
|
task.task.deployment_uuid.return_value = "fake_uuid"
|
|
self.context = {"task": task}
|
|
|
|
@mock.patch(CONTEXT + ".os.mkdir")
|
|
@mock.patch(TEMPEST + ".Tempest.generate_config_file")
|
|
@mock.patch(TEMPEST + ".Tempest.is_configured", return_value=True)
|
|
@mock.patch(TEMPEST + ".Tempest.install")
|
|
@mock.patch(TEMPEST + ".Tempest.is_installed", return_value=True)
|
|
def test_setup(self, mock_is_install, mock_install, mock_is_cfg, mock_cfg,
|
|
mock_mkdir):
|
|
benchmark = tempest.Tempest(self.context)
|
|
|
|
benchmark.setup()
|
|
|
|
self.assertEqual(0, mock_install.call_count)
|
|
self.assertEqual(0, mock_cfg.call_count)
|
|
self.assertEqual('/dev/null', benchmark.verifier.log_file_raw)
|
|
|
|
@mock.patch(CONTEXT + ".os.mkdir")
|
|
@mock.patch(TEMPEST + ".Tempest.is_configured")
|
|
@mock.patch(TEMPEST + ".Tempest.is_installed", return_value=False)
|
|
@mock.patch(TEMPEST + ".Tempest.install")
|
|
def test_setup_failure_on_tempest_installation(
|
|
self, mock_install, mock_is_installed, mock_is_cfg, mock_mkdir):
|
|
mock_install.side_effect = tempest_verifier.TempestSetupFailure()
|
|
|
|
benchmark = tempest.Tempest(self.context)
|
|
|
|
self.assertRaises(exceptions.BenchmarkSetupFailure, benchmark.setup)
|
|
self.assertEqual(0, mock_is_cfg.call_count)
|
|
|
|
@mock.patch(CONTEXT + ".os.mkdir")
|
|
@mock.patch(TEMPEST + ".Tempest.is_configured", return_value=False)
|
|
@mock.patch(TEMPEST + ".Tempest.is_installed", return_value=True)
|
|
@mock.patch(TEMPEST + ".Tempest.generate_config_file")
|
|
def test_setup_failure_on_tempest_configuration(
|
|
self, mock_gen, mock_is_installed, mock_is_cfg, mock_mkdir):
|
|
mock_gen.side_effect = config.TempestConfigCreationFailure()
|
|
|
|
benchmark = tempest.Tempest(self.context)
|
|
|
|
self.assertRaises(exceptions.BenchmarkSetupFailure, benchmark.setup)
|
|
self.assertEqual(1, mock_is_cfg.call_count)
|
|
|
|
@mock.patch(CONTEXT + ".os.mkdir")
|
|
@mock.patch(TEMPEST + ".Tempest.is_configured", return_value=False)
|
|
@mock.patch(TEMPEST + ".Tempest.is_installed", return_value=True)
|
|
@mock.patch(TEMPEST + ".Tempest.generate_config_file")
|
|
def test_setup_with_no_configuration(
|
|
self, mock_gen, mock_is_installed, mock_is_cfg, mock_mkdir):
|
|
|
|
benchmark = tempest.Tempest(self.context)
|
|
benchmark.setup()
|
|
self.assertEqual(1, mock_is_installed.call_count)
|
|
self.assertEqual('/dev/null', benchmark.verifier.log_file_raw)
|
|
self.assertEqual(1, mock_gen.call_count)
|
|
|
|
@mock.patch(CONTEXT + ".os.path.exists", return_value=True)
|
|
@mock.patch(CONTEXT + ".shutil")
|
|
@mock.patch(CONTEXT + ".subprocess")
|
|
def test_cleanup(self, mock_sp, mock_shutil, mock_os_path_exists):
|
|
benchmark = tempest.Tempest(self.context)
|
|
benchmark.verifier = mock.MagicMock()
|
|
benchmark.results_dir = "/tmp/path"
|
|
|
|
benchmark.cleanup()
|
|
|
|
mock_sp.check_call.assert_called_once_with(
|
|
"cd %s && %s python tempest/stress/tools/cleanup.py" %
|
|
(benchmark.verifier.path, benchmark.verifier.venv_wrapper),
|
|
shell=True, cwd=benchmark.verifier.path,
|
|
env=benchmark.verifier.env)
|
|
mock_shutil.rmtree.assert_called_once_with("/tmp/path")
|
|
|
|
@mock.patch(CONTEXT + ".os.path.exists", return_value=False)
|
|
@mock.patch(CONTEXT + ".shutil")
|
|
@mock.patch(CONTEXT + ".subprocess")
|
|
def test_cleanup_fail(self, mock_sp, mock_shutil, mock_os_path_exists):
|
|
benchmark = tempest.Tempest(self.context)
|
|
benchmark.verifier = mock.MagicMock()
|
|
benchmark.results_dir = "/tmp/path"
|
|
benchmark.cleanup()
|
|
mock_sp.check_call.side_effect = subprocess.CalledProcessError(0, '')
|
|
self.assertRaises(subprocess.CalledProcessError, benchmark.cleanup)
|