Skip to content

Commit

Permalink
mdraid.py lib: Check if /usr/sbin/mdadm exists
Browse files Browse the repository at this point in the history
Praviously the check was implemented using OSError return from `run`
function. However, in this particular case it's not safe and leads
to unexpected behaviour. Check the existence of the file explicitly
instead prior the `run` function is called.
  • Loading branch information
pirat89 committed Jul 17, 2023
1 parent c7b1e75 commit aca9b54
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions repos/system_upgrade/common/libraries/mdraid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from leapp.libraries.stdlib import api, CalledProcessError, run


Expand All @@ -12,11 +14,13 @@ def is_mdraid_dev(dev):
:raises CalledProcessError: If an error occurred
"""
fail_msg = 'Could not check if device "{}" is an md device: {}'
if not os.path.exists('/usr/sbin/mdadm'):
api.current_logger().warning(fail_msg.format(
dev, '/usr/sbin/mdadm is not installed.'
))
return False
try:
result = run(['mdadm', '--query', dev])
except OSError as err:
api.current_logger().warning(fail_msg.format(dev, err))
return False
except CalledProcessError as err:
err.message = fail_msg.format(dev, err)
raise # let the calling actor handle the exception
Expand Down

0 comments on commit aca9b54

Please sign in to comment.