Add required_platform@openstack validator
With Rally > 0.12 we need to handle checks for admin/users credentials manually. Depends-On: I546bbd9b0e35abb30195b0f8c98756a9cce10107 Change-Id: Icaafd9d038fb789b9f9e5ed63cc220d301d9b48e
This commit is contained in:
parent
1bb492eaf4
commit
0101e8a7c1
@ -26,6 +26,7 @@ from rally import exceptions
|
|||||||
from rally.plugins.common import validators
|
from rally.plugins.common import validators
|
||||||
from rally.task import types
|
from rally.task import types
|
||||||
|
|
||||||
|
import rally_openstack
|
||||||
from rally_openstack import consts
|
from rally_openstack import consts
|
||||||
from rally_openstack.contexts.keystone import roles
|
from rally_openstack.contexts.keystone import roles
|
||||||
from rally_openstack.contexts.nova import flavors as flavors_ctx
|
from rally_openstack.contexts.nova import flavors as flavors_ctx
|
||||||
@ -35,6 +36,46 @@ from rally_openstack import types as openstack_types
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class RequiredOpenStackValidator(validation.RequiredPlatformValidator):
|
||||||
|
def __init__(self, admin=False, users=False):
|
||||||
|
"""Validates credentials for OpenStack platform.
|
||||||
|
|
||||||
|
This allows us to create 3 kind of tests cases:
|
||||||
|
1) requires platform with admin
|
||||||
|
2) requires platform with admin + users
|
||||||
|
3) requires platform with users
|
||||||
|
|
||||||
|
:param admin: requires admin credential
|
||||||
|
:param users: requires user credentials
|
||||||
|
"""
|
||||||
|
super(RequiredOpenStackValidator, self).__init__(platform="openstack")
|
||||||
|
self.admin = admin
|
||||||
|
self.users = users
|
||||||
|
|
||||||
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
|
if not (self.admin or self.users):
|
||||||
|
self.fail("You should specify admin=True or users=True or both.")
|
||||||
|
|
||||||
|
context = context["platforms"].get(self.platform, {})
|
||||||
|
|
||||||
|
if self.admin and context.get("admin") is None:
|
||||||
|
self.fail("No admin credentials for openstack")
|
||||||
|
if self.users and len(context.get("users", ())) == 0:
|
||||||
|
if context.get("admin") is None:
|
||||||
|
self.fail("No user credentials for openstack")
|
||||||
|
else:
|
||||||
|
# NOTE(andreykurilin): It is a case when the plugin requires
|
||||||
|
# 'users' for launching, but there are no specified users in
|
||||||
|
# deployment. Let's assume that 'users' context can create
|
||||||
|
# them via admin user and do not fail."
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if rally_openstack.__rally_version__ >= (0, 13):
|
||||||
|
RequiredOpenStackValidator = validation.configure(
|
||||||
|
"required_platform", platform="openstack")(RequiredOpenStackValidator)
|
||||||
|
|
||||||
|
|
||||||
def with_roles_ctx():
|
def with_roles_ctx():
|
||||||
"""Add roles to users for validate
|
"""Add roles to users for validate
|
||||||
|
|
||||||
|
@ -66,6 +66,49 @@ def test_with_roles_ctx(mock_role_generator):
|
|||||||
mock_role_generator().setup.assert_called_once_with()
|
mock_role_generator().setup.assert_called_once_with()
|
||||||
|
|
||||||
|
|
||||||
|
class RequiredOpenStackValidatorTestCase(test.TestCase):
|
||||||
|
def validate(self):
|
||||||
|
validator = validators.RequiredOpenStackValidator(admin=True)
|
||||||
|
validator.validate(
|
||||||
|
{"platforms": {"openstack": {"admin": "foo"}}}, {}, None, None)
|
||||||
|
|
||||||
|
validator = validators.RequiredOpenStackValidator(users=True)
|
||||||
|
validator.validate(
|
||||||
|
{"platforms": {"openstack": {"admin": "foo"}}}, {}, None, None)
|
||||||
|
|
||||||
|
validator = validators.RequiredOpenStackValidator(users=True)
|
||||||
|
validator.validate(
|
||||||
|
{"platforms": {"openstack": {"users": ["foo"]}}}, {}, None, None)
|
||||||
|
|
||||||
|
def test_validate_failed(self):
|
||||||
|
# case #1: wrong configuration of validator
|
||||||
|
validator = validators.RequiredOpenStackValidator()
|
||||||
|
e = self.assertRaises(
|
||||||
|
validators.validation.ValidationError,
|
||||||
|
validator.validate, {}, {}, None, None)
|
||||||
|
self.assertEqual(
|
||||||
|
"You should specify admin=True or users=True or both.",
|
||||||
|
e.message)
|
||||||
|
|
||||||
|
# case #2: admin is not present
|
||||||
|
validator = validators.RequiredOpenStackValidator(admin=True)
|
||||||
|
e = self.assertRaises(
|
||||||
|
validators.validation.ValidationError,
|
||||||
|
validator.validate,
|
||||||
|
{"platforms": {"openstack": {}}}, {}, None, None)
|
||||||
|
self.assertEqual("No admin credentials for openstack",
|
||||||
|
e.message)
|
||||||
|
|
||||||
|
# case #3: users are not present
|
||||||
|
validator = validators.RequiredOpenStackValidator(users=True)
|
||||||
|
e = self.assertRaises(
|
||||||
|
validators.validation.ValidationError,
|
||||||
|
validator.validate,
|
||||||
|
{"platforms": {"openstack": {}}}, {}, None, None)
|
||||||
|
self.assertEqual("No user credentials for openstack",
|
||||||
|
e.message)
|
||||||
|
|
||||||
|
|
||||||
@ddt.ddt
|
@ddt.ddt
|
||||||
class ImageExistsValidatorTestCase(test.TestCase):
|
class ImageExistsValidatorTestCase(test.TestCase):
|
||||||
|
|
||||||
|
@ -30,9 +30,15 @@ class WorkaroundTestCase(test.TestCase):
|
|||||||
([0, 12], [
|
([0, 12], [
|
||||||
"'rally_openstack.__init__' module contains a hack for loading "
|
"'rally_openstack.__init__' module contains a hack for loading "
|
||||||
"configuration options.",
|
"configuration options.",
|
||||||
|
|
||||||
"'rally_openstack.types' module contains a compatibility layer for"
|
"'rally_openstack.types' module contains a compatibility layer for"
|
||||||
" an old interface of ResourceTypes."]
|
" an old interface of ResourceTypes."]
|
||||||
)
|
),
|
||||||
|
([0, 13], [
|
||||||
|
"'rally_openstack.validators' module has a check to do not "
|
||||||
|
"register 'required_platforms@openstack' validator for old Rally "
|
||||||
|
"releases."
|
||||||
|
])
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_min_required_version(self):
|
def get_min_required_version(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user