summaryrefslogtreecommitdiff
path: root/lib/ansible/plugins
diff options
context:
space:
mode:
authorSam Doran <sdoran@redhat.com>2021-06-11 12:32:30 -0400
committerGitHub <noreply@github.com>2021-06-11 11:32:30 -0500
commit578fa17af58ae665cc652c530f1de6562659665c (patch)
tree9a09782df7951a966be558436585a122569437ef /lib/ansible/plugins
parent46378f0086f7c84587c94df444f594153fbced50 (diff)
downloadansible-578fa17af58ae665cc652c530f1de6562659665c.tar.gz
[stable-2.11] version test - improve message when value is empty (#74754) (#74789)
When an empty value is provided, no `version` attribute will exist on the `LooseVersion` or `StrictVersion` object. We catch and handle this, but it's not immediatebly clear that an AttributeError means an empty value was provided. Specifically handle the case where value or version are empty and add more helpful error messages. Add integration tests. (cherry picked from commit 71e33d2578) Co-authored-by: Sam Doran <sdoran@redhat.com>
Diffstat (limited to 'lib/ansible/plugins')
-rw-r--r--lib/ansible/plugins/test/core.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/ansible/plugins/test/core.py b/lib/ansible/plugins/test/core.py
index 4b3995dd16..42aec36a06 100644
--- a/lib/ansible/plugins/test/core.py
+++ b/lib/ansible/plugins/test/core.py
@@ -168,6 +168,12 @@ def version_compare(value, version, operator='eq', strict=None, version_type=Non
if strict is not None and version_type is not None:
raise errors.AnsibleFilterError("Cannot specify both 'strict' and 'version_type'")
+ if not value:
+ raise errors.AnsibleFilterError("Input version value cannot be empty")
+
+ if not version:
+ raise errors.AnsibleFilterError("Version parameter to compare against cannot be empty")
+
Version = LooseVersion
if strict:
Version = StrictVersion