From 25f7d0e524bf4ddcb11cfffd31ea3189dc3012d2 Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Tue, 31 Aug 2021 14:10:16 -0300 Subject: [PATCH 1/4] Fix call to Popen.communicate The call is wrongly passing a string when only bytes-like are allowed. --- charmhelpers/contrib/storage/linux/lvm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charmhelpers/contrib/storage/linux/lvm.py b/charmhelpers/contrib/storage/linux/lvm.py index d0a572115..42255ff5a 100644 --- a/charmhelpers/contrib/storage/linux/lvm.py +++ b/charmhelpers/contrib/storage/linux/lvm.py @@ -60,7 +60,7 @@ def remove_lvm_physical_volume(block_device): ''' p = Popen(['pvremove', '-ff', block_device], stdin=PIPE) - p.communicate(input='y\n') + p.communicate(input=b'y\n') def list_lvm_volume_group(block_device): From 1b19313ebf4e4a935758c1cab9c19330c372cb13 Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Fri, 3 Sep 2021 18:13:14 -0300 Subject: [PATCH 2/4] Use '--yes' and 'check_call' instead of 'Popen' and 'communicate'. --- charmhelpers/contrib/storage/linux/lvm.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/charmhelpers/contrib/storage/linux/lvm.py b/charmhelpers/contrib/storage/linux/lvm.py index 42255ff5a..9888de933 100644 --- a/charmhelpers/contrib/storage/linux/lvm.py +++ b/charmhelpers/contrib/storage/linux/lvm.py @@ -58,9 +58,7 @@ def remove_lvm_physical_volume(block_device): :param block_device: str: Full path of block device to scrub. ''' - p = Popen(['pvremove', '-ff', block_device], - stdin=PIPE) - p.communicate(input=b'y\n') + check_call(['pvremove', '-ff', '--yes', block_device]) def list_lvm_volume_group(block_device): From 2f5c28ecc9ac215f97616c804f0ab42032412fb4 Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Mon, 20 Sep 2021 15:22:14 -0300 Subject: [PATCH 3/4] Fix unit test for 'remove_lvm_physical_volume' This PR modified the call to no longer use 'Popen', but it was missing the corresponding fix in the unit test for said function. --- tests/contrib/storage/test_linux_storage_lvm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/contrib/storage/test_linux_storage_lvm.py b/tests/contrib/storage/test_linux_storage_lvm.py index 1b63c274e..a308504c9 100644 --- a/tests/contrib/storage/test_linux_storage_lvm.py +++ b/tests/contrib/storage/test_linux_storage_lvm.py @@ -80,9 +80,9 @@ def test_deactivate_lvm_volume_groups(self, ls_vg): def test_remove_lvm_physical_volume(self): """It removes LVM physical volume signatures from block device""" - with patch(STORAGE_LINUX_LVM + '.Popen') as popen: + with patch(STORAGE_LINUX_LVM + '.check_call') as popen: lvm.remove_lvm_physical_volume('/dev/foo') - popen.assert_called_with(['pvremove', '-ff', '/dev/foo'], stdin=-1) + popen.assert_called_with(['pvremove', '-ff', '--yes', '/dev/foo']) def test_is_physical_volume(self): """It properly reports block dev is an LVM PV""" From e44a15ef61f91685ac7b6cee531004e13074a252 Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Sat, 9 Oct 2021 15:39:11 -0300 Subject: [PATCH 4/4] Remove unused imports --- charmhelpers/contrib/storage/linux/lvm.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/charmhelpers/contrib/storage/linux/lvm.py b/charmhelpers/contrib/storage/linux/lvm.py index 9888de933..0d294c794 100644 --- a/charmhelpers/contrib/storage/linux/lvm.py +++ b/charmhelpers/contrib/storage/linux/lvm.py @@ -17,8 +17,6 @@ CalledProcessError, check_call, check_output, - Popen, - PIPE, )