From bc1cde83298e0f407a5739a4bd8df114dbe9d4b7 Mon Sep 17 00:00:00 2001 From: Alexander Maretskiy Date: Tue, 12 Jul 2016 18:51:27 +0300 Subject: [PATCH] [Core] Make iterations numeration starting from `1' As discussed on daily meeting, iterations numbers in logging and reports must be synchronized and starting from `1' Change-Id: I5967c51b033e1a98f2617c5aa8f8e7916de90a08 --- rally/common/objects/task.py | 6 ++++-- rally/plugins/openstack/context/keystone/users.py | 11 +++++++---- rally/task/processing/plot.py | 2 +- rally/task/runner.py | 2 +- tests/unit/plugins/common/runners/test_serial.py | 2 +- .../plugins/openstack/context/keystone/test_users.py | 2 +- tests/unit/task/test_runner.py | 2 +- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/rally/common/objects/task.py b/rally/common/objects/task.py index 2f6a328bd1..a44175a50a 100644 --- a/rally/common/objects/task.py +++ b/rally/common/objects/task.py @@ -468,10 +468,12 @@ class Task(object): "tstamp_start": tstamp_start, "full_duration": scenario["data"]["full_duration"], "load_duration": scenario["data"]["load_duration"]} + iterations = sorted(scenario["data"]["raw"], + key=lambda itr: itr["timestamp"]) if serializable: - scenario["iterations"] = scenario["data"]["raw"] + scenario["iterations"] = list(iterations) else: - scenario["iterations"] = iter(scenario["data"]["raw"]) + scenario["iterations"] = iter(iterations) scenario["sla"] = scenario["data"]["sla"] del scenario["data"] del scenario["task_uuid"] diff --git a/rally/plugins/openstack/context/keystone/users.py b/rally/plugins/openstack/context/keystone/users.py index f39c793196..2a956404ee 100644 --- a/rally/plugins/openstack/context/keystone/users.py +++ b/rally/plugins/openstack/context/keystone/users.py @@ -87,12 +87,15 @@ class UserContextMixin(object): else: # Second and last case - 'round_robin'. tenants_amount = len(context_obj["tenants"]) - tenant_id = sorted(context_obj["tenants"].keys())[ - context_obj["iteration"] % tenants_amount] + # NOTE(amaretskiy): iteration is subtracted by `1' because it + # starts from `1' but we count from `0' + tenant_index = int((context_obj["iteration"] - 1) % tenants_amount) + tenant_id = sorted(context_obj["tenants"].keys())[tenant_index] tenant = context_obj["tenants"][tenant_id] users = context_obj["tenants"][tenant_id]["users"] - user = users[ - int(context_obj["iteration"] / tenants_amount) % len(users)] + user_index = int(((context_obj["iteration"] - 1) / tenants_amount) + % len(users)) + user = users[user_index] scenario_ctx["user"], scenario_ctx["tenant"] = user, tenant diff --git a/rally/task/processing/plot.py b/rally/task/processing/plot.py index e2040d966d..3219a2c3e9 100644 --- a/rally/task/processing/plot.py +++ b/rally/task/processing/plot.py @@ -38,7 +38,7 @@ def _process_scenario(data, pos): output_errors = [] additive_output_charts = [] complete_output = [] - for idx, itr in enumerate(data["iterations"]): + for idx, itr in enumerate(data["iterations"], 1): if itr["error"]: typ, msg, trace = itr["error"] errors.append({"iteration": idx, diff --git a/rally/task/runner.py b/rally/task/runner.py index fc2bfecf13..4a4faba91f 100644 --- a/rally/task/runner.py +++ b/rally/task/runner.py @@ -47,7 +47,7 @@ def format_result_on_timeout(exc, timeout): def _get_scenario_context(iteration, context_obj): context_obj = copy.deepcopy(context_obj) - context_obj["iteration"] = iteration + context_obj["iteration"] = iteration + 1 # Numeration starts from `1' return context.ContextManager(context_obj).map_for_scenario() diff --git a/tests/unit/plugins/common/runners/test_serial.py b/tests/unit/plugins/common/runners/test_serial.py index 2f24c86f74..c28928fff8 100644 --- a/tests/unit/plugins/common/runners/test_serial.py +++ b/tests/unit/plugins/common/runners/test_serial.py @@ -43,7 +43,7 @@ class SerialScenarioRunnerTestCase(test.TestCase): expected_calls = [] for i in range(times): ctxt = fakes.FakeContext().context - ctxt["iteration"] = i + ctxt["iteration"] = i + 1 ctxt["task"] = mock.ANY expected_calls.append( mock.call(fakes.FakeScenario, "do_it", ctxt, {}) diff --git a/tests/unit/plugins/openstack/context/keystone/test_users.py b/tests/unit/plugins/openstack/context/keystone/test_users.py index 157044192a..bd480dab61 100644 --- a/tests/unit/plugins/openstack/context/keystone/test_users.py +++ b/tests/unit/plugins/openstack/context/keystone/test_users.py @@ -120,7 +120,7 @@ class UserContextMixinTestCase(test.TestCase): } expected_ids = ["0_0", "1_0", "0_1", "1_1"] * 4 mapped_ids = [] - for i in range(16): + for i in range(1, 17): context["iteration"] = i user = self.mixin.map_for_scenario(context) mapped_ids.append(user["user"]["id"]) diff --git a/tests/unit/task/test_runner.py b/tests/unit/task/test_runner.py index 220cd7c8c8..6ab0af5495 100644 --- a/tests/unit/task/test_runner.py +++ b/tests/unit/task/test_runner.py @@ -59,7 +59,7 @@ class ScenarioRunnerHelpersTestCase(test.TestCase): result ) - mock_context_manager.assert_called_once_with({"iteration": 13}) + mock_context_manager.assert_called_once_with({"iteration": 14}) mock_map_for_scenario.assert_called_once_with() def test_run_scenario_once_internal_logic(self):