Merge "Implement new random name generator for keystone scenarios"

This commit is contained in:
Jenkins 2015-10-18 21:22:23 +00:00 committed by Gerrit Code Review
commit f871de8422
30 changed files with 141 additions and 303 deletions

View File

@ -18,8 +18,6 @@
KeystoneBasic.create_and_list_tenants: KeystoneBasic.create_and_list_tenants:
- -
args:
name_length: 10
context: context:
{{ user_context(tenants_amount, users_amount, use_existing_users) }} {{ user_context(tenants_amount, users_amount, use_existing_users) }}
runner: runner:
@ -56,11 +54,9 @@
KeystoneBasic.create_update_and_delete_tenant: KeystoneBasic.create_update_and_delete_tenant:
- -
args:
name_length: 10
context: context:
{{ user_context(tenants_amount, users_amount, use_existing_users) }} {{ user_context(tenants_amount, users_amount, use_existing_users) }}
runner: runner:
{{ constant_runner(15*controllers_amount,60*controllers_amount) }} {{ constant_runner(15*controllers_amount,60*controllers_amount) }}
sla: sla:
{{ no_failures_sla() }} {{ no_failures_sla() }}

View File

@ -84,9 +84,7 @@ As an example, let's edit our configuration file from :ref:`step 1 <tutorial_ste
], ],
"KeystoneBasic.create_delete_user": [ "KeystoneBasic.create_delete_user": [
{ {
"args": { "args": {},
"name_length": 10
},
"runner": { "runner": {
"type": "constant", "type": "constant",
"times": 10, "times": 10,

View File

@ -262,8 +262,7 @@ As an example, let us make up a task file that will create new users with increa
KeystoneBasic.create_user: KeystoneBasic.create_user:
{% for i in range(2, 11, 2) %} {% for i in range(2, 11, 2) %}
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10
@ -289,8 +288,7 @@ In this case, you dont need to pass any arguments via *--task-args/--task-arg
KeystoneBasic.create_user: KeystoneBasic.create_user:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10
@ -300,8 +298,7 @@ In this case, you dont need to pass any arguments via *--task-args/--task-arg
max: 0 max: 0
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10
@ -311,8 +308,7 @@ In this case, you dont need to pass any arguments via *--task-args/--task-arg
max: 0 max: 0
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10
@ -322,8 +318,7 @@ In this case, you dont need to pass any arguments via *--task-args/--task-arg
max: 0 max: 0
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10
@ -333,8 +328,7 @@ In this case, you dont need to pass any arguments via *--task-args/--task-arg
max: 0 max: 0
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10

View File

@ -2,8 +2,7 @@
KeystoneBasic.create_user: KeystoneBasic.create_user:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 1 times: 1
@ -14,8 +13,7 @@
KeystoneBasic.create_delete_user: KeystoneBasic.create_delete_user:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 1 times: 1
@ -26,8 +24,7 @@
KeystoneBasic.create_and_list_tenants: KeystoneBasic.create_and_list_tenants:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 1 times: 1
@ -38,8 +35,7 @@
KeystoneBasic.create_and_list_users: KeystoneBasic.create_and_list_users:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 1 times: 1
@ -50,8 +46,7 @@
KeystoneBasic.create_tenant: KeystoneBasic.create_tenant:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 1 times: 1
@ -63,7 +58,6 @@
KeystoneBasic.create_tenant_with_users: KeystoneBasic.create_tenant_with_users:
- -
args: args:
name_length: 10
users_per_tenant: 10 users_per_tenant: 10
runner: runner:
type: "constant" type: "constant"
@ -78,8 +72,7 @@
KeystoneBasic.create_delete_user: KeystoneBasic.create_delete_user:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 1 times: 1

View File

@ -1,8 +1,7 @@
--- ---
KeystoneBasic.create_user: KeystoneBasic.create_user:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10
@ -13,8 +12,7 @@
KeystoneBasic.create_delete_user: KeystoneBasic.create_delete_user:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10
@ -47,8 +45,7 @@
KeystoneBasic.create_and_list_tenants: KeystoneBasic.create_and_list_tenants:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10
@ -127,8 +124,7 @@
KeystoneBasic.create_and_list_users: KeystoneBasic.create_and_list_users:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10
@ -139,8 +135,7 @@
KeystoneBasic.create_tenant: KeystoneBasic.create_tenant:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10
@ -152,7 +147,6 @@
KeystoneBasic.create_tenant_with_users: KeystoneBasic.create_tenant_with_users:
- -
args: args:
name_length: 10
users_per_tenant: 10 users_per_tenant: 10
runner: runner:
type: "constant" type: "constant"
@ -167,9 +161,7 @@
KeystoneBasic.create_user_update_password: KeystoneBasic.create_user_update_password:
- -
args: args: {}
name_length: 10
password_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10
@ -180,8 +172,7 @@
KeystoneBasic.create_update_and_delete_tenant: KeystoneBasic.create_update_and_delete_tenant:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10
@ -192,8 +183,7 @@
KeystoneBasic.create_delete_user: KeystoneBasic.create_delete_user:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10

View File

@ -22,29 +22,25 @@ from rally.task import validation
class KeystoneBasic(kutils.KeystoneScenario): class KeystoneBasic(kutils.KeystoneScenario):
"""Basic benchmark scenarios for Keystone.""" """Basic benchmark scenarios for Keystone."""
@validation.number("name_length", minval=10)
@validation.required_openstack(admin=True) @validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]}) @scenario.configure(context={"admin_cleanup": ["keystone"]})
def create_user(self, name_length=10, **kwargs): def create_user(self, **kwargs):
"""Create a keystone user with random name. """Create a keystone user with random name.
:param name_length: length of the random part of user name
:param kwargs: Other optional parameters to create users like :param kwargs: Other optional parameters to create users like
"tenant_id", "enabled". "tenant_id", "enabled".
""" """
self._user_create(name_length=name_length, **kwargs) self._user_create(**kwargs)
@validation.number("name_length", minval=10)
@validation.required_openstack(admin=True) @validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]}) @scenario.configure(context={"admin_cleanup": ["keystone"]})
def create_delete_user(self, name_length=10, **kwargs): def create_delete_user(self, **kwargs):
"""Create a keystone user with random name and then delete it. """Create a keystone user with random name and then delete it.
:param name_length: length of the random part of user name
:param kwargs: Other optional parameters to create users like :param kwargs: Other optional parameters to create users like
"tenant_id", "enabled". "tenant_id", "enabled".
""" """
user = self._user_create(name_length=name_length, **kwargs) user = self._user_create(**kwargs)
self._resource_delete(user) self._resource_delete(user)
@validation.required_openstack(admin=True) @validation.required_openstack(admin=True)
@ -61,57 +57,47 @@ class KeystoneBasic(kutils.KeystoneScenario):
self._update_user_enabled(user, not enabled) self._update_user_enabled(user, not enabled)
self._resource_delete(user) self._resource_delete(user)
@validation.number("name_length", minval=10)
@validation.required_openstack(admin=True) @validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]}) @scenario.configure(context={"admin_cleanup": ["keystone"]})
def create_tenant(self, name_length=10, **kwargs): def create_tenant(self, **kwargs):
"""Create a keystone tenant with random name. """Create a keystone tenant with random name.
:param name_length: length of the random part of tenant name
:param kwargs: Other optional parameters :param kwargs: Other optional parameters
""" """
self._tenant_create(name_length=name_length, **kwargs) self._tenant_create(**kwargs)
@validation.number("name_length", minval=10)
@validation.number("users_per_tenant", minval=1) @validation.number("users_per_tenant", minval=1)
@validation.required_openstack(admin=True) @validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]}) @scenario.configure(context={"admin_cleanup": ["keystone"]})
def create_tenant_with_users(self, users_per_tenant, name_length=10, def create_tenant_with_users(self, users_per_tenant, **kwargs):
**kwargs):
"""Create a keystone tenant and several users belonging to it. """Create a keystone tenant and several users belonging to it.
:param name_length: length of the random part of tenant/user name
:param users_per_tenant: number of users to create for the tenant :param users_per_tenant: number of users to create for the tenant
:param kwargs: Other optional parameters for tenant creation :param kwargs: Other optional parameters for tenant creation
:returns: keystone tenant instance :returns: keystone tenant instance
""" """
tenant = self._tenant_create(name_length=name_length, **kwargs) tenant = self._tenant_create(**kwargs)
self._users_create(tenant, users_per_tenant=users_per_tenant, self._users_create(tenant, users_per_tenant=users_per_tenant)
name_length=name_length)
@validation.number("name_length", minval=10)
@validation.required_openstack(admin=True) @validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]}) @scenario.configure(context={"admin_cleanup": ["keystone"]})
def create_and_list_users(self, name_length=10, **kwargs): def create_and_list_users(self, **kwargs):
"""Create a keystone user with random name and list all users. """Create a keystone user with random name and list all users.
:param name_length: length of the random part of user name
:param kwargs: Other optional parameters to create users like :param kwargs: Other optional parameters to create users like
"tenant_id", "enabled". "tenant_id", "enabled".
""" """
self._user_create(name_length=name_length, **kwargs) self._user_create(**kwargs)
self._list_users() self._list_users()
@validation.number("name_length", minval=10)
@validation.required_openstack(admin=True) @validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]}) @scenario.configure(context={"admin_cleanup": ["keystone"]})
def create_and_list_tenants(self, name_length=10, **kwargs): def create_and_list_tenants(self, **kwargs):
"""Create a keystone tenant with random name and list all tenants. """Create a keystone tenant with random name and list all tenants.
:param name_length: length of the random part of tenant name
:param kwargs: Other optional parameters :param kwargs: Other optional parameters
""" """
self._tenant_create(name_length=name_length, **kwargs) self._tenant_create(**kwargs)
self._list_tenants() self._list_tenants()
@validation.required_openstack(admin=True, users=True) @validation.required_openstack(admin=True, users=True)
@ -157,8 +143,8 @@ class KeystoneBasic(kutils.KeystoneScenario):
None, to create an ephemeral service and None, to create an ephemeral service and
get it by ID. get it by ID.
""" """
tenant = self._tenant_create(name_length=5) tenant = self._tenant_create()
user = self._user_create(name_length=10) user = self._user_create()
role = self._role_create() role = self._role_create()
self._get_tenant(tenant.id) self._get_tenant(tenant.id)
self._get_user(user.id) self._get_user(user.id)
@ -184,31 +170,23 @@ class KeystoneBasic(kutils.KeystoneScenario):
service = self._service_create(service_type, description) service = self._service_create(service_type, description)
self._delete_service(service.id) self._delete_service(service.id)
@validation.number("name_length", minval=10)
@validation.required_openstack(admin=True) @validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]}) @scenario.configure(context={"admin_cleanup": ["keystone"]})
def create_update_and_delete_tenant(self, name_length=10, **kwargs): def create_update_and_delete_tenant(self, **kwargs):
"""Create, update and delete tenant. """Create, update and delete tenant.
:param name_length: length of the random part of tenant name
:param kwargs: Other optional parameters for tenant creation :param kwargs: Other optional parameters for tenant creation
""" """
tenant = self._tenant_create(name_length=name_length, **kwargs) tenant = self._tenant_create(**kwargs)
self._update_tenant(tenant) self._update_tenant(tenant)
self._resource_delete(tenant) self._resource_delete(tenant)
@validation.number("password_length", minval=10)
@validation.number("name_length", minval=10)
@validation.required_openstack(admin=True) @validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]}) @scenario.configure(context={"admin_cleanup": ["keystone"]})
def create_user_update_password(self, name_length=10, password_length=10): def create_user_update_password(self):
"""Create user and update password for that user. """Create user and update password for that user."""
password = self.generate_random_name()
:param name_length: length of the user name user = self._user_create()
:param password_length: length of the password
"""
password = self._generate_random_name(length=password_length)
user = self._user_create(name_length=name_length)
self._update_user_password(user.id, password) self._update_user_password(user.id, password)
@validation.required_openstack(admin=True) @validation.required_openstack(admin=True)

View File

@ -15,29 +15,27 @@
import uuid import uuid
from rally.common import utils
from rally.plugins.openstack import scenario from rally.plugins.openstack import scenario
from rally.task import atomic from rally.task import atomic
def is_temporary(resource): def is_temporary(resource):
return resource.name.startswith(KeystoneScenario.RESOURCE_NAME_PREFIX) return utils.name_matches_object(resource.name, KeystoneScenario)
class KeystoneScenario(scenario.OpenStackScenario): class KeystoneScenario(scenario.OpenStackScenario):
"""Base class for Keystone scenarios with basic atomic actions.""" """Base class for Keystone scenarios with basic atomic actions."""
RESOURCE_NAME_PREFIX = "rally_keystone_"
@atomic.action_timer("keystone.create_user") @atomic.action_timer("keystone.create_user")
def _user_create(self, name_length=10, email=None, **kwargs): def _user_create(self, email=None, **kwargs):
"""Creates keystone user with random name. """Creates keystone user with random name.
:param name_length: length of generated (random) part of name
:param kwargs: Other optional parameters to create users like :param kwargs: Other optional parameters to create users like
"tenant_id", "enabled". "tenant_id", "enabled".
:returns: keystone user instance :returns: keystone user instance
""" """
name = self._generate_random_name(length=name_length) name = self.generate_random_name()
# NOTE(boris-42): password and email parameters are required by # NOTE(boris-42): password and email parameters are required by
# keystone client v2.0. This should be cleanuped # keystone client v2.0. This should be cleanuped
# when we switch to v3. # when we switch to v3.
@ -63,14 +61,13 @@ class KeystoneScenario(scenario.OpenStackScenario):
resource.delete() resource.delete()
@atomic.action_timer("keystone.create_tenant") @atomic.action_timer("keystone.create_tenant")
def _tenant_create(self, name_length=10, **kwargs): def _tenant_create(self, **kwargs):
"""Creates keystone tenant with random name. """Creates keystone tenant with random name.
:param name_length: length of generated (random) part of name
:param kwargs: Other optional parameters :param kwargs: Other optional parameters
:returns: keystone tenant instance :returns: keystone tenant instance
""" """
name = self._generate_random_name(length=name_length) name = self.generate_random_name()
return self.admin_clients("keystone").tenants.create(name, **kwargs) return self.admin_clients("keystone").tenants.create(name, **kwargs)
@atomic.action_timer("keystone.create_service") @atomic.action_timer("keystone.create_service")
@ -78,41 +75,37 @@ class KeystoneScenario(scenario.OpenStackScenario):
description=None): description=None):
"""Creates keystone service with random name. """Creates keystone service with random name.
:param name: name of the service
:param service_type: type of the service :param service_type: type of the service
:param description: description of the service :param description: description of the service
:returns: keystone service instance :returns: keystone service instance
""" """
description = description or self._generate_random_name( description = description or self.generate_random_name()
prefix="rally_test_service_description_")
return self.admin_clients("keystone").services.create( return self.admin_clients("keystone").services.create(
self._generate_random_name(), self.generate_random_name(),
service_type, description) service_type, description)
@atomic.action_timer("keystone.create_users") @atomic.action_timer("keystone.create_users")
def _users_create(self, tenant, users_per_tenant, name_length=10): def _users_create(self, tenant, users_per_tenant):
"""Adds users to a tenant. """Adds users to a tenant.
:param tenant: tenant object :param tenant: tenant object
:param users_per_tenant: number of users in per tenant :param users_per_tenant: number of users in per tenant
:param name_length: length of generated (random) part of name for user
""" """
for i in range(users_per_tenant): for i in range(users_per_tenant):
name = self._generate_random_name(length=name_length) name = self.generate_random_name()
password = name password = name
email = (name + "@rally.me") email = name + "@rally.me"
self.admin_clients("keystone").users.create( self.admin_clients("keystone").users.create(
name, password=password, email=email, tenant_id=tenant.id) name, password=password, email=email, tenant_id=tenant.id)
@atomic.action_timer("keystone.create_role") @atomic.action_timer("keystone.create_role")
def _role_create(self, name_length=5): def _role_create(self):
"""Creates keystone user role with random name. """Creates keystone user role with random name.
:param name_length: length of generated (random) part of role name
:returns: keystone user role instance :returns: keystone user role instance
""" """
role = self.admin_clients("keystone").roles.create( role = self.admin_clients("keystone").roles.create(
self._generate_random_name(length=name_length)) self.generate_random_name())
return role return role
@atomic.action_timer("keystone.list_users") @atomic.action_timer("keystone.list_users")
@ -207,15 +200,14 @@ class KeystoneScenario(scenario.OpenStackScenario):
self.admin_clients("keystone").services.delete(service_id) self.admin_clients("keystone").services.delete(service_id)
@atomic.action_timer("keystone.update_tenant") @atomic.action_timer("keystone.update_tenant")
def _update_tenant(self, tenant, name=None, description=None): def _update_tenant(self, tenant, description=None):
"""Update tenant name and description. """Update tenant name and description.
:param tenant: tenant to be updated :param tenant: tenant to be updated
:param name: tenant name to be set
:param description: tenant description to be set :param description: tenant description to be set
""" """
name = name or (tenant.name + "_updated") name = self.generate_random_name()
description = description or (tenant.name + "_description_updated") description = description or self.generate_random_name()
self.admin_clients("keystone").tenants.update(tenant.id, self.admin_clients("keystone").tenants.update(tenant.id,
name, description) name, description)

View File

@ -93,23 +93,30 @@ class ConfigurePluginMeta(type):
@six.add_metaclass(ConfigurePluginMeta) @six.add_metaclass(ConfigurePluginMeta)
class Scenario(plugin.Plugin, class Scenario(plugin.Plugin,
atomic.ActionTimerMixin, atomic.ActionTimerMixin,
functional.FunctionalMixin): functional.FunctionalMixin,
utils.RandomNameGeneratorMixin):
"""This is base class for any benchmark scenario. """This is base class for any benchmark scenario.
You should create subclass of this class. And your test scenarios will You should create subclass of this class. And your test scenarios will
be auto discoverable and you will be able to specify it in test config. be auto discoverable and you will be able to specify it in test config.
""" """
# NOTE(stpierre): Old random name generator parameters, to be
# removed in a subsequent commit
RESOURCE_NAME_PREFIX = "rally_" RESOURCE_NAME_PREFIX = "rally_"
RESOURCE_NAME_LENGTH = 10 RESOURCE_NAME_LENGTH = 10
RESOURCE_NAME_FORMAT = "s_rally_XXXXXXXX_XXXXXXXX"
def __init__(self, context=None): def __init__(self, context=None):
super(Scenario, self).__init__() super(Scenario, self).__init__()
self.context = context self.context = context or {}
self.task = self.context.get("task", {})
self._idle_duration = 0 self._idle_duration = 0
# TODO(amaretskiy): consider about prefix part of benchmark uuid
@classmethod @classmethod
def _generate_random_name(cls, prefix=None, length=None): def _generate_random_name(cls, prefix=None, length=None):
# NOTE(stpierre): Old random name generator function, to be
# removed in a subsequent commit
prefix = cls.RESOURCE_NAME_PREFIX if prefix is None else prefix prefix = cls.RESOURCE_NAME_PREFIX if prefix is None else prefix
length = length or cls.RESOURCE_NAME_LENGTH length = length or cls.RESOURCE_NAME_LENGTH
return utils.generate_random_name(prefix, length) return utils.generate_random_name(prefix, length)

View File

@ -1,9 +1,7 @@
{ {
"KeystoneBasic.create_delete_user": [ "KeystoneBasic.create_delete_user": [
{ {
"args": { "args": {},
"name_length": 10
},
"runner": { "runner": {
"type": "constant", "type": "constant",
"times": 100, "times": 100,

View File

@ -1,8 +1,7 @@
--- ---
KeystoneBasic.create_delete_user: KeystoneBasic.create_delete_user:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 100 times: 100

View File

@ -1,9 +1,7 @@
{ {
"KeystoneBasic.create_and_list_tenants": [ "KeystoneBasic.create_and_list_tenants": [
{ {
"args": { "args": {},
"name_length": 10
},
"runner": { "runner": {
"type": "constant", "type": "constant",
"times": 10, "times": 10,

View File

@ -1,8 +1,7 @@
--- ---
KeystoneBasic.create_and_list_tenants: KeystoneBasic.create_and_list_tenants:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 10 times: 10

View File

@ -1,9 +1,7 @@
{ {
"KeystoneBasic.create_and_list_users": [ "KeystoneBasic.create_and_list_users": [
{ {
"args": { "args": {},
"name_length": 10
},
"runner": { "runner": {
"type": "constant", "type": "constant",
"times": 100, "times": 100,

View File

@ -1,8 +1,7 @@
--- ---
KeystoneBasic.create_and_list_users: KeystoneBasic.create_and_list_users:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 100 times: 100

View File

@ -2,7 +2,6 @@
"KeystoneBasic.create_tenant_with_users": [ "KeystoneBasic.create_tenant_with_users": [
{ {
"args": { "args": {
"name_length": 10,
"users_per_tenant": 10 "users_per_tenant": 10
}, },
"runner": { "runner": {

View File

@ -2,7 +2,6 @@
KeystoneBasic.create_tenant_with_users: KeystoneBasic.create_tenant_with_users:
- -
args: args:
name_length: 10
users_per_tenant: 10 users_per_tenant: 10
runner: runner:
type: "constant" type: "constant"

View File

@ -1,9 +1,7 @@
{ {
"KeystoneBasic.create_tenant": [ "KeystoneBasic.create_tenant": [
{ {
"args": { "args": {},
"name_length": 10
},
"runner": { "runner": {
"type": "constant", "type": "constant",
"times": 100, "times": 100,

View File

@ -1,8 +1,7 @@
--- ---
KeystoneBasic.create_tenant: KeystoneBasic.create_tenant:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 100 times: 100

View File

@ -1,9 +1,7 @@
{ {
"KeystoneBasic.create_update_and_delete_tenant": [ "KeystoneBasic.create_update_and_delete_tenant": [
{ {
"args": { "args": {},
"name_length": 10
},
"runner": { "runner": {
"type": "constant", "type": "constant",
"times": 100, "times": 100,

View File

@ -1,8 +1,7 @@
--- ---
KeystoneBasic.create_update_and_delete_tenant: KeystoneBasic.create_update_and_delete_tenant:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 100 times: 100

View File

@ -1,9 +1,7 @@
{ {
"KeystoneBasic.create_user": [ "KeystoneBasic.create_user": [
{ {
"args": { "args": {},
"name_length": 10
},
"runner": { "runner": {
"type": "constant", "type": "constant",
"times": 100, "times": 100,

View File

@ -1,8 +1,7 @@
--- ---
KeystoneBasic.create_user: KeystoneBasic.create_user:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 100 times: 100

View File

@ -1,10 +1,7 @@
{ {
"KeystoneBasic.create_user_update_password": [ "KeystoneBasic.create_user_update_password": [
{ {
"args": { "args": {},
"name_length": 10,
"password_length": 10
},
"runner": { "runner": {
"type": "constant", "type": "constant",
"times": 100, "times": 100,
@ -12,4 +9,4 @@
} }
} }
] ]
} }

View File

@ -1,10 +1,8 @@
--- ---
KeystoneBasic.create_user_update_password: KeystoneBasic.create_user_update_password:
- -
args: args: {}
name_length: 10
password_length: 10
runner: runner:
type: "constant" type: "constant"
times: 100 times: 100
concurrency: 10 concurrency: 10

View File

@ -1,9 +1,7 @@
{ {
"KeystoneBasic.create_delete_user": [ "KeystoneBasic.create_delete_user": [
{ {
"args": { "args": {},
"name_length": 10
},
"runner": { "runner": {
"type": "constant", "type": "constant",
"times": 100, "times": 100,

View File

@ -1,8 +1,7 @@
--- ---
KeystoneBasic.create_delete_user: KeystoneBasic.create_delete_user:
- -
args: args: {}
name_length: 10
runner: runner:
type: "constant" type: "constant"
times: 100 times: 100

View File

@ -722,7 +722,7 @@ class SLATestCase(unittest.TestCase):
"KeystoneBasic.create_and_list_users": [ "KeystoneBasic.create_and_list_users": [
{ {
"args": { "args": {
"name_length": 10 "enabled": True
}, },
"runner": { "runner": {
"type": "constant", "type": "constant",

View File

@ -36,27 +36,23 @@ class KeystoneBasicTestCase(test.ScenarioTestCase):
}) })
return context return context
@mock.patch("rally.common.utils.generate_random_name") def test_create_user(self):
def test_create_user(self, mock_generate_random_name):
scenario = basic.KeystoneBasic(self.context) scenario = basic.KeystoneBasic(self.context)
scenario._user_create = mock.MagicMock() scenario._user_create = mock.MagicMock()
scenario.create_user(name_length=20, password="tttt", tenant_id="id") scenario.create_user(password="tttt", tenant_id="id")
scenario._user_create.assert_called_once_with(name_length=20, scenario._user_create.assert_called_once_with(password="tttt",
password="tttt",
tenant_id="id") tenant_id="id")
@mock.patch("rally.common.utils.generate_random_name") def test_create_delete_user(self):
def test_create_delete_user(self, mock_generate_random_name):
create_result = mock.MagicMock() create_result = mock.MagicMock()
scenario = basic.KeystoneBasic(self.context) scenario = basic.KeystoneBasic(self.context)
scenario._user_create = mock.MagicMock(return_value=create_result) scenario._user_create = mock.MagicMock(return_value=create_result)
scenario._resource_delete = mock.MagicMock() scenario._resource_delete = mock.MagicMock()
scenario.create_delete_user(name_length=30, email="abcd", enabled=True) scenario.create_delete_user(email="abcd", enabled=True)
scenario._user_create.assert_called_once_with(name_length=30, scenario._user_create.assert_called_once_with(email="abcd",
email="abcd",
enabled=True) enabled=True)
scenario._resource_delete.assert_called_once_with(create_result) scenario._resource_delete.assert_called_once_with(create_result)
@ -75,48 +71,37 @@ class KeystoneBasicTestCase(test.ScenarioTestCase):
scenario._resource_delete.assert_called_once_with( scenario._resource_delete.assert_called_once_with(
scenario._user_create.return_value) scenario._user_create.return_value)
@mock.patch("rally.common.utils.generate_random_name") def test_create_tenant(self):
def test_create_tenant(self, mock_generate_random_name):
scenario = basic.KeystoneBasic(self.context) scenario = basic.KeystoneBasic(self.context)
scenario._tenant_create = mock.MagicMock() scenario._tenant_create = mock.MagicMock()
scenario.create_tenant(name_length=20, enabled=True) scenario.create_tenant(enabled=True)
scenario._tenant_create.assert_called_once_with(name_length=20, scenario._tenant_create.assert_called_once_with(enabled=True)
enabled=True)
@mock.patch("rally.common.utils.generate_random_name") def test_create_tenant_with_users(self):
def test_create_tenant_with_users(self, mock_generate_random_name):
scenario = basic.KeystoneBasic(self.context) scenario = basic.KeystoneBasic(self.context)
fake_tenant = mock.MagicMock() fake_tenant = mock.MagicMock()
scenario._tenant_create = mock.MagicMock(return_value=fake_tenant) scenario._tenant_create = mock.MagicMock(return_value=fake_tenant)
scenario._users_create = mock.MagicMock() scenario._users_create = mock.MagicMock()
scenario.create_tenant_with_users(users_per_tenant=1, name_length=20, scenario.create_tenant_with_users(users_per_tenant=1, enabled=True)
enabled=True) scenario._tenant_create.assert_called_once_with(enabled=True)
scenario._tenant_create.assert_called_once_with(name_length=20,
enabled=True)
scenario._users_create.assert_called_once_with(fake_tenant, scenario._users_create.assert_called_once_with(fake_tenant,
users_per_tenant=1, users_per_tenant=1)
name_length=20)
@mock.patch("rally.common.utils.generate_random_name") def test_create_and_list_users(self):
def test_create_and_list_users(self, mock_generate_random_name):
scenario = basic.KeystoneBasic(self.context) scenario = basic.KeystoneBasic(self.context)
scenario._user_create = mock.MagicMock() scenario._user_create = mock.MagicMock()
scenario._list_users = mock.MagicMock() scenario._list_users = mock.MagicMock()
scenario.create_and_list_users(name_length=20, password="tttt", scenario.create_and_list_users(password="tttt", tenant_id="id")
tenant_id="id") scenario._user_create.assert_called_once_with(password="tttt",
scenario._user_create.assert_called_once_with(name_length=20,
password="tttt",
tenant_id="id") tenant_id="id")
scenario._list_users.assert_called_once_with() scenario._list_users.assert_called_once_with()
@mock.patch("rally.common.utils.generate_random_name") def test_create_and_list_tenants(self):
def test_create_and_list_tenants(self, mock_generate_random_name):
scenario = basic.KeystoneBasic(self.context) scenario = basic.KeystoneBasic(self.context)
scenario._tenant_create = mock.MagicMock() scenario._tenant_create = mock.MagicMock()
scenario._list_tenants = mock.MagicMock() scenario._list_tenants = mock.MagicMock()
scenario.create_and_list_tenants(name_length=20, enabled=True) scenario.create_and_list_tenants(enabled=True)
scenario._tenant_create.assert_called_once_with(name_length=20, scenario._tenant_create.assert_called_once_with(enabled=True)
enabled=True)
scenario._list_tenants.assert_called_with() scenario._list_tenants.assert_called_with()
def test_assign_and_remove_user_role(self): def test_assign_and_remove_user_role(self):
@ -187,8 +172,8 @@ class KeystoneBasicTestCase(test.ScenarioTestCase):
scenario.get_entities(service_name) scenario.get_entities(service_name)
scenario._tenant_create.assert_called_once_with(name_length=5) scenario._tenant_create.assert_called_once_with()
scenario._user_create.assert_called_once_with(name_length=10) scenario._user_create.assert_called_once_with()
scenario._role_create.assert_called_once_with() scenario._role_create.assert_called_once_with()
scenario._get_tenant.assert_called_once_with(fake_tenant.id) scenario._get_tenant.assert_called_once_with(fake_tenant.id)
@ -240,13 +225,13 @@ class KeystoneBasicTestCase(test.ScenarioTestCase):
fake_password = "pswd" fake_password = "pswd"
fake_user = mock.MagicMock() fake_user = mock.MagicMock()
scenario._user_create = mock.MagicMock(return_value=fake_user) scenario._user_create = mock.MagicMock(return_value=fake_user)
scenario._generate_random_name = mock.MagicMock( scenario.generate_random_name = mock.MagicMock(
return_value=fake_password) return_value=fake_password)
scenario._update_user_password = mock.MagicMock() scenario._update_user_password = mock.MagicMock()
scenario.create_user_update_password(name_length=9, password_length=9) scenario.create_user_update_password()
scenario._generate_random_name.assert_called_once_with(length=9) scenario.generate_random_name.assert_called_once_with()
scenario._user_create.assert_called_once_with(name_length=9) scenario._user_create.assert_called_once_with()
scenario._update_user_password.assert_called_once_with(fake_user.id, scenario._update_user_password.assert_called_once_with(fake_user.id,
fake_password) fake_password)

View File

@ -14,7 +14,6 @@
# under the License. # under the License.
import mock import mock
import six
from rally.plugins.openstack.scenarios.keystone import utils from rally.plugins.openstack.scenarios.keystone import utils
from tests.unit import fakes from tests.unit import fakes
@ -25,33 +24,21 @@ UTILS = "rally.plugins.openstack.scenarios.keystone.utils."
class KeystoneUtilsTestCase(test.TestCase): class KeystoneUtilsTestCase(test.TestCase):
def test_RESOURCE_NAME_PREFIX(self): @mock.patch("rally.common.utils.name_matches_object")
self.assertIsInstance(utils.KeystoneScenario.RESOURCE_NAME_PREFIX, def test_is_temporary(self, mock_name_matches_object):
six.string_types) resource = mock.Mock()
# Prefix must be long enough to guarantee that resource self.assertEqual(utils.is_temporary(resource),
# to be recognized as created by rally mock_name_matches_object.return_value)
self.assertTrue( mock_name_matches_object.assert_called_once_with(
len(utils.KeystoneScenario.RESOURCE_NAME_PREFIX) > 7) resource.name, utils.KeystoneScenario)
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)
class KeystoneScenarioTestCase(test.ScenarioTestCase): class KeystoneScenarioTestCase(test.ScenarioTestCase):
@mock.patch(UTILS + "uuid.uuid4", return_value="pwd") @mock.patch("uuid.uuid4", return_value="pwd")
@mock.patch("rally.common.utils.generate_random_name", def test_user_create(self, mock_uuid4):
return_value="foobarov")
def test_user_create(self, mock_generate_random_name, mock_uuid4):
scenario = utils.KeystoneScenario(self.context) scenario = utils.KeystoneScenario(self.context)
scenario.generate_random_name = mock.Mock(return_value="foobarov")
result = scenario._user_create() result = scenario._user_create()
self.assertEqual( self.assertEqual(
@ -77,15 +64,15 @@ class KeystoneScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(), self._test_atomic_action_timer(scenario.atomic_actions(),
"keystone.update_user_enabled") "keystone.update_user_enabled")
@mock.patch("rally.common.utils.generate_random_name") def test_role_create(self):
def test_role_create(self, mock_generate_random_name):
scenario = utils.KeystoneScenario(self.context) scenario = utils.KeystoneScenario(self.context)
scenario.generate_random_name = mock.Mock()
result = scenario._role_create() result = scenario._role_create()
self.assertEqual( self.assertEqual(
self.admin_clients("keystone").roles.create.return_value, result) self.admin_clients("keystone").roles.create.return_value, result)
self.admin_clients("keystone").roles.create.assert_called_once_with( 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(), self._test_atomic_action_timer(scenario.atomic_actions(),
"keystone.create_role") "keystone.create_role")
@ -142,24 +129,23 @@ class KeystoneScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(), self._test_atomic_action_timer(scenario.atomic_actions(),
"keystone.remove_role") "keystone.remove_role")
@mock.patch("rally.common.utils.generate_random_name") def test_tenant_create(self):
def test_tenant_create(self, mock_generate_random_name):
scenario = utils.KeystoneScenario(self.context) scenario = utils.KeystoneScenario(self.context)
scenario.generate_random_name = mock.Mock()
result = scenario._tenant_create() result = scenario._tenant_create()
self.assertEqual( self.assertEqual(
self.admin_clients("keystone").tenants.create.return_value, result) self.admin_clients("keystone").tenants.create.return_value, result)
self.admin_clients("keystone").tenants.create.assert_called_once_with( 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(), self._test_atomic_action_timer(scenario.atomic_actions(),
"keystone.create_tenant") "keystone.create_tenant")
def test_service_create(self): def test_service_create(self):
service_type = "service_type" service_type = "service_type"
description = "_description" description = "description"
scenario = utils.KeystoneScenario(self.context) 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, result = scenario._service_create(service_type=service_type,
description=description) description=description)
@ -168,18 +154,17 @@ class KeystoneScenarioTestCase(test.ScenarioTestCase):
self.admin_clients("keystone").services.create.return_value, self.admin_clients("keystone").services.create.return_value,
result) result)
self.admin_clients("keystone").services.create.assert_called_once_with( 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) service_type, description)
self._test_atomic_action_timer(scenario.atomic_actions(), self._test_atomic_action_timer(scenario.atomic_actions(),
"keystone.create_service") "keystone.create_service")
@mock.patch("rally.common.utils.generate_random_name", def test_tenant_create_with_users(self):
return_value="foobarov")
def test_tenant_create_with_users(self, mock_generate_random_name):
tenant = mock.MagicMock() tenant = mock.MagicMock()
scenario = utils.KeystoneScenario(self.context) 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( self.admin_clients("keystone").users.create.assert_called_once_with(
"foobarov", password="foobarov", email="foobarov@rally.me", "foobarov", password="foobarov", email="foobarov@rally.me",
@ -261,14 +246,15 @@ class KeystoneScenarioTestCase(test.ScenarioTestCase):
def test_update_tenant(self): def test_update_tenant(self):
tenant = mock.MagicMock() tenant = mock.MagicMock()
description = tenant.name + "_description_updated_test" description = "new description"
name = tenant.name + "test_updated_test"
scenario = utils.KeystoneScenario(self.context) scenario = utils.KeystoneScenario(self.context)
scenario._update_tenant(tenant=tenant, name=name, scenario.generate_random_name = mock.Mock()
description=description) scenario._update_tenant(tenant=tenant, description=description)
self.admin_clients("keystone").tenants.update.assert_called_once_with( 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(), self._test_atomic_action_timer(scenario.atomic_actions(),
"keystone.update_tenant") "keystone.update_tenant")

View File

@ -16,7 +16,6 @@
import traceback import traceback
import mock import mock
import six
from rally import consts from rally import consts
from rally import exceptions from rally import exceptions
@ -219,55 +218,3 @@ class ScenarioTestCase(test.TestCase):
print(traceback.format_exc()) print(traceback.format_exc())
self.assertTrue(False, self.assertTrue(False,
"Scenario `%s` has wrong context" % scenario) "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)