Compare commits

...

11 commits

Author SHA1 Message Date
Alfonso Escribano Merino
6ed47789f1
Merge 6782f88e39 into 12a1c25f5e 2023-07-07 23:19:14 +01:00
softwarefactory-project-zuul[bot]
12a1c25f5e
Merge pull request #478 from maxamillion/test/rhel_updates
Update azure-pipelines for new RHEL versions

SUMMARY

Change to the CI system annnounced in the following required this change:
ansible-collections/news-for-maintainers#47
2023-07-06 22:34:53 +00:00
Adam Miller
7062be892e only for devel
Signed-off-by: Adam Miller <admiller@redhat.com>
2023-07-06 10:19:58 -05:00
softwarefactory-project-zuul[bot]
20c2c30d23
Merge pull request #477 from saito-hideki/issue/476/1
Update CI tests to address changes on ansible-core

SUMMARY
Replace Python3.9 with 3.12 for ansible-test

Addresses issue #476

ISSUE TYPE

CI Test Pull Request

COMPONENT NAME

ansible.posix

ADDITIONAL INFORMATION
None
2023-07-04 01:39:12 +00:00
Hideki Saito
4f1e6b4a6d Drop Python3.9 and update versions of RHEL,Fedora and FreeBSD for ansible-core:devel
* Addresses issue #476
* Drop Python3.9
* Replace Fedora 37 with 38
* Replace FreeBSD13.1 with 13.2
* Replace RHEL 8.7 with 8.8
* Replace RHEL 9.1 with 9.2

Signed-off-by: Hideki Saito <saito@fgrep.org>
2023-07-04 09:15:24 +09:00
Adam Miller
806ab9ef9d Update azure-pipelines for new RHEL versions
Change to the CI system annnounced in the following required this
change:

  https://github.com/ansible-collections/news-for-maintainers/issues/47

Signed-off-by: Adam Miller <admiller@redhat.com>
2023-06-29 10:57:49 -05:00
Alfonso Escribano Merino
6782f88e39
Update changelogs/fragments/197-acl-fix-performance.yml
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
2021-05-31 13:44:03 +02:00
alfonso-escribano
119bba68a6 Add Changelog fragment for PR#197 2021-05-31 12:31:16 +02:00
alfonso-escribano
d0e01dd77f Clean old ansible versions commented code 2021-05-31 10:57:36 +02:00
Alfonso Escribano
b1db0b8276 Correct identation 2021-05-28 13:48:07 +02:00
Alfonso Escribano
8e645bb9ce Fix acl performance 2021-05-28 13:42:34 +02:00
5 changed files with 92 additions and 22 deletions

View file

@ -53,8 +53,8 @@ stages:
targets:
- name: CentOS 7
test: centos7
- name: Fedora 37
test: fedora37
- name: Fedora 38
test: fedora38
- name: openSUSE 15 py3
test: opensuse15
- name: Ubuntu 20.04
@ -213,14 +213,14 @@ stages:
test: macos/13.2
- name: RHEL 7.9
test: rhel/7.9
- name: RHEL 8.7
test: rhel/8.7
- name: RHEL 9.1
test: rhel/9.1
- name: RHEL 8.8
test: rhel/8.8
- name: RHEL 9.2
test: rhel/9.2
- name: FreeBSD 12.4
test: freebsd/12.4
- name: FreeBSD 13.1
test: freebsd/13.1
- name: FreeBSD 13.2
test: freebsd/13.2
- stage: Remote_2_15
displayName: Remote 2.15
dependsOn: []

View file

@ -0,0 +1,2 @@
bugfixes:
- acl - Fix module performance (https://github.com/ansible-collections/ansible.posix/pull/197).

View file

@ -0,0 +1,3 @@
---
trivial:
- "Drop Python3.9 and update versions of RHEL,Fedora and FreeBSD for ansible-core:devel test(https://github.com/ansible-collections/ansible.posix/issues/476)."

View file

@ -141,9 +141,13 @@ acl:
import os
import platform
import fcntl
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
from ansible.module_utils.compat import selectors
from ansible.module_utils.common.text.converters import to_native, to_text, to_bytes
from ansible.module_utils.six import b
def split_entry(entry):
@ -223,7 +227,7 @@ def build_command(module, mode, path, follow, default, recursive, recalculate_ma
return cmd
def acl_changed(module, cmd):
def acl_changed(module, cmd, check_rc=True):
'''Returns true if the provided command affects the existing ACLs, false otherwise.'''
# FreeBSD do not have a --test flag, so by default, it is safer to always say "true"
if platform.system().lower() == 'freebsd':
@ -231,11 +235,63 @@ def acl_changed(module, cmd):
cmd = cmd[:] # lists are mutables so cmd would be overwritten without this
cmd.insert(1, '--test')
lines = run_acl(module, cmd)
module._acl_changed = False
for line in lines:
if not line.endswith('*,*'):
return True
def _process_stdout_from_pipe(proc, _acl_module=module):
stdout = b''
try:
selector = selectors.DefaultSelector()
except (IOError, OSError):
# Failed to detect default selector for the given platform
# Select PollSelector which is supported by major platforms
selector = selectors.PollSelector()
selector.register(proc.stdout, selectors.EVENT_READ)
if os.name == 'posix':
fcntl.fcntl(proc.stdout.fileno(), fcntl.F_SETFL, fcntl.fcntl(proc.stdout.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK)
while True:
events = selector.select(1)
for key, event in events:
b_chunk = key.fileobj.read()
if b_chunk == b(''):
selector.unregister(key.fileobj)
if key.fileobj == proc.stdout:
stdout = b_chunk
if _acl_module._acl_changed:
continue
lines = []
for l in stdout.splitlines():
lines.append(l.strip())
for line in lines:
if not line.endswith(b'*,*'):
proc.terminate()
_acl_module._acl_changed = True
proc.returncode = 0
# only break out if no pipes are left to read or
# the pipes are completely read and
# the process is terminated
if (not events or not selector.get_map()) and proc.poll() is not None:
break
# No pipes are left to read but process is not yet terminated
# Only then it is safe to wait for the process to be finished
# NOTE: Actually proc.poll() is always None here if no selectors are left
elif not selector.get_map() and proc.poll() is None:
proc.wait()
# The process is terminated. Since no pipes to read from are
# left, there is no need to call select() again.
break
try:
(rc, out, err) = module.run_command(
cmd, check_rc=check_rc,
before_communicate_callback=_process_stdout_from_pipe)
except Exception as e:
module.fail_json(msg=to_native(e))
if module._acl_changed:
return True
return False
@ -356,7 +412,10 @@ def main():
if changed and not module.check_mode:
run_acl(module, command)
msg = "%s is present" % entry
if recursive:
msg = "%s is present recursively" % entry
else:
msg = "%s is present" % entry
elif state == 'absent':
entry = build_entry(etype, entity, use_nfsv4_acls)
@ -368,15 +427,23 @@ def main():
if changed and not module.check_mode:
run_acl(module, command, False)
msg = "%s is absent" % entry
if recursive:
msg = "%s is absent recursively" % entry
else:
msg = "%s is absent" % entry
elif state == 'query':
msg = "current acl"
acl = run_acl(
module,
build_command(module, 'get', path, follow, default, recursive, recalculate_mask)
)
if recursive:
acl = []
warn = "Not showing resulting acls in the recursive mode"
module.exit_json(changed=changed, msg=msg, acl=acl, warnings=warn)
else:
acl = run_acl(
module,
build_command(module, 'get', path, follow, default, recursive, recalculate_mask)
)
module.exit_json(changed=changed, msg=msg, acl=acl)

View file

@ -145,9 +145,7 @@ function cleanup
fi
if [ "${process_coverage}" ]; then
# use python 3.9 for coverage to avoid running out of memory during coverage xml processing
# only use it for coverage to avoid the additional overhead of setting up a virtual environment for a potential no-op job
virtualenv --python /usr/bin/python3.9 ~/ansible-venv
python3 -m venv ~/ansible-venv
set +ux
. ~/ansible-venv/bin/activate
set -ux