From a082416462290e75bafea040ab370742a0959da2 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/plugins/openstack/context/keystone/users.py | 11 +++++++---- .../plugins/openstack/context/keystone/test_users.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/rally/plugins/openstack/context/keystone/users.py b/rally/plugins/openstack/context/keystone/users.py index f39c7931..2a956404 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/tests/unit/plugins/openstack/context/keystone/test_users.py b/tests/unit/plugins/openstack/context/keystone/test_users.py index 15704419..bd480dab 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"])