mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-03-26 21:33:32 +00:00
Partially revert "mount: Check if src exists before mounted (ansible/ansible#61752)" (#33)
This reverts part of ansible commit 72023d7462e78635264fd12bfdb23894b4163cba. The immediate reason is that it breaks mounts where src is not a path. Examples of such mounts are network-based filesystems such as nfs, cifs, glusterfs, ceph, virtual filesystems such as tmpfs or overlayfs, and also UUID-based mounts. It is too hard to come with an exhaustive list, especially if we take non-Linux systems into account, so don't even try. Additionally, it did not really fix the issue (ansible/ansible#59183) that it intended to fix, because the mount could fail but leave a non-working fstab entry for reasons other than non-existing src path. Restore fstab and remove the mount point after a failed mount Add a reminder that not only devices can be mounted Fixes: ansible/ansible#65855 Fixes: ansible/ansible#67588 Fixes: ansible/ansible#67966 Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com> Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> Co-authored-by: Alexander E. Patrakov <patrakov@gmail.com>
This commit is contained in:
@@ -2,4 +2,3 @@ needs/privileged
|
||||
needs/root
|
||||
shippable/posix/group1
|
||||
skip/aix
|
||||
disabled # fixme
|
||||
|
||||
@@ -2,9 +2,14 @@ import os
|
||||
import tempfile
|
||||
|
||||
from ansible_collections.ansible.posix.tests.unit.compat import unittest
|
||||
from ansible_collections.ansible.posix.tests.unit.compat.mock import MagicMock
|
||||
from ansible.module_utils._text import to_bytes
|
||||
|
||||
from ansible_collections.ansible.posix.plugins.modules.mount import get_linux_mounts
|
||||
from ansible_collections.ansible.posix.plugins.modules.mount import (
|
||||
get_linux_mounts,
|
||||
_set_mount_save_old,
|
||||
set_mount,
|
||||
)
|
||||
|
||||
|
||||
class LinuxMountsTestCase(unittest.TestCase):
|
||||
@@ -23,3 +28,32 @@ class LinuxMountsTestCase(unittest.TestCase):
|
||||
)
|
||||
mounts = get_linux_mounts(None, path)
|
||||
self.assertEqual(mounts['/tmp/bbb']['src'], '/tmp/aaa')
|
||||
|
||||
def test_set_mount_save_old(self):
|
||||
module = MagicMock(name='AnsibleModule')
|
||||
module.check_mode = True
|
||||
module.params = {'backup': False}
|
||||
|
||||
fstab_data = [
|
||||
'UUID=8ac075e3-1124-4bb6-bef7-a6811bf8b870 / xfs defaults 0 0\n',
|
||||
'/swapfile none swap defaults 0 0\n'
|
||||
]
|
||||
path = self._create_file("".join(fstab_data))
|
||||
args = {
|
||||
'fstab': path,
|
||||
'name': '/data',
|
||||
'src': '/dev/sdb1',
|
||||
'fstype': 'ext4',
|
||||
'opts': 'defaults',
|
||||
'dump': '0',
|
||||
'passno': '0',
|
||||
}
|
||||
|
||||
name, changed = set_mount(module, args)
|
||||
self.assertEqual(name, '/data')
|
||||
self.assertTrue(changed)
|
||||
|
||||
name, backup_lines, changed = _set_mount_save_old(module, args)
|
||||
self.assertEqual(backup_lines, fstab_data)
|
||||
self.assertEqual(name, '/data')
|
||||
self.assertTrue(changed)
|
||||
|
||||
Reference in New Issue
Block a user