Skip to content

Commit

Permalink
Remove ansible.posix dependency (#1157)
Browse files Browse the repository at this point in the history
* 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 <john@johnrbarker.com>

* Bump to major changes.

Co-authored-by: John R Barker <john@johnrbarker.com>
(cherry picked from commit 20f470c)
  • Loading branch information
felixfontein authored and Patchback committed Oct 28, 2020
1 parent 88bd8fc commit 5026cbd
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/remove-ansible.posix-dependency.yml
Original file line number Diff line number Diff line change
@@ -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)."
1 change: 0 additions & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
90 changes: 90 additions & 0 deletions plugins/module_utils/_mount.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion plugins/modules/system/aix_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
'''

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


Expand Down
1 change: 0 additions & 1 deletion tests/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ integration_tests_dependencies:
- community.kubernetes
unit_tests_dependencies:
- ansible.netcommon
- ansible.posix
- community.internal_test_tools
- community.kubernetes
- google.cloud
2 changes: 2 additions & 0 deletions tests/sanity/ignore-2.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/sanity/ignore-2.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/sanity/ignore-2.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions tests/utils/shippable/shippable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 5026cbd

Please sign in to comment.