From e862f86e3f8f6c0770a53cf4772f9b8b6df388d5 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 16 Oct 2015 07:46:25 -0500 Subject: [PATCH] Implement new random name generator for keystone scenarios This switches keystone scenarios to using the new consistent random name generator. Implements blueprint: consistent-resource-names Change-Id: Ie753b6c6b570ce40bd17df545df4a2cde2c4bc50 --- .../openstack/scenario/keystone.yaml | 6 +- .../tutorial/step_2_input_task_format.rst | 4 +- doc/source/tutorial/step_5_task_templates.rst | 18 ++--- rally-jobs/rally-mos.yaml | 19 ++--- rally-jobs/rally.yaml | 26 +++---- .../openstack/scenarios/keystone/basic.py | 64 ++++++----------- .../openstack/scenarios/keystone/utils.py | 40 +++++------ rally/task/scenario.py | 13 +++- .../keystone/create-and-delete-user.json | 4 +- .../keystone/create-and-delete-user.yaml | 3 +- .../keystone/create-and-list-tenants.json | 4 +- .../keystone/create-and-list-tenants.yaml | 3 +- .../keystone/create-and-list-users.json | 4 +- .../keystone/create-and-list-users.yaml | 3 +- .../keystone/create-tenant-with-users.json | 1 - .../keystone/create-tenant-with-users.yaml | 1 - .../scenarios/keystone/create-tenant.json | 4 +- .../scenarios/keystone/create-tenant.yaml | 3 +- .../create-update-and-delete-tenant.json | 4 +- .../create-update-and-delete-tenant.yaml | 3 +- .../tasks/scenarios/keystone/create-user.json | 4 +- .../tasks/scenarios/keystone/create-user.yaml | 3 +- .../keystone/create_user_update_password.json | 7 +- .../keystone/create_user_update_password.yaml | 6 +- samples/tasks/sla/create-and-delete-user.json | 4 +- samples/tasks/sla/create-and-delete-user.yaml | 3 +- tests/functional/test_cli_task.py | 2 +- .../scenarios/keystone/test_basic.py | 65 +++++++---------- .../scenarios/keystone/test_utils.py | 70 ++++++++----------- tests/unit/task/test_scenario.py | 53 -------------- 30 files changed, 141 insertions(+), 303 deletions(-) diff --git a/certification/openstack/scenario/keystone.yaml b/certification/openstack/scenario/keystone.yaml index cce279b871..a79a8c582a 100644 --- a/certification/openstack/scenario/keystone.yaml +++ b/certification/openstack/scenario/keystone.yaml @@ -18,8 +18,6 @@ KeystoneBasic.create_and_list_tenants: - - args: - name_length: 10 context: {{ user_context(tenants_amount, users_amount, use_existing_users) }} runner: @@ -56,11 +54,9 @@ KeystoneBasic.create_update_and_delete_tenant: - - args: - name_length: 10 context: {{ user_context(tenants_amount, users_amount, use_existing_users) }} runner: {{ constant_runner(15*controllers_amount,60*controllers_amount) }} sla: - {{ no_failures_sla() }} \ No newline at end of file + {{ no_failures_sla() }} diff --git a/doc/source/tutorial/step_2_input_task_format.rst b/doc/source/tutorial/step_2_input_task_format.rst index 022ed8456c..33bb909262 100644 --- a/doc/source/tutorial/step_2_input_task_format.rst +++ b/doc/source/tutorial/step_2_input_task_format.rst @@ -84,9 +84,7 @@ As an example, let's edit our configuration file from :ref:`step 1 7) - - def test_is_temporary(self): - prefix = utils.KeystoneScenario.RESOURCE_NAME_PREFIX - tests = [ - (fakes.FakeResource(name=prefix + "abc"), True), - (fakes.FakeResource(name="another"), False), - (fakes.FakeResource(name=prefix[:-3] + "abc"), False) - ] - - for resource, is_valid in tests: - self.assertEqual(utils.is_temporary(resource), is_valid) + @mock.patch("rally.common.utils.name_matches_object") + def test_is_temporary(self, mock_name_matches_object): + resource = mock.Mock() + self.assertEqual(utils.is_temporary(resource), + mock_name_matches_object.return_value) + mock_name_matches_object.assert_called_once_with( + resource.name, utils.KeystoneScenario) class KeystoneScenarioTestCase(test.ScenarioTestCase): - @mock.patch(UTILS + "uuid.uuid4", return_value="pwd") - @mock.patch("rally.common.utils.generate_random_name", - return_value="foobarov") - def test_user_create(self, mock_generate_random_name, mock_uuid4): + @mock.patch("uuid.uuid4", return_value="pwd") + def test_user_create(self, mock_uuid4): scenario = utils.KeystoneScenario(self.context) + scenario.generate_random_name = mock.Mock(return_value="foobarov") result = scenario._user_create() self.assertEqual( @@ -77,15 +64,15 @@ class KeystoneScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.update_user_enabled") - @mock.patch("rally.common.utils.generate_random_name") - def test_role_create(self, mock_generate_random_name): + def test_role_create(self): scenario = utils.KeystoneScenario(self.context) + scenario.generate_random_name = mock.Mock() result = scenario._role_create() self.assertEqual( self.admin_clients("keystone").roles.create.return_value, result) self.admin_clients("keystone").roles.create.assert_called_once_with( - mock_generate_random_name.return_value) + scenario.generate_random_name.return_value) self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.create_role") @@ -142,24 +129,23 @@ class KeystoneScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.remove_role") - @mock.patch("rally.common.utils.generate_random_name") - def test_tenant_create(self, mock_generate_random_name): + def test_tenant_create(self): scenario = utils.KeystoneScenario(self.context) + scenario.generate_random_name = mock.Mock() result = scenario._tenant_create() self.assertEqual( self.admin_clients("keystone").tenants.create.return_value, result) self.admin_clients("keystone").tenants.create.assert_called_once_with( - mock_generate_random_name.return_value) + scenario.generate_random_name.return_value) self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.create_tenant") def test_service_create(self): service_type = "service_type" - description = "_description" - + description = "description" scenario = utils.KeystoneScenario(self.context) - scenario._generate_random_name = mock.Mock() + scenario.generate_random_name = mock.Mock() result = scenario._service_create(service_type=service_type, description=description) @@ -168,18 +154,17 @@ class KeystoneScenarioTestCase(test.ScenarioTestCase): self.admin_clients("keystone").services.create.return_value, result) self.admin_clients("keystone").services.create.assert_called_once_with( - scenario._generate_random_name.return_value, + scenario.generate_random_name.return_value, service_type, description) self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.create_service") - @mock.patch("rally.common.utils.generate_random_name", - return_value="foobarov") - def test_tenant_create_with_users(self, mock_generate_random_name): + def test_tenant_create_with_users(self): tenant = mock.MagicMock() scenario = utils.KeystoneScenario(self.context) + scenario.generate_random_name = mock.Mock(return_value="foobarov") - scenario._users_create(tenant, users_per_tenant=1, name_length=10) + scenario._users_create(tenant, users_per_tenant=1) self.admin_clients("keystone").users.create.assert_called_once_with( "foobarov", password="foobarov", email="foobarov@rally.me", @@ -261,14 +246,15 @@ class KeystoneScenarioTestCase(test.ScenarioTestCase): def test_update_tenant(self): tenant = mock.MagicMock() - description = tenant.name + "_description_updated_test" - name = tenant.name + "test_updated_test" + description = "new description" + scenario = utils.KeystoneScenario(self.context) - scenario._update_tenant(tenant=tenant, name=name, - description=description) + scenario.generate_random_name = mock.Mock() + scenario._update_tenant(tenant=tenant, description=description) self.admin_clients("keystone").tenants.update.assert_called_once_with( - tenant.id, name, description) + tenant.id, scenario.generate_random_name.return_value, + description) self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.update_tenant") diff --git a/tests/unit/task/test_scenario.py b/tests/unit/task/test_scenario.py index d66edb2e46..59bcd40c50 100644 --- a/tests/unit/task/test_scenario.py +++ b/tests/unit/task/test_scenario.py @@ -16,7 +16,6 @@ import traceback import mock -import six from rally import consts from rally import exceptions @@ -219,55 +218,3 @@ class ScenarioTestCase(test.TestCase): print(traceback.format_exc()) self.assertTrue(False, "Scenario `%s` has wrong context" % scenario) - - def test_RESOURCE_NAME_PREFIX(self): - self.assertIsInstance(scenario.Scenario.RESOURCE_NAME_PREFIX, - six.string_types) - - def test_RESOURCE_NAME_LENGTH(self): - self.assertIsInstance(scenario.Scenario.RESOURCE_NAME_LENGTH, int) - self.assertTrue(scenario.Scenario.RESOURCE_NAME_LENGTH > 4) - - def test_generate_random_name(self): - set_by_length = lambda lst: set(map(len, lst)) - len_by_prefix = (lambda lst, prefix: - len([i.startswith(prefix) for i in lst])) - range_num = 50 - - # Defaults - result = [scenario.Scenario._generate_random_name() - for i in range(range_num)] - self.assertEqual(len(result), len(set(result))) - self.assertEqual( - set_by_length(result), - set([(len( - scenario.Scenario.RESOURCE_NAME_PREFIX) + - scenario.Scenario.RESOURCE_NAME_LENGTH)])) - self.assertEqual( - len_by_prefix(result, scenario.Scenario.RESOURCE_NAME_PREFIX), - range_num) - - # Custom prefix - prefix = "another_prefix_" - result = [scenario.Scenario._generate_random_name(prefix) - for i in range(range_num)] - self.assertEqual(len(result), len(set(result))) - self.assertEqual( - set_by_length(result), - set([len(prefix) + scenario.Scenario.RESOURCE_NAME_LENGTH])) - self.assertEqual( - len_by_prefix(result, prefix), range_num) - - # Custom length - name_length = 12 - result = [ - scenario.Scenario._generate_random_name(length=name_length) - for i in range(range_num)] - self.assertEqual(len(result), len(set(result))) - self.assertEqual( - set_by_length(result), - set([len( - scenario.Scenario.RESOURCE_NAME_PREFIX) + name_length])) - self.assertEqual( - len_by_prefix(result, scenario.Scenario.RESOURCE_NAME_PREFIX), - range_num)