From cfff8a3806b0c592f449162a82d7d2c3ce4a9388 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Sat, 29 May 2021 20:57:27 +0900 Subject: [PATCH 01/10] Modify boot option handling on Linux systems * Address the issue #28 * Modified behavior to set noauto option if boot is 'no' on Linux system * Modified integration test to use filesize module instead of dd Signed-off-by: Hideki Saito --- .../fragments/196_boot_opt_for_linux.yml | 4 ++ plugins/modules/mount.py | 42 +++++++++++++++---- .../integration/targets/mount/tasks/main.yml | 42 ++++++++++++++++++- 3 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/196_boot_opt_for_linux.yml diff --git a/changelogs/fragments/196_boot_opt_for_linux.yml b/changelogs/fragments/196_boot_opt_for_linux.yml new file mode 100644 index 0000000..62afecf --- /dev/null +++ b/changelogs/fragments/196_boot_opt_for_linux.yml @@ -0,0 +1,4 @@ +--- +minor_changes: + - mount - Change behavior of ``boot`` option to set ``noauto`` on Linux nodes + (https://github.com/ansible-collections/ansible.posix/issues/28). diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index dd7a5c0..5c4970d 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -93,7 +93,10 @@ options: boot: description: - Determines if the filesystem should be mounted on boot. - - Only applies to Solaris systems. + - Only applies to Solaris and Linux systems. + - For Solaris systems, C(true) will set C(yes) as the value of mount at boot + in I(/etc/vfstab). + - For Linux systems, C(true) will add C(noauto) to mount options in I(/etc/fstab). type: bool default: yes backup: @@ -169,6 +172,15 @@ EXAMPLES = r''' opts: rw,sync,hard,intr state: mounted fstype: nfs + +- name: Mount NFS volumes with noauto according to boot option + ansible.posix.mount: + src: 192.168.1.100:/nfs/ssd/shared_data + path: /mnt/shared_data + opts: rw,sync,hard,intr + boot: no + state: mounted + fstype: nfs ''' @@ -227,7 +239,7 @@ def _set_mount_save_old(module, args): old_lines = [] exists = False changed = False - escaped_args = dict([(k, _escape_fstab(v)) for k, v in iteritems(args)]) + escaped_args = dict([(k, _escape_fstab(v)) for k, v in iteritems(args) if k != 'warnings']) new_line = '%(src)s %(name)s %(fstype)s %(opts)s %(dump)s %(passno)s\n' if platform.system() == 'SunOS': @@ -673,7 +685,8 @@ def main(): opts='-', passno='-', fstab=module.params['fstab'], - boot='yes' if module.params['boot'] else 'no' + boot='yes' if module.params['boot'] else 'no', + warnings=[] ) if args['fstab'] is None: args['fstab'] = '/etc/vfstab' @@ -683,7 +696,9 @@ def main(): opts='defaults', dump='0', passno='0', - fstab=module.params['fstab'] + fstab=module.params['fstab'], + boot='yes', + warnings=[] ) if args['fstab'] is None: args['fstab'] = '/etc/fstab' @@ -700,14 +715,27 @@ def main(): linux_mounts = get_linux_mounts(module) if linux_mounts is None: - args['warnings'] = ( - 'Cannot open file /proc/self/mountinfo. ' - 'Bind mounts might be misinterpreted.') + args['warnings'].append('Cannot open file /proc/self/mountinfo.' + ' Bind mounts might be misinterpreted.') # Override defaults with user specified params for key in ('src', 'fstype', 'passno', 'opts', 'dump', 'fstab'): if module.params[key] is not None: args[key] = module.params[key] + if platform.system().lower() == 'linux': + # Linux has 'noauto' as mount opts to handle mount on boot + # So boot option should manage 'noauto' in opts + # TODO: We need to support other system like *BSD that 'noauto' option available + opts = args['opts'].split(',') + if 'noauto' in opts: + args['warnings'].append("Ignore the 'boot' due to 'opts' contains 'noauto'.") + elif not module.params['boot']: + args['boot'] = 'no' + if 'defaults' in opts: + args['warnings'].append("Ignore the 'boot' due to 'opts' contains 'defaults'.") + else: + opts.append('noauto') + args['opts'] = ','.join(opts) # If fstab file does not exist, we first need to create it. This mainly # happens when fstab option is passed to the module. diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index 7eacc59..44e120b 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -227,11 +227,13 @@ - name: Block to test remounted option block: - name: Create empty file - command: dd if=/dev/zero of=/tmp/myfs.img bs=1048576 count=20 + community.general.filesize: + path: /tmp/myfs.img + size: 20M when: ansible_system in ('Linux') - name: Format FS when: ansible_system in ('Linux') - community.general.system.filesystem: + community.general.filesystem: fstype: ext3 dev: /tmp/myfs.img - name: Mount the FS for the first time @@ -294,3 +296,39 @@ - /tmp/myfs.img - /tmp/myfs when: ansible_system in ('Linux') + +- name: Block to test boot option for Linux + block: + - name: Create empty file + community.general.filesize: + path: /tmp/myfs.img + size: 20M + - name: Format FS + community.general.filesystem: + fstype: ext3 + dev: /tmp/myfs.img + - name: Mount the FS with noauto option + mount: + path: /tmp/myfs + src: /tmp/myfs.img + fstype: ext3 + state: mounted + boot: no + opts: rw,user,async + register: mount_info + - name: assert the mount without noauto was successful + assert: + that: + - mount_info['opts'] == 'rw,user,async,noauto' + - name: Unmount FS + mount: + path: /tmp/myfs + state: absent + - name: Remove the test FS + file: + path: '{{ item }}' + state: absent + loop: + - /tmp/myfs.img + - /tmp/myfs + when: ansible_system in ('Linux') From 6ba8445fb14cf5f12d0a5bf6ba91c17936229db3 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Fri, 4 Jun 2021 15:51:56 +0530 Subject: [PATCH 02/10] acl: Add new alias Added new alias ``recurse`` for parameter ``recursive``. Fixes: #124 Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/124_acl.yml | 3 +++ plugins/modules/acl.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/124_acl.yml diff --git a/changelogs/fragments/124_acl.yml b/changelogs/fragments/124_acl.yml new file mode 100644 index 0000000..5eee72a --- /dev/null +++ b/changelogs/fragments/124_acl.yml @@ -0,0 +1,3 @@ +--- +minor_changes: +- acl - add new alias ``recurse`` for ``recursive`` parameter (https://github.com/ansible-collections/ansible.posix/issues/124). diff --git a/plugins/modules/acl.py b/plugins/modules/acl.py index c4a5542..a2e3d6d 100644 --- a/plugins/modules/acl.py +++ b/plugins/modules/acl.py @@ -67,8 +67,10 @@ options: description: - Recursively sets the specified ACL. - Incompatible with C(state=query). + - Alias C(recurse) added in version 1.3.0. type: bool default: no + aliases: [ recurse ] use_nfsv4_acls: description: - Use NFSv4 ACLs instead of POSIX ACLs. @@ -273,7 +275,7 @@ def main(): ), follow=dict(type='bool', default=True), default=dict(type='bool', default=False), - recursive=dict(type='bool', default=False), + recursive=dict(type='bool', default=False, aliases=['recurse']), recalculate_mask=dict( type='str', default='default', From 5cebc906239270e456d3a1f9ca2a81af6e493e00 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Fri, 4 Jun 2021 11:28:24 +0530 Subject: [PATCH 03/10] firewalld: Specify unit for timeout Timeout parameter takes value which is specified in seconds. Fixes: #193 Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/193_firewalld.yml | 3 +++ plugins/modules/firewalld.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/193_firewalld.yml diff --git a/changelogs/fragments/193_firewalld.yml b/changelogs/fragments/193_firewalld.yml new file mode 100644 index 0000000..088a268 --- /dev/null +++ b/changelogs/fragments/193_firewalld.yml @@ -0,0 +1,3 @@ +--- +trivial: +- firewalld - specify unit for ``timeout`` parameter in docs (https://github.com/ansible-collections/ansible.posix/issues/193). diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index c87dd36..818ed20 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -99,7 +99,7 @@ options: choices: [ absent, disabled, enabled, present ] timeout: description: - - The amount of time the rule should be in effect for when non-permanent. + - The amount of time in seconds the rule should be in effect for when non-permanent. type: int default: 0 masquerade: From 07fe3a91b6998f252eb088a6621f844a8bdb1476 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 3 Jun 2021 15:15:12 +0530 Subject: [PATCH 04/10] firewalld: Ensure idempotency Use APIs like ``query*`` instead of ``get*``. Fixes: #179 Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/179_firewalld.yml | 3 + plugins/modules/firewalld.py | 44 +++--------- .../targets/firewalld/tasks/main.yml | 16 +---- .../tasks/port_forward_test_cases.yml | 16 +---- .../firewalld/tasks/port_test_cases.yml | 71 +++++++++++++++---- .../targets/firewalld/tasks/run_all_tests.yml | 18 +---- 6 files changed, 73 insertions(+), 95 deletions(-) create mode 100644 changelogs/fragments/179_firewalld.yml diff --git a/changelogs/fragments/179_firewalld.yml b/changelogs/fragments/179_firewalld.yml new file mode 100644 index 0000000..782cebb --- /dev/null +++ b/changelogs/fragments/179_firewalld.yml @@ -0,0 +1,3 @@ +--- +bugfixes: +- firewalld - ensure idempotency with firewalld 0.9.3 (https://github.com/ansible-collections/ansible.posix/issues/179). diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index c87dd36..dc96c87 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -393,26 +393,14 @@ class PortTransaction(FirewallTransaction): ) def get_enabled_immediate(self, port, protocol, timeout): - port_proto = [port, protocol] if self.fw_offline: - fw_zone, fw_settings = self.get_fw_zone_settings() - ports_list = fw_settings.getPorts() - else: - ports_list = self.fw.getPorts(self.zone) - - if port_proto in ports_list: - return True - else: - return False + dummy, fw_settings = self.get_fw_zone_settings() + return fw_settings.queryPort(port=port, protocol=protocol) + return self.fw.queryPort(zone=self.zone, port=port, protocol=protocol) def get_enabled_permanent(self, port, protocol, timeout): - port_proto = (port, protocol) - fw_zone, fw_settings = self.get_fw_zone_settings() - - if port_proto in fw_settings.getPorts(): - return True - else: - return False + dummy, fw_settings = self.get_fw_zone_settings() + return fw_settings.queryPort(port=port, protocol=protocol) def set_enabled_immediate(self, port, protocol, timeout): self.fw.addPort(self.zone, port, protocol, timeout) @@ -715,26 +703,14 @@ class ForwardPortTransaction(FirewallTransaction): ) def get_enabled_immediate(self, port, proto, toport, toaddr, timeout): - forward_port = [port, proto, toport, toaddr] if self.fw_offline: - fw_zone, fw_settings = self.get_fw_zone_settings() - forward_list = fw_settings.getForwardPorts() - else: - forward_list = self.fw.getForwardPorts(self.zone) - - if forward_port in forward_list: - return True - else: - return False + dummy, fw_settings = self.get_fw_zone_settings() + return fw_settings.queryForwardPort(port=port, protocol=proto, to_port=toport, to_addr=toaddr) + return self.fw.queryForwardPort(port=port, protocol=proto, to_port=toport, to_addr=toaddr) def get_enabled_permanent(self, port, proto, toport, toaddr, timeout): - forward_port = (port, proto, toport, toaddr) - fw_zone, fw_settings = self.get_fw_zone_settings() - - if forward_port in fw_settings.getForwardPorts(): - return True - else: - return False + dummy, fw_settings = self.get_fw_zone_settings() + return fw_settings.queryForwardPort(port=port, protocol=proto, to_port=toport, to_addr=toaddr) def set_enabled_immediate(self, port, proto, toport, toaddr, timeout): self.fw.addForwardPort(self.zone, port, proto, toport, toaddr, timeout) diff --git a/tests/integration/targets/firewalld/tasks/main.yml b/tests/integration/targets/firewalld/tasks/main.yml index 84af185..4e83ee8 100644 --- a/tests/integration/targets/firewalld/tasks/main.yml +++ b/tests/integration/targets/firewalld/tasks/main.yml @@ -1,20 +1,6 @@ # Test playbook for the firewalld module # (c) 2017, Adam Miller - -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - name: Run firewalld tests block: diff --git a/tests/integration/targets/firewalld/tasks/port_forward_test_cases.yml b/tests/integration/targets/firewalld/tasks/port_forward_test_cases.yml index c2a982d..78a451d 100644 --- a/tests/integration/targets/firewalld/tasks/port_forward_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/port_forward_test_cases.yml @@ -1,20 +1,6 @@ # Test playbook for the firewalld module - port operations # (c) 2017, Adam Miller - -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - name: firewalld port forward test permanent enabled firewalld: diff --git a/tests/integration/targets/firewalld/tasks/port_test_cases.yml b/tests/integration/targets/firewalld/tasks/port_test_cases.yml index 5891e75..2beb8ca 100644 --- a/tests/integration/targets/firewalld/tasks/port_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/port_test_cases.yml @@ -1,20 +1,63 @@ # Test playbook for the firewalld module - port operations # (c) 2017, Adam Miller +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +- name: firewalld port range test permanent enabled + firewalld: + port: 5500-6950/tcp + permanent: true + state: enabled + register: result + +- name: assert firewalld port range test permanent enabled worked + assert: + that: + - result is changed + +- name: firewalld port range test permanent enabled rerun (verify not changed) + firewalld: + port: 5500-6950/tcp + permanent: true + state: enabled + register: result + +- name: assert firewalld port range test permanent enabled rerun worked (verify not changed) + assert: + that: + - result is not changed + +- name: firewalld port test permanent enabled + firewalld: + port: 6900/tcp + permanent: true + state: enabled + register: result + +- name: assert firewalld port test permanent enabled worked + assert: + that: + - result is changed + +- name: firewalld port test permanent enabled + firewalld: + port: 6900/tcp + permanent: true + state: enabled + register: result + +- name: assert firewalld port test permanent enabled worked + assert: + that: + - result is not changed + +- name: firewalld port test disabled + firewalld: + port: "{{ item }}" + permanent: true + state: disabled + loop: + - 6900/tcp + - 5500-6950/tcp - name: firewalld port test permanent enabled firewalld: diff --git a/tests/integration/targets/firewalld/tasks/run_all_tests.yml b/tests/integration/targets/firewalld/tasks/run_all_tests.yml index 79c0ca7..f46deb6 100644 --- a/tests/integration/targets/firewalld/tasks/run_all_tests.yml +++ b/tests/integration/targets/firewalld/tasks/run_all_tests.yml @@ -1,20 +1,6 @@ # Test playbook for the firewalld module # (c) 2017, Adam Miller - -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - name: Ensure /run/firewalld exists file: @@ -28,8 +14,6 @@ # firewalld port operation test cases - include_tasks: port_test_cases.yml - # Skipping on CentOS 8 due to https://github.com/ansible/ansible/issues/64750 - when: not (ansible_facts.distribution == "CentOS" and ansible_distribution_major_version is version('8', '==')) # firewalld source operation test cases - import_tasks: source_test_cases.yml From 7d928e6e9dc65f4f900d613361a2da6c9798f555 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Fri, 4 Jun 2021 11:38:14 +0530 Subject: [PATCH 05/10] synchronize: fix misc typo Docs should read ``--delete-after`` instead of ``--delete-excluded``. Fixes: #175 Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/175_synchronize.yml | 3 +++ plugins/modules/synchronize.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/175_synchronize.yml diff --git a/changelogs/fragments/175_synchronize.yml b/changelogs/fragments/175_synchronize.yml new file mode 100644 index 0000000..4d1a161 --- /dev/null +++ b/changelogs/fragments/175_synchronize.yml @@ -0,0 +1,3 @@ +--- +trivial: +- synchronize - fix typo in ``delete`` parameter (https://github.com/ansible-collections/ansible.posix/issues/175). diff --git a/plugins/modules/synchronize.py b/plugins/modules/synchronize.py index dafaf78..2fcb7a4 100644 --- a/plugins/modules/synchronize.py +++ b/plugins/modules/synchronize.py @@ -75,7 +75,7 @@ options: description: - Delete files in C(dest) that don't exist (after transfer, not before) in the C(src) path. - This option requires C(recursive=yes). - - This option ignores excluded files and behaves like the rsync opt --delete-excluded. + - This option ignores excluded files and behaves like the rsync opt --delete-after. type: bool default: no dirs: From 7bed8ce79e7624a9c19cc61fda73fee949f3e196 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Fri, 4 Jun 2021 18:39:50 +0530 Subject: [PATCH 06/10] review requests Signed-off-by: Abhijeet Kasurde --- plugins/modules/synchronize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/synchronize.py b/plugins/modules/synchronize.py index 2fcb7a4..2676275 100644 --- a/plugins/modules/synchronize.py +++ b/plugins/modules/synchronize.py @@ -73,9 +73,9 @@ options: default: no delete: description: - - Delete files in C(dest) that don't exist (after transfer, not before) in the C(src) path. - - This option requires C(recursive=yes). - - This option ignores excluded files and behaves like the rsync opt --delete-after. + - Delete files in I(dest) that do not exist (after transfer, not before) in the I(src) path. + - This option requires I(recursive=yes). + - This option ignores excluded files and behaves like the rsync opt C(--delete-after). type: bool default: no dirs: From c29bbd265bebb98c14f61c3f30fb508440dc795d Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Tue, 8 Jun 2021 19:59:59 +0900 Subject: [PATCH 07/10] Modify boot option handling on BSD systems * Fixes #28 for BSD systems * Porting PR #196 to BSD systems Signed-off-by: Hideki Saito --- changelogs/fragments/203_boot_opt_for_bsd.yml | 4 ++++ plugins/modules/mount.py | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/203_boot_opt_for_bsd.yml diff --git a/changelogs/fragments/203_boot_opt_for_bsd.yml b/changelogs/fragments/203_boot_opt_for_bsd.yml new file mode 100644 index 0000000..0fdd50a --- /dev/null +++ b/changelogs/fragments/203_boot_opt_for_bsd.yml @@ -0,0 +1,4 @@ +--- +minor_changes: + - mount - Change behavior of ``boot`` option to set ``noauto`` on BSD nodes + (https://github.com/ansible-collections/ansible.posix/issues/28). diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index 5c4970d..5b22e43 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -96,7 +96,10 @@ options: - Only applies to Solaris and Linux systems. - For Solaris systems, C(true) will set C(yes) as the value of mount at boot in I(/etc/vfstab). - - For Linux systems, C(true) will add C(noauto) to mount options in I(/etc/fstab). + - For Linux, FreeBSD, NetBSD and OpenBSD systems, C(false) will add C(noauto) + to mount options in I(/etc/fstab). + - To avoid mount option conflicts, if C(noauto) specified in C(opts), + mount module will ignore C(boot). type: bool default: yes backup: @@ -722,10 +725,10 @@ def main(): for key in ('src', 'fstype', 'passno', 'opts', 'dump', 'fstab'): if module.params[key] is not None: args[key] = module.params[key] - if platform.system().lower() == 'linux': - # Linux has 'noauto' as mount opts to handle mount on boot - # So boot option should manage 'noauto' in opts - # TODO: We need to support other system like *BSD that 'noauto' option available + if platform.system().lower() == 'linux' or platform.system().lower().endswith('bsd'): + # Linux, FreeBSD, NetBSD and OpenBSD have 'noauto' as mount option to + # handle mount on boot. To avoid mount option conflicts, if 'noauto' + # specified in 'opts', mount module will ignore 'boot'. opts = args['opts'].split(',') if 'noauto' in opts: args['warnings'].append("Ignore the 'boot' due to 'opts' contains 'noauto'.") From 51d117285f035736aded6c915f8713a0ab736d7e Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 9 Jun 2021 17:44:51 +0530 Subject: [PATCH 08/10] csh: Define ``ECHO`` and ``COMMAND_SEP`` Fixes: #204 Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/204_csh_shell.yml | 3 +++ plugins/shell/csh.py | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 changelogs/fragments/204_csh_shell.yml diff --git a/changelogs/fragments/204_csh_shell.yml b/changelogs/fragments/204_csh_shell.yml new file mode 100644 index 0000000..6d157a8 --- /dev/null +++ b/changelogs/fragments/204_csh_shell.yml @@ -0,0 +1,3 @@ +--- +bugfixes: +- csh - define ``ECHO`` and ``COMMAND_SEP`` (https://github.com/ansible-collections/ansible.posix/issues/204). diff --git a/plugins/shell/csh.py b/plugins/shell/csh.py index 18dee95..bce5734 100644 --- a/plugins/shell/csh.py +++ b/plugins/shell/csh.py @@ -26,6 +26,10 @@ class ShellModule(ShellBase): # Family of shells this has. Must match the filename without extension SHELL_FAMILY = 'csh' + # commonly used + ECHO = 'echo' + COMMAND_SEP = ';' + # How to end lines in a python script one-liner _SHELL_EMBEDDED_PY_EOL = '\\\n' _SHELL_REDIRECT_ALLNULL = '>& /dev/null' From 0b597f2e66353bfa26bd104e735e4896e98340bb Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Fri, 11 Jun 2021 11:15:28 +0200 Subject: [PATCH 09/10] mount integration tests: make them more human readable --- .../integration/targets/mount/tasks/main.yml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index 44e120b..e733e64 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -2,10 +2,12 @@ file: state: directory path: '{{ output_dir }}/mount_dest' + - name: Create a directory to bind mount file: state: directory path: '{{ output_dir }}/mount_source' + - name: Put something in the directory so we see that it worked copy: content: 'Testing @@ -13,6 +15,7 @@ ' dest: '{{ output_dir }}/mount_source/test_file' register: orig_info + - name: Bind mount a filesystem (Linux) mount: src: '{{ output_dir }}/mount_source' @@ -22,6 +25,7 @@ opts: bind when: ansible_system == 'Linux' register: bind_result_linux + - name: Bind mount a filesystem (FreeBSD) mount: src: '{{ output_dir }}/mount_source' @@ -30,11 +34,13 @@ fstype: nullfs when: ansible_system == 'FreeBSD' register: bind_result_freebsd + - name: get checksum for bind mounted file stat: path: '{{ output_dir }}/mount_dest/test_file' when: ansible_system in ('FreeBSD', 'Linux') register: dest_stat + - name: assert the bind mount was successful assert: that: @@ -42,6 +48,7 @@ - dest_stat['stat']['exists'] - orig_info['checksum'] == dest_stat['stat']['checksum'] when: ansible_system in ('FreeBSD', 'Linux') + - name: Bind mount a filesystem (Linux) mount: src: '{{ output_dir }}/mount_source' @@ -51,6 +58,7 @@ opts: bind when: ansible_system == 'Linux' register: bind_result_linux + - name: Bind mount a filesystem (FreeBSD) mount: src: '{{ output_dir }}/mount_source' @@ -59,11 +67,13 @@ fstype: nullfs when: ansible_system == 'FreeBSD' register: bind_result_freebsd + - name: Make sure we didn't mount a second time assert: that: - (ansible_system == 'Linux' and not bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and not bind_result_freebsd['changed']) when: ansible_system in ('FreeBSD', 'Linux') + - name: Remount filesystem with different opts (Linux) mount: src: '{{ output_dir }}/mount_source' @@ -73,6 +83,7 @@ opts: bind,ro when: ansible_system == 'Linux' register: bind_result_linux + - name: Remount filesystem with different opts (FreeBSD) mount: src: '{{ output_dir }}/mount_source' @@ -82,9 +93,11 @@ opts: ro when: ansible_system == 'FreeBSD' register: bind_result_freebsd + - name: Get mount options shell: mount | grep mount_dest | grep -E -w '(ro|read-only)' | wc -l register: remount_options + - name: Make sure the filesystem now has the new opts assert: that: @@ -92,23 +105,27 @@ - '''1'' in remount_options.stdout' - 1 == remount_options.stdout_lines | length when: ansible_system in ('FreeBSD', 'Linux') + - name: Unmount the bind mount mount: name: '{{ output_dir }}/mount_dest' state: absent when: ansible_system in ('Linux', 'FreeBSD') register: unmount_result + - name: Make sure the file no longer exists in dest stat: path: '{{ output_dir }}/mount_dest/test_file' when: ansible_system in ('FreeBSD', 'Linux') register: dest_stat + - name: Check that we unmounted assert: that: - unmount_result['changed'] - not dest_stat['stat']['exists'] when: ansible_system in ('FreeBSD', 'Linux') + - name: Create fstab record for the first swap file mount: name: none @@ -118,6 +135,7 @@ state: present register: swap1_created when: ansible_system in ('Linux') + - name: Try to create fstab record for the first swap file again mount: name: none @@ -127,12 +145,14 @@ state: present register: swap1_created_again when: ansible_system in ('Linux') + - name: Check that we created the swap1 record assert: that: - swap1_created['changed'] - not swap1_created_again['changed'] when: ansible_system in ('Linux') + - name: Create fstab record for the second swap file mount: name: none @@ -142,6 +162,7 @@ state: present register: swap2_created when: ansible_system in ('Linux') + - name: Try to create fstab record for the second swap file again mount: name: none @@ -151,12 +172,14 @@ state: present register: swap2_created_again when: ansible_system in ('Linux') + - name: Check that we created the swap2 record assert: that: - swap2_created['changed'] - not swap2_created_again['changed'] when: ansible_system in ('Linux') + - name: Remove the fstab record for the first swap file mount: name: none @@ -164,6 +187,7 @@ state: absent register: swap1_removed when: ansible_system in ('Linux') + - name: Try to remove the fstab record for the first swap file again mount: name: none @@ -171,12 +195,14 @@ state: absent register: swap1_removed_again when: ansible_system in ('Linux') + - name: Check that we removed the swap1 record assert: that: - swap1_removed['changed'] - not swap1_removed_again['changed'] when: ansible_system in ('Linux') + - name: Remove the fstab record for the second swap file mount: name: none @@ -184,6 +210,7 @@ state: absent register: swap2_removed when: ansible_system in ('Linux') + - name: Try to remove the fstab record for the second swap file again mount: name: none @@ -191,12 +218,14 @@ state: absent register: swap2_removed_again when: ansible_system in ('Linux') + - name: Check that we removed the swap2 record assert: that: - swap2_removed['changed'] - not swap2_removed_again['changed'] when: ansible_system in ('Linux') + - name: Create fstab record with missing last two fields copy: dest: /etc/fstab @@ -204,6 +233,7 @@ ' when: ansible_system in ('Linux') + - name: Try to change the fstab record with the missing last two fields mount: src: //nas/photo @@ -213,10 +243,12 @@ state: present register: optional_fields_update when: ansible_system in ('Linux') + - name: Get the content of the fstab file shell: cat /etc/fstab register: optional_fields_content when: ansible_system in ('Linux') + - name: Check if the line containing the missing last two fields was changed assert: that: @@ -224,6 +256,7 @@ - ''' 0 0'' in optional_fields_content.stdout' - 1 == optional_fields_content.stdout_lines | length when: ansible_system in ('Linux') + - name: Block to test remounted option block: - name: Create empty file @@ -231,11 +264,13 @@ path: /tmp/myfs.img size: 20M when: ansible_system in ('Linux') + - name: Format FS when: ansible_system in ('Linux') community.general.filesystem: fstype: ext3 dev: /tmp/myfs.img + - name: Mount the FS for the first time mount: path: /tmp/myfs @@ -243,43 +278,52 @@ fstype: ext2 state: mounted when: ansible_system in ('Linux') + - name: Get the last write time shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-' register: last_write_time when: ansible_system in ('Linux') + - name: Wait 2 second pause: seconds: 2 when: ansible_system in ('Linux') + - name: Test if the FS is remounted mount: path: /tmp/myfs state: remounted when: ansible_system in ('Linux') + - name: Get again the last write time shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-' register: last_write_time2 when: ansible_system in ('Linux') + - name: Fail if they are the same fail: msg: Filesytem was not remounted, testing of the module failed! when: last_write is defined and last_write_time2 is defined and last_write_time.stdout == last_write_time2.stdout and ansible_system in ('Linux') + - name: Remount filesystem with different opts using remounted option (Linux only) mount: path: /tmp/myfs state: remounted opts: rw,noexec when: ansible_system == 'Linux' + - name: Get remounted options (Linux only) shell: mount | grep myfs | grep -E -w 'noexec' | wc -l register: remounted_options when: ansible_system == 'Linux' + - name: Make sure the filesystem now has the new opts after using remounted (Linux only) assert: that: - "'1' in remounted_options.stdout" - "1 == remounted_options.stdout_lines | length" when: ansible_system == 'Linux' + always: - name: Umount the test FS mount: @@ -288,6 +332,7 @@ opts: loop state: absent when: ansible_system in ('Linux') + - name: Remove the test FS file: path: '{{ item }}' @@ -303,10 +348,12 @@ community.general.filesize: path: /tmp/myfs.img size: 20M + - name: Format FS community.general.filesystem: fstype: ext3 dev: /tmp/myfs.img + - name: Mount the FS with noauto option mount: path: /tmp/myfs @@ -316,14 +363,17 @@ boot: no opts: rw,user,async register: mount_info + - name: assert the mount without noauto was successful assert: that: - mount_info['opts'] == 'rw,user,async,noauto' + - name: Unmount FS mount: path: /tmp/myfs state: absent + - name: Remove the test FS file: path: '{{ item }}' From 1671173e992624d84adca6b482bc57b30052e578 Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Fri, 11 Jun 2021 11:40:55 +0200 Subject: [PATCH 10/10] Add changelog fragment --- changelogs/fragments/207-mount_tests.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/207-mount_tests.yml diff --git a/changelogs/fragments/207-mount_tests.yml b/changelogs/fragments/207-mount_tests.yml new file mode 100644 index 0000000..f5256d6 --- /dev/null +++ b/changelogs/fragments/207-mount_tests.yml @@ -0,0 +1,3 @@ +--- +trivial: + - Make the mount module integration tests more human readable.