summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2016-09-23 12:38:31 -0700
committerGitHub <noreply@github.com>2016-09-23 12:38:31 -0700
commit0bf92d2b5c56416ba8812afe0dec59e10ba89ffe (patch)
treebe2ad401b51e625140bc320e3b21cbd543023eb5
parenteeb4e258f867646b6a6e67ba13f3b486171c2050 (diff)
downloadansible-0bf92d2b5c56416ba8812afe0dec59e10ba89ffe.tar.gz
Add tests for the mount module (#17718)
* Add tests for the mount module * Switch from unmounted to absent... the code for mounting always modifies fstab so we need to always modify fstab to cleanup as well. * Fix comments and copyright
-rw-r--r--test/integration/non_destructive.yml1
-rw-r--r--test/integration/roles/test_mount/tasks/main.yml113
2 files changed, 114 insertions, 0 deletions
diff --git a/test/integration/non_destructive.yml b/test/integration/non_destructive.yml
index ef70bbaf65..1dbadaac57 100644
--- a/test/integration/non_destructive.yml
+++ b/test/integration/non_destructive.yml
@@ -44,3 +44,4 @@
- { role: test_add_host, tags: test_add_host }
- { role: test_binary, tags: test_binary }
- { role: test_loops, tags: test_loops }
+ - { role: test_mount, tags: [test_mount, requires_root] }
diff --git a/test/integration/roles/test_mount/tasks/main.yml b/test/integration/roles/test_mount/tasks/main.yml
new file mode 100644
index 0000000000..ab3e0c5f4a
--- /dev/null
+++ b/test/integration/roles/test_mount/tasks/main.yml
@@ -0,0 +1,113 @@
+# (c) 2016, Toshio Kuratomi <tkuratomi@ansible.com>
+
+# 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 <http://www.gnu.org/licenses/>.
+
+- name: Create the mount point
+ file:
+ state: "directory"
+ path: "{{ outputdir }}/mount_dest"
+
+- name: Create a directory to bind mount
+ file:
+ state: "directory"
+ path: "{{ outputdir }}/mount_source"
+
+- name: Put something in the directory so we see that it worked
+ copy:
+ content: "Testing\n"
+ dest: "{{ outputdir }}/mount_source/test_file"
+ register: orig_info
+
+# The opts type of bind mount only works on Linux
+- name: Bind mount a filesystem (Linux)
+ mount:
+ src: "{{ outputdir }}/mount_source"
+ name: "{{ outputdir }}/mount_dest"
+ state: "mounted"
+ fstype: "None"
+ opts: "bind"
+ when: ansible_system == 'Linux'
+ register: bind_result_linux
+
+# Nullfs is freebsd only
+- name: Bind mount a filesystem (FreeBSD)
+ mount:
+ src: "{{ outputdir }}/mount_source"
+ name: "{{ outputdir }}/mount_dest"
+ state: "mounted"
+ fstype: "nullfs"
+ when: ansible_system == 'FreeBSD'
+ register: bind_result_freebsd
+
+- name: get checksum for bind mounted file
+ stat:
+ path: "{{ outputdir }}/mount_dest/test_file"
+ when: ansible_system in ('FreeBSD', 'Linux')
+ register: dest_stat
+
+- name: assert the bind mount was successful
+ assert:
+ that:
+ - "(ansible_system == 'Linux' and bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and bind_result_freebsd['changed'])"
+ - "dest_stat['stat']['exists']"
+ - "orig_info['checksum'] == dest_stat['stat']['checksum']"
+ when: ansible_system in ('FreeBSD', 'Linux')
+
+# The opts type of bind mount only works on Linux
+- name: Bind mount a filesystem (Linux)
+ mount:
+ src: "{{ outputdir }}/mount_source"
+ name: "{{ outputdir }}/mount_dest"
+ state: "mounted"
+ fstype: "None"
+ opts: "bind"
+ when: ansible_system == 'Linux'
+ register: bind_result_linux
+
+# Nullfs is freebsd only
+- name: Bind mount a filesystem (FreeBSD)
+ mount:
+ src: "{{ outputdir }}/mount_source"
+ name: "{{ outputdir }}/mount_dest"
+ state: "mounted"
+ fstype: "nullfs"
+ when: ansible_system == 'FreeBSD'
+ register: bind_result_freebsd
+
+- name: Make sure we didn't mount a second time
+ assert:
+ that:
+ - "not bind_result_linux['changed'] and not bind_result_freebsd['changed']"
+
+- name: Unmount the bind mount
+ mount:
+ name: "{{ outputdir }}/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: "{{ outputdir }}/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')