From 8980d275a0b8c42ee0231d8459f025db6449a3b5 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Fri, 9 Mar 2018 17:09:58 -0600 Subject: [PATCH] Support recursive suboptions schema (#37206) * Support recursive suboptions schema * Remove todo line, add voluptuous version constraint --- test/runner/requirements/constraints.txt | 1 + test/sanity/validate-modules/schema.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/runner/requirements/constraints.txt b/test/runner/requirements/constraints.txt index c143e520d57..16c1272a5ee 100644 --- a/test/runner/requirements/constraints.txt +++ b/test/runner/requirements/constraints.txt @@ -15,3 +15,4 @@ pytest < 3.3.0 ; python_version < '2.7' # pytest 3.3.0 drops support for python ntlm-auth >= 1.0.6 # message encryption support requests-ntlm >= 1.1.0 # message encryption support requests-credssp >= 0.1.0 # message encryption support +voluptuous >= 0.11.0 # Schema recursion via Self diff --git a/test/sanity/validate-modules/schema.py b/test/sanity/validate-modules/schema.py index 53f38e84bd4..e30ab30a1ee 100644 --- a/test/sanity/validate-modules/schema.py +++ b/test/sanity/validate-modules/schema.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from voluptuous import PREVENT_EXTRA, Any, Required, Schema +from voluptuous import PREVENT_EXTRA, Any, Required, Schema, Self from ansible.module_utils.six import string_types list_string_types = list(string_types) @@ -29,7 +29,9 @@ suboption_schema = Schema( 'version_added': Any(float, *string_types), 'default': Any(None, float, int, bool, list, dict, *string_types), # Note: Types are strings, not literal bools, such as True or False - 'type': Any(None, "bool") + 'type': Any(None, "bool"), + # Recursive suboptions + 'suboptions': Any(None, *list({str_type: Self} for str_type in string_types)), }, extra=PREVENT_EXTRA ) @@ -171,6 +173,5 @@ def metadata_1_1_schema(deprecated): # 1) Don't allow empty options for choices, aliases, etc # 2) If type: bool ensure choices isn't set - perhaps use Exclusive # 3) both version_added should be quoted floats -# 4) Use Recursive Schema: https://github.com/alecthomas/voluptuous/issues/128 though don't allow two layers # Tool that takes JSON and generates RETURN skeleton (needs to support complex structures)