Add required_contexts validator
Add a validator that checks if a benchmark scenario has defined in its configuration file the context(s) that it requires to run first. Example: @validation.required_contexts("context1", "context2") def benchmark_scenario(): pass Change-Id: Id83a6ff93acde2abbb29ec8351210e38d725ce48
This commit is contained in:
parent
54dbf08b86
commit
54d793fb25
@ -371,3 +371,13 @@ def required_services(config, clients, task, *required_services):
|
||||
if service not in available_services:
|
||||
return ValidationResult(
|
||||
False, _("Service is not available: %s") % service)
|
||||
|
||||
|
||||
@validator
|
||||
def required_contexts(config, clients, task, *context_names):
|
||||
missing_contexts = set(context_names) - set(config.get("context", {}))
|
||||
if missing_contexts:
|
||||
message = (_("The following contexts are required but missing from "
|
||||
"the benchmark configuration file: %s") %
|
||||
", ".join(missing_contexts))
|
||||
return ValidationResult(False, message)
|
||||
|
@ -80,6 +80,22 @@ class ValidationUtilsTestCase(test.TestCase):
|
||||
validator, = self._get_scenario_validators(func_failure, scenario)
|
||||
self.assertFalse(validator(None, None, None).is_valid)
|
||||
|
||||
def test_required_contexts(self):
|
||||
config = {"context": {"context01": {}, "context02": {}}}
|
||||
|
||||
required_contexts = (lambda *contexts:
|
||||
validation.required_contexts(*contexts)
|
||||
(lambda: None).validators.pop()
|
||||
(config, None, None))
|
||||
|
||||
# All the required contexts are defined
|
||||
result = required_contexts("context01", "context02")
|
||||
self.assertTrue(result.is_valid)
|
||||
|
||||
# A required context is not defined
|
||||
result = required_contexts("context03")
|
||||
self.assertFalse(result.is_valid)
|
||||
|
||||
def test_required_services(self):
|
||||
available_services = {
|
||||
consts.ServiceType.IDENTITY: consts.Service.KEYSTONE,
|
||||
|
Loading…
Reference in New Issue
Block a user