Merge "Keystone get_entities scenario backwards compat"

This commit is contained in:
Jenkins 2015-06-23 10:49:28 +00:00 committed by Gerrit Code Review
commit 117584c6f8
3 changed files with 62 additions and 7 deletions

View File

@ -44,6 +44,26 @@
sla:
failure_rate:
max: 0
-
args:
service_name: null
runner:
type: "constant"
times: 20
concurrency: 10
sla:
failure_rate:
max: 0
-
args:
service_name: "nova"
runner:
type: "constant"
times: 20
concurrency: 10
sla:
failure_rate:
max: 0
KeystoneBasic.add_and_remove_user_role:
-

View File

@ -128,15 +128,30 @@ class KeystoneBasic(kutils.KeystoneScenario):
@validation.required_openstack(admin=True)
@base.scenario(context={"admin_cleanup": ["keystone"]})
def get_entities(self):
"""Get instance of a tenant, user, role and service by id's."""
def get_entities(self, service_name="keystone"):
"""Get instance of a tenant, user, role and service by id's.
An ephemeral tenant, user, and role are each created. By
default, fetches the 'keystone' service. This can be
overridden (for instance, to get the 'Identity Service'
service on older OpenStack), or None can be passed explicitly
to service_name to create a new service and then query it by
ID.
:param service_name: The name of the service to get by ID; or
None, to create an ephemeral service and
get it by ID.
"""
tenant = self._tenant_create(name_length=5)
user = self._user_create(name_length=10)
role = self._role_create()
self._get_tenant(tenant.id)
self._get_user(user.id)
self._get_role(role.id)
service = self._get_service_by_name("keystone")
if service_name is None:
service = self._service_create()
else:
service = self._get_service_by_name(service_name)
self._get_service(service.id)
@validation.required_openstack(admin=True)

View File

@ -146,32 +146,52 @@ class KeystoneBasicTestCase(test.TestCase):
scenario._list_roles_for_user.assert_called_once_with(fake_user,
fake_tenant)
@mock.patch("rally.common.utils.generate_random_name")
def test_get_entities(self, mock_generate_random_name):
def _test_get_entities(self, service_name="keystone"):
scenario = basic.KeystoneBasic()
fake_tenant = mock.MagicMock()
fake_user = mock.MagicMock()
fake_role = mock.MagicMock()
fake_service = mock.MagicMock()
scenario._tenant_create = mock.MagicMock(return_value=fake_tenant)
scenario._user_create = mock.MagicMock(return_value=fake_user)
scenario._role_create = mock.MagicMock(return_value=fake_role)
scenario._service_create = mock.MagicMock(return_value=fake_service)
scenario._get_tenant = mock.MagicMock(return_value=fake_tenant)
scenario._get_user = mock.MagicMock(return_value=fake_user)
scenario._get_role = mock.MagicMock(return_value=fake_role)
scenario._get_service_by_name = mock.MagicMock(
return_value=fake_service)
scenario._get_service = mock.MagicMock(return_value=fake_service)
scenario.get_entities()
scenario.get_entities(service_name)
scenario._tenant_create.assert_called_once_with(name_length=5)
scenario._user_create.assert_called_once_with(name_length=10)
scenario._role_create.assert_called_once_with()
scenario._get_tenant.assert_called_once_with(fake_tenant.id)
scenario._get_user.assert_called_once_with(fake_user.id)
scenario._get_role.assert_called_once_with(fake_role.id)
scenario._get_service_by_name("keystone")
if service_name is None:
scenario._service_create.assert_called_once_with()
self.assertFalse(scenario._get_service_by_name.called)
else:
scenario._get_service_by_name.assert_called_once_with(service_name)
self.assertFalse(scenario._service_create.called)
scenario._get_service.assert_called_once_with(fake_service.id)
def test_get_entities(self):
self._test_get_entities()
def test_get_entities_with_service_name(self):
self._test_get_entities(service_name="fooservice")
def test_get_entities_create_service(self):
self._test_get_entities(service_name=None)
def test_create_and_delete_service(self):
scenario = basic.KeystoneBasic()
name = "Rally_test_service"