diff --git a/test/integration/targets/filters/aliases b/test/integration/targets/filter_core/aliases similarity index 100% rename from test/integration/targets/filters/aliases rename to test/integration/targets/filter_core/aliases diff --git a/test/integration/targets/filters/files/9851.txt b/test/integration/targets/filter_core/files/9851.txt similarity index 100% rename from test/integration/targets/filters/files/9851.txt rename to test/integration/targets/filter_core/files/9851.txt diff --git a/test/integration/targets/filters/files/fileglob/one.txt b/test/integration/targets/filter_core/files/fileglob/one.txt similarity index 100% rename from test/integration/targets/filters/files/fileglob/one.txt rename to test/integration/targets/filter_core/files/fileglob/one.txt diff --git a/test/integration/targets/filters/files/fileglob/two.txt b/test/integration/targets/filter_core/files/fileglob/two.txt similarity index 100% rename from test/integration/targets/filters/files/fileglob/two.txt rename to test/integration/targets/filter_core/files/fileglob/two.txt diff --git a/test/integration/targets/filters/files/foo.txt b/test/integration/targets/filter_core/files/foo.txt similarity index 100% rename from test/integration/targets/filters/files/foo.txt rename to test/integration/targets/filter_core/files/foo.txt diff --git a/test/integration/targets/filters/host_vars/localhost b/test/integration/targets/filter_core/host_vars/localhost similarity index 100% rename from test/integration/targets/filters/host_vars/localhost rename to test/integration/targets/filter_core/host_vars/localhost diff --git a/test/integration/targets/filter_core/runme.sh b/test/integration/targets/filter_core/runme.sh new file mode 100755 index 00000000000..ac4361f3a45 --- /dev/null +++ b/test/integration/targets/filter_core/runme.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -eux + +ANSIBLE_ROLES_PATH=../ ansible-playbook runme.yml "$@" diff --git a/test/integration/targets/filter_core/runme.yml b/test/integration/targets/filter_core/runme.yml new file mode 100644 index 00000000000..4af4b23c423 --- /dev/null +++ b/test/integration/targets/filter_core/runme.yml @@ -0,0 +1,3 @@ +- hosts: localhost + roles: + - { role: filter_core } diff --git a/test/integration/targets/filters/tasks/main.yml b/test/integration/targets/filter_core/tasks/main.yml similarity index 60% rename from test/integration/targets/filters/tasks/main.yml rename to test/integration/targets/filter_core/tasks/main.yml index 5bf52522cfe..e14889eb23e 100644 --- a/test/integration/targets/filters/tasks/main.yml +++ b/test/integration/targets/filter_core/tasks/main.yml @@ -61,42 +61,6 @@ that: - 'diff_result.stdout == ""' -- name: Verify human_readable - tags: "human_readable" - assert: - that: - - '"1.00 Bytes" == 1|human_readable' - - '"1.00 bits" == 1|human_readable(isbits=True)' - - '"10.00 KB" == 10240|human_readable' - - '"97.66 MB" == 102400000|human_readable' - - '"0.10 GB" == 102400000|human_readable(unit="G")' - - '"0.10 Gb" == 102400000|human_readable(isbits=True, unit="G")' - -- name: Verify human_to_bytes - tags: "human_to_bytes" - assert: - that: - - "{{'0'|human_to_bytes}} == 0" - - "{{'0.1'|human_to_bytes}} == 0" - - "{{'0.9'|human_to_bytes}} == 1" - - "{{'1'|human_to_bytes}} == 1" - - "{{'10.00 KB'|human_to_bytes}} == 10240" - - "{{ '11 MB'|human_to_bytes}} == 11534336" - - "{{ '1.1 GB'|human_to_bytes}} == 1181116006" - - "{{'10.00 Kb'|human_to_bytes(isbits=True)}} == 10240" - -- name: Verify human_to_bytes (bad string) - set_fact: - bad_string: "{{ '10.00 foo' | human_to_bytes }}" - ignore_errors: yes - tags: human_to_bytes - register: _human_bytes_test - -- name: Verify human_to_bytes (bad string) - tags: human_to_bytes - assert: - that: "{{_human_bytes_test.failed}}" - - name: Test extract assert: that: @@ -139,62 +103,12 @@ - "'localhost' | extract(hostvars, ['badsubkey', 'subsubkey']) | default('a') == 'a'" - "('localhost' | extract(hostvars, 'badsubkey')).subsubkey | default('a') == 'a'" -- name: Test json_query filter - assert: - that: - - "users | json_query('[*].hosts[].host') == ['host_a', 'host_b', 'host_c', 'host_d']" - - name: Test hash filter assert: that: - '"{{ "hash" | hash("sha1") }}" == "2346ad27d7568ba9896f1b7da6b5991251debdf2"' - '"{{ "café" | hash("sha1") }}" == "f424452a9673918c6f09b0cdd35b20be8e6ae7d7"' -- debug: - var: "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit" - verbosity: 1 - tags: debug - -- name: Test urlsplit filter - assert: - that: - - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('fragment') == 'fragment'" - - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('hostname') == 'www.acme.com'" - - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('netloc') == 'mary:MySecret@www.acme.com:9000'" - - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('path') == '/dir/index.html'" - - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('port') == 9000" - - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('query') == 'query=term'" - - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('scheme') == 'http'" - - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('username') == 'mary'" - - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('password') == 'MySecret'" - - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit == { 'fragment': 'fragment', 'hostname': 'www.acme.com', 'netloc': 'mary:MySecret@www.acme.com:9000', 'password': 'MySecret', 'path': '/dir/index.html', 'port': 9000, 'query': 'query=term', 'scheme': 'http', 'username': 'mary' }" - - -- name: Test urlsplit filter bad argument - debug: - var: "'http://www.acme.com:9000/dir/index.html' | urlsplit('bad_filter')" - register: _bad_urlsplit_filter - ignore_errors: yes - -- name: Verify urlsplit filter showed an error message - assert: - that: - - _bad_urlsplit_filter is failed - - "'unknown URL component' in _bad_urlsplit_filter.msg" - -- name: Test urldecode filter - set_fact: - urldecoded_string: key="@{}é&%£ foo bar '(;\<>""°) - -- name: Test urlencode filter - set_fact: - urlencoded_string: '{{ urldecoded_string|urlencode }}' - -- name: Verify urlencode en urldecode - assert: - that: - - urldecoded_string == urlencoded_string|urldecode - - name: Flatten tests block: - name: use flatten @@ -274,46 +188,6 @@ - "'00:00:00' | random_mac(seed='test') == '00:00:00' | random_mac(seed='test')" - "'00:00:00' | random_mac(seed='test') != '00:00:00' | random_mac(seed='another_test')" -- name: Verify that union can be chained - vars: - unions: '{{ [1,2,3]|union([4,5])|union([6,7]) }}' - assert: - that: - - "unions|type_debug == 'list'" - - "unions|length == 7" - -- name: Test union with unhashable item - vars: - unions: '{{ [1,2,3]|union([{}]) }}' - assert: - that: - - "unions|type_debug == 'list'" - - "unions|length == 4" - -- name: Test ipaddr filter - assert: - that: - - "'192.168.0.1/32' | ipaddr('netmask') == '255.255.255.255'" - - "'192.168.0.1/24' | ipaddr('netmask') == '255.255.255.0'" - - "not '192.168.0.1/31' | ipaddr('broadcast')" - - "'192.168.0.1/24' | ipaddr('broadcast') == '192.168.0.255'" - - "'192.168.0.1/24' | ipaddr('prefix') == 24" - - "'192.168.0.1/24' | ipaddr('address') == '192.168.0.1'" - - "'192.168.0.1/24' | ipaddr('network') == '192.168.0.0'" - - "'fe80::dead:beef/64' | ipaddr('broadcast') == 'fe80::ffff:ffff:ffff:ffff'" - - "'::1/120' | ipaddr('netmask') == 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00'" - - "{{ subnets | ipaddr(1) }} == ['10.1.1.1/24', '10.1.2.1/24']" - - "{{ subnets | ipaddr('1') }} == ['10.1.1.1/24', '10.1.2.1/24']" - - "{{ subnets | ipaddr(-1) }} == ['10.1.1.255/24', '10.1.2.255/24']" - - "{{ subnets | ipaddr('-1') }} == ['10.1.1.255/24', '10.1.2.255/24']" - - "'{{ prefix | ipaddr(1) }}' == '10.1.1.1/24'" - - "'{{ prefix | ipaddr('1') }}' == '10.1.1.1/24'" - - "'{{ prefix | ipaddr('network') }}' == '10.1.1.0'" - - "'{{ prefix | ipaddr('-1') }}' == '10.1.1.255/24'" - vars: - subnets: ['10.1.1.0/24', '10.1.2.0/24'] - prefix: '10.1.1.0/24' - - name: Ensure dict2items works with hostvars debug: msg: "{{ item.key }}" diff --git a/test/integration/targets/filters/templates/foo.j2 b/test/integration/targets/filter_core/templates/foo.j2 similarity index 100% rename from test/integration/targets/filters/templates/foo.j2 rename to test/integration/targets/filter_core/templates/foo.j2 diff --git a/test/integration/targets/filters/templates/py26json.j2 b/test/integration/targets/filter_core/templates/py26json.j2 similarity index 100% rename from test/integration/targets/filters/templates/py26json.j2 rename to test/integration/targets/filter_core/templates/py26json.j2 diff --git a/test/integration/targets/filters/vars/main.yml b/test/integration/targets/filter_core/vars/main.yml similarity index 94% rename from test/integration/targets/filters/vars/main.yml rename to test/integration/targets/filter_core/vars/main.yml index bd7ac68c3a1..aedecd8f997 100644 --- a/test/integration/targets/filters/vars/main.yml +++ b/test/integration/targets/filter_core/vars/main.yml @@ -5,18 +5,6 @@ some_structure: warp: 9 where: endor -users: - - name: steve - hosts: - - host: host_a - password: abc - - host: host_b - - name: bill - hosts: - - host: host_c - password: default - - host: host_d - other_data: level1: foo: bar diff --git a/test/integration/targets/filter_ipaddr/aliases b/test/integration/targets/filter_ipaddr/aliases new file mode 100644 index 00000000000..1603f4351b6 --- /dev/null +++ b/test/integration/targets/filter_ipaddr/aliases @@ -0,0 +1,3 @@ +shippable/posix/group2 +skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller +skip/aix diff --git a/test/integration/targets/filters/runme.sh b/test/integration/targets/filter_ipaddr/runme.sh similarity index 69% rename from test/integration/targets/filters/runme.sh rename to test/integration/targets/filter_ipaddr/runme.sh index 2266ba3cc55..d498a5fc67f 100755 --- a/test/integration/targets/filters/runme.sh +++ b/test/integration/targets/filter_ipaddr/runme.sh @@ -7,6 +7,6 @@ source virtualenv.sh # Requirements have to be installed prior to running ansible-playbook # because plugins and requirements are loaded before the task runs -pip install jmespath netaddr +pip install netaddr -ANSIBLE_ROLES_PATH=../ ansible-playbook filters.yml "$@" +ANSIBLE_ROLES_PATH=../ ansible-playbook runme.yml "$@" diff --git a/test/integration/targets/filter_ipaddr/runme.yml b/test/integration/targets/filter_ipaddr/runme.yml new file mode 100644 index 00000000000..d2c5bda7320 --- /dev/null +++ b/test/integration/targets/filter_ipaddr/runme.yml @@ -0,0 +1,3 @@ +- hosts: localhost + roles: + - { role: filter_ipaddr } diff --git a/test/integration/targets/filter_ipaddr/tasks/main.yml b/test/integration/targets/filter_ipaddr/tasks/main.yml new file mode 100644 index 00000000000..c0fde7ced83 --- /dev/null +++ b/test/integration/targets/filter_ipaddr/tasks/main.yml @@ -0,0 +1,23 @@ +- name: Test ipaddr filter + assert: + that: + - "'192.168.0.1/32' | ipaddr('netmask') == '255.255.255.255'" + - "'192.168.0.1/24' | ipaddr('netmask') == '255.255.255.0'" + - "not '192.168.0.1/31' | ipaddr('broadcast')" + - "'192.168.0.1/24' | ipaddr('broadcast') == '192.168.0.255'" + - "'192.168.0.1/24' | ipaddr('prefix') == 24" + - "'192.168.0.1/24' | ipaddr('address') == '192.168.0.1'" + - "'192.168.0.1/24' | ipaddr('network') == '192.168.0.0'" + - "'fe80::dead:beef/64' | ipaddr('broadcast') == 'fe80::ffff:ffff:ffff:ffff'" + - "'::1/120' | ipaddr('netmask') == 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00'" + - "{{ subnets | ipaddr(1) }} == ['10.1.1.1/24', '10.1.2.1/24']" + - "{{ subnets | ipaddr('1') }} == ['10.1.1.1/24', '10.1.2.1/24']" + - "{{ subnets | ipaddr(-1) }} == ['10.1.1.255/24', '10.1.2.255/24']" + - "{{ subnets | ipaddr('-1') }} == ['10.1.1.255/24', '10.1.2.255/24']" + - "'{{ prefix | ipaddr(1) }}' == '10.1.1.1/24'" + - "'{{ prefix | ipaddr('1') }}' == '10.1.1.1/24'" + - "'{{ prefix | ipaddr('network') }}' == '10.1.1.0'" + - "'{{ prefix | ipaddr('-1') }}' == '10.1.1.255/24'" + vars: + subnets: ['10.1.1.0/24', '10.1.2.0/24'] + prefix: '10.1.1.0/24' diff --git a/test/integration/targets/filter_json_query/aliases b/test/integration/targets/filter_json_query/aliases new file mode 100644 index 00000000000..1603f4351b6 --- /dev/null +++ b/test/integration/targets/filter_json_query/aliases @@ -0,0 +1,3 @@ +shippable/posix/group2 +skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller +skip/aix diff --git a/test/integration/targets/filter_json_query/runme.sh b/test/integration/targets/filter_json_query/runme.sh new file mode 100755 index 00000000000..a0db5e5400e --- /dev/null +++ b/test/integration/targets/filter_json_query/runme.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -eux + +source virtualenv.sh + +# Requirements have to be installed prior to running ansible-playbook +# because plugins and requirements are loaded before the task runs + +pip install jmespath + +ANSIBLE_ROLES_PATH=../ ansible-playbook runme.yml "$@" diff --git a/test/integration/targets/filter_json_query/runme.yml b/test/integration/targets/filter_json_query/runme.yml new file mode 100644 index 00000000000..68f6372c2f4 --- /dev/null +++ b/test/integration/targets/filter_json_query/runme.yml @@ -0,0 +1,3 @@ +- hosts: localhost + roles: + - { role: filter_json_query } diff --git a/test/integration/targets/filter_json_query/tasks/main.yml b/test/integration/targets/filter_json_query/tasks/main.yml new file mode 100644 index 00000000000..02ad2f87ec7 --- /dev/null +++ b/test/integration/targets/filter_json_query/tasks/main.yml @@ -0,0 +1,4 @@ +- name: Test json_query filter + assert: + that: + - "users | json_query('[*].hosts[].host') == ['host_a', 'host_b', 'host_c', 'host_d']" diff --git a/test/integration/targets/filter_json_query/vars/main.yml b/test/integration/targets/filter_json_query/vars/main.yml new file mode 100644 index 00000000000..36964115b43 --- /dev/null +++ b/test/integration/targets/filter_json_query/vars/main.yml @@ -0,0 +1,11 @@ +users: + - name: steve + hosts: + - host: host_a + password: abc + - host: host_b + - name: bill + hosts: + - host: host_c + password: default + - host: host_d diff --git a/test/integration/targets/filter_mathstuff/aliases b/test/integration/targets/filter_mathstuff/aliases new file mode 100644 index 00000000000..1603f4351b6 --- /dev/null +++ b/test/integration/targets/filter_mathstuff/aliases @@ -0,0 +1,3 @@ +shippable/posix/group2 +skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller +skip/aix diff --git a/test/integration/targets/filter_mathstuff/tasks/main.yml b/test/integration/targets/filter_mathstuff/tasks/main.yml new file mode 100644 index 00000000000..ffd2cad0510 --- /dev/null +++ b/test/integration/targets/filter_mathstuff/tasks/main.yml @@ -0,0 +1,51 @@ +- name: Verify human_readable + tags: "human_readable" + assert: + that: + - '"1.00 Bytes" == 1|human_readable' + - '"1.00 bits" == 1|human_readable(isbits=True)' + - '"10.00 KB" == 10240|human_readable' + - '"97.66 MB" == 102400000|human_readable' + - '"0.10 GB" == 102400000|human_readable(unit="G")' + - '"0.10 Gb" == 102400000|human_readable(isbits=True, unit="G")' + +- name: Verify human_to_bytes + tags: "human_to_bytes" + assert: + that: + - "{{'0'|human_to_bytes}} == 0" + - "{{'0.1'|human_to_bytes}} == 0" + - "{{'0.9'|human_to_bytes}} == 1" + - "{{'1'|human_to_bytes}} == 1" + - "{{'10.00 KB'|human_to_bytes}} == 10240" + - "{{ '11 MB'|human_to_bytes}} == 11534336" + - "{{ '1.1 GB'|human_to_bytes}} == 1181116006" + - "{{'10.00 Kb'|human_to_bytes(isbits=True)}} == 10240" + +- name: Verify human_to_bytes (bad string) + set_fact: + bad_string: "{{ '10.00 foo' | human_to_bytes }}" + ignore_errors: yes + tags: human_to_bytes + register: _human_bytes_test + +- name: Verify human_to_bytes (bad string) + tags: human_to_bytes + assert: + that: "{{_human_bytes_test.failed}}" + +- name: Verify that union can be chained + vars: + unions: '{{ [1,2,3]|union([4,5])|union([6,7]) }}' + assert: + that: + - "unions|type_debug == 'list'" + - "unions|length == 7" + +- name: Test union with unhashable item + vars: + unions: '{{ [1,2,3]|union([{}]) }}' + assert: + that: + - "unions|type_debug == 'list'" + - "unions|length == 4" diff --git a/test/integration/targets/filter_urls/aliases b/test/integration/targets/filter_urls/aliases new file mode 100644 index 00000000000..1603f4351b6 --- /dev/null +++ b/test/integration/targets/filter_urls/aliases @@ -0,0 +1,3 @@ +shippable/posix/group2 +skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller +skip/aix diff --git a/test/integration/targets/filter_urls/tasks/main.yml b/test/integration/targets/filter_urls/tasks/main.yml new file mode 100644 index 00000000000..59d55d9092a --- /dev/null +++ b/test/integration/targets/filter_urls/tasks/main.yml @@ -0,0 +1,12 @@ +- name: Test urldecode filter + set_fact: + urldecoded_string: key="@{}é&%£ foo bar '(;\<>""°) + +- name: Test urlencode filter + set_fact: + urlencoded_string: '{{ urldecoded_string|urlencode }}' + +- name: Verify urlencode en urldecode + assert: + that: + - urldecoded_string == urlencoded_string|urldecode diff --git a/test/integration/targets/filter_urlsplit/aliases b/test/integration/targets/filter_urlsplit/aliases new file mode 100644 index 00000000000..1603f4351b6 --- /dev/null +++ b/test/integration/targets/filter_urlsplit/aliases @@ -0,0 +1,3 @@ +shippable/posix/group2 +skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller +skip/aix diff --git a/test/integration/targets/filter_urlsplit/tasks/main.yml b/test/integration/targets/filter_urlsplit/tasks/main.yml new file mode 100644 index 00000000000..c3ff3ec9431 --- /dev/null +++ b/test/integration/targets/filter_urlsplit/tasks/main.yml @@ -0,0 +1,30 @@ +- debug: + var: "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit" + verbosity: 1 + tags: debug + +- name: Test urlsplit filter + assert: + that: + - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('fragment') == 'fragment'" + - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('hostname') == 'www.acme.com'" + - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('netloc') == 'mary:MySecret@www.acme.com:9000'" + - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('path') == '/dir/index.html'" + - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('port') == 9000" + - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('query') == 'query=term'" + - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('scheme') == 'http'" + - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('username') == 'mary'" + - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('password') == 'MySecret'" + - "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit == { 'fragment': 'fragment', 'hostname': 'www.acme.com', 'netloc': 'mary:MySecret@www.acme.com:9000', 'password': 'MySecret', 'path': '/dir/index.html', 'port': 9000, 'query': 'query=term', 'scheme': 'http', 'username': 'mary' }" + +- name: Test urlsplit filter bad argument + debug: + var: "'http://www.acme.com:9000/dir/index.html' | urlsplit('bad_filter')" + register: _bad_urlsplit_filter + ignore_errors: yes + +- name: Verify urlsplit filter showed an error message + assert: + that: + - _bad_urlsplit_filter is failed + - "'unknown URL component' in _bad_urlsplit_filter.msg" diff --git a/test/integration/targets/filters/filters.yml b/test/integration/targets/filters/filters.yml deleted file mode 100644 index acac43bc64a..00000000000 --- a/test/integration/targets/filters/filters.yml +++ /dev/null @@ -1,4 +0,0 @@ -- hosts: localhost - gather_facts: yes - roles: - - { role: filters } diff --git a/test/integration/targets/filters/meta/main.yml b/test/integration/targets/filters/meta/main.yml deleted file mode 100644 index 07faa217762..00000000000 --- a/test/integration/targets/filters/meta/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -dependencies: - - prepare_tests