1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

LVG: add new parameter pvresize (#422)

* enabling resize in pv.

* change pvresize default behavior to false

* includes changelog on pvresize

* punctuation fix

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* fixes typo and changes pvresize_cmd location

* Update changelogs/fragments/442-add-new-parameter-pvresize.yaml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/system/lvg.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* rebase and add EXAMPLE for pvresize

* fix wrongly submited merge conflict

* Update plugins/modules/system/lvg.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* adding tests

* add test for check_mode

* fix identation

* Update tests/integration/targets/lvg/tasks/test_pvresize.yml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update tests/integration/targets/lvg/tasks/test_pvresize.yml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* fix identation

Co-authored-by: CASSIO ALVES <cassioalves@bocombbm.com.br>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: cassio alves <cassio@localhost.localdomain>
This commit is contained in:
cassio-santos 2020-05-29 16:16:23 -03:00 committed by GitHub
parent 317532f8bd
commit 9de5c0c53c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 118 additions and 0 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- lvg - add ``pvresize`` new parameter (https://github.com/ansible/ansible/issues/29139).

View file

@ -40,6 +40,11 @@ options:
description: description:
- Additional options to pass to C(pvcreate) when creating the volume group. - Additional options to pass to C(pvcreate) when creating the volume group.
type: str type: str
pvresize:
description:
- If C(yes), resize the physical volume to the maximum available size.
type: bool
default: false
vg_options: vg_options:
description: description:
- Additional options to pass to C(vgcreate) when creating the volume group. - Additional options to pass to C(vgcreate) when creating the volume group.
@ -89,6 +94,12 @@ EXAMPLES = r'''
lvg: lvg:
vg: vg.services vg: vg.services
state: absent state: absent
- name: Create a volume group on top of /dev/sda3 and resize the volume group /dev/sda3 to the maximum possible
lvg:
vg: resizableVG
pvs: /dev/sda3
pvresize: yes
''' '''
import itertools import itertools
@ -140,6 +151,7 @@ def main():
pvs=dict(type='list'), pvs=dict(type='list'),
pesize=dict(type='str', default='4'), pesize=dict(type='str', default='4'),
pv_options=dict(type='str', default=''), pv_options=dict(type='str', default=''),
pvresize=dict(type='bool', default=False),
vg_options=dict(type='str', default=''), vg_options=dict(type='str', default=''),
state=dict(type='str', default='present', choices=['absent', 'present']), state=dict(type='str', default='present', choices=['absent', 'present']),
force=dict(type='bool', default=False), force=dict(type='bool', default=False),
@ -150,6 +162,7 @@ def main():
vg = module.params['vg'] vg = module.params['vg']
state = module.params['state'] state = module.params['state']
force = module.boolean(module.params['force']) force = module.boolean(module.params['force'])
pvresize = module.boolean(module.params['pvresize'])
pesize = module.params['pesize'] pesize = module.params['pesize']
pvoptions = module.params['pv_options'].split() pvoptions = module.params['pv_options'].split()
vgoptions = module.params['vg_options'].split() vgoptions = module.params['vg_options'].split()
@ -249,6 +262,31 @@ def main():
devs_to_remove = list(set(current_devs) - set(dev_list)) devs_to_remove = list(set(current_devs) - set(dev_list))
devs_to_add = list(set(dev_list) - set(current_devs)) devs_to_add = list(set(dev_list) - set(current_devs))
if current_devs:
if state == 'present' and pvresize:
for device in current_devs:
pvresize_cmd = module.get_bin_path('pvresize', True)
pvdisplay_cmd = module.get_bin_path('pvdisplay', True)
pvdisplay_ops = ["--units", "b", "--columns", "--noheadings", "--nosuffix"]
pvdisplay_cmd_device_options = [pvdisplay_cmd, device] + pvdisplay_ops
rc, dev_size, err = module.run_command(pvdisplay_cmd_device_options + ["-o", "dev_size"])
dev_size = int(dev_size.replace(" ", ""))
rc, pv_size, err = module.run_command(pvdisplay_cmd_device_options + ["-o", "pv_size"])
pv_size = int(pv_size.replace(" ", ""))
rc, pe_start, err = module.run_command(pvdisplay_cmd_device_options + ["-o", "pe_start"])
pe_start = int(pe_start.replace(" ", ""))
rc, vg_extent_size, err = module.run_command(pvdisplay_cmd_device_options + ["-o", "vg_extent_size"])
vg_extent_size = int(vg_extent_size.replace(" ", ""))
if (dev_size - (pe_start + pv_size)) > vg_extent_size:
if module.check_mode:
changed = True
else:
rc, _, err = module.run_command([pvresize_cmd, device])
if rc != 0:
module.fail_json(msg="Failed executing pvresize command.", rc=rc, err=err)
else:
changed = True
if devs_to_add or devs_to_remove: if devs_to_add or devs_to_remove:
if module.check_mode: if module.check_mode:
changed = True changed = True

View file

@ -11,5 +11,7 @@
- import_tasks: test_indempotency.yml - import_tasks: test_indempotency.yml
- import_tasks: test_grow_reduce.yml - import_tasks: test_grow_reduce.yml
- import_tasks: test_pvresize.yml
always: always:
- import_tasks: teardown.yml - import_tasks: teardown.yml

View file

@ -0,0 +1,76 @@
- name: "Create volume group on first disk"
lvg:
vg: testvg
pvs: "{{ loop_device1.stdout }}"
- name: Gets current vg size
shell: vgs -v testvg -o pv_size --noheading --units b | xargs
register: cmd_result
- name: Assert the testvg size is 8388608B
assert:
that:
- "'8388608B' == cmd_result.stdout"
- name: Increases size in file
command: "dd if=/dev/zero bs=8MiB count=1 of={{ remote_tmp_dir }}/img1 conv=notrunc oflag=append"
- name: "Reread size of file associated with loop_device1"
command: "losetup -c {{ loop_device1.stdout }}"
- name: "Reruns lvg with pvresize:no"
lvg:
vg: testvg
pvs: "{{ loop_device1.stdout }}"
pvresize: no
register: cmd_result
- assert:
that:
- cmd_result is not changed
- name: Gets current vg size
shell: vgs -v testvg -o pv_size --noheading --units b | xargs
register: cmd_result
- name: Assert the testvg size is still 8388608B
assert:
that:
- "'8388608B' == cmd_result.stdout"
- name: "Reruns lvg with pvresize:yes and check_mode:yes"
lvg:
vg: testvg
pvs: "{{ loop_device1.stdout }}"
pvresize: yes
check_mode: yes
register: cmd_result
- name: Assert that the module returned the state was changed
assert:
that:
- cmd_result is changed
- name: Gets current vg size
shell: vgs -v testvg -o pv_size --noheading --units b | xargs
register: cmd_result
- name: Assert the testvg size is still 8388608B
assert:
that:
- "'8388608B' == cmd_result.stdout"
- name: "Reruns lvg with pvresize:yes"
lvg:
vg: testvg
pvs: "{{ loop_device1.stdout }}"
pvresize: yes
- name: Gets current vg size
shell: vgs -v testvg -o pv_size --noheading --units b | xargs
register: cmd_result
- name: Assert the testvg size is now 16777216B
assert:
that:
- "'16777216B' == cmd_result.stdout"