summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansiballz_python
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/ansiballz_python')
-rw-r--r--test/integration/targets/ansiballz_python/aliases2
-rw-r--r--test/integration/targets/ansiballz_python/library/check_rlimit_and_maxfd.py31
-rw-r--r--test/integration/targets/ansiballz_python/library/custom_module.py19
-rw-r--r--test/integration/targets/ansiballz_python/library/sys_check.py23
-rw-r--r--test/integration/targets/ansiballz_python/module_utils/custom_util.py6
-rw-r--r--test/integration/targets/ansiballz_python/tasks/main.yml68
6 files changed, 149 insertions, 0 deletions
diff --git a/test/integration/targets/ansiballz_python/aliases b/test/integration/targets/ansiballz_python/aliases
new file mode 100644
index 0000000..7ae73ab
--- /dev/null
+++ b/test/integration/targets/ansiballz_python/aliases
@@ -0,0 +1,2 @@
+shippable/posix/group1
+context/target
diff --git a/test/integration/targets/ansiballz_python/library/check_rlimit_and_maxfd.py b/test/integration/targets/ansiballz_python/library/check_rlimit_and_maxfd.py
new file mode 100644
index 0000000..a01ee99
--- /dev/null
+++ b/test/integration/targets/ansiballz_python/library/check_rlimit_and_maxfd.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+#
+# Copyright 2018 Red Hat | Ansible
+# 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
+
+import resource
+import subprocess
+
+from ansible.module_utils.basic import AnsibleModule
+
+
+def main():
+ module = AnsibleModule(
+ argument_spec=dict()
+ )
+
+ rlimit_nofile = resource.getrlimit(resource.RLIMIT_NOFILE)
+
+ try:
+ maxfd = subprocess.MAXFD
+ except AttributeError:
+ maxfd = -1
+
+ module.exit_json(rlimit_nofile=rlimit_nofile, maxfd=maxfd, infinity=resource.RLIM_INFINITY)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/test/integration/targets/ansiballz_python/library/custom_module.py b/test/integration/targets/ansiballz_python/library/custom_module.py
new file mode 100644
index 0000000..625823e
--- /dev/null
+++ b/test/integration/targets/ansiballz_python/library/custom_module.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+
+from __future__ import absolute_import, division, print_function
+__metaclass__ = type
+
+from ..module_utils.basic import AnsibleModule # pylint: disable=relative-beyond-top-level
+from ..module_utils.custom_util import forty_two # pylint: disable=relative-beyond-top-level
+
+
+def main():
+ module = AnsibleModule(
+ argument_spec=dict()
+ )
+
+ module.exit_json(answer=forty_two())
+
+
+if __name__ == '__main__':
+ main()
diff --git a/test/integration/targets/ansiballz_python/library/sys_check.py b/test/integration/targets/ansiballz_python/library/sys_check.py
new file mode 100644
index 0000000..aa22fe6
--- /dev/null
+++ b/test/integration/targets/ansiballz_python/library/sys_check.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+# https://github.com/ansible/ansible/issues/64664
+# https://github.com/ansible/ansible/issues/64479
+
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+import sys
+
+from ansible.module_utils.basic import AnsibleModule
+
+
+def main():
+ module = AnsibleModule({})
+
+ this_module = sys.modules[__name__]
+ module.exit_json(
+ failed=not getattr(this_module, 'AnsibleModule', False)
+ )
+
+
+if __name__ == '__main__':
+ main()
diff --git a/test/integration/targets/ansiballz_python/module_utils/custom_util.py b/test/integration/targets/ansiballz_python/module_utils/custom_util.py
new file mode 100644
index 0000000..0393db4
--- /dev/null
+++ b/test/integration/targets/ansiballz_python/module_utils/custom_util.py
@@ -0,0 +1,6 @@
+from __future__ import absolute_import, division, print_function
+__metaclass__ = type
+
+
+def forty_two():
+ return 42
diff --git a/test/integration/targets/ansiballz_python/tasks/main.yml b/test/integration/targets/ansiballz_python/tasks/main.yml
new file mode 100644
index 0000000..0aaa645
--- /dev/null
+++ b/test/integration/targets/ansiballz_python/tasks/main.yml
@@ -0,0 +1,68 @@
+- name: get the ansible-test imposed file descriptor limit
+ check_rlimit_and_maxfd:
+ register: rlimit_limited_return
+
+- name: get existing file descriptor limit
+ check_rlimit_and_maxfd:
+ register: rlimit_original_return
+ vars:
+ ansible_python_module_rlimit_nofile: 0 # ignore limit set by ansible-test
+
+- name: attempt to set a value lower than existing soft limit
+ check_rlimit_and_maxfd:
+ vars:
+ ansible_python_module_rlimit_nofile: '{{ rlimit_original_return.rlimit_nofile[0] - 1 }}'
+ register: rlimit_below_soft_return
+
+- name: attempt to set a value higher than existing soft limit
+ check_rlimit_and_maxfd:
+ vars:
+ ansible_python_module_rlimit_nofile: '{{ rlimit_original_return.rlimit_nofile[0] + 1 }}'
+ register: rlimit_above_soft_return
+
+- name: attempt to set a value lower than existing hard limit
+ check_rlimit_and_maxfd:
+ vars:
+ ansible_python_module_rlimit_nofile: '{{ rlimit_original_return.rlimit_nofile[1] - 1 }}'
+ register: rlimit_below_hard_return
+
+- name: attempt to set a value higher than existing hard limit
+ check_rlimit_and_maxfd:
+ vars:
+ ansible_python_module_rlimit_nofile: '{{ rlimit_original_return.rlimit_nofile[1] + 1 }}'
+ register: rlimit_above_hard_return
+
+- name: run a role module which uses a role module_util using relative imports
+ custom_module:
+ register: custom_module_return
+
+- assert:
+ that:
+ # make sure ansible-test was able to set the limit unless it exceeds the hard limit or the value is lower on macOS
+ - rlimit_limited_return.rlimit_nofile[0] == 1024 or rlimit_original_return.rlimit_nofile[1] < 1024 or (rlimit_limited_return.rlimit_nofile[0] < 1024 and ansible_distribution == 'MacOSX')
+ # make sure that maxfd matches the soft limit on Python 2.x (-1 on Python 3.x)
+ - rlimit_limited_return.maxfd == rlimit_limited_return.rlimit_nofile[0] or rlimit_limited_return.maxfd == -1
+
+ # we should always be able to set the limit lower than the existing soft limit
+ - rlimit_below_soft_return.rlimit_nofile[0] == rlimit_original_return.rlimit_nofile[0] - 1
+ # the hard limit should not have changed
+ - rlimit_below_soft_return.rlimit_nofile[1] == rlimit_original_return.rlimit_nofile[1]
+ # lowering the limit should also lower the max file descriptors reported by Python 2.x (-1 on Python 3.x)
+ - rlimit_below_soft_return.maxfd == rlimit_original_return.rlimit_nofile[0] - 1 or rlimit_below_soft_return.maxfd == -1
+
+ # we should be able to set the limit higher than the existing soft limit if it does not exceed the hard limit (except on macOS)
+ - rlimit_above_soft_return.rlimit_nofile[0] == rlimit_original_return.rlimit_nofile[0] + 1 or rlimit_original_return.rlimit_nofile[0] == rlimit_original_return.rlimit_nofile[1] or ansible_distribution == 'MacOSX'
+
+ # we should be able to set the limit lower than the existing hard limit (except on macOS)
+ - rlimit_below_hard_return.rlimit_nofile[0] == rlimit_original_return.rlimit_nofile[1] - 1 or ansible_distribution == 'MacOSX'
+
+ # setting the limit higher than the existing hard limit should use the hard limit (except on macOS)
+ - rlimit_above_hard_return.rlimit_nofile[0] == rlimit_original_return.rlimit_nofile[1] or ansible_distribution == 'MacOSX'
+
+ # custom module returned the correct answer
+ - custom_module_return.answer == 42
+
+# https://github.com/ansible/ansible/issues/64664
+# https://github.com/ansible/ansible/issues/64479
+- name: Run module that tries to access itself via sys.modules
+ sys_check: