Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix module schema #74295

Merged
merged 8 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/fix_module_schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- schema validation now uses dynamic range of versions for valid deprecation entries vs hardcoded out of date list.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ansible.module_utils.six import string_types
from ansible.module_utils.common.collections import is_iterable
from ansible.utils.version import SemanticVersion
from ansible.release import __version__

from .utils import parse_isodate

Expand Down Expand Up @@ -59,6 +60,12 @@ def collection_name(v, error_code=None):
return v


def deprecation_versions():
"""Create a list of valid version for deprecation entries, current+4"""
major, minor = [int(version) for version in __version__.split('.')[0:2]]
return Any(*['{0}.{1}'.format(major, minor + increment) for increment in range(0, 5)])
Comment on lines +65 to +66
Copy link
Member

@webknjaz webknjaz Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

from decimal import Context, Decimal

def emit_version_range(ver, num):
    ctx = Context(3)  # x.xx
    for _ in range(num):
        ver = ver.next_plus(ctx)
        yield ver

and then

Suggested change
major, minor = [int(version) for version in __version__.split('.')[0:2]]
return Any(*['{0}.{1}'.format(major, minor + increment) for increment in range(0, 5)])
ver = Decimal('.'.join(__version__.split('.')[:2]))
return Any(*[str(v) for v in emit_version_range(ver, 5)])

(inspired by @nitzmahone's comments on Slack but it's probably overkill)



def version(for_collection=False):
if for_collection:
# We do not accept floats for versions in collections
Expand Down Expand Up @@ -446,11 +453,7 @@ def deprecation_schema(for_collection):
}
else:
version_schema = {
# Only list branches that are deprecated or may have docs stubs in
# Deprecation cycle changed at 2.4 (though not retroactively)
# 2.3 -> removed_in: "2.5" + n for docs stub
# 2.4 -> removed_in: "2.8" + n for docs stub
Required('removed_in'): Any("2.12", "2.13", "2.14", "2.15", "2.16"),
Required('removed_in'): deprecation_versions(),
}
version_schema.update(main_fields)

Expand Down