diff --git a/rally-jobs/rally.yaml b/rally-jobs/rally.yaml index 433bbb9707..4a758334b0 100755 --- a/rally-jobs/rally.yaml +++ b/rally-jobs/rally.yaml @@ -98,6 +98,16 @@ failure_rate: max: 0 + KeystoneBasic.create_and_delete_service: + - + runner: + type: "constant" + times: 10 + concurrency: 5 + sla: + failure_rate: + max: 0 + CeilometerAlarms.create_alarm: - args: @@ -1453,9 +1463,9 @@ - args: flavor: - name: "m1.tiny" + name: "m1.tiny" image: - name: {{image_name}} + name: {{image_name}} runner: type: "constant" times: 3 @@ -1466,4 +1476,4 @@ users_per_tenant: 1 sla: failure_rate: - max: 0 + max: 0 \ No newline at end of file diff --git a/rally/benchmark/scenarios/keystone/basic.py b/rally/benchmark/scenarios/keystone/basic.py index 41dc05c302..00b8d29e7e 100644 --- a/rally/benchmark/scenarios/keystone/basic.py +++ b/rally/benchmark/scenarios/keystone/basic.py @@ -111,3 +111,16 @@ class KeystoneBasic(kutils.KeystoneScenario): self._get_role(role.id) service = self._get_service_by_name("keystone") self._get_service(service.id) + + @validation.required_openstack(admin=True) + @base.scenario(context={"admin_cleanup": ["keystone"]}) + def create_and_delete_service(self, name=None, service_type=None, + description=None): + """Create and delete service. + + :param name: name of the service + :param service_type: type of the service + :param description: description of the service + """ + service = self._service_create(name, service_type, description) + self._delete_service(service.id) diff --git a/rally/benchmark/scenarios/keystone/utils.py b/rally/benchmark/scenarios/keystone/utils.py index a23fd0e87e..0f7f9e0f1a 100644 --- a/rally/benchmark/scenarios/keystone/utils.py +++ b/rally/benchmark/scenarios/keystone/utils.py @@ -62,6 +62,23 @@ class KeystoneScenario(base.Scenario): name = self._generate_random_name(length=name_length) return self.admin_clients("keystone").tenants.create(name, **kwargs) + @base.atomic_action_timer("keystone.create_service") + def _service_create(self, name=None, service_type="rally_test_type", + description=None): + """Creates keystone service with random name. + + :param name: name of the service + :param service_type: type of the service + :param description: description of the service + :returns: keystone service instance + """ + name = name or self._generate_random_name(prefix="rally_test_service_") + description = description or self._generate_random_name( + prefix="rally_test_service_description_") + return self.admin_clients("keystone").services.create(name, + service_type, + description) + @base.atomic_action_timer("keystone.create_users") def _users_create(self, tenant, users_per_tenant, name_length=10): """Adds users to a tenant. @@ -139,3 +156,11 @@ class KeystoneScenario(base.Scenario): for i in self._list_services(): if i.name == name: return i + + @base.atomic_action_timer("keystone.delete_service") + def _delete_service(self, service_id): + """Delete service. + + :param service_id: service to be deleted + """ + self.admin_clients("keystone").services.delete(service_id) diff --git a/samples/tasks/scenarios/keystone/create-and-delete-service.json b/samples/tasks/scenarios/keystone/create-and-delete-service.json new file mode 100644 index 0000000000..ce649e333e --- /dev/null +++ b/samples/tasks/scenarios/keystone/create-and-delete-service.json @@ -0,0 +1,16 @@ +{ + "KeystoneBasic.create_and_delete_service": [ + { + "args": { + "name": "Rally_test_service", + "service_type": "Really_test_type", + "description": "test_description" + }, + "runner": { + "type": "constant", + "times": 100, + "concurrency": 10 + } + } + ] +} \ No newline at end of file diff --git a/samples/tasks/scenarios/keystone/create-and-delete-service.yaml b/samples/tasks/scenarios/keystone/create-and-delete-service.yaml new file mode 100644 index 0000000000..a1895262cb --- /dev/null +++ b/samples/tasks/scenarios/keystone/create-and-delete-service.yaml @@ -0,0 +1,11 @@ +--- + KeystoneBasic.create_and_delete_service: + - + args: + name: "Rally_test_service" + service_type: "Really_test_type" + description: "test_description" + runner: + type: "constant" + times: 100 + concurrency: 10 \ No newline at end of file diff --git a/tests/unit/benchmark/scenarios/keystone/test_basic.py b/tests/unit/benchmark/scenarios/keystone/test_basic.py index 22c0944dda..91cf3ab458 100644 --- a/tests/unit/benchmark/scenarios/keystone/test_basic.py +++ b/tests/unit/benchmark/scenarios/keystone/test_basic.py @@ -124,3 +124,19 @@ class KeystoneBasicTestCase(test.TestCase): scenario._get_role.assert_called_once_with(fake_role.id) scenario._get_service_by_name("keystone") scenario._get_service.assert_called_once_with(fake_service.id) + + def test_create_and_delete_service(self): + scenario = basic.KeystoneBasic() + name = "Rally_test_service" + service_type = "rally_test_type" + description = "test_description" + fake_service = mock.MagicMock() + scenario._service_create = mock.MagicMock(return_value=fake_service) + scenario._delete_service = mock.MagicMock() + scenario.create_and_delete_service(name=name, + service_type=service_type, + description=description) + scenario._service_create.assert_called_once_with(name, + service_type, + description) + scenario._delete_service.assert_called_once_with(fake_service.id) diff --git a/tests/unit/benchmark/scenarios/keystone/test_utils.py b/tests/unit/benchmark/scenarios/keystone/test_utils.py index 1c6b963317..ccfba83fb6 100644 --- a/tests/unit/benchmark/scenarios/keystone/test_utils.py +++ b/tests/unit/benchmark/scenarios/keystone/test_utils.py @@ -121,6 +121,31 @@ class KeystoneScenarioTestCase(test.TestCase): self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.create_tenant") + @mock.patch(UTILS + "KeystoneScenario._generate_random_name") + def test_service_create(self, mock_gen_name): + name = "abc" + mock_gen_name.return_value = name + service_type = name + "service_type" + description = name + "_description" + + service = {} + fake_keystone = fakes.FakeKeystoneClient() + fake_keystone.services.create = mock.MagicMock(return_value=service) + fake_clients = fakes.FakeClients() + fake_clients._keystone = fake_keystone + scenario = utils.KeystoneScenario(admin_clients=fake_clients) + + result = scenario._service_create(name=name, + service_type=service_type, + description=description) + + self.assertEqual(service, result) + fake_keystone.services.create.assert_called_once_with(name, + service_type, + description) + self._test_atomic_action_timer(scenario.atomic_actions(), + "keystone.create_service") + @mock.patch(UTILS + "KeystoneScenario._generate_random_name") def test_tenant_create_with_users(self, mock_gen_name): name = "abc" @@ -163,6 +188,33 @@ class KeystoneScenarioTestCase(test.TestCase): self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.list_tenants") + def test_list_services(self): + fake_keystone = fakes.FakeKeystoneClient() + fake_keystone.services.list = mock.MagicMock() + fake_clients = fakes.FakeClients() + fake_clients._keystone = fake_keystone + scenario = utils.KeystoneScenario(admin_clients=fake_clients) + + scenario._list_services() + + fake_keystone.services.list.assert_called_once_with() + self._test_atomic_action_timer(scenario.atomic_actions(), + "keystone.service_list") + + def test_delete_service(self): + service = mock.MagicMock() + fake_keystone = fakes.FakeKeystoneClient() + fake_keystone.services.delete = mock.MagicMock() + fake_clients = fakes.FakeClients() + fake_clients._keystone = fake_keystone + scenario = utils.KeystoneScenario(admin_clients=fake_clients) + + scenario._delete_service(service_id=service.id) + + fake_keystone.services.delete.assert_called_once_with(service.id) + self._test_atomic_action_timer(scenario.atomic_actions(), + "keystone.delete_service") + def test_get_tenant(self): tenant = mock.MagicMock() fake_keystone = fakes.FakeKeystoneClient()