Add a required_api_version validator
New validator required_api_version is introduced to validating the api version needed to run the scenario. This patch also adds the validator to the keystone v2 specific scenarios. Change-Id: I1cd97d88545fa3a363009e36515f5ae1cb5bc3a9 Closes-bug: #1442633
This commit is contained in:
parent
fe1d52afbb
commit
1245976850
|
@ -64,6 +64,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
|
|||
self._resource_delete(user)
|
||||
|
||||
@validation.required_openstack(admin=True)
|
||||
@validation.required_api_versions(component="keystone", versions=[2.0])
|
||||
@scenario.configure(context={"admin_cleanup": ["keystone"]})
|
||||
@logging.log_deprecated_args(
|
||||
"The 'name_length' argument to create_tenant is ignored",
|
||||
|
@ -77,6 +78,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
|
|||
|
||||
@validation.number("users_per_tenant", minval=1)
|
||||
@validation.required_openstack(admin=True)
|
||||
@validation.required_api_versions(component="keystone", versions=[2.0])
|
||||
@scenario.configure(context={"admin_cleanup": ["keystone"]})
|
||||
@logging.log_deprecated_args(
|
||||
"The 'name_length' argument to create_tenant_with_users is ignored",
|
||||
|
@ -107,6 +109,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
|
|||
self._list_users()
|
||||
|
||||
@validation.required_openstack(admin=True)
|
||||
@validation.required_api_versions(component="keystone", versions=[2.0])
|
||||
@scenario.configure(context={"admin_cleanup": ["keystone"]})
|
||||
@logging.log_deprecated_args(
|
||||
"The 'name_length' argument to create_and_list_tenants is ignored",
|
||||
|
@ -147,6 +150,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
|
|||
self._list_roles_for_user(user_id, tenant_id)
|
||||
|
||||
@validation.required_openstack(admin=True)
|
||||
@validation.required_api_versions(component="keystone", versions=[2.0])
|
||||
@scenario.configure(context={"admin_cleanup": ["keystone"]})
|
||||
def get_entities(self, service_name="keystone"):
|
||||
"""Get instance of a tenant, user, role and service by id's.
|
||||
|
@ -190,6 +194,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
|
|||
self._delete_service(service.id)
|
||||
|
||||
@validation.required_openstack(admin=True)
|
||||
@validation.required_api_versions(component="keystone", versions=[2.0])
|
||||
@scenario.configure(context={"admin_cleanup": ["keystone"]})
|
||||
@logging.log_deprecated_args(
|
||||
"The 'name_length' argument to create_update_and_delete_tenant is "
|
||||
|
|
|
@ -611,6 +611,35 @@ def required_openstack(config, clients, deployment, admin=False, users=False):
|
|||
return ValidationResult(False, _("Admin credentials required"))
|
||||
|
||||
|
||||
@validator
|
||||
def required_api_versions(config, clients, deployment, component, versions):
|
||||
"""Validator checks component API versions."""
|
||||
versions = [str(v) for v in versions]
|
||||
versions_str = ", ".join(versions)
|
||||
msg = _("Task was designed to be used with %(component)s "
|
||||
"V%(version)s, but V%(found_version)s is "
|
||||
"selected.")
|
||||
if component == "keystone":
|
||||
if "2.0" in versions and not hasattr(clients.keystone(), "tenants"):
|
||||
return ValidationResult(False, msg % {"component": component,
|
||||
"version": versions_str,
|
||||
"found_version": "3"})
|
||||
if "3" in versions and not hasattr(clients.keystone(), "projects"):
|
||||
return ValidationResult(False, msg % {"component": component,
|
||||
"version": versions_str,
|
||||
"found_version": "2.0"})
|
||||
else:
|
||||
used_version = getattr(clients, component).choose_version()
|
||||
if not used_version:
|
||||
return ValidationResult(
|
||||
False, _("Unable to determine the API version."))
|
||||
if str(used_version) not in versions:
|
||||
return ValidationResult(
|
||||
False, msg % {"component": component,
|
||||
"version": versions_str,
|
||||
"found_version": used_version})
|
||||
|
||||
|
||||
@validator
|
||||
def volume_type_exists(config, clients, deployment, param_name):
|
||||
"""Returns validator for volume types.
|
||||
|
|
|
@ -883,3 +883,33 @@ class ValidatorsTestCase(test.TestCase):
|
|||
self.assertEqual("Heat template validation failed on fake_path1."
|
||||
" Original error message: fake_msg.", result.msg)
|
||||
self.assertFalse(result.is_valid)
|
||||
|
||||
def test_required_api_versions(self):
|
||||
validatorv2 = self._unwrap_validator(
|
||||
validation.required_api_versions, component="keystone",
|
||||
versions=[2.0])
|
||||
clients = mock.MagicMock()
|
||||
if hasattr(clients.keystone(), "tenants"):
|
||||
del clients.keystone().tenants
|
||||
self.assertFalse(validatorv2(None, clients, None).is_valid)
|
||||
clients.keystone().tenants = mock.MagicMock
|
||||
self.assertTrue(validatorv2(None, clients, None).is_valid)
|
||||
|
||||
validatorv3 = self._unwrap_validator(
|
||||
validation.required_api_versions, component="keystone",
|
||||
versions=[3])
|
||||
if hasattr(clients.keystone(), "projects"):
|
||||
del clients.keystone().projects
|
||||
self.assertFalse(validatorv3(None, clients, None).is_valid)
|
||||
clients.keystone().projects = mock.MagicMock
|
||||
self.assertTrue(validatorv3(None, clients, None).is_valid)
|
||||
|
||||
validatorother = self._unwrap_validator(
|
||||
validation.required_api_versions, component="nova",
|
||||
versions=[2])
|
||||
clients.nova.choose_version.return_value = 2
|
||||
self.assertTrue(validatorother(None, clients, None).is_valid)
|
||||
clients.nova.choose_version.return_value = 3
|
||||
self.assertFalse(validatorother(None, clients, None).is_valid)
|
||||
clients.nova.choose_version.return_value = None
|
||||
self.assertFalse(validatorother(None, clients, None).is_valid)
|
||||
|
|
Loading…
Reference in New Issue