diff options
Diffstat (limited to '')
-rw-r--r-- | tools/crm_verify.c | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/tools/crm_verify.c b/tools/crm_verify.c index 43b09da..199814e 100644 --- a/tools/crm_verify.c +++ b/tools/crm_verify.c @@ -85,10 +85,23 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) { "Check the consistency of the configuration in the running cluster:\n\n" "\tcrm_verify --live-check\n\n" "Check the consistency of the configuration in a given file and " + "produce quiet output:\n\n" + "\tcrm_verify --xml-file file.xml --quiet\n\n" + "Check the consistency of the configuration in a given file and " "produce verbose output:\n\n" "\tcrm_verify --xml-file file.xml --verbose\n\n"; + GOptionEntry extra_prog_entries[] = { + { "quiet", 'q', 0, G_OPTION_ARG_NONE, &(args->quiet), + "Don't print verify information", + NULL }, + { NULL } + }; + context = pcmk__build_arg_context(args, "text (default), xml", group, NULL); + + pcmk__add_main_args(context, extra_prog_entries); + g_option_context_set_description(context, description); pcmk__add_arg_group(context, "data", "Data sources:", @@ -105,8 +118,7 @@ main(int argc, char **argv) xmlNode *cib_object = NULL; xmlNode *status = NULL; - pe_working_set_t *data_set = NULL; - const char *xml_tag = NULL; + pcmk_scheduler_t *scheduler = NULL; int rc = pcmk_rc_ok; crm_exit_t exit_code = CRM_EX_OK; @@ -126,6 +138,10 @@ main(int argc, char **argv) goto done; } + if (args->verbosity > 0) { + args->verbosity -= args->quiet; + } + pcmk__cli_init_logging("crm_verify", args->verbosity); rc = pcmk__output_new(&out, args->output_ty, args->output_dest, argv); @@ -143,6 +159,9 @@ main(int argc, char **argv) pcmk__register_lib_messages(out); + pcmk__set_config_error_handler((pcmk__config_error_func) out->err, out); + pcmk__set_config_warning_handler((pcmk__config_warning_func) out->err, out); + crm_info("=#=#=#=#= Getting XML =#=#=#=#="); if (options.use_live_cib) { @@ -184,8 +203,7 @@ main(int argc, char **argv) goto done; } - xml_tag = crm_element_name(cib_object); - if (!pcmk__str_eq(xml_tag, XML_TAG_CIB, pcmk__str_casei)) { + if (!pcmk__xe_is(cib_object, XML_TAG_CIB)) { rc = EBADMSG; g_set_error(&error, PCMK__RC_ERROR, rc, "This tool can only check complete configurations (i.e. those starting with <cib>)."); @@ -201,7 +219,7 @@ main(int argc, char **argv) create_xml_node(cib_object, XML_CIB_TAG_STATUS); } - if (validate_xml(cib_object, NULL, FALSE) == FALSE) { + if (pcmk__validate_xml(cib_object, NULL, (xmlRelaxNGValidityErrorFunc) out->err, out) == FALSE) { pcmk__config_err("CIB did not pass schema validation"); free_xml(cib_object); cib_object = NULL; @@ -215,13 +233,14 @@ main(int argc, char **argv) xml_latest_schema()); } - data_set = pe_new_working_set(); - if (data_set == NULL) { + scheduler = pe_new_working_set(); + if (scheduler == NULL) { rc = errno; - crm_perror(LOG_CRIT, "Unable to allocate working set"); + g_set_error(&error, PCMK__RC_ERROR, rc, + "Could not allocate scheduler data: %s", pcmk_rc_str(rc)); goto done; } - data_set->priv = out; + scheduler->priv = out; /* Process the configuration to set crm_config_error/crm_config_warning. * @@ -229,31 +248,31 @@ main(int argc, char **argv) * example, action configuration), so we aren't necessarily checking those. */ if (cib_object != NULL) { - unsigned long long flags = pe_flag_no_counts|pe_flag_no_compat; + unsigned long long flags = pcmk_sched_no_counts|pcmk_sched_no_compat; if ((status == NULL) && !options.use_live_cib) { // No status available, so do minimal checks - flags |= pe_flag_check_config; + flags |= pcmk_sched_validate_only; } - pcmk__schedule_actions(cib_object, flags, data_set); + pcmk__schedule_actions(cib_object, flags, scheduler); } - pe_free_working_set(data_set); + pe_free_working_set(scheduler); if (crm_config_error) { rc = pcmk_rc_schema_validation; - if (args->verbosity > 0) { + if (args->verbosity > 0 || pcmk__str_eq(args->output_ty, "xml", pcmk__str_none)) { g_set_error(&error, PCMK__RC_ERROR, rc, "Errors found during check: config not valid"); } else { g_set_error(&error, PCMK__RC_ERROR, rc, "Errors found during check: config not valid\n-V may provide more details"); - } + } } else if (crm_config_warning) { rc = pcmk_rc_schema_validation; - if (args->verbosity > 0) { + if (args->verbosity > 0 || pcmk__str_eq(args->output_ty, "xml", pcmk__str_none)) { g_set_error(&error, PCMK__RC_ERROR, rc, "Warnings found during check: config may not be valid"); } else { @@ -273,7 +292,7 @@ main(int argc, char **argv) exit_code = pcmk_rc2exitc(rc); } - pcmk__output_and_clear_error(&error, NULL); + pcmk__output_and_clear_error(&error, out); if (out != NULL) { out->finish(out, exit_code, true, NULL); |