-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* for better readability/understanding of what is tested, and what OS is targetted * extend tests to FreeBSD when possible and: * convert swap source if it is an UUID or a LABEL (linux), or a memory disk (freebsd) * override default opts and boot when fstype=swap * do not honor 'fstab' when fstype=swap (fail instead) * also fail when fstype=swap and 'path' is not 'none' ('-' for Solaris)
- Loading branch information
Showing
9 changed files
with
631 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
# Tasks to validate bind mounts (i.e. mount of a directory to another one). | ||
# Linux and FreeBSD only. | ||
|
||
- name: Create the mount point (the target of the mount) | ||
file: | ||
state: directory | ||
path: '{{ output_dir }}/mount_dest' | ||
|
||
- name: Create a directory to bind mount (the source of the mount) | ||
file: | ||
state: directory | ||
path: '{{ output_dir }}/mount_source' | ||
|
||
- name: Put something in the directory so we see that it worked | ||
copy: | ||
content: 'Testing | ||
' | ||
dest: '{{ output_dir }}/mount_source/test_file' | ||
register: orig_info | ||
|
||
- name: Bind mount a directory | ||
mount: | ||
src: '{{ output_dir }}/mount_source' | ||
name: '{{ output_dir }}/mount_dest' | ||
state: mounted | ||
fstype: "{{ 'none' if ansible_system == 'Linux' else 'nullfs' }}" | ||
opts: "{{ 'bind' if ansible_system == 'Linux' else omit }}" | ||
register: bind_result | ||
|
||
- 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: | ||
- bind_result is changed | ||
- dest_stat.stat.exists | ||
- orig_info.checksum == dest_stat.stat.checksum | ||
|
||
- name: Bind mount a directory again | ||
mount: | ||
src: '{{ output_dir }}/mount_source' | ||
name: '{{ output_dir }}/mount_dest' | ||
state: mounted | ||
fstype: "{{ 'none' if ansible_system == 'Linux' else 'nullfs' }}" | ||
opts: "{{ 'bind' if ansible_system == 'Linux' else omit }}" | ||
register: bind_result | ||
|
||
- name: Make sure we didn't mount a second time | ||
assert: | ||
that: | ||
- bind_result is not changed | ||
|
||
- name: Remount directory with different options | ||
mount: | ||
src: '{{ output_dir }}/mount_source' | ||
name: '{{ output_dir }}/mount_dest' | ||
state: mounted | ||
fstype: "{{ 'none' if ansible_system == 'Linux' else 'nullfs' }}" | ||
opts: "{{ 'bind,' if ansible_system == 'Linux' else '' }}ro" | ||
register: bind_result | ||
|
||
- 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: | ||
- bind_result is changed | ||
- '''1'' in remount_options.stdout' | ||
- 1 == remount_options.stdout_lines | length | ||
|
||
- name: Unmount the bind mount | ||
mount: | ||
name: '{{ output_dir }}/mount_dest' | ||
state: absent | ||
register: unmount_result | ||
|
||
- name: Check if the file still exists in dest | ||
stat: | ||
path: '{{ output_dir }}/mount_dest/test_file' | ||
register: dest_stat | ||
|
||
- name: Assert that we unmounted | ||
assert: | ||
that: | ||
- unmount_result is changed | ||
- not dest_stat.stat.exists |
30 changes: 30 additions & 0 deletions
30
tests/integration/targets/mount/tasks/fstab_last_fields.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
# Tasks to validate the two last fields in fstab, that are optional on Linux, | ||
# are added if missing. | ||
|
||
- name: Create fstab record with missing last two fields | ||
copy: | ||
dest: /etc/fstab | ||
content: '//nas/photo /home/jik/pictures cifs defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev | ||
' | ||
|
||
- name: Try to change the fstab record with the missing last two fields | ||
mount: | ||
src: //nas/photo | ||
path: /home/jik/pictures | ||
fstype: cifs | ||
opts: defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev,x-systemd.mount-timeout=0 | ||
state: present | ||
register: optional_fields_update | ||
|
||
- name: Get the content of the fstab file | ||
shell: cat /etc/fstab | ||
register: optional_fields_content | ||
|
||
- name: Check if the line containing the missing last two fields was changed | ||
assert: | ||
that: | ||
- optional_fields_update is changed | ||
- ''' 0 0'' in optional_fields_content.stdout' | ||
- 1 == optional_fields_content.stdout_lines | length |
Oops, something went wrong.