Convert task execution time to float value

For tempest scenario test, task execution time extracted from tempest
log is a string rather than a number value. This causes type validation
error when task engine parses the task result. This patch fixes this
issue by converting this value to float type.

Change-Id: I95efb88c57b2d57609ad9a3934632c118b995301
Closes-Bug: #1566712
This commit is contained in:
yanyanhu 2016-04-06 04:26:30 -04:00
parent 590bccbe56
commit dc12401539
2 changed files with 17 additions and 1 deletions

View File

@ -48,7 +48,8 @@ def tempest_log_wrapper(func):
kwargs["log_file"])
if results:
total = results.total
scenario_obj._atomic_actions["test_execution"] = total["time"]
test_execution = float(total["time"])
scenario_obj._atomic_actions["test_execution"] = test_execution
if total.get("failures") or total.get("unexpected_success"):
raise TempestBenchmarkFailure([
test["name"] for test in six.itervalues(results.tests)

View File

@ -58,3 +58,18 @@ class TempestLogWrappersTestCase(test.TestCase):
target_func.assert_called_once_with(self.scenario,
log_file="log_file")
self.assertEqual(0, mock_tempfile.NamedTemporaryFile.call_count)
def test_func_time_result_is_string(self):
verifier = mock.MagicMock()
verifier.parse_results.return_value = mock.MagicMock(
total={"time": "0.1"}, tests={})
context = test.get_test_context()
context.update({"tmp_results_dir": "/tmp/dir", "verifier": verifier})
scenario = tempest.TempestScenario(context)
target_func = mock.MagicMock()
target_func.__name__ = "target_func"
func = utils.tempest_log_wrapper(target_func)
func(scenario)
self.assertEqual(0.1, scenario._atomic_actions["test_execution"])