Merge "Add required_parameters validator"
This commit is contained in:
commit
a680e0ec57
@ -16,6 +16,7 @@
|
|||||||
from rally.benchmark.context import cleaner as context_cleaner
|
from rally.benchmark.context import cleaner as context_cleaner
|
||||||
from rally.benchmark.scenarios import base
|
from rally.benchmark.scenarios import base
|
||||||
from rally.benchmark.scenarios.keystone import utils as kutils
|
from rally.benchmark.scenarios.keystone import utils as kutils
|
||||||
|
from rally.benchmark import validation as valid
|
||||||
|
|
||||||
|
|
||||||
class KeystoneBasic(kutils.KeystoneScenario):
|
class KeystoneBasic(kutils.KeystoneScenario):
|
||||||
@ -36,9 +37,10 @@ class KeystoneBasic(kutils.KeystoneScenario):
|
|||||||
self._tenant_create(name_length=name_length, **kwargs)
|
self._tenant_create(name_length=name_length, **kwargs)
|
||||||
|
|
||||||
@base.scenario(admin_only=True)
|
@base.scenario(admin_only=True)
|
||||||
|
@valid.add_validator(valid.required_parameters(['users_per_tenant']))
|
||||||
@context_cleaner.cleanup([])
|
@context_cleaner.cleanup([])
|
||||||
def create_tenant_with_users(self, name_length=10,
|
def create_tenant_with_users(self, users_per_tenant, name_length=10,
|
||||||
users_per_tenant=10, **kwargs):
|
**kwargs):
|
||||||
tenant = self._tenant_create(name_length=name_length, **kwargs)
|
tenant = self._tenant_create(name_length=name_length, **kwargs)
|
||||||
self._users_create(tenant, name_length=name_length,
|
self._users_create(tenant, users_per_tenant, name_length=name_length,
|
||||||
users_per_tenant=users_per_tenant, **kwargs)
|
**kwargs)
|
||||||
|
@ -74,11 +74,11 @@ class KeystoneScenario(base.Scenario):
|
|||||||
return self.admin_clients("keystone").tenants.create(name, **kwargs)
|
return self.admin_clients("keystone").tenants.create(name, **kwargs)
|
||||||
|
|
||||||
@scenario_utils.atomic_action_timer('keystone.create_users')
|
@scenario_utils.atomic_action_timer('keystone.create_users')
|
||||||
def _users_create(self, tenant, name_length=10, users_per_tenant=10):
|
def _users_create(self, tenant, users_per_tenant, name_length=10):
|
||||||
"""Adds users to a tenant.
|
"""Adds users to a tenant.
|
||||||
|
|
||||||
:param name_length: length of generated (random) part of name for user
|
|
||||||
: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 = generate_keystone_name(length=name_length)
|
name = generate_keystone_name(length=name_length)
|
||||||
|
@ -130,3 +130,18 @@ def image_valid_on_flavor(flavor_name, image_name):
|
|||||||
|
|
||||||
return ValidationResult()
|
return ValidationResult()
|
||||||
return image_valid_on_flavor_validator
|
return image_valid_on_flavor_validator
|
||||||
|
|
||||||
|
|
||||||
|
def required_parameters(params):
|
||||||
|
"""Returns validator for required parameters
|
||||||
|
|
||||||
|
:param params: list of required parameters
|
||||||
|
"""
|
||||||
|
def required_parameters_validator(**kwargs):
|
||||||
|
missing = set(params) - set(kwargs)
|
||||||
|
if missing:
|
||||||
|
message = _("%s parameters are not defined in "
|
||||||
|
"the benchmark config file") % ", ".join(missing)
|
||||||
|
return ValidationResult(False, message)
|
||||||
|
return ValidationResult()
|
||||||
|
return required_parameters_validator
|
||||||
|
@ -115,7 +115,7 @@ class KeystoneScenarioTestCase(test.TestCase):
|
|||||||
fake_clients._keystone = fake_keystone
|
fake_clients._keystone = fake_keystone
|
||||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||||
|
|
||||||
scenario._users_create(tenant, 10, 1)
|
scenario._users_create(tenant, users_per_tenant=1, name_length=10)
|
||||||
|
|
||||||
fake_keystone.users.create.assert_called_once_with(name, name,
|
fake_keystone.users.create.assert_called_once_with(name, name,
|
||||||
name + "@rally.me",
|
name + "@rally.me",
|
||||||
|
Loading…
Reference in New Issue
Block a user