Skip to content

Commit

Permalink
Merge pull request #10 from shibutd/cloudlinux
Browse files Browse the repository at this point in the history
Handle possible failures of xfs_info command
  • Loading branch information
prilr authored Apr 10, 2024
2 parents c18549c + e619aee commit 4b046ae
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from leapp.libraries.stdlib import api, run, CalledProcessError
import os

from leapp.libraries.stdlib import api, CalledProcessError, run
from leapp.models import StorageInfo, XFSPresence


Expand All @@ -21,18 +23,21 @@ def scan_xfs_mount(data):


def is_xfs_without_ftype(mp):
try:
for l in run(['/usr/sbin/xfs_info', '{}'.format(mp)], split=True)['stdout']:
if 'ftype=0' in l:
return True
if not os.path.ismount(mp):
# Check if mp is actually a mountpoint
api.current_logger().warning('{} is not mounted'.format(mp))
return False
# xfs_info can sometimes throw errors like the following if fed a CageFS mountpoint.
# xfs_info: /usr/share/cagefs-skeleton/var/www/cgi-bin\040(deleted) is not a mounted XFS filesystem
try:
xfs_info = run(['/usr/sbin/xfs_info', '{}'.format(mp)], split=True)
except CalledProcessError as err:
if "cagefs" in mp:
api.current_logger().info("CageFS XFS mountpoint {} ignored in scanner".format(mp))
return False
raise err
api.current_logger().warning('Error during command execution: {}'.format(err))
return False

for l in xfs_info['stdout']:
if 'ftype=0' in l:
return True

return False


def scan_xfs():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os

from leapp.libraries.actor import xfsinfoscanner
from leapp.libraries.common.testutils import produce_mocked
from leapp.libraries.stdlib import api
from leapp.models import StorageInfo, FstabEntry, MountEntry, SystemdMountEntry, XFSPresence
from leapp.libraries.stdlib import api, CalledProcessError
from leapp.models import FstabEntry, MountEntry, StorageInfo, SystemdMountEntry, XFSPresence


class run_mocked(object):
Expand Down Expand Up @@ -87,6 +89,7 @@ def test_scan_xfs_mount(monkeypatch):

def test_is_xfs_without_ftype(monkeypatch):
monkeypatch.setattr(xfsinfoscanner, "run", run_mocked())
monkeypatch.setattr(os.path, "ismount", lambda _: True)

assert xfsinfoscanner.is_xfs_without_ftype("/var")
assert ' '.join(xfsinfoscanner.run.args) == "/usr/sbin/xfs_info /var"
Expand All @@ -95,8 +98,22 @@ def test_is_xfs_without_ftype(monkeypatch):
assert ' '.join(xfsinfoscanner.run.args) == "/usr/sbin/xfs_info /boot"


def test_is_xfs_command_failed(monkeypatch):
def _run_mocked_exception(*args, **kwargs):
raise CalledProcessError(message="No such file or directory", command=["xfs_info", "/nosuchmountpoint"],
result=1)
# not a mountpoint
monkeypatch.setattr(os.path, "ismount", lambda _: False)
monkeypatch.setattr(xfsinfoscanner, "run", _run_mocked_exception)
assert not xfsinfoscanner.is_xfs_without_ftype("/nosuchmountpoint")
# a real mountpoint but something else caused command to fail
monkeypatch.setattr(os.path, "ismount", lambda _: True)
assert not xfsinfoscanner.is_xfs_without_ftype("/nosuchmountpoint")


def test_scan_xfs(monkeypatch):
monkeypatch.setattr(xfsinfoscanner, "run", run_mocked())
monkeypatch.setattr(os.path, "ismount", lambda _: True)

def consume_no_xfs_message_mocked(*models):
yield StorageInfo()
Expand Down

0 comments on commit 4b046ae

Please sign in to comment.