Prepare tests to moving validators to 'openstack/validators.py'
Change-Id: I8ae17f57afdb2129fc39452f19b3c24bbabb53a9
This commit is contained in:
parent
3e66c8f2b0
commit
5f083986ad
@ -20,9 +20,12 @@ from rally.plugins.openstack.cleanup import manager
|
|||||||
|
|
||||||
@validation.configure("check_cleanup_resources")
|
@validation.configure("check_cleanup_resources")
|
||||||
class CheckCleanupResourcesValidator(validation.Validator):
|
class CheckCleanupResourcesValidator(validation.Validator):
|
||||||
"""Validates that openstack resource managers exist"""
|
|
||||||
|
|
||||||
def __init__(self, admin_required):
|
def __init__(self, admin_required):
|
||||||
|
"""Validates that openstack resource managers exist
|
||||||
|
|
||||||
|
:param admin_required: describes access level to resource
|
||||||
|
"""
|
||||||
super(CheckCleanupResourcesValidator, self).__init__()
|
super(CheckCleanupResourcesValidator, self).__init__()
|
||||||
self.admin_required = admin_required
|
self.admin_required = admin_required
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
@context.configure(name="lbaas", order=360)
|
@context.configure(name="lbaas", order=360)
|
||||||
class Lbaas(context.Context):
|
class Lbaas(context.Context):
|
||||||
|
"""Creates a lb-pool for every subnet created in network context."""
|
||||||
CONFIG_SCHEMA = {
|
CONFIG_SCHEMA = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"$schema": consts.JSON_SCHEMA,
|
"$schema": consts.JSON_SCHEMA,
|
||||||
|
@ -25,6 +25,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
@context.configure(name="keypair", order=310)
|
@context.configure(name="keypair", order=310)
|
||||||
class Keypair(context.Context):
|
class Keypair(context.Context):
|
||||||
|
"""Create Nova KeyPair for each user."""
|
||||||
|
|
||||||
# NOTE(andreykurilin): "type" != "null", since we need to support backward
|
# NOTE(andreykurilin): "type" != "null", since we need to support backward
|
||||||
# compatibility(previously empty dict was valid) and I hope in near
|
# compatibility(previously empty dict was valid) and I hope in near
|
||||||
|
@ -25,6 +25,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
@context.configure(name="swift_objects", order=360)
|
@context.configure(name="swift_objects", order=360)
|
||||||
class SwiftObjectGenerator(swift_utils.SwiftObjectMixin, context.Context):
|
class SwiftObjectGenerator(swift_utils.SwiftObjectMixin, context.Context):
|
||||||
|
"""Create containers and objects in each tenant."""
|
||||||
CONFIG_SCHEMA = {
|
CONFIG_SCHEMA = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"$schema": consts.JSON_SCHEMA,
|
"$schema": consts.JSON_SCHEMA,
|
||||||
|
@ -15,12 +15,11 @@
|
|||||||
|
|
||||||
from rally.common.plugin import info
|
from rally.common.plugin import info
|
||||||
from rally.common.plugin import plugin
|
from rally.common.plugin import plugin
|
||||||
|
from rally.common import validation
|
||||||
from rally import plugins
|
from rally import plugins
|
||||||
|
from rally.task import scenario
|
||||||
from tests.unit import test
|
from tests.unit import test
|
||||||
|
|
||||||
EXCEPTIONS_DOCSTR = "missed_docstrings.txt"
|
|
||||||
EXCEPTIONS_FORMAT = "wrong_format.txt"
|
|
||||||
|
|
||||||
|
|
||||||
class DocstringsTestCase(test.TestCase):
|
class DocstringsTestCase(test.TestCase):
|
||||||
|
|
||||||
@ -28,59 +27,58 @@ class DocstringsTestCase(test.TestCase):
|
|||||||
super(DocstringsTestCase, self).setUp()
|
super(DocstringsTestCase, self).setUp()
|
||||||
plugins.load()
|
plugins.load()
|
||||||
|
|
||||||
self.exceptions = self._open_file(
|
def _validate_code_block(self, plg_cls, code_block):
|
||||||
EXCEPTIONS_DOCSTR) + self._open_file(EXCEPTIONS_FORMAT)
|
ignored_params = ["self", "scenario_obj"]
|
||||||
|
params_count = code_block.co_argcount
|
||||||
def _open_file(self, filename):
|
params = code_block.co_varnames[:params_count]
|
||||||
with open("./tests/unit/doc/%s" % filename) as file:
|
param_data = plg_cls.get_info()["parameters"]
|
||||||
return (file.read().lower().split())
|
documented_params = [p["name"] for p in param_data]
|
||||||
|
result = []
|
||||||
|
for param in params:
|
||||||
|
if param not in ignored_params:
|
||||||
|
if param not in documented_params:
|
||||||
|
msg = ("Class: %(class)s Docstring for "
|
||||||
|
"%(scenario)s should"
|
||||||
|
" describe the '%(param)s' parameter"
|
||||||
|
" in the :param <name>: clause."
|
||||||
|
% {"class": plg_cls.__name__,
|
||||||
|
"scenario": plg_cls.get_name(),
|
||||||
|
"param": param})
|
||||||
|
result.append(msg)
|
||||||
|
return result
|
||||||
|
|
||||||
def _check_docstrings(self, msg_buffer):
|
def _check_docstrings(self, msg_buffer):
|
||||||
for plg_cls in plugin.Plugin.get_all():
|
for plg_cls in plugin.Plugin.get_all():
|
||||||
if plg_cls.__module__.startswith("rally."):
|
if plg_cls.__module__.startswith("rally."):
|
||||||
if plg_cls.get_name().lower() not in self.exceptions:
|
doc = info.parse_docstring(plg_cls.__doc__)
|
||||||
doc = info.parse_docstring(plg_cls.__doc__)
|
short_description = doc["short_description"]
|
||||||
short_description = doc["short_description"]
|
if short_description.startswith("Test"):
|
||||||
if short_description.startswith("Test"):
|
msg_buffer.append("One-line description for %s"
|
||||||
msg_buffer.append("One-line description for %s"
|
" should be declarative and not"
|
||||||
" should be declarative and not"
|
" start with 'Test(s) ...'"
|
||||||
" start with 'Test(s) ...'"
|
% plg_cls.__name__)
|
||||||
% plg_cls.__name__)
|
if not plg_cls.get_info()["title"]:
|
||||||
if not plg_cls.get_info()["title"]:
|
msg = "Class '{}.{}' should have a docstring."
|
||||||
msg = ("Class '{}' should have a docstring.")
|
msg_buffer.append(msg.format(plg_cls.__module__,
|
||||||
inst_name = plg_cls.__name__
|
plg_cls.__name__))
|
||||||
msg_buffer.append(msg.format(inst_name))
|
|
||||||
|
|
||||||
def _check_described_params(self, msg_buffer):
|
def _check_described_params(self, msg_buffer):
|
||||||
for plg_cls in plugin.Plugin.get_all():
|
for plg_cls in plugin.Plugin.get_all():
|
||||||
if plg_cls.get_name().lower() not in self.exceptions:
|
msg = []
|
||||||
ignored_params = ["self", "scenario_obj"]
|
if hasattr(plg_cls, "run") and issubclass(
|
||||||
if hasattr(plg_cls, "run"):
|
plg_cls, scenario.Scenario):
|
||||||
code_block = plg_cls.run.__code__
|
msg = self._validate_code_block(plg_cls,
|
||||||
params_count = code_block.co_argcount
|
plg_cls.run.__code__)
|
||||||
params = code_block.co_varnames[:params_count]
|
elif hasattr(plg_cls, "validate") and issubclass(
|
||||||
param_data = plg_cls.get_info()["parameters"]
|
plg_cls, validation.Validator):
|
||||||
documented_params = [p["name"] for p in param_data]
|
msg = self._validate_code_block(plg_cls,
|
||||||
for param in params:
|
plg_cls.__init__.__code__)
|
||||||
if param not in ignored_params:
|
msg_buffer.extend(msg) if len(msg) else None
|
||||||
if param not in documented_params:
|
|
||||||
msg = ("Class: %(class)s Docstring for "
|
|
||||||
"%(scenario)s should"
|
|
||||||
" describe the '%(param)s' parameter"
|
|
||||||
" in the :param <name>: clause."
|
|
||||||
% {"class": plg_cls.__name__,
|
|
||||||
"scenario": plg_cls.get_name(),
|
|
||||||
"param": param})
|
|
||||||
msg_buffer.append(msg)
|
|
||||||
|
|
||||||
def test_all_plugins_have_docstrings(self):
|
def test_all_plugins_have_docstrings(self):
|
||||||
|
|
||||||
msg_buffer = []
|
msg_buffer = []
|
||||||
self._check_docstrings(msg_buffer)
|
self._check_docstrings(msg_buffer)
|
||||||
if msg_buffer:
|
|
||||||
self.fail("\n%s" % "\n".join(msg_buffer))
|
|
||||||
|
|
||||||
msg_buffer = []
|
|
||||||
self._check_described_params(msg_buffer)
|
self._check_described_params(msg_buffer)
|
||||||
if msg_buffer:
|
if msg_buffer:
|
||||||
self.fail("\n%s" % "\n".join(msg_buffer))
|
self.fail("\n%s" % "\n".join(msg_buffer))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user