Skip to content

Commit

Permalink
Add new test case for FS resize
Browse files Browse the repository at this point in the history
1.resize to size_after more then  size_before
2.resize to size_after less then  size_before
3.resize to too-large volume size
4.resize to volume size equal disk's size
5.resize to invalid size
6.add basic resize test for ext2/3
  • Loading branch information
zhongchanghui authored and yizhanglinux committed Aug 22, 2020
1 parent e181c10 commit a981d8f
Showing 1 changed file with 290 additions and 1 deletion.
291 changes: 290 additions & 1 deletion tests/tests_resize.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
- hosts: all
become: true
vars:
storage_safe_mode: false
mount_location: '/opt/test1'
volume_group_size: '10g'
volume_size_before: '5g'
volume_size_after: '9g'
invalid_size1: 'xyz GiB'
invalid_size2: 'none'
unused_disk_subfact: '{{ ansible_devices[unused_disks[0]] }}'
too_large_size: '{{ (unused_disk_subfact.sectors|int + 1) *
unused_disk_subfact.sectorsize|int }}'
disk_size: '{{ unused_disk_subfact.sectors|int *
unused_disk_subfact.sectorsize|int }}'

tasks:
- include_role:
Expand All @@ -14,6 +23,8 @@
min_size: "{{ volume_group_size }}"
max_return: 1

# For ext4 FS

- name: Create one LVM logical volume with "{{ volume_size_before }}" under one volume group
include_role:
name: storage
Expand Down Expand Up @@ -47,6 +58,154 @@

- include_tasks: verify-role-results.yml

- name: Change volume size to "{{ volume_size_before }}"
include_role:
name: storage
vars:
storage_pools:
- name: foo
type: lvm
disks: "{{ unused_disks }}"
volumes:
- name: test1
fs_type: 'ext4'
size: "{{ volume_size_before }}"
mount_point: "{{ mount_location }}"

- include_tasks: verify-role-results.yml

- name: Test for correct handling of too-large volume size
block:
- name: Try to create LVM with a too-large volume size, resize to "{{ too_large_size }}"
include_role:
name: storage
vars:
storage_pools:
- name: foo
disks: "{{ unused_disks }}"
volumes:
- name: test1
fs_type: 'ext4'
size: "{{ too_large_size }}"
mount_point: "{{ mount_location }}"

- name: Unreachable task
fail:
msg: UNREACH

rescue:
- name: Check that we failed in the role
assert:
that:
- ansible_failed_result.msg != 'UNREACH'
msg: "Role has not failed when it should have"

- name: Verify the output
assert:
that: "blivet_output.failed and
blivet_output.msg|regex_search('volume.+cannot be resized to.+') and
not blivet_output.changed"
msg: "Unexpected behavior w/ invalid volume size"

- name: Test for correct handling of volume size equal disk's size
block:
- name: Try to create LVM with volume size equal disk's size, resize to "{{ disk_size }}"
include_role:
name: storage
vars:
storage_pools:
- name: foo
disks: "{{ unused_disks }}"
volumes:
- name: test1
fs_type: 'ext4'
size: "{{ disk_size }}"
mount_point: "{{ mount_location }}"

- name: Unreachable task
fail:
msg: UNREACH

rescue:
- name: Check that we failed in the role
assert:
that:
- ansible_failed_result.msg != 'UNREACH'
msg: "Role has not failed when it should have"

- name: Verify the output
assert:
that: "blivet_output.failed and
blivet_output.msg|regex_search('volume.+cannot be resized to.+') and
not blivet_output.changed"
msg: "Unexpected behavior w/ invalid volume size"

- name: Test for correct handling of invalid size specification
block:
- name: Try to create LVM with an invalid size specification, resize to "{{ invalid_size1 }}"
include_role:
name: storage
vars:
storage_pools:
- name: foo
disks: "{{ unused_disks }}"
volumes:
- name: test1
fs_type: 'ext4'
size: "{{ invalid_size1 }}"
mount_point: "{{ mount_location }}"

- name: Unreachable task
fail:
msg: UNREACH

rescue:
- name: Check that we failed in the role
assert:
that:
- ansible_failed_result.msg != 'UNREACH'
msg: "Role has not failed when it should have"

- name: Verify the output
assert:
that: "blivet_output.failed and
blivet_output.msg|regex_search('invalid size.+for volume') and
not blivet_output.changed"
msg: "Unexpected behavior w/ invalid volume size"

- name: Test for correct handling of invalid size specification
block:
- name: Try to create LVM with an invalid size specification, resize to "{{ invalid_size2 }}"
include_role:
name: storage
vars:
storage_pools:
- name: foo
disks: "{{ unused_disks }}"
volumes:
- name: test1
fs_type: 'ext4'
size: "{{ invalid_size2 }}"
mount_point: "{{ mount_location }}"

- name: Unreachable task
fail:
msg: UNREACH

rescue:
- name: Check that we failed in the role
assert:
that:
- ansible_failed_result.msg != 'UNREACH'
msg: "Role has not failed when it should have"

- name: Verify the output
assert:
that: "blivet_output.failed and
blivet_output.msg|regex_search('invalid size.+for volume') and
not blivet_output.changed"
msg: "Unexpected behavior w/ invalid volume size"

- name: Clean up
include_role:
name: storage
Expand All @@ -57,7 +216,137 @@
state: absent
volumes:
- name: test1
size: "{{ volume_size_after }}"
size: "{{ volume_size_before }}"
mount_point: "{{ mount_location }}"

- include_tasks: verify-role-results.yml

# For ext3 FS

- name: Create a LVM logical volume with "{{ volume_size_before }}" for ext3 FS
include_role:
name: storage
vars:
storage_pools:
- name: foo
type: lvm
disks: "{{ unused_disks }}"
volumes:
- name: test1
fs_type: 'ext3'
size: "{{ volume_size_before }}"
mount_point: "{{ mount_location }}"

- include_tasks: verify-role-results.yml

- name: Change volume size to "{{ volume_size_after }}"
include_role:
name: storage
vars:
storage_pools:
- name: foo
type: lvm
disks: "{{ unused_disks }}"
volumes:
- name: test1
fs_type: 'ext3'
size: "{{ volume_size_after }}"
mount_point: "{{ mount_location }}"

- include_tasks: verify-role-results.yml

- name: Change volume size to "{{ volume_size_before }}"
include_role:
name: storage
vars:
storage_pools:
- name: foo
type: lvm
disks: "{{ unused_disks }}"
volumes:
- name: test1
fs_type: 'ext3'
size: "{{ volume_size_before }}"
mount_point: "{{ mount_location }}"

- include_tasks: verify-role-results.yml

- name: Clean up
include_role:
name: storage
vars:
storage_pools:
- name: foo
disks: "{{ unused_disks }}"
state: absent
volumes:
- name: test1
size: "{{ volume_size_before }}"
mount_point: "{{ mount_location }}"

- include_tasks: verify-role-results.yml

# For ext2 FS

- name: Create a LVM logical volume with "{{ volume_size_before }}" for ext2 FS
include_role:
name: storage
vars:
storage_pools:
- name: foo
type: lvm
disks: "{{ unused_disks }}"
volumes:
- name: test1
fs_type: 'ext2'
size: "{{ volume_size_before }}"
mount_point: "{{ mount_location }}"

- include_tasks: verify-role-results.yml

- name: Change volume size to "{{ volume_size_after }}"
include_role:
name: storage
vars:
storage_pools:
- name: foo
type: lvm
disks: "{{ unused_disks }}"
volumes:
- name: test1
fs_type: 'ext2'
size: "{{ volume_size_after }}"
mount_point: "{{ mount_location }}"

- include_tasks: verify-role-results.yml

- name: Change volume size to "{{ volume_size_before }}"
include_role:
name: storage
vars:
storage_pools:
- name: foo
type: lvm
disks: "{{ unused_disks }}"
volumes:
- name: test1
fs_type: 'ext2'
size: "{{ volume_size_before }}"
mount_point: "{{ mount_location }}"

- include_tasks: verify-role-results.yml

- name: Clean up
include_role:
name: storage
vars:
storage_pools:
- name: foo
disks: "{{ unused_disks }}"
state: absent
volumes:
- name: test1
size: "{{ volume_size_before }}"
mount_point: "{{ mount_location }}"

- include_tasks: verify-role-results.yml

0 comments on commit a981d8f

Please sign in to comment.