Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
waltdisgrace committed Jul 17, 2024
1 parent 533b1ad commit defebc5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 49 deletions.
1 change: 1 addition & 0 deletions include/crm/common/schemas_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ bool pcmk__validate_xml(xmlNode *xml_blob, const char *validation,
bool pcmk__configured_schema_validates(xmlNode *xml);
int pcmk__update_schema(xmlNode **xml, const char *max_schema_name,
bool transform, bool to_logs);
int pcmk__update_configured_schema(xmlNode **xml, pcmk__output_t *out);
void pcmk__warn_if_schema_deprecated(const char *schema);

#ifdef __cplusplus
Expand Down
93 changes: 44 additions & 49 deletions lib/common/schemas.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,21 @@ pcmk__update_schema(xmlNode **xml, const char *max_schema_name, bool transform,
* \return Standard Pacemaker return code
*/
int
pcmk_update_configured_schema(xmlNode **xml, bool to_logs)
pcmk_update_configured_schema(xmlNode **xml, bool to_logs) {
pcmk__output_t *out = NULL;
int rc = pcmk_rc_ok;

rc = pcmk__xml_output_new(&out, xml);
if (rc != pcmk_rc_ok) {
return rc;
}

rc = pcmk__update_configured_schema(xml, out);
return rc;
}

int
pcmk__update_configured_schema(xmlNode **xml, pcmk__output_t *out)
{
int rc = pcmk_rc_ok;
char *original_schema_name = NULL;
Expand Down Expand Up @@ -1222,7 +1236,7 @@ pcmk_update_configured_schema(xmlNode **xml, bool to_logs)

entry = NULL;
converted = pcmk__xml_copy(NULL, *xml);
if (pcmk__update_schema(&converted, NULL, true, to_logs) == pcmk_rc_ok) {
if (pcmk__update_schema(&converted, NULL, true, out) == pcmk_rc_ok) {
new_schema_name = crm_element_value(converted,
PCMK_XA_VALIDATE_WITH);
entry = pcmk__get_schema(new_schema_name);
Expand All @@ -1236,38 +1250,20 @@ pcmk_update_configured_schema(xmlNode **xml, bool to_logs)
if ((orig_version == -1) || (schema == NULL)
|| (schema->schema_index < orig_version)) {
// We couldn't validate any schema at all
if (to_logs) {
pcmk__config_err("Cannot upgrade configuration (claiming "
"%s schema) to at least %s because it "
"does not validate with any schema from "
"%s to the latest",
pcmk__s(original_schema_name, "no"),
x_0_schema->name, effective_original_name);
} else {
fprintf(stderr, "Cannot upgrade configuration (claiming "
"%s schema) to at least %s because it "
"does not validate with any schema from "
"%s to the latest\n",
pcmk__s(original_schema_name, "no"),
x_0_schema->name, effective_original_name);
}
out->err(out, "Cannot upgrade configuration (claiming "
"%s schema) to at least %s because it "
"does not validate with any schema from "
"%s to the latest",
pcmk__s(original_schema_name, "no"),
x_0_schema->name, effective_original_name);
} else {
// We updated configuration successfully, but still too low
if (to_logs) {
pcmk__config_err("Cannot upgrade configuration (claiming "
"%s schema) to at least %s because it "
"would not upgrade past %s",
pcmk__s(original_schema_name, "no"),
x_0_schema->name,
pcmk__s(new_schema_name, "unspecified version"));
} else {
fprintf(stderr, "Cannot upgrade configuration (claiming "
"%s schema) to at least %s because it "
"would not upgrade past %s\n",
pcmk__s(original_schema_name, "no"),
x_0_schema->name,
pcmk__s(new_schema_name, "unspecified version"));
}
out->err(out, "Cannot upgrade configuration (claiming "
"%s schema) to at least %s because it "
"would not upgrade past %s",
pcmk__s(original_schema_name, "no"),
x_0_schema->name,
pcmk__s(new_schema_name, "unspecified version"));
}

pcmk__xml_free(converted);
Expand All @@ -1280,18 +1276,17 @@ pcmk_update_configured_schema(xmlNode **xml, bool to_logs)
*xml = converted;

if (schema->schema_index < xml_latest_schema_index()) {
if (to_logs) {
pcmk__config_warn("Configuration with %s schema was "
"internally upgraded to acceptable (but "
"not most recent) %s",
pcmk__s(original_schema_name, "no"),
schema->name);
}
} else if (to_logs) {
crm_info("Configuration with %s schema was internally "
"upgraded to latest version %s",
pcmk__s(original_schema_name, "no"),
schema->name);
// NOTE: originally warn, not info
out->info(out, "Configuration with %s schema was "
"internally upgraded to acceptable (but "
"not most recent) %s",
pcmk__s(original_schema_name, "no"),
schema->name);
} else {
out->info(out, "Configuration with %s schema was internally "
"upgraded to latest version %s",
pcmk__s(original_schema_name, "no"),
schema->name);
}
}

Expand All @@ -1303,11 +1298,11 @@ pcmk_update_configured_schema(xmlNode **xml, bool to_logs)
CRM_ASSERT((entry != NULL) && (entry->data != NULL));

none_schema = entry->data;
if (!to_logs && (orig_version >= none_schema->schema_index)) {
fprintf(stderr, "Schema validation of configuration is "
"disabled (support for " PCMK_XA_VALIDATE_WITH
" set to \"" PCMK_VALUE_NONE "\" is deprecated"
" and will be removed in a future release)\n");
if (orig_version >= none_schema->schema_index) {
out->err(out, "Schema validation of configuration is "
"disabled (support for " PCMK_XA_VALIDATE_WITH
" set to \"" PCMK_VALUE_NONE "\" is deprecated"
" and will be removed in a future release)\n");
}
}

Expand Down

0 comments on commit defebc5

Please sign in to comment.