Exemple #1
0
def _validate_devices(
    reporter, resources_el, devices, force_device=False, allow_force=True
):
    if not devices:
        reporter.append(
            reports.required_option_is_missing(["stonith devices"])
        )
    invalid_devices = []
    for dev in devices:
        errors = reporter.errors_count
        validate_id(dev, description="device id", reporter=reporter)
        if reporter.errors_count > errors:
            continue
        # TODO use the new finding function
        if not is_stonith_resource(resources_el, dev):
            invalid_devices.append(dev)
    if invalid_devices:
        reporter.append(
            reports.stonith_resources_do_not_exist(
                invalid_devices,
                ReportItemSeverity.WARNING if force_device and allow_force
                    else ReportItemSeverity.ERROR
                ,
                None if force_device or not allow_force
                    else report_codes.FORCE_STONITH_RESOURCE_DOES_NOT_EXIST
            )
        )
def _validate_devices(
    reporter, resources_el, devices, force_device=False, allow_force=True
):
    if not devices:
        reporter.add(
            reports.required_option_is_missing(["stonith devices"])
        )
    invalid_devices = []
    for dev in devices:
        errors = reporter.errors_count
        validate_id(dev, description="device id", reporter=reporter)
        if reporter.errors_count > errors:
            continue
        # TODO use the new finding function
        if not is_stonith_resource(resources_el, dev):
            invalid_devices.append(dev)
    if invalid_devices:
        reporter.add(
            reports.stonith_resources_do_not_exist(
                invalid_devices,
                ReportItemSeverity.WARNING if force_device and allow_force
                    else ReportItemSeverity.ERROR
                ,
                None if force_device or not allow_force
                    else report_codes.FORCE_STONITH_RESOURCE_DOES_NOT_EXIST
            )
        )
Exemple #3
0
def _validate_devices(resources_el,
                      devices,
                      force_device=False,
                      allow_force=True) -> ReportItemList:
    report_list: ReportItemList = []
    if not devices:
        report_list.append(
            reports.required_options_are_missing(["stonith devices"]))
    invalid_devices = []
    for dev in devices:
        validate_id_report_list: ReportItemList = []
        validate_id(dev,
                    description="device id",
                    reporter=validate_id_report_list)
        report_list.extend(validate_id_report_list)
        if has_errors(validate_id_report_list):
            continue
        # TODO use the new finding function
        if not is_stonith_resource(resources_el, dev):
            invalid_devices.append(dev)
    if invalid_devices:
        report_list.append(
            reports.stonith_resources_do_not_exist(
                invalid_devices, ReportItemSeverity.WARNING
                if force_device and allow_force else ReportItemSeverity.ERROR,
                None if force_device or not allow_force else
                report_codes.FORCE_STONITH_RESOURCE_DOES_NOT_EXIST))
    return report_list
Exemple #4
0
 def test_invalid_devices(self, mock_val_level, mock_val_target,
                          mock_val_devices, mock_val_dupl, mock_append):
     mock_val_devices.side_effect = (
         lambda reporter, resources, devices, force: reporter.append(
             reports.stonith_resources_do_not_exist(["device"])))
     self.assert_called_invalid(mock_val_level,
                                mock_val_target,
                                mock_val_devices,
                                mock_val_dupl,
                                mock_append,
                                dupl_called=False)
 def test_invalid_devices(
     self, mock_val_level, mock_val_target, mock_val_devices, mock_val_dupl,
     mock_append
 ):
     mock_val_devices.side_effect = (
         lambda reporter, resources, devices, force:
             reporter.add(
                 reports.stonith_resources_do_not_exist(["device"])
             )
     )
     self.assert_called_invalid(
         mock_val_level, mock_val_target, mock_val_devices, mock_val_dupl,
         mock_append, dupl_called=False
     )
Exemple #6
0
 def test_invalid_devices(self, mock_val_level, mock_val_target,
                          mock_val_devices, mock_val_dupl, mock_append):
     mock_val_devices.return_value = [
         reports.stonith_resources_do_not_exist(self.devices)
     ]
     report_list = [
         fixture.error(
             report_codes.STONITH_RESOURCES_DO_NOT_EXIST,
             stonith_ids=self.devices,
         ),
     ]
     self.assert_called_invalid(mock_val_level,
                                mock_val_target,
                                mock_val_devices,
                                mock_val_dupl,
                                mock_append,
                                dupl_called=False,
                                report_list=report_list)