diff --git a/repos/system_upgrade/common/actors/detectgrubconfigerror/actor.py b/repos/system_upgrade/common/actors/detectgrubconfigerror/actor.py new file mode 100644 index 0000000000..e576c8aacd --- /dev/null +++ b/repos/system_upgrade/common/actors/detectgrubconfigerror/actor.py @@ -0,0 +1,87 @@ +from leapp import reporting +from leapp.actors import Actor +from leapp.models import GrubConfigError +from leapp.reporting import create_report, Report +from leapp.tags import ChecksPhaseTag, IPUWorkflowTag + + +def _create_grub_error_report(error, title, summary, severity=reporting.Severity.LOW, + remediation=None, is_inhibitor=False): + """ + A helper that produces a specific grub error report + """ + # set default group for a grub error report + groups = [reporting.Groups.BOOT] + # set an inhibitor group + if is_inhibitor: + groups.append(reporting.Groups.INHIBITOR) + report_fields = [reporting.Title(title), + reporting.Summary(summary), + reporting.Severity(severity), + reporting.Groups(groups)] + if remediation: + report_fields.append(remediation) + # add information about grub config files + report_fields.extend([reporting.RelatedResource('file', config_file) for config_file in error.files]) + # finally produce a report + create_report(report_fields) + + +class DetectGrubConfigError(Actor): + """ + Check grub configuration for various errors. + + Currently 3 types of errors are detected: + - Syntax error in GRUB_CMDLINE_LINUX value; + - Missing newline at the end of file; + - Grubenv config file has a 1K size and doesn't end with a line feed. + + There should be only one message of each error type. If for any reason there are more - only the first error of + each type is reported. + """ + + name = 'detect_grub_config_error' + consumes = (GrubConfigError,) + produces = (Report,) + tags = (ChecksPhaseTag, IPUWorkflowTag) + + def process(self): + # syntax error in GRUB_CMDLINE_LINUX, recoverable + for error in [err for err in self.consume(GrubConfigError) + if err.error_type == GrubConfigError.ERROR_GRUB_CMDLINE_LINUX_SYNTAX]: + _create_grub_error_report( + error=error, + title='Syntax error detected in grub configuration', + summary=('Syntax error was detected in GRUB_CMDLINE_LINUX value of grub configuration. ' + 'This error is causing booting and other issues. ' + 'Error is automatically fixed by add_upgrade_boot_entry actor.'), + ) + break + # missing newline, recoverable + for error in [err for err in self.consume(GrubConfigError) + if err.error_type == GrubConfigError.ERROR_MISSING_NEWLINE]: + _create_grub_error_report( + error=error, + title='Detected a missing newline at the end of grub configuration file', + summary=('The missing newline in /etc/default/grub causes booting issues when appending ' + 'new entries to this file during the upgrade. Leapp will automatically fix this ' + 'problem by appending the missing newline to the grub configuration file.') + ) + break + # corrupted configuration, inhibitor + for error in [err for err in self.consume(GrubConfigError) + if err.error_type == GrubConfigError.ERROR_CORRUPTED_GRUBENV]: + _create_grub_error_report( + error=error, + title='Detected a corrupted grubenv file', + summary=('The grubenv file must be valid to pass the upgrade correctly: \n' + '- an exact size of 1024 bytes is expected \n' + '- it cannot end with a newline. \n' + 'The corruption could be caused by a manual modification of the file which ' + 'is not recommended.'), + severity=reporting.Severity.HIGH, + is_inhibitor=True, + remediation=reporting.Remediation( + hint='Delete {} file(s) and regenerate grubenv using the grub2-mkconfig tool'.format( + ','.join(error.files)))) + break diff --git a/repos/system_upgrade/common/actors/detectgrubconfigerror/tests/test_detectgrubconfigerror.py b/repos/system_upgrade/common/actors/detectgrubconfigerror/tests/test_detectgrubconfigerror.py new file mode 100644 index 0000000000..274d857e8b --- /dev/null +++ b/repos/system_upgrade/common/actors/detectgrubconfigerror/tests/test_detectgrubconfigerror.py @@ -0,0 +1,58 @@ +from leapp.models import GrubConfigError, Report +from leapp.utils import report + +grub_cmdline_syntax_error = GrubConfigError(error_type=GrubConfigError.ERROR_GRUB_CMDLINE_LINUX_SYNTAX, + files=['/etc/default/grub.cfg']) +grub_cmdline_syntax_error2 = GrubConfigError(error_type=GrubConfigError.ERROR_GRUB_CMDLINE_LINUX_SYNTAX, + files=['/boot/grub2/grub.cfg', '/etc/default/someothergrub.cfg']) + +grub_missing_newline_error = GrubConfigError(error_type=GrubConfigError.ERROR_MISSING_NEWLINE, + files=['/etc/default/someothergrub.cfg']) +grub_missing_newline_error2 = GrubConfigError(error_type=GrubConfigError.ERROR_MISSING_NEWLINE, + files=['/etc/default/grub']) + +grub_corrupted_config = GrubConfigError(error_type=GrubConfigError.ERROR_CORRUPTED_GRUBENV, + files=['/boot/grub2/grub.cfg', '/boot/efi/EFI/redhat/grub.cfg']) +grub_corrupted_config2 = GrubConfigError(error_type=GrubConfigError.ERROR_CORRUPTED_GRUBENV, + files=['/boot/grub2/grub.cfg']) + + +def test_cmdline_syntax_error(current_actor_context): + # Make sure that just 1 low priority report message is created with config files present. + current_actor_context.feed(grub_cmdline_syntax_error) + current_actor_context.feed(grub_cmdline_syntax_error2) + current_actor_context.run() + messages = current_actor_context.consume(Report) + assert len(messages) == 1 + message = messages[0] + assert 'Syntax error detected in grub configuration' in message.report['title'] + assert message.report['severity'] == 'low' + assert message.report['detail']['related_resources'][0]['title'] == '/etc/default/grub.cfg' + + +def test_missing_newline(current_actor_context): + # Make sure that just 1 low priority report message is created with config files present + current_actor_context.feed(grub_missing_newline_error) + current_actor_context.feed(grub_missing_newline_error2) + current_actor_context.run() + messages = current_actor_context.consume(Report) + assert len(messages) == 1 + message = messages[0] + assert 'Detected a missing newline at the end of grub configuration file' in message.report['title'] + assert message.report['severity'] == 'low' + assert message.report['detail']['related_resources'][0]['title'] == '/etc/default/someothergrub.cfg' + + +def test_corrupted_config(current_actor_context): + # Make sure that just 1 high priority report message is created with config files present + current_actor_context.feed(grub_corrupted_config) + current_actor_context.feed(grub_corrupted_config2) + current_actor_context.run() + messages = current_actor_context.consume(Report) + assert len(messages) == 1 + message = messages[0] + assert 'Detected a corrupted grubenv file' in message.report['title'] + assert message.report['severity'] == 'high' + assert message.report['detail']['related_resources'][0]['title'] == '/boot/grub2/grub.cfg' + assert message.report['detail']['related_resources'][1]['title'] == '/boot/efi/EFI/redhat/grub.cfg' + assert report.is_inhibitor(message.report) diff --git a/repos/system_upgrade/common/actors/detectmissingnewlineingrubcfg/actor.py b/repos/system_upgrade/common/actors/detectmissingnewlineingrubcfg/actor.py deleted file mode 100644 index 5ad90e0057..0000000000 --- a/repos/system_upgrade/common/actors/detectmissingnewlineingrubcfg/actor.py +++ /dev/null @@ -1,35 +0,0 @@ -from leapp import reporting -from leapp.actors import Actor -from leapp.libraries.actor.detectmissingnewlineingrubcfg import is_grub_config_missing_final_newline -from leapp.models import GrubConfigError -from leapp.reporting import create_report, Report -from leapp.tags import ChecksPhaseTag, IPUWorkflowTag - - -class DetectMissingNewlineInGrubCfg(Actor): - """ - Check the grub configuration for a missing newline at its end. - """ - - name = 'detect_missing_newline_in_grub_cfg' - consumes = () - produces = (Report, GrubConfigError) - tags = (ChecksPhaseTag, IPUWorkflowTag) - - def process(self): - config = '/etc/default/grub' - if is_grub_config_missing_final_newline(config): - create_report([ - reporting.Title('Detected a missing newline at the end of grub configuration file.'), - reporting.Summary( - 'The missing newline in /etc/default/grub causes booting issues when appending ' - 'new entries to this file during the upgrade. Leapp will automatically fix this ' - 'problem by appending the missing newline to the grub configuration file.' - ), - reporting.Severity(reporting.Severity.LOW), - reporting.Groups([reporting.Groups.BOOT]), - reporting.RelatedResource('file', config) - ]) - - config_error = GrubConfigError(error_detected=True, error_type='missing newline') - self.produce(config_error) diff --git a/repos/system_upgrade/common/actors/detectmissingnewlineingrubcfg/libraries/detectmissingnewlineingrubcfg.py b/repos/system_upgrade/common/actors/detectmissingnewlineingrubcfg/libraries/detectmissingnewlineingrubcfg.py deleted file mode 100644 index 17a81e7ca2..0000000000 --- a/repos/system_upgrade/common/actors/detectmissingnewlineingrubcfg/libraries/detectmissingnewlineingrubcfg.py +++ /dev/null @@ -1,13 +0,0 @@ -import os - - -def _get_config_contents(config_path): - if os.path.isfile(config_path): - with open(config_path, 'r') as config: - return config.read() - return '' - - -def is_grub_config_missing_final_newline(conf_file): - config_contents = _get_config_contents(conf_file) - return config_contents != '' and config_contents[-1] != '\n' diff --git a/repos/system_upgrade/common/actors/detectmissingnewlineingrubcfg/tests/test_detectmissingnewlineingrubcfg.py b/repos/system_upgrade/common/actors/detectmissingnewlineingrubcfg/tests/test_detectmissingnewlineingrubcfg.py deleted file mode 100644 index b7c148df6d..0000000000 --- a/repos/system_upgrade/common/actors/detectmissingnewlineingrubcfg/tests/test_detectmissingnewlineingrubcfg.py +++ /dev/null @@ -1,23 +0,0 @@ -import pytest - -from leapp.libraries.actor import detectmissingnewlineingrubcfg - - -@pytest.mark.parametrize( - ('config_contents', 'error_detected'), - [ - ('GRUB_DEFAULT=saved\nGRUB_DISABLE_SUBMENU=true\n', False), - ('GRUB_DEFAULT=saved\nGRUB_DISABLE_SUBMENU=true', True) - ] -) -def test_is_grub_config_missing_final_newline(monkeypatch, config_contents, error_detected): - - config_path = '/etc/default/grub' - - def mocked_get_config_contents(path): - assert path == config_path - return config_contents - - monkeypatch.setattr(detectmissingnewlineingrubcfg, '_get_config_contents', mocked_get_config_contents) - - assert detectmissingnewlineingrubcfg.is_grub_config_missing_final_newline(config_path) == error_detected diff --git a/repos/system_upgrade/common/actors/scangrubconfig/actor.py b/repos/system_upgrade/common/actors/scangrubconfig/actor.py new file mode 100644 index 0000000000..22815f5b39 --- /dev/null +++ b/repos/system_upgrade/common/actors/scangrubconfig/actor.py @@ -0,0 +1,21 @@ +from leapp.actors import Actor +from leapp.libraries.actor import scanner +from leapp.models import GrubConfigError +from leapp.tags import FactsPhaseTag, IPUWorkflowTag + + +class ScanGrubConfig(Actor): + """ + Scan grub configuration files for errors. + """ + + name = 'scan_grub_config' + consumes = () + produces = (GrubConfigError,) + tags = (FactsPhaseTag, IPUWorkflowTag) + + def process(self): + errors = scanner.scan() + if errors: + for error in errors: + self.produce(error) diff --git a/repos/system_upgrade/common/actors/scangrubconfig/libraries/scanner.py b/repos/system_upgrade/common/actors/scangrubconfig/libraries/scanner.py new file mode 100644 index 0000000000..86bba22be5 --- /dev/null +++ b/repos/system_upgrade/common/actors/scangrubconfig/libraries/scanner.py @@ -0,0 +1,73 @@ +import os +import re + +from leapp.libraries.common.config import architecture, version +from leapp.models import GrubConfigError + + +def is_grubenv_corrupted(conf_file): + # grubenv can be missing + if not os.path.exists(conf_file): + return False + # ignore when /boot/grub2/grubenv is a symlink to its EFI counterpart + if os.path.islink(conf_file) and os.readlink(conf_file) == '../efi/EFI/redhat/grubenv': + return False + with open(conf_file, 'r') as config: + config_contents = config.read() + return len(config_contents) != 1024 or config_contents[-1] == '\n' + + +def _get_config_contents(config_path): + if os.path.isfile(config_path): + with open(config_path, 'r') as config: + return config.read() + return '' + + +def is_grub_config_missing_final_newline(conf_file): + config_contents = _get_config_contents(conf_file) + return config_contents and config_contents[-1] != '\n' + + +def detect_config_error(conf_file): + """ + Check grub configuration for syntax error in GRUB_CMDLINE_LINUX value. + + :return: Function returns True if error was detected, otherwise False. + """ + with open(conf_file, 'r') as f: + config = f.read() + + pattern = r'GRUB_CMDLINE_LINUX="[^"]+"(?!(\s*$)|(\s+(GRUB|#)))' + return re.search(pattern, config) is not None + + +def scan(): + errors = [] + # Check for corrupted grubenv + if not architecture.matches_architecture(architecture.ARCH_S390X): + configs = ['/boot/grub2/grubenv', '/boot/efi/EFI/redhat/grubenv'] + corrupted = [] + for cfg in configs: + if is_grubenv_corrupted(cfg): + corrupted.append(cfg) + if corrupted: + errors.append(GrubConfigError(error_type=GrubConfigError.ERROR_CORRUPTED_GRUBENV, files=corrupted)) + + config = '/etc/default/grub' + # Check for GRUB_CMDLINE_LINUX syntax errors + # XXX FIXME(ivasilev) Can we make this check a common one? For now let's limit it to rhel7->rhel8 only + if version.get_source_major_version() == '7': + if not architecture.matches_architecture(architecture.ARCH_S390X): + # For now, skip just s390x, that's only one that is failing now + # because ZIPL is used there + if detect_config_error(config): + errors.append(GrubConfigError(error_detected=True, files=[config], + error_type=GrubConfigError.ERROR_GRUB_CMDLINE_LINUX_SYNTAX)) + + # Check for missing newline errors + if is_grub_config_missing_final_newline(config): + errors.append(GrubConfigError(error_detected=True, error_type=GrubConfigError.ERROR_MISSING_NEWLINE, + files=[config])) + + return errors diff --git a/repos/system_upgrade/common/actors/scangrubconfig/tests/files/corrupted_grubenv/grubenv.correct b/repos/system_upgrade/common/actors/scangrubconfig/tests/files/corrupted_grubenv/grubenv.correct new file mode 100644 index 0000000000..6190c66b79 --- /dev/null +++ b/repos/system_upgrade/common/actors/scangrubconfig/tests/files/corrupted_grubenv/grubenv.correct @@ -0,0 +1,3 @@ +# GRUB Environment Block +saved_entry=Red Hat Enterprise Linux Server (3.10.0-1160.80.1.el7.x86_64) 7.9 (Maipo) +################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################# \ No newline at end of file diff --git a/repos/system_upgrade/common/actors/scangrubconfig/tests/files/corrupted_grubenv/grubenv.wrong1 b/repos/system_upgrade/common/actors/scangrubconfig/tests/files/corrupted_grubenv/grubenv.wrong1 new file mode 100644 index 0000000000..41dc4a93c7 --- /dev/null +++ b/repos/system_upgrade/common/actors/scangrubconfig/tests/files/corrupted_grubenv/grubenv.wrong1 @@ -0,0 +1,4 @@ +# GRUB Environment Block +saved_entry=Red Hat Enterprise Linux Server (3.10.0-1160.80.1.el7.x86_64) 7.9 (Maipo) +############################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################### + diff --git a/repos/system_upgrade/common/actors/scangrubconfig/tests/files/corrupted_grubenv/grubenv.wrong2 b/repos/system_upgrade/common/actors/scangrubconfig/tests/files/corrupted_grubenv/grubenv.wrong2 new file mode 100644 index 0000000000..22f95aaf05 --- /dev/null +++ b/repos/system_upgrade/common/actors/scangrubconfig/tests/files/corrupted_grubenv/grubenv.wrong2 @@ -0,0 +1,2 @@ +saved_entry=Red Hat Enterprise Linux Server (3.10.0-1160.80.1.el7.x86_64) 7.9 (Maipo) +################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################# diff --git a/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/files/grub.correct b/repos/system_upgrade/common/actors/scangrubconfig/tests/files/error_detection/grub.correct similarity index 100% rename from repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/files/grub.correct rename to repos/system_upgrade/common/actors/scangrubconfig/tests/files/error_detection/grub.correct diff --git a/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/files/grub.correct_comment b/repos/system_upgrade/common/actors/scangrubconfig/tests/files/error_detection/grub.correct_comment similarity index 100% rename from repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/files/grub.correct_comment rename to repos/system_upgrade/common/actors/scangrubconfig/tests/files/error_detection/grub.correct_comment diff --git a/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/files/grub.correct_puppet b/repos/system_upgrade/common/actors/scangrubconfig/tests/files/error_detection/grub.correct_puppet similarity index 100% rename from repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/files/grub.correct_puppet rename to repos/system_upgrade/common/actors/scangrubconfig/tests/files/error_detection/grub.correct_puppet diff --git a/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/files/grub.correct_trailing_space b/repos/system_upgrade/common/actors/scangrubconfig/tests/files/error_detection/grub.correct_trailing_space similarity index 100% rename from repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/files/grub.correct_trailing_space rename to repos/system_upgrade/common/actors/scangrubconfig/tests/files/error_detection/grub.correct_trailing_space diff --git a/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/files/grub.wrong b/repos/system_upgrade/common/actors/scangrubconfig/tests/files/error_detection/grub.wrong similarity index 100% rename from repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/files/grub.wrong rename to repos/system_upgrade/common/actors/scangrubconfig/tests/files/error_detection/grub.wrong diff --git a/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/files/grub.wrong1 b/repos/system_upgrade/common/actors/scangrubconfig/tests/files/error_detection/grub.wrong1 similarity index 100% rename from repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/files/grub.wrong1 rename to repos/system_upgrade/common/actors/scangrubconfig/tests/files/error_detection/grub.wrong1 diff --git a/repos/system_upgrade/common/actors/scangrubconfig/tests/test_scangrubconfig.py b/repos/system_upgrade/common/actors/scangrubconfig/tests/test_scangrubconfig.py new file mode 100644 index 0000000000..926f0f2772 --- /dev/null +++ b/repos/system_upgrade/common/actors/scangrubconfig/tests/test_scangrubconfig.py @@ -0,0 +1,69 @@ +import os + +import pytest + +from leapp.libraries.actor import scanner +from leapp.libraries.common.config import architecture, version +from leapp.models import GrubConfigError, Report + +CUR_DIR = os.path.dirname(os.path.abspath(__file__)) + + +def test_correct_config_error_detection(): + assert not scanner.detect_config_error(os.path.join(CUR_DIR, 'files/error_detection/grub.correct')) + assert not scanner.detect_config_error(os.path.join(CUR_DIR, 'files/error_detection/grub.correct_trailing_space')) + assert not scanner.detect_config_error(os.path.join(CUR_DIR, 'files/error_detection/grub.correct_comment')) + assert not scanner.detect_config_error(os.path.join(CUR_DIR, 'files/error_detection/grub.correct_puppet')) + + +def test_wrong_config_error_detection(): + assert scanner.detect_config_error(os.path.join(CUR_DIR, 'files/error_detection/grub.wrong')) + assert scanner.detect_config_error(os.path.join(CUR_DIR, 'files/error_detection/grub.wrong1')) + + +def test_all_errors_produced(current_actor_context, monkeypatch): + # Tell the actor we are not running on s390x + monkeypatch.setattr(architecture, 'matches_architecture', lambda _: False) + monkeypatch.setattr(version, 'get_source_version', lambda: '7.9') + # Set that all checks failed + monkeypatch.setattr(scanner, 'is_grub_config_missing_final_newline', lambda _: True) + monkeypatch.setattr(scanner, 'is_grubenv_corrupted', lambda _: True) + monkeypatch.setattr(scanner, 'detect_config_error', lambda _: True) + # Run the actor + current_actor_context.run() + # Check that exactly 3 messages of different types are produced + errors = current_actor_context.consume(GrubConfigError) + assert len(errors) == 3 + for err_type in [GrubConfigError.ERROR_MISSING_NEWLINE, GrubConfigError.ERROR_CORRUPTED_GRUBENV, + GrubConfigError.ERROR_GRUB_CMDLINE_LINUX_SYNTAX]: + distinct_error = next((e for e in errors if e.error_type == err_type), None) + assert distinct_error + assert distinct_error.files + + +@pytest.mark.parametrize( + ('config_contents', 'error_detected'), + [ + ('GRUB_DEFAULT=saved\nGRUB_DISABLE_SUBMENU=true\n', False), + ('GRUB_DEFAULT=saved\nGRUB_DISABLE_SUBMENU=true', True) + ] +) +def test_is_grub_config_missing_final_newline(monkeypatch, config_contents, error_detected): + + config_path = '/etc/default/grub' + + def mocked_get_config_contents(path): + assert path == config_path + return config_contents + + monkeypatch.setattr(scanner, '_get_config_contents', mocked_get_config_contents) + assert scanner.is_grub_config_missing_final_newline(config_path) == error_detected + + +def test_correct_config_corrupted_grubenv(): + assert not scanner.is_grubenv_corrupted(os.path.join(CUR_DIR, 'files/corrupted_grubenv/grubenv.correct')) + + +def test_wrong_config_corrupted_grubenv(): + assert scanner.is_grubenv_corrupted(os.path.join(CUR_DIR, 'files/corrupted_grubenv/grubenv.wrong1')) + assert scanner.is_grubenv_corrupted(os.path.join(CUR_DIR, 'files/corrupted_grubenv/grubenv.wrong2')) diff --git a/repos/system_upgrade/common/models/grubconfigerror.py b/repos/system_upgrade/common/models/grubconfigerror.py index aac45bc7b2..1b3f1664c0 100644 --- a/repos/system_upgrade/common/models/grubconfigerror.py +++ b/repos/system_upgrade/common/models/grubconfigerror.py @@ -3,7 +3,15 @@ class GrubConfigError(Model): + ERROR_CORRUPTED_GRUBENV = 'corrupted grubenv' + ERROR_MISSING_NEWLINE = 'missing newline' + ERROR_GRUB_CMDLINE_LINUX_SYNTAX = 'GRUB_CMDLINE_LINUX syntax' + topic = SystemFactsTopic + # XXX FIXME(ivasilev) Rename to error_resolvable? + # If error can be automatically resolved (ex. in addupgradebootentry actor) error_detected = fields.Boolean(default=False) - error_type = fields.StringEnum(['GRUB_CMDLINE_LINUX syntax', 'missing newline']) + error_type = fields.StringEnum([ERROR_CORRUPTED_GRUBENV, ERROR_MISSING_NEWLINE, ERROR_GRUB_CMDLINE_LINUX_SYNTAX]) + # Paths to config files + files = fields.List(fields.String()) diff --git a/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/actor.py b/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/actor.py deleted file mode 100644 index dae88d974a..0000000000 --- a/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/actor.py +++ /dev/null @@ -1,41 +0,0 @@ -from leapp import reporting -from leapp.actors import Actor -from leapp.libraries.actor.scanner import detect_config_error -from leapp.libraries.common.config import architecture -from leapp.models import GrubConfigError -from leapp.reporting import create_report, Report -from leapp.tags import ChecksPhaseTag, IPUWorkflowTag - - -class DetectGrubConfigError(Actor): - """ - Check grub configuration for syntax error in GRUB_CMDLINE_LINUX value. - """ - - name = 'detect_grub_config_error' - consumes = () - produces = (Report, GrubConfigError) - tags = (ChecksPhaseTag, IPUWorkflowTag) - - def process(self): - if architecture.matches_architecture(architecture.ARCH_S390X): - # For now, skip just s390x, that's only one that is failing now - # because ZIPL is used there - return - config = '/etc/default/grub' - if detect_config_error(config): - create_report([ - reporting.Title('Syntax error detected in grub configuration'), - reporting.Summary( - 'Syntax error was detected in GRUB_CMDLINE_LINUX value of grub configuration. ' - 'This error is causing booting and other issues. ' - 'Error is automatically fixed by add_upgrade_boot_entry actor.' - ), - reporting.Severity(reporting.Severity.LOW), - reporting.Groups([reporting.Groups.BOOT]), - reporting.RelatedResource('file', config) - ]) - - config_error = GrubConfigError(error_detected=True, - error_type='GRUB_CMDLINE_LINUX syntax') - self.produce(config_error) diff --git a/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/libraries/scanner.py b/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/libraries/scanner.py deleted file mode 100644 index da2e71750d..0000000000 --- a/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/libraries/scanner.py +++ /dev/null @@ -1,14 +0,0 @@ -import re - - -def detect_config_error(conf_file): - """ - Check grub configuration for syntax error in GRUB_CMDLINE_LINUX value. - - :return: Function returns True if error was detected, otherwise False. - """ - with open(conf_file, 'r') as f: - config = f.read() - - pattern = r'GRUB_CMDLINE_LINUX="[^"]+"(?!(\s*$)|(\s+(GRUB|#)))' - return re.search(pattern, config) is not None diff --git a/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/test_detectgrubconfigerror.py b/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/test_detectgrubconfigerror.py deleted file mode 100644 index 1740720805..0000000000 --- a/repos/system_upgrade/el7toel8/actors/detectgrubconfigerror/tests/test_detectgrubconfigerror.py +++ /dev/null @@ -1,17 +0,0 @@ -import os - -from leapp.libraries.actor.scanner import detect_config_error - -CUR_DIR = os.path.dirname(os.path.abspath(__file__)) - - -def test_correct_config(): - assert not detect_config_error(os.path.join(CUR_DIR, 'files/grub.correct')) - assert not detect_config_error(os.path.join(CUR_DIR, 'files/grub.correct_trailing_space')) - assert not detect_config_error(os.path.join(CUR_DIR, 'files/grub.correct_comment')) - assert not detect_config_error(os.path.join(CUR_DIR, 'files/grub.correct_puppet')) - - -def test_wrong_config(): - assert detect_config_error(os.path.join(CUR_DIR, 'files/grub.wrong')) - assert detect_config_error(os.path.join(CUR_DIR, 'files/grub.wrong1'))