summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/argspec
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:03:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:03:01 +0000
commita453ac31f3428614cceb99027f8efbdb9258a40b (patch)
treef61f87408f32a8511cbd91799f9cececb53e0374 /test/integration/targets/argspec
parentInitial commit. (diff)
downloadansible-a453ac31f3428614cceb99027f8efbdb9258a40b.tar.xz
ansible-a453ac31f3428614cceb99027f8efbdb9258a40b.zip
Adding upstream version 2.10.7+merged+base+2.10.8+dfsg.upstream/2.10.7+merged+base+2.10.8+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/argspec')
-rw-r--r--test/integration/targets/argspec/aliases1
-rw-r--r--test/integration/targets/argspec/library/argspec.py153
-rw-r--r--test/integration/targets/argspec/tasks/main.yml419
-rw-r--r--test/integration/targets/argspec/tasks/password_no_log.yml14
4 files changed, 587 insertions, 0 deletions
diff --git a/test/integration/targets/argspec/aliases b/test/integration/targets/argspec/aliases
new file mode 100644
index 00000000..70a7b7a9
--- /dev/null
+++ b/test/integration/targets/argspec/aliases
@@ -0,0 +1 @@
+shippable/posix/group5
diff --git a/test/integration/targets/argspec/library/argspec.py b/test/integration/targets/argspec/library/argspec.py
new file mode 100644
index 00000000..08dad1a0
--- /dev/null
+++ b/test/integration/targets/argspec/library/argspec.py
@@ -0,0 +1,153 @@
+#!/usr/bin/python
+# Copyright: (c) 2020, Matt Martz <matt@sivel.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+from __future__ import absolute_import, division, print_function
+__metaclass__ = type
+
+from ansible.module_utils.basic import AnsibleModule
+
+
+def main():
+ module = AnsibleModule(
+ {
+ 'required': {
+ 'required': True,
+ },
+ 'required_one_of_one': {},
+ 'required_one_of_two': {},
+ 'required_by_one': {},
+ 'required_by_two': {},
+ 'required_by_three': {},
+ 'state': {
+ 'type': 'str',
+ 'choices': ['absent', 'present'],
+ },
+ 'path': {},
+ 'content': {},
+ 'mapping': {
+ 'type': 'dict',
+ },
+ 'required_one_of': {
+ 'required_one_of': [['thing', 'other']],
+ 'type': 'list',
+ 'elements': 'dict',
+ 'options': {
+ 'thing': {},
+ 'other': {},
+ },
+ },
+ 'required_by': {
+ 'required_by': {'thing': 'other'},
+ 'type': 'list',
+ 'elements': 'dict',
+ 'options': {
+ 'thing': {},
+ 'other': {},
+ },
+ },
+ 'required_together': {
+ 'required_together': [['thing', 'other']],
+ 'type': 'list',
+ 'elements': 'dict',
+ 'options': {
+ 'thing': {},
+ 'other': {},
+ 'another': {},
+ },
+ },
+ 'required_if': {
+ 'required_if': (
+ ('thing', 'foo', ('other',), True),
+ ),
+ 'type': 'list',
+ 'elements': 'dict',
+ 'options': {
+ 'thing': {},
+ 'other': {},
+ 'another': {},
+ },
+ },
+ 'json': {
+ 'type': 'json',
+ },
+ 'fail_on_missing_params': {
+ 'type': 'list',
+ 'default': [],
+ },
+ 'needed_param': {},
+ 'required_together_one': {},
+ 'required_together_two': {},
+ 'suboptions_list_no_elements': {
+ 'type': 'list',
+ 'options': {
+ 'thing': {},
+ },
+ },
+ 'choices_with_strings_like_bools': {
+ 'type': 'str',
+ 'choices': [
+ 'on',
+ 'off',
+ ],
+ },
+ 'choices': {
+ 'type': 'str',
+ 'choices': [
+ 'foo',
+ 'bar',
+ ],
+ },
+ 'list_choices': {
+ 'type': 'list',
+ 'choices': [
+ 'foo',
+ 'bar',
+ 'baz',
+ ],
+ },
+ 'primary': {
+ 'type': 'str',
+ 'aliases': [
+ 'alias',
+ ],
+ },
+ 'password': {
+ 'type': 'str',
+ 'no_log': True,
+ },
+ 'not_a_password': {
+ 'type': 'str',
+ 'no_log': False,
+ },
+ 'maybe_password': {
+ 'type': 'str',
+ },
+ 'int': {
+ 'type': 'int',
+ },
+ },
+ required_if=(
+ ('state', 'present', ('path', 'content'), True),
+ ),
+ mutually_exclusive=(
+ ('path', 'content'),
+ ),
+ required_one_of=(
+ ('required_one_of_one', 'required_one_of_two'),
+ ),
+ required_by={
+ 'required_by_one': ('required_by_two', 'required_by_three'),
+ },
+ required_together=(
+ ('required_together_one', 'required_together_two'),
+ ),
+ )
+
+ module.fail_on_missing_params(module.params['fail_on_missing_params'])
+
+ module.exit_json(**module.params)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/test/integration/targets/argspec/tasks/main.yml b/test/integration/targets/argspec/tasks/main.yml
new file mode 100644
index 00000000..d90bdf02
--- /dev/null
+++ b/test/integration/targets/argspec/tasks/main.yml
@@ -0,0 +1,419 @@
+- argspec:
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ required_one_of_one: value
+ register: argspec_required_fail
+ ignore_errors: true
+
+- argspec:
+ required: value
+ required_one_of_two: value
+
+- argspec:
+ required: value
+ register: argspec_required_one_of_fail
+ ignore_errors: true
+
+- argspec:
+ required: value
+ required_one_of_two: value
+ required_by_one: value
+ required_by_two: value
+ required_by_three: value
+
+- argspec:
+ required: value
+ required_one_of_two: value
+ required_by_one: value
+ required_by_two: value
+ register: argspec_required_by_fail
+ ignore_errors: true
+
+- argspec:
+ state: absent
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ state: present
+ required: value
+ required_one_of_one: value
+ register: argspec_required_if_fail
+ ignore_errors: true
+
+- argspec:
+ state: present
+ path: foo
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ state: present
+ content: foo
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ state: present
+ content: foo
+ path: foo
+ required: value
+ required_one_of_one: value
+ register: argspec_mutually_exclusive_fail
+ ignore_errors: true
+
+- argspec:
+ mapping:
+ foo: bar
+ required: value
+ required_one_of_one: value
+ register: argspec_good_mapping
+
+- argspec:
+ mapping: foo=bar
+ required: value
+ required_one_of_one: value
+ register: argspec_good_mapping_kv
+
+- argspec:
+ mapping: !!str '{"foo": "bar"}'
+ required: value
+ required_one_of_one: value
+ register: argspec_good_mapping_json
+
+- argspec:
+ mapping: !!str '{"foo": False}'
+ required: value
+ required_one_of_one: value
+ register: argspec_good_mapping_dict_repr
+
+- argspec:
+ mapping: foo
+ required: value
+ required_one_of_one: value
+ register: argspec_bad_mapping_string
+ ignore_errors: true
+
+- argspec:
+ mapping: 1
+ required: value
+ required_one_of_one: value
+ register: argspec_bad_mapping_int
+ ignore_errors: true
+
+- argspec:
+ mapping:
+ - foo
+ - bar
+ required: value
+ required_one_of_one: value
+ register: argspec_bad_mapping_list
+ ignore_errors: true
+
+- argspec:
+ required_together:
+ - thing: foo
+ other: bar
+ another: baz
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ required_together:
+ - another: baz
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ required_together:
+ - thing: foo
+ required: value
+ required_one_of_one: value
+ register: argspec_required_together_fail
+ ignore_errors: true
+
+- argspec:
+ required_together:
+ - thing: foo
+ other: bar
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ required_if:
+ - thing: bar
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ required_if:
+ - thing: foo
+ other: bar
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ required_if:
+ - thing: foo
+ required: value
+ required_one_of_one: value
+ register: argspec_required_if_fail_2
+ ignore_errors: true
+
+- argspec:
+ required_one_of:
+ - thing: foo
+ other: bar
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ required_one_of:
+ - {}
+ required: value
+ required_one_of_one: value
+ register: argspec_required_one_of_fail_2
+ ignore_errors: true
+
+- argspec:
+ required_by:
+ - thing: foo
+ other: bar
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ required_by:
+ - thing: foo
+ required: value
+ required_one_of_one: value
+ register: argspec_required_by_fail_2
+ ignore_errors: true
+
+- argspec:
+ json: !!str '{"foo": "bar"}'
+ required: value
+ required_one_of_one: value
+ register: argspec_good_json_string
+
+- argspec:
+ json:
+ foo: bar
+ required: value
+ required_one_of_one: value
+ register: argspec_good_json_dict
+
+- argspec:
+ json: 1
+ required: value
+ required_one_of_one: value
+ register: argspec_bad_json
+ ignore_errors: true
+
+- argspec:
+ fail_on_missing_params:
+ - needed_param
+ needed_param: whatever
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ fail_on_missing_params:
+ - needed_param
+ required: value
+ required_one_of_one: value
+ register: argspec_fail_on_missing_params_bad
+ ignore_errors: true
+
+- argspec:
+ required_together_one: foo
+ required_together_two: bar
+ required: value
+ required_one_of_one: value
+
+- argspec:
+ required_together_one: foo
+ required: value
+ required_one_of_one: value
+ register: argspec_fail_required_together_2
+ ignore_errors: true
+
+- argspec:
+ suboptions_list_no_elements:
+ - thing: foo
+ required: value
+ required_one_of_one: value
+ register: argspec_suboptions_list_no_elements
+
+- argspec:
+ choices_with_strings_like_bools: on
+ required: value
+ required_one_of_one: value
+ register: argspec_choices_with_strings_like_bools_true
+
+- argspec:
+ choices_with_strings_like_bools: 'on'
+ required: value
+ required_one_of_one: value
+ register: argspec_choices_with_strings_like_bools_true_bool
+
+- argspec:
+ choices_with_strings_like_bools: off
+ required: value
+ required_one_of_one: value
+ register: argspec_choices_with_strings_like_bools_false
+
+- argspec:
+ required: value
+ required_one_of_one: value
+ choices: foo
+
+- argspec:
+ required: value
+ required_one_of_one: value
+ choices: baz
+ register: argspec_choices_bad_choice
+ ignore_errors: true
+
+- argspec:
+ required: value
+ required_one_of_one: value
+ list_choices:
+ - bar
+ - baz
+
+- argspec:
+ required: value
+ required_one_of_one: value
+ list_choices:
+ - bar
+ - baz
+ - qux
+ register: argspec_list_choices_bad_choice
+ ignore_errors: true
+
+- argspec:
+ required: value
+ required_one_of_one: value
+ primary: foo
+ register: argspec_aliases_primary
+
+- argspec:
+ required: value
+ required_one_of_one: value
+ alias: foo
+ register: argspec_aliases_alias
+
+- argspec:
+ required: value
+ required_one_of_one: value
+ primary: foo
+ alias: foo
+ register: argspec_aliases_both
+
+- argspec:
+ required: value
+ required_one_of_one: value
+ primary: foo
+ alias: bar
+ register: argspec_aliases_both_different
+
+- command: >-
+ ansible localhost -m argspec
+ -a 'required=value required_one_of_one=value primary=foo alias=bar'
+ environment:
+ ANSIBLE_LIBRARY: '{{ role_path }}/library'
+ register: argspec_aliases_both_warning
+
+- command: ansible localhost -m import_role -a 'role=argspec tasks_from=password_no_log.yml'
+ register: argspec_password_no_log
+
+- argspec:
+ required: value
+ required_one_of_one: value
+ int: 1
+
+- argspec:
+ required: value
+ required_one_of_one: value
+ int: foo
+ register: argspec_int_invalid
+ ignore_errors: true
+
+- assert:
+ that:
+ - argspec_required_fail is failed
+
+ - argspec_required_one_of_fail is failed
+
+ - argspec_required_by_fail is failed
+
+ - argspec_required_if_fail is failed
+
+ - argspec_mutually_exclusive_fail is failed
+
+ - argspec_good_mapping is successful
+ - >-
+ argspec_good_mapping.mapping == {'foo': 'bar'}
+ - argspec_good_mapping_json is successful
+ - >-
+ argspec_good_mapping_json.mapping == {'foo': 'bar'}
+ - argspec_good_mapping_dict_repr is successful
+ - >-
+ argspec_good_mapping_dict_repr.mapping == {'foo': False}
+ - argspec_good_mapping_kv is successful
+ - >-
+ argspec_good_mapping_kv.mapping == {'foo': 'bar'}
+ - argspec_bad_mapping_string is failed
+ - argspec_bad_mapping_int is failed
+ - argspec_bad_mapping_list is failed
+
+ - argspec_required_together_fail is failed
+
+ - argspec_required_if_fail_2 is failed
+
+ - argspec_required_one_of_fail_2 is failed
+
+ - argspec_required_by_fail_2 is failed
+
+ - argspec_good_json_string is successful
+ - >-
+ argspec_good_json_string.json == '{"foo": "bar"}'
+ - argspec_good_json_dict is successful
+ - >-
+ argspec_good_json_dict.json == '{"foo": "bar"}'
+ - argspec_bad_json is failed
+
+ - argspec_fail_on_missing_params_bad is failed
+
+ - argspec_fail_required_together_2 is failed
+
+ - >-
+ argspec_suboptions_list_no_elements.suboptions_list_no_elements.0 == {'thing': 'foo'}
+
+ - argspec_choices_with_strings_like_bools_true.choices_with_strings_like_bools == 'on'
+ - argspec_choices_with_strings_like_bools_true_bool.choices_with_strings_like_bools == 'on'
+ - argspec_choices_with_strings_like_bools_false.choices_with_strings_like_bools == 'off'
+
+ - argspec_choices_bad_choice is failed
+
+ - argspec_list_choices_bad_choice is failed
+
+ - argspec_aliases_primary.primary == 'foo'
+ - argspec_aliases_primary.alias is undefined
+ - argspec_aliases_alias.primary == 'foo'
+ - argspec_aliases_alias.alias == 'foo'
+ - argspec_aliases_both.primary == 'foo'
+ - argspec_aliases_both.alias == 'foo'
+ - argspec_aliases_both_different.primary == 'bar'
+ - argspec_aliases_both_different.alias == 'bar'
+ - '"[WARNING]: Both option primary and its alias alias are set." in argspec_aliases_both_warning.stderr'
+
+ - '"Module did not set no_log for maybe_password" in argspec_password_no_log.stderr'
+ - '"Module did not set no_log for password" not in argspec_password_no_log.stderr'
+ - '"Module did not set no_log for not_a_password" not in argspec_password_no_log.stderr'
+ - argspec_password_no_log.stdout|regex_findall('VALUE_SPECIFIED_IN_NO_LOG_PARAMETER')|length == 1
+
+ - argspec_int_invalid is failed
diff --git a/test/integration/targets/argspec/tasks/password_no_log.yml b/test/integration/targets/argspec/tasks/password_no_log.yml
new file mode 100644
index 00000000..99c3307b
--- /dev/null
+++ b/test/integration/targets/argspec/tasks/password_no_log.yml
@@ -0,0 +1,14 @@
+- argspec:
+ required: value
+ required_one_of_one: value
+ password: foo
+
+- argspec:
+ required: value
+ required_one_of_one: value
+ not_a_password: foo
+
+- argspec:
+ required: value
+ required_one_of_one: value
+ maybe_password: foo