From 50226cd7222a8fa486aa523bdce5ddd7c2409639 Mon Sep 17 00:00:00 2001 From: wangcichen Date: Wed, 24 May 2023 17:16:02 +0800 Subject: [PATCH] Inhibit if any CIFS entries found in /etc/fstab --- .../el7toel8/actors/checkcifs/actor.py | 21 ++++++++++++ .../actors/checkcifs/libraries/checkcifs.py | 19 +++++++++++ .../actors/checkcifs/tests/test_checkcifs.py | 34 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 repos/system_upgrade/el7toel8/actors/checkcifs/actor.py create mode 100644 repos/system_upgrade/el7toel8/actors/checkcifs/libraries/checkcifs.py create mode 100644 repos/system_upgrade/el7toel8/actors/checkcifs/tests/test_checkcifs.py diff --git a/repos/system_upgrade/el7toel8/actors/checkcifs/actor.py b/repos/system_upgrade/el7toel8/actors/checkcifs/actor.py new file mode 100644 index 00000000..f124b853 --- /dev/null +++ b/repos/system_upgrade/el7toel8/actors/checkcifs/actor.py @@ -0,0 +1,21 @@ +from leapp.actors import Actor +from leapp.libraries.actor.checkcifs import checkcifs +from leapp.models import StorageInfo +from leapp.reporting import Report +from leapp.tags import ChecksPhaseTag, IPUWorkflowTag + + +class CheckCIFS(Actor): + """ + Check if CIFS filesystem is in use. If yes, inhibit the upgrade process. + + Actor looks for CIFS in /ets/fstab. + If there is a CIFS entry, the upgrade is inhibited. + """ + name = "check_cifs" + consumes = (StorageInfo,) + produces = (Report,) + tags = (ChecksPhaseTag, IPUWorkflowTag,) + + def process(self): + checkcifs(self.consume(StorageInfo)) diff --git a/repos/system_upgrade/el7toel8/actors/checkcifs/libraries/checkcifs.py b/repos/system_upgrade/el7toel8/actors/checkcifs/libraries/checkcifs.py new file mode 100644 index 00000000..5569c1d5 --- /dev/null +++ b/repos/system_upgrade/el7toel8/actors/checkcifs/libraries/checkcifs.py @@ -0,0 +1,19 @@ +from leapp import reporting +from leapp.reporting import create_report + + +def checkcifs(storage_info): + for storage in storage_info: + if any(entry.fs_vfstype == "cifs" for entry in storage.fstab): + create_report([ + reporting.Title("Use of CIFS detected. Upgrade can't proceed"), + reporting.Summary("CIFS is currently not supported by the inplace upgrade."), + reporting.Severity(reporting.Severity.HIGH), + reporting.Tags([ + reporting.Tags.FILESYSTEM, + reporting.Tags.NETWORK + ]), + reporting.Remediation(hint='Comment out CIFS entries to proceed with the upgrade.'), + reporting.Flags([reporting.Flags.INHIBITOR]), + reporting.RelatedResource('file', '/etc/fstab') + ]) diff --git a/repos/system_upgrade/el7toel8/actors/checkcifs/tests/test_checkcifs.py b/repos/system_upgrade/el7toel8/actors/checkcifs/tests/test_checkcifs.py new file mode 100644 index 00000000..ebed4adb --- /dev/null +++ b/repos/system_upgrade/el7toel8/actors/checkcifs/tests/test_checkcifs.py @@ -0,0 +1,34 @@ +from leapp.snactor.fixture import current_actor_context +from leapp.models import StorageInfo, FstabEntry +from leapp.reporting import Report + + +def test_actor_with_fstab_entry(current_actor_context): + with_fstab_entry = [FstabEntry(fs_spec="//10.20.30.42/share1", fs_file="/mnt/win_share1", + fs_vfstype="cifs", + fs_mntops="credentials=/etc/win-credentials,file_mode=0755,dir_mode=0755", + fs_freq="0", fs_passno="0"), + FstabEntry(fs_spec="//10.20.30.42/share2", fs_file="/mnt/win_share2", + fs_vfstype="cifs", + fs_mntops="credentials=/etc/win-credentials,file_mode=0755,dir_mode=0755", + fs_freq="0", fs_passno="0"), + FstabEntry(fs_spec="/dev/mapper/fedora-home", fs_file="/home", + fs_vfstype="ext4", + fs_mntops="defaults,x-systemd.device-timeout=0", + fs_freq="1", fs_passno="2")] + current_actor_context.feed(StorageInfo(fstab=with_fstab_entry)) + current_actor_context.run() + report_fields = current_actor_context.consume(Report)[0].report + assert 'inhibitor' in report_fields['flags'] + assert report_fields['severity'] == 'high' + assert report_fields['title'] == "Use of CIFS detected. Upgrade can't proceed" + + +def test_actor_no_cifs(current_actor_context): + with_fstab_entry = [FstabEntry(fs_spec="/dev/mapper/fedora-home", fs_file="/home", + fs_vfstype="ext4", + fs_mntops="defaults,x-systemd.device-timeout=0", + fs_freq="1", fs_passno="2")] + current_actor_context.feed(StorageInfo(fstab=with_fstab_entry)) + current_actor_context.run() + assert not current_actor_context.consume(Report) -- Gitee