def test_remove_removed_check_plugins_from_ignored_checks( uc: update_config.UpdateConfig) -> None: ruleset = Ruleset("ignored_checks", {}) ruleset.from_config( Folder(""), [ { "id": "1", "condition": {}, "options": { "disabled": False }, "value": ["a", "b", "mgmt_c"], }, { "id": "2", "condition": {}, "options": { "disabled": False }, "value": ["d", "e"], }, { "id": "3", "condition": {}, "options": { "disabled": False }, "value": ["mgmt_f"], }, { "id": "4", "condition": {}, "options": { "disabled": False }, "value": ["a", "g"], }, ], ) rulesets = RulesetCollection() rulesets.set_rulesets({"ignored_checks": ruleset}) uc._remove_removed_check_plugins_from_ignored_checks( rulesets, { CheckPluginName("b"), CheckPluginName("d"), CheckPluginName("e"), CheckPluginName("f"), }, ) leftover_rules = [ rule for (_folder, idx, rule) in rulesets.get("ignored_checks").get_rules() ] assert len(leftover_rules) == 2 assert leftover_rules[0].id == "1" assert leftover_rules[1].id == "4" assert leftover_rules[0].value == ["a", "mgmt_c"] assert leftover_rules[1].value == ["a", "g"]
def test__transform_wato_rulesets_params( uc: update_config.UpdateConfig, ruleset_name: RulesetName, param_value: RuleValue, transformed_param_value: RuleValue, ) -> None: ruleset = _instantiate_ruleset(ruleset_name, param_value) rulesets = RulesetCollection() rulesets.set_rulesets({ruleset_name: ruleset}) uc._transform_wato_rulesets_params(rulesets) assert len(ruleset.get_rules()[0]) == 3 assert ruleset.get_rules()[0][2].value == transformed_param_value
def test__transform_wato_rulesets_params( ruleset_name, param_value, transformed_param_value, ): ruleset = _instantiate_ruleset(ruleset_name, param_value) rulesets = RulesetCollection() rulesets.set_rulesets({ruleset_name: ruleset}) uc = update_config.UpdateConfig(cmk.utils.log.logger, argparse.Namespace()) uc._transform_wato_rulesets_params(rulesets) assert len(ruleset.get_rules()[0]) == 3 assert ruleset.get_rules()[0][2].value == transformed_param_value
def test__transform_discovery_disabled_services( uc: update_config.UpdateConfig, ruleset_spec: Sequence[RuleSpec], expected_ruleset: Sequence[RuleSpec], ) -> None: ruleset = Ruleset("ignored_services", {}) ruleset.from_config(Folder(""), ruleset_spec) assert ruleset.get_rules() rulesets = RulesetCollection() rulesets.set_rulesets({"ignored_services": ruleset}) uc._transform_discovery_disabled_services(rulesets) folder_rules = ruleset.get_folder_rules(Folder("")) assert [r.to_config() for r in folder_rules] == expected_ruleset
def test__transform_discovery_disabled_services( ruleset_spec, expected_ruleset, ): ruleset = Ruleset("ignored_services", {}) ruleset.from_config(Folder(''), ruleset_spec) assert ruleset.get_rules() rulesets = RulesetCollection() rulesets.set_rulesets({"ignored_services": ruleset}) uc = update_config.UpdateConfig(cmk.utils.log.logger, argparse.Namespace()) uc._transform_discovery_disabled_services(rulesets) folder_rules = ruleset.get_folder_rules(Folder('')) assert [r.to_config() for r in folder_rules] == expected_ruleset
def test_validate_rule_values( mocker: MockerFixture, uc: update_config.UpdateConfig, rulesets: Mapping[RulesetName, RuleValue], n_expected_warnings: int, ) -> None: all_rulesets = RulesetCollection() all_rulesets.set_rulesets({ ruleset_name: _instantiate_ruleset( ruleset_name, rule_value, ) for ruleset_name, rule_value in rulesets.items() }) mock_warner = mocker.patch.object( uc._logger, "warning", ) uc._validate_rule_values(all_rulesets) assert mock_warner.call_count == n_expected_warnings
def test__transform_replaced_wato_rulesets_and_params( uc: update_config.UpdateConfig, ruleset_name: RulesetName, param_value: RuleValue, new_ruleset_name: RulesetName, transformed_param_value: RuleValue, ) -> None: all_rulesets = RulesetCollection() # checkmk: all_rulesets are loaded via # all_rulesets = cmk.gui.watolib.rulesets.AllRulesets() all_rulesets.set_rulesets({ ruleset_name: _instantiate_ruleset(ruleset_name, param_value), new_ruleset_name: Ruleset(new_ruleset_name, {}), }) uc._transform_replaced_wato_rulesets(all_rulesets) uc._transform_wato_rulesets_params(all_rulesets) assert not all_rulesets.exists(ruleset_name) rules = all_rulesets.get(new_ruleset_name).get_rules() assert len(rules) == 1 rule = rules[0] assert len(rule) == 3 assert rule[2].value == transformed_param_value