Fix sequence lookup message and add tests (#74472)
* add test for bad kv arg value * add simple form parsing tests and make error messages the same * add changelog
This commit is contained in:
parent
74b2add460
commit
f1a5c411d9
3 changed files with 141 additions and 3 deletions
3
changelogs/fragments/74472-sequence-lookup.yaml
Normal file
3
changelogs/fragments/74472-sequence-lookup.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
bugfixes:
|
||||||
|
- sequence - fix error message so that unrecognized options to the plugin display correctly as a list
|
||||||
|
and normalize error messages.
|
|
@ -159,15 +159,15 @@ class LookupModule(LookupBase):
|
||||||
setattr(self, arg, arg_cooked)
|
setattr(self, arg, arg_cooked)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise AnsibleError(
|
raise AnsibleError(
|
||||||
"can't parse arg %s=%r as integer"
|
"can't parse %s=%s as integer"
|
||||||
% (arg, arg_raw)
|
% (arg, arg_raw)
|
||||||
)
|
)
|
||||||
if 'format' in args:
|
if 'format' in args:
|
||||||
self.format = args.pop("format")
|
self.format = args.pop("format")
|
||||||
if args:
|
if args:
|
||||||
raise AnsibleError(
|
raise AnsibleError(
|
||||||
"unrecognized arguments to with_sequence: %r"
|
"unrecognized arguments to with_sequence: %s"
|
||||||
% args.keys()
|
% list(args.keys())
|
||||||
)
|
)
|
||||||
|
|
||||||
def parse_simple_args(self, term):
|
def parse_simple_args(self, term):
|
||||||
|
|
|
@ -61,3 +61,138 @@
|
||||||
- "ws_z_6 == 'stride_6'"
|
- "ws_z_6 == 'stride_6'"
|
||||||
- "ws_z_host07 == 'host07'"
|
- "ws_z_host07 == 'host07'"
|
||||||
- "ws_z_host08 == 'host08'"
|
- "ws_z_host08 == 'host08'"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE - test invalid arg
|
||||||
|
set_fact: "{{ 'x' + item }}={{ item }}"
|
||||||
|
with_sequence: start=0 junk=3
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test invalid arg"
|
||||||
|
- ansible_failed_result.msg in [expected1, expected2]
|
||||||
|
vars:
|
||||||
|
expected1: "unrecognized arguments to with_sequence: ['junk']"
|
||||||
|
expected2: "unrecognized arguments to with_sequence: [u'junk']"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE - test bad kv value
|
||||||
|
set_fact: "{{ 'x' + item }}={{ item }}"
|
||||||
|
with_sequence: start=A end=3
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test bad kv value"
|
||||||
|
- ansible_failed_result.msg == "can't parse start=A as integer"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE - test bad simple form start value
|
||||||
|
set_fact: "{{ 'x' + item }}={{ item }}"
|
||||||
|
with_sequence: A-4/2
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test bad simple form start value"
|
||||||
|
- ansible_failed_result.msg == "can't parse start=A as integer"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE - test bad simple form end value
|
||||||
|
set_fact: "{{ 'x' + item }}={{ item }}"
|
||||||
|
with_sequence: 1-B/2
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test bad simple form end value"
|
||||||
|
- ansible_failed_result.msg == "can't parse end=B as integer"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE - test bad simple form stride value
|
||||||
|
set_fact: "{{ 'x' + item }}={{ item }}"
|
||||||
|
with_sequence: 1-4/C
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test bad simple form stride value"
|
||||||
|
- ansible_failed_result.msg == "can't parse stride=C as integer"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE - test no count or end
|
||||||
|
set_fact: "{{ 'x' + item }}={{ item }}"
|
||||||
|
with_sequence: start=1
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test no count or end"
|
||||||
|
- ansible_failed_result.msg == "must specify count or end in with_sequence"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE - test both count and end
|
||||||
|
set_fact: "{{ 'x' + item }}={{ item }}"
|
||||||
|
with_sequence: start=1 end=4 count=2
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test both count and end"
|
||||||
|
- ansible_failed_result.msg == "can't specify both count and end in with_sequence"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE - test count backwards message
|
||||||
|
set_fact: "{{ 'x' + item }}={{ item }}"
|
||||||
|
with_sequence: start=4 end=1 stride=2
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test count backwards message"
|
||||||
|
- ansible_failed_result.msg == "to count backwards make stride negative"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE - test count forward message
|
||||||
|
set_fact: "{{ 'x' + item }}={{ item }}"
|
||||||
|
with_sequence: start=1 end=4 stride=-2
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test count forward message"
|
||||||
|
- ansible_failed_result.msg == "to count forward don't make stride negative"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE - test bad format string message
|
||||||
|
set_fact: "{{ 'x' + item }}={{ item }}"
|
||||||
|
with_sequence: start=1 end=4 format=d
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test bad format string message"
|
||||||
|
- ansible_failed_result.msg == expected
|
||||||
|
vars:
|
||||||
|
expected: "bad formatting string: d"
|
Loading…
Reference in a new issue