Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated version of #50 #104

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 57 additions & 6 deletions tests/tests_change_disk_fs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
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
name: linux-system-roles.storage

- include_tasks: get_unused_disk.yml
vars:
Expand All @@ -18,19 +18,36 @@

- name: Create a disk device with the default file system type
include_role:
name: storage
name: linux-system-roles.storage
vars:
storage_volumes:
- name: test1
type: disk
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string must be quoted because jinja2/yaml doesn't like the colon : character in is::

Exception when running tests: mapping values are not allowed here
  in "<unicode string>", line 37, column 23:
            msg: device is: {{ ( _test_change_disk_fs_fsta ... 
                                   ^ (line: 37)

| 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 }}"
include_role:
name: storage
name: linux-system-roles.storage
vars:
storage_volumes:
- name: test1
Expand All @@ -39,11 +56,28 @@
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
include_role:
name: storage
name: linux-system-roles.storage
vars:
storage_volumes:
- name: test1
Expand All @@ -52,11 +86,28 @@
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 }}"

- include_tasks: verify-role-results.yml

- name: Clean up
include_role:
name: storage
name: linux-system-roles.storage
vars:
storage_volumes:
- name: test1
Expand Down