Skip to content

Commit

Permalink
Merge pull request #636 from lmlg/fix-popen-communicate
Browse files Browse the repository at this point in the history
Fix call to Popen.communicate
  • Loading branch information
ajkavanagh authored Mar 4, 2024
2 parents 279e113 + e44a15e commit b78107d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
6 changes: 1 addition & 5 deletions charmhelpers/contrib/storage/linux/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
CalledProcessError,
check_call,
check_output,
Popen,
PIPE,
)


Expand Down Expand Up @@ -58,9 +56,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='y\n')
check_call(['pvremove', '-ff', '--yes', block_device])


def list_lvm_volume_group(block_device):
Expand Down
4 changes: 2 additions & 2 deletions tests/contrib/storage/test_linux_storage_lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down

0 comments on commit b78107d

Please sign in to comment.