From ea5821ce667c626aeb220ffe618883e3563d4e81 Mon Sep 17 00:00:00 2001 From: Pavel Cahyna Date: Fri, 18 Oct 2019 13:38:11 +0200 Subject: [PATCH] Verify that disk volumes are mounted by UUID in fstab Note that disk volumes mean filesystems directly on disks. Currently the test fails: on first invocation the filesystem gets mounted by device name and only on the second by UUID. This should be also aught by a real idempotence test. XXX this should be part of the existing verification task lists: there is already a task called "Verify that the device identifier appears in /etc/fstab", but it does not check for this condition. --- tests/tests_change_disk_fs.yml | 55 +++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/tests/tests_change_disk_fs.yml b/tests/tests_change_disk_fs.yml index b6aa80ba..ab5e1710 100644 --- a/tests/tests_change_disk_fs.yml +++ b/tests/tests_change_disk_fs.yml @@ -5,7 +5,7 @@ mount_location: '/opt/test' volume_size: '5g' fs_type_after: "{{ 'ext3' if (ansible_distribution == 'RedHat' and ansible_distribution_major_version == '6') else 'ext4' }}" - + pat: "{{ '^([^#\\s]+)\\s+' + mount_location + '\\s.*' }}" tasks: - include_role: name: storage @@ -25,6 +25,23 @@ mount_point: "{{ mount_location }}" disks: "{{ unused_disks }}" + - name: Load fstab + command: cat /etc/fstab + changed_when: false + check_mode: no + register: _test_change_disk_fs_fstab1 + + - name: print fstab device + debug: + msg: "device is: {{ ( _test_change_disk_fs_fstab1.stdout_lines|select('search', pat) + | map('regex_replace', pat, '\\1') | list )[0] }}" + + - name: verify that we mount by UUID + assert: + that: "{{ _test_change_disk_fs_fstab1.stdout_lines|select('search', pat) + | map('regex_replace', pat, '\\1') | select('match', 'UUID=') + | list | length > 0 }}" + - include_tasks: verify-role-results.yml - name: Change the disk device file system type to "{{ fs_type_after }}" @@ -38,6 +55,23 @@ fs_type: "{{ fs_type_after }}" disks: "{{ unused_disks }}" + - name: Load fstab + command: cat /etc/fstab + changed_when: false + check_mode: no + register: _test_change_disk_fs_fstab2 + + - name: print fstab device + debug: + msg: "device is: {{ (_test_change_disk_fs_fstab2.stdout_lines|select('search', pat) + | map('regex_replace', pat, '\\1') | list)[0] }}" + + - name: verify that we mount by UUID + assert: + that: "{{_test_change_disk_fs_fstab2.stdout_lines|select('search', pat) + | map('regex_replace', pat, '\\1') | select('match', 'UUID=') + | list | length > 0 }}" + - include_tasks: verify-role-results.yml - name: Repeat the previous invocation to verify idempotence @@ -51,6 +85,25 @@ fs_type: "{{ fs_type_after }}" disks: "{{ unused_disks }}" + - name: Load fstab + command: cat /etc/fstab + changed_when: false + check_mode: no + register: _test_change_disk_fs_fstab3 + + - name: print fstab device + debug: + msg: "device is: {{ (_test_change_disk_fs_fstab3.stdout_lines|select('search', pat) + | map('regex_replace', pat, '\\1') | list)[0] }}" + + - name: verify that we mount by UUID + assert: + that: "{{ _test_change_disk_fs_fstab3.stdout_lines|select('search', pat) + | map('regex_replace', pat, '\\1') | select('match', 'UUID=' ) + | list | length > 0 }}" + + - pause: + - include_tasks: verify-role-results.yml - name: Clean up