From 6708ee1afdb3a529eaf8f3a1df2a6869250db40a Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2020 20:57:07 +0100 Subject: [PATCH] Remove ansible.posix dependency (#1157) (#1191) * Vendor plugins/module_utils/mount.py from ansible.posix, and drop ansible.posix dependency (except for testing). * Add ignore.txt entries. * Install test requirements conditionally. * Apply suggestions from code review Co-authored-by: John R Barker * Bump to major changes. Co-authored-by: John R Barker (cherry picked from commit 20f470cc6491087e739c00f3a7429079b57c36e9) Co-authored-by: Felix Fontein --- .../remove-ansible.posix-dependency.yml | 2 + galaxy.yml | 1 - plugins/module_utils/_mount.py | 90 +++++++++++++++++++ plugins/modules/system/aix_filesystem.py | 2 +- tests/requirements.yml | 1 - tests/sanity/ignore-2.10.txt | 2 + tests/sanity/ignore-2.11.txt | 2 + tests/sanity/ignore-2.9.txt | 2 + tests/utils/shippable/shippable.sh | 15 +++- 9 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/remove-ansible.posix-dependency.yml create mode 100644 plugins/module_utils/_mount.py diff --git a/changelogs/fragments/remove-ansible.posix-dependency.yml b/changelogs/fragments/remove-ansible.posix-dependency.yml new file mode 100644 index 0000000000..089432c019 --- /dev/null +++ b/changelogs/fragments/remove-ansible.posix-dependency.yml @@ -0,0 +1,2 @@ +major_changes: +- "The community.general collection no longer depends on the ansible.posix collection (https://github.com/ansible-collections/community.general/pull/1157)." diff --git a/galaxy.yml b/galaxy.yml index e435dc9414..a25854d11d 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -10,7 +10,6 @@ tags: [community] # NOTE: No more dependencies can be added to this list dependencies: ansible.netcommon: '>=1.0.0' - ansible.posix: '>=1.0.0' community.kubernetes: '>=1.0.0' google.cloud: '>=1.0.0' repository: https://github.com/ansible-collections/community.general diff --git a/plugins/module_utils/_mount.py b/plugins/module_utils/_mount.py new file mode 100644 index 0000000000..62feb354cc --- /dev/null +++ b/plugins/module_utils/_mount.py @@ -0,0 +1,90 @@ +# This code is part of Ansible, but is an independent component. +# This particular file snippet, and this file snippet only, is based on +# Lib/posixpath.py of cpython +# It is licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 +# +# 1. This LICENSE AGREEMENT is between the Python Software Foundation +# ("PSF"), and the Individual or Organization ("Licensee") accessing and +# otherwise using this software ("Python") in source or binary form and +# its associated documentation. +# +# 2. Subject to the terms and conditions of this License Agreement, PSF hereby +# grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, +# analyze, test, perform and/or display publicly, prepare derivative works, +# distribute, and otherwise use Python alone or in any derivative version, +# provided, however, that PSF's License Agreement and PSF's notice of copyright, +# i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, +# 2011, 2012, 2013, 2014, 2015 Python Software Foundation; All Rights Reserved" +# are retained in Python alone or in any derivative version prepared by Licensee. +# +# 3. In the event Licensee prepares a derivative work that is based on +# or incorporates Python or any part thereof, and wants to make +# the derivative work available to others as provided herein, then +# Licensee hereby agrees to include in any such work a brief summary of +# the changes made to Python. +# +# 4. PSF is making Python available to Licensee on an "AS IS" +# basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR +# IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND +# DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS +# FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT +# INFRINGE ANY THIRD PARTY RIGHTS. +# +# 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON +# FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS +# A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, +# OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. +# +# 6. This License Agreement will automatically terminate upon a material +# breach of its terms and conditions. +# +# 7. Nothing in this License Agreement shall be deemed to create any +# relationship of agency, partnership, or joint venture between PSF and +# Licensee. This License Agreement does not grant permission to use PSF +# trademarks or trade name in a trademark sense to endorse or promote +# products or services of Licensee, or any third party. +# +# 8. By copying, installing or otherwise using Python, Licensee +# agrees to be bound by the terms and conditions of this License +# Agreement. + +import os + + +def ismount(path): + """Test whether a path is a mount point + This is a copy of the upstream version of ismount(). Originally this was copied here as a workaround + until Python issue 2466 was fixed. Now it is here so this will work on older versions of Python + that may not have the upstream fix. + https://github.com/ansible/ansible-modules-core/issues/2186 + http://bugs.python.org/issue2466 + """ + try: + s1 = os.lstat(path) + except (OSError, ValueError): + # It doesn't exist -- so not a mount point. :-) + return False + else: + # A symlink can never be a mount point + if os.path.stat.S_ISLNK(s1.st_mode): + return False + + if isinstance(path, bytes): + parent = os.path.join(path, b'..') + else: + parent = os.path.join(path, '..') + parent = os.path.realpath(parent) + try: + s2 = os.lstat(parent) + except (OSError, ValueError): + return False + + dev1 = s1.st_dev + dev2 = s2.st_dev + if dev1 != dev2: + return True # path/.. on a different device as path + ino1 = s1.st_ino + ino2 = s2.st_ino + if ino1 == ino2: + return True # path/.. is the same i-node as path + return False diff --git a/plugins/modules/system/aix_filesystem.py b/plugins/modules/system/aix_filesystem.py index f22577c828..02396c5eac 100644 --- a/plugins/modules/system/aix_filesystem.py +++ b/plugins/modules/system/aix_filesystem.py @@ -170,7 +170,7 @@ msg: ''' from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.posix.plugins.module_utils.mount import ismount +from ansible_collections.community.general.plugins.module_utils._mount import ismount import re diff --git a/tests/requirements.yml b/tests/requirements.yml index ba1bb07ecd..71491e700e 100644 --- a/tests/requirements.yml +++ b/tests/requirements.yml @@ -5,7 +5,6 @@ integration_tests_dependencies: - community.kubernetes unit_tests_dependencies: - ansible.netcommon -- ansible.posix - community.internal_test_tools - community.kubernetes - google.cloud diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 5f127ebb95..bc9b8067f9 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -2,6 +2,8 @@ plugins/callback/hipchat.py pylint:blacklisted-name plugins/connection/lxc.py pylint:blacklisted-name plugins/module_utils/compat/ipaddress.py no-assert plugins/module_utils/compat/ipaddress.py no-unicode-literals +plugins/module_utils/_mount.py future-import-boilerplate +plugins/module_utils/_mount.py metaclass-boilerplate plugins/modules/cloud/atomic/atomic_container.py validate-modules:doc-required-mismatch plugins/modules/cloud/centurylink/clc_aa_policy.py validate-modules:doc-missing-type plugins/modules/cloud/centurylink/clc_aa_policy.py yamllint:unparsable-with-libyaml diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index 5f127ebb95..bc9b8067f9 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -2,6 +2,8 @@ plugins/callback/hipchat.py pylint:blacklisted-name plugins/connection/lxc.py pylint:blacklisted-name plugins/module_utils/compat/ipaddress.py no-assert plugins/module_utils/compat/ipaddress.py no-unicode-literals +plugins/module_utils/_mount.py future-import-boilerplate +plugins/module_utils/_mount.py metaclass-boilerplate plugins/modules/cloud/atomic/atomic_container.py validate-modules:doc-required-mismatch plugins/modules/cloud/centurylink/clc_aa_policy.py validate-modules:doc-missing-type plugins/modules/cloud/centurylink/clc_aa_policy.py yamllint:unparsable-with-libyaml diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index 8f353c19e2..8b8b8afb68 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -2,6 +2,8 @@ plugins/callback/hipchat.py pylint:blacklisted-name plugins/connection/lxc.py pylint:blacklisted-name plugins/module_utils/compat/ipaddress.py no-assert plugins/module_utils/compat/ipaddress.py no-unicode-literals +plugins/module_utils/_mount.py future-import-boilerplate +plugins/module_utils/_mount.py metaclass-boilerplate plugins/modules/cloud/centurylink/clc_aa_policy.py validate-modules:doc-missing-type plugins/modules/cloud/centurylink/clc_alert_policy.py validate-modules:doc-missing-type plugins/modules/cloud/centurylink/clc_alert_policy.py validate-modules:no-default-for-required-parameter diff --git a/tests/utils/shippable/shippable.sh b/tests/utils/shippable/shippable.sh index f067ce6d7c..2a6aa09ac0 100755 --- a/tests/utils/shippable/shippable.sh +++ b/tests/utils/shippable/shippable.sh @@ -68,12 +68,21 @@ cd "${TEST_DIR}" # START: HACK install dependencies retry ansible-galaxy -vvv collection install ansible.netcommon -retry ansible-galaxy -vvv collection install ansible.posix -retry ansible-galaxy -vvv collection install community.crypto -retry ansible-galaxy -vvv collection install community.internal_test_tools retry ansible-galaxy -vvv collection install community.kubernetes retry ansible-galaxy -vvv collection install google.cloud +if [ "${script}" != "sanity" ] || [ "${test}" == "sanity/extra" ]; then + # Nothing further should be added to this list. + # This is to prevent modules or plugins in this collection having a runtime dependency on other collections. + retry ansible-galaxy -vvv collection install community.internal_test_tools +fi + +if [ "${script}" != "sanity" ] && [ "${script}" != "units" ]; then + # To prevent Python dependencies on other collections only install other collections for integration tests + retry ansible-galaxy -vvv collection install ansible.posix + retry ansible-galaxy -vvv collection install community.crypto +fi + # END: HACK export PYTHONIOENCODING='utf-8'