mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
List correctly current PV in "lvg" module: fix lvg reduce (#49731)
* Refactor integration test for lvg module to introduce grow/reduce test * List correctly current PV in lvg module: fix lvg reduce Previous behaviour was to only take into account PV passed in 'pvs' argument. This lead to reduce not working as expecting: * with state=present and list of wanted pvs, lvg found only the pvs to add or already present and ignored the pv to remove (obviously absent from the list of given PV) * with state=absent and a pv to remove, lvg found that the remaining pvs list is empty (ignoring possible other PV in the vg) and decides to remove the vg entirely (as supposely no PV are left anymore to store lvm metadata) * Add changelog fragment
This commit is contained in:
parent
e2b39a0607
commit
3e303bea4c
7 changed files with 91 additions and 39 deletions
|
@ -86,6 +86,7 @@ EXAMPLES = '''
|
|||
state: absent
|
||||
'''
|
||||
|
||||
import itertools
|
||||
import os
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
@ -167,8 +168,12 @@ def main():
|
|||
# get pv list
|
||||
pvs_cmd = module.get_bin_path('pvs', True)
|
||||
if dev_list:
|
||||
pvs_filter = ' || '. join(['pv_name = {0}'.format(x) for x in dev_list + module.params['pvs']])
|
||||
pvs_filter = "--select '%s'" % pvs_filter
|
||||
pvs_filter_pv_name = ' || '.join(
|
||||
'pv_name = {0}'.format(x)
|
||||
for x in itertools.chain(dev_list, module.params['pvs'])
|
||||
)
|
||||
pvs_filter_vg_name = 'vg_name = {0}'.format(vg)
|
||||
pvs_filter = "--select '{0} || {1}' ".format(pvs_filter_pv_name, pvs_filter_vg_name)
|
||||
else:
|
||||
pvs_filter = ''
|
||||
rc, current_pvs, err = module.run_command("%s --noheadings -o pv_name,vg_name --separator ';' %s" % (pvs_cmd, pvs_filter))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue