Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #1157/20f470cc backport][stable-1] Remove ansible.posix dependency #1191

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions 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)."
1 change: 0 additions & 1 deletion galaxy.yml
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
@@ -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
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
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
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
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
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
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