mirror of https://github.com/ansible/ansible.git
Filesystem: refactor, improvements, add tests (#25519)
* filesystem: list used tools * filesystem: btrfs and reiserfs don't support resizing * filesystem: list supported filesystems use formatting functions and 'filesystem' instead of 'file system' * filesystem: PEP8 * filesystem: remove useless calls to module.boolean * filesystem: fail when the requested action isn't implemented * filesystem: resizefs: list supported FS rather than unsupported * filesystem: refactor * filesystem: add integration tests * filesystem: allow to use image file with 'dev' param * filesystem: test resizefs (ext2/3/4 filesystems only) * filesystem: Btrfs, handle older version than v0.20-rc1 * filesystem: use loop keyword (integration tests) * filesystem: new test, check when another filesystem already exists * filesystem: add myself as a maintainer * filesystem: fix tests as filterspull/34742/head
parent
303894dd17
commit
e9e316c76b
@ -0,0 +1,3 @@
|
|||||||
|
destructive
|
||||||
|
posix/ci/group3
|
||||||
|
skip/osx
|
@ -0,0 +1,14 @@
|
|||||||
|
tested_filesystems:
|
||||||
|
# key: fstype
|
||||||
|
# fssize: size (Mo)
|
||||||
|
# grow: True if resizefs is supported
|
||||||
|
# Other minimal sizes:
|
||||||
|
# - XFS: 20Mo
|
||||||
|
# - Btrfs: 100Mo (50Mo when "--metadata single" is used)
|
||||||
|
ext4: {fssize: 10, grow: True}
|
||||||
|
ext4dev: {fssize: 10, grow: True}
|
||||||
|
ext3: {fssize: 10, grow: True}
|
||||||
|
ext2: {fssize: 10, grow: True}
|
||||||
|
xfs: {fssize: 20, grow: False} # grow requires a mounted filesystem
|
||||||
|
btrfs: {fssize: 100, grow: False} # grow not implemented
|
||||||
|
# untested: lvm, requires a block device
|
@ -0,0 +1,88 @@
|
|||||||
|
- block:
|
||||||
|
- name: 'Create a "disk" file'
|
||||||
|
command: 'dd if=/dev/zero of={{ dev }} bs=1M count={{ fssize }}'
|
||||||
|
|
||||||
|
- name: filesystem creation
|
||||||
|
filesystem:
|
||||||
|
dev: '{{ dev }}'
|
||||||
|
fstype: '{{ fstype }}'
|
||||||
|
register: fs_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- 'fs_result is changed'
|
||||||
|
- 'fs_result is success'
|
||||||
|
|
||||||
|
- command: 'blkid -c /dev/null -o value -s UUID {{ dev }}'
|
||||||
|
register: uuid
|
||||||
|
|
||||||
|
- name: "Check that filesystem isn't created if force isn't used"
|
||||||
|
filesystem:
|
||||||
|
dev: '{{ dev }}'
|
||||||
|
fstype: '{{ fstype }}'
|
||||||
|
register: fs2_result
|
||||||
|
|
||||||
|
- command: 'blkid -c /dev/null -o value -s UUID {{ dev }}'
|
||||||
|
register: uuid2
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- 'not (fs2_result is changed)'
|
||||||
|
- 'fs2_result is success'
|
||||||
|
- 'uuid.stdout == uuid2.stdout'
|
||||||
|
|
||||||
|
- name: Check that filesystem is recreated if force is used
|
||||||
|
filesystem:
|
||||||
|
dev: '{{ dev }}'
|
||||||
|
fstype: '{{ fstype }}'
|
||||||
|
force: yes
|
||||||
|
register: fs3_result
|
||||||
|
|
||||||
|
- command: 'blkid -c /dev/null -o value -s UUID {{ dev }}'
|
||||||
|
register: uuid3
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- 'fs3_result is changed'
|
||||||
|
- 'fs3_result is success'
|
||||||
|
- 'uuid.stdout != uuid3.stdout'
|
||||||
|
|
||||||
|
- name: increase fake device
|
||||||
|
shell: 'dd if=/dev/zero bs=1M count=20 >> {{ dev }}'
|
||||||
|
|
||||||
|
- when: 'grow|bool'
|
||||||
|
block:
|
||||||
|
- name: Expand filesystem
|
||||||
|
filesystem:
|
||||||
|
dev: '{{ dev }}'
|
||||||
|
fstype: '{{ fstype }}'
|
||||||
|
resizefs: yes
|
||||||
|
register: fs4_result
|
||||||
|
|
||||||
|
- command: 'blkid -c /dev/null -o value -s UUID {{ dev }}'
|
||||||
|
register: uuid4
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- 'fs4_result is changed'
|
||||||
|
- 'fs4_result is success'
|
||||||
|
- 'uuid3.stdout == uuid4.stdout' # unchanged
|
||||||
|
|
||||||
|
- name: Try to expand filesystem again
|
||||||
|
filesystem:
|
||||||
|
dev: '{{ dev }}'
|
||||||
|
fstype: '{{ fstype }}'
|
||||||
|
resizefs: yes
|
||||||
|
register: fs5_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- 'not (fs5_result is changed)'
|
||||||
|
- 'fs5_result is successful'
|
||||||
|
|
||||||
|
- import_tasks: overwrite_another_fs.yml
|
||||||
|
|
||||||
|
always:
|
||||||
|
- file:
|
||||||
|
name: '{{ dev }}'
|
||||||
|
state: absent
|
@ -0,0 +1,44 @@
|
|||||||
|
- name: 'Recreate "disk" file'
|
||||||
|
command: 'dd if=/dev/zero of={{ dev }} bs=1M count={{ fssize }}'
|
||||||
|
|
||||||
|
- name: 'Create a vfat filesystem'
|
||||||
|
command: 'mkfs.vfat {{ dev }}'
|
||||||
|
when: ansible_system != 'FreeBSD'
|
||||||
|
|
||||||
|
- name: 'Create a vfat filesystem'
|
||||||
|
command: 'newfs_msdos -F12 {{ dev }}'
|
||||||
|
when: ansible_system == 'FreeBSD'
|
||||||
|
|
||||||
|
- command: 'blkid -c /dev/null -o value -s UUID {{ dev }}'
|
||||||
|
register: uuid
|
||||||
|
|
||||||
|
- name: "Check that an existing filesystem (not handled by this module) isn't overwritten when force isn't used"
|
||||||
|
filesystem:
|
||||||
|
dev: '{{ dev }}'
|
||||||
|
fstype: '{{ fstype }}'
|
||||||
|
register: fs_result
|
||||||
|
ignore_errors: True
|
||||||
|
|
||||||
|
- command: 'blkid -c /dev/null -o value -s UUID {{ dev }}'
|
||||||
|
register: uuid2
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- 'fs_result is failed'
|
||||||
|
- 'uuid.stdout == uuid2.stdout'
|
||||||
|
|
||||||
|
- name: "Check that an existing filesystem (not handled by this module) is overwritten when force is used"
|
||||||
|
filesystem:
|
||||||
|
dev: '{{ dev }}'
|
||||||
|
fstype: '{{ fstype }}'
|
||||||
|
force: yes
|
||||||
|
register: fs_result2
|
||||||
|
|
||||||
|
- command: 'blkid -c /dev/null -o value -s UUID {{ dev }}'
|
||||||
|
register: uuid3
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- 'fs_result2 is successful'
|
||||||
|
- 'fs_result2 is changed'
|
||||||
|
- 'uuid2.stdout != uuid3.stdout'
|
@ -0,0 +1,45 @@
|
|||||||
|
- name: install filesystem tools
|
||||||
|
package:
|
||||||
|
name: '{{ item }}'
|
||||||
|
state: present
|
||||||
|
when: ansible_system == 'Linux' or item != 'dosfstools'
|
||||||
|
with_items:
|
||||||
|
- e2fsprogs
|
||||||
|
- xfsprogs
|
||||||
|
- dosfstools
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: install btrfs progs
|
||||||
|
package:
|
||||||
|
name: btrfs-progs
|
||||||
|
state: present
|
||||||
|
when: ansible_os_family != 'Suse' and not (ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('16.04', '<='))
|
||||||
|
|
||||||
|
- name: install btrfs progs (Ubuntu <= 16.04)
|
||||||
|
package:
|
||||||
|
name: btrfs-tools
|
||||||
|
state: present
|
||||||
|
when: ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('16.04', '<=')
|
||||||
|
|
||||||
|
- name: install btrfs progs (OpenSuse)
|
||||||
|
package:
|
||||||
|
name: '{{ item }}'
|
||||||
|
state: present
|
||||||
|
when: ansible_os_family == 'Suse'
|
||||||
|
with_items:
|
||||||
|
- python-xml
|
||||||
|
- btrfsprogs
|
||||||
|
when: ansible_system == 'Linux'
|
||||||
|
|
||||||
|
- command: mke2fs -V
|
||||||
|
register: mke2fs
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
# mke2fs 1.43.6 (29-Aug-2017)
|
||||||
|
e2fsprogs_version: '{{ mke2fs.stderr_lines[0] | regex_search("[0-9]{1,2}\.[0-9]{1,2}(\.[0-9]{1,2})?") }}'
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
# http://e2fsprogs.sourceforge.net/e2fsprogs-release.html#1.43
|
||||||
|
# Mke2fs no longer complains if the user tries to create a file system
|
||||||
|
# using the entire block device.
|
||||||
|
force_creation: "{{ e2fsprogs_version is version('1.43', '<') }}"
|
Loading…
Reference in New Issue