Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T727 #3578

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

T727 #3578

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion daemons/based/based_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ readCibXmlFile(const char *dir, const char *file, gboolean discard_status)

// @COMPAT Not specifying validate-with is deprecated since 2.1.8
} else if (validation == NULL) {
pcmk__update_schema(&root, NULL, false, false);
pcmk__update_schema(&root, NULL, false); //todo: to_logs was false
validation = crm_element_value(root, PCMK_XA_VALIDATE_WITH);
if (validation != NULL) {
crm_notice("Enabling %s validation on"
Expand Down
2 changes: 1 addition & 1 deletion daemons/based/based_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ cib_process_upgrade_server(const char *op, int options, const char *section, xml
crm_trace("Processing \"%s\" event", op);
original_schema = crm_element_value(existing_cib,
PCMK_XA_VALIDATE_WITH);
rc = pcmk__update_schema(&scratch, NULL, true, true);
rc = pcmk__update_schema(&scratch, NULL, true); //todo: to_logs was true
rc = pcmk_rc2legacy(rc);
new_schema = crm_element_value(scratch, PCMK_XA_VALIDATE_WITH);

Expand Down
2 changes: 1 addition & 1 deletion include/crm/common/schemas.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C" {
*/

int
pcmk_update_configured_schema(xmlNode **xml);
pcmk_update_configured_schema(xmlNode **xml, bool to_logs);

#ifdef __cplusplus
}
Expand Down
5 changes: 2 additions & 3 deletions include/crm/common/schemas_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ bool pcmk__validate_xml(xmlNode *xml_blob, const char *validation,
void *error_handler_context);
bool pcmk__configured_schema_validates(xmlNode *xml);
int pcmk__update_schema(xmlNode **xml, const char *max_schema_name,
bool transform, bool to_logs);
bool transform);
int pcmk__update_configured_schema(xmlNode **xml, pcmk__output_t *out);
void pcmk__warn_if_schema_deprecated(const char *schema);

int pcmk__update_configured_schema(xmlNode **xml, bool to_logs);

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions lib/cib/cib_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ cib_process_upgrade(const char *op, int options, const char *section, xmlNode *
crm_trace("Processing \"%s\" event with max=%s", op, max_schema);

original_schema = crm_element_value(existing_cib, PCMK_XA_VALIDATE_WITH);
rc = pcmk__update_schema(result_cib, max_schema, true,
!pcmk_is_set(options, cib_verbose));
rc = pcmk__update_schema(result_cib, max_schema, true);
//todo: !pcmk_is_set(options, cib_verbose) was the to_logs argument
rc = pcmk_rc2legacy(rc);
new_schema = crm_element_value(*result_cib, PCMK_XA_VALIDATE_WITH);

Expand Down
139 changes: 63 additions & 76 deletions lib/common/schemas.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,14 +938,11 @@ cib_upgrade_err(void *ctx, const char *fmt, ...)
*
* \param[in] xml XML to transform
* \param[in] transform XSL name
* \param[in] to_logs If false, certain validation errors will be sent to
* stderr rather than logged
*
* \return Transformed XML on success, otherwise NULL
*/
static xmlNode *
apply_transformation(const xmlNode *xml, const char *transform,
gboolean to_logs)
apply_transformation(const xmlNode *xml, const char *transform)
{
char *xform = NULL;
xmlNode *out = NULL;
Expand All @@ -956,11 +953,9 @@ apply_transformation(const xmlNode *xml, const char *transform,
transform);

/* for capturing, e.g., what's emitted via <xsl:message> */
if (to_logs) {
xsltSetGenericErrorFunc(NULL, cib_upgrade_err);
} else {
xsltSetGenericErrorFunc(&crm_log_level, cib_upgrade_err);
}
xsltSetGenericErrorFunc(&crm_log_level, cib_upgrade_err);
//todo: need new error handler (instead of cib_upgrade_err)
//to properly get rid of to_logs but convey the same info

xslt = xsltParseStylesheetFile((pcmkXmlStr) xform);
CRM_CHECK(xslt != NULL, goto cleanup);
Expand Down Expand Up @@ -989,13 +984,11 @@ apply_transformation(const xmlNode *xml, const char *transform,
* \param[in] input_xml XML to transform
* \param[in] schema_index Index of schema that successfully validates
* \p original_xml
* \param[in] to_logs If false, certain validation errors will be sent to
* stderr rather than logged
*
*
* \return XML result of schema transforms if successful, otherwise NULL
*/
static xmlNode *
apply_upgrade(const xmlNode *input_xml, int schema_index, gboolean to_logs)
apply_upgrade(const xmlNode *input_xml, int schema_index)
{
pcmk__schema_t *schema = g_list_nth_data(known_schemas, schema_index);
pcmk__schema_t *upgraded_schema = g_list_nth_data(known_schemas,
Expand All @@ -1007,9 +1000,8 @@ apply_upgrade(const xmlNode *input_xml, int schema_index, gboolean to_logs)

CRM_ASSERT((schema != NULL) && (upgraded_schema != NULL));

if (to_logs) {
error_handler = (xmlRelaxNGValidityErrorFunc) xml_log;
}
error_handler = (xmlRelaxNGValidityErrorFunc) xml_log;
//todo: this was conditional on to_logs

for (GList *iter = schema->transforms; iter != NULL; iter = iter->next) {
const struct dirent *entry = iter->data;
Expand All @@ -1018,7 +1010,7 @@ apply_upgrade(const xmlNode *input_xml, int schema_index, gboolean to_logs)
crm_debug("Upgrading schema from %s to %s: applying XSL transform %s",
schema->name, upgraded_schema->name, transform);

new_xml = apply_transformation(input_xml, transform, to_logs);
new_xml = apply_transformation(input_xml, transform);
pcmk__xml_free(old_xml);

if (new_xml == NULL) {
Expand Down Expand Up @@ -1074,14 +1066,11 @@ get_configured_schema(const xmlNode *xml)
* schema later than this one
* \param[in] transform If false, do not update \p xml to any schema
* that requires an XSL transform
* \param[in] to_logs If false, certain validation errors will be
* sent to stderr rather than logged
*
*
* \return Standard Pacemaker return code
*/
int
pcmk__update_schema(xmlNode **xml, const char *max_schema_name, bool transform,
bool to_logs)
pcmk__update_schema(xmlNode **xml, const char *max_schema_name, bool transform)
{
int max_stable_schemas = xml_latest_schema_index();
int max_schema_index = 0;
Expand All @@ -1090,7 +1079,8 @@ pcmk__update_schema(xmlNode **xml, const char *max_schema_name, bool transform,
pcmk__schema_t *best_schema = NULL;
pcmk__schema_t *original_schema = NULL;
xmlRelaxNGValidityErrorFunc error_handler =
to_logs ? (xmlRelaxNGValidityErrorFunc) xml_log : NULL;
(xmlRelaxNGValidityErrorFunc) xml_log;
//todo: this was the case that to_logs was true, otherwise it was set to NULL

CRM_CHECK((xml != NULL) && (*xml != NULL) && ((*xml)->doc != NULL),
return EINVAL);
Expand Down Expand Up @@ -1154,7 +1144,7 @@ pcmk__update_schema(xmlNode **xml, const char *max_schema_name, bool transform,
continue;
}

upgrade = apply_upgrade(*xml, current_schema->schema_index, to_logs);
upgrade = apply_upgrade(*xml, current_schema->schema_index);
if (upgrade == NULL) {
/* The transform failed, so this schema can't be used. Later
* schemas are unlikely to validate, but try anyway until we
Expand All @@ -1180,12 +1170,6 @@ pcmk__update_schema(xmlNode **xml, const char *max_schema_name, bool transform,
return rc;
}

int
pcmk_update_configured_schema(xmlNode **xml)
{
return pcmk__update_configured_schema(xml, true);
}

/*!
* \brief Update XML from its configured schema to the latest major series
*
Expand All @@ -1196,7 +1180,22 @@ pcmk_update_configured_schema(xmlNode **xml)
* \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);
waltdisgrace marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -1228,7 +1227,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) == pcmk_rc_ok) {
new_schema_name = crm_element_value(converted,
PCMK_XA_VALIDATE_WITH);
entry = pcmk__get_schema(new_schema_name);
Expand All @@ -1242,38 +1241,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);
}
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 {
// 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"));
}
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"));
}

pcmk__xml_free(converted);
Expand All @@ -1286,14 +1267,13 @@ 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) {
// NOTE: originally warn, not info
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 {
crm_info("Configuration with %s schema was internally "
"upgraded to latest version %s",
pcmk__s(original_schema_name, "no"),
Expand All @@ -1309,11 +1289,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) {
pcmk__config_err("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 Expand Up @@ -1535,7 +1515,14 @@ pcmk__warn_if_schema_deprecated(const char *schema)
gboolean
cli_config_update(xmlNode **xml, int *best_version, gboolean to_logs)
{
int rc = pcmk__update_configured_schema(xml, to_logs);
pcmk__output_t *out = NULL;

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

rc = pcmk__update_configured_schema(xml, out);

if (best_version != NULL) {
const char *name = crm_element_value(*xml, PCMK_XA_VALIDATE_WITH);
Expand Down
2 changes: 1 addition & 1 deletion tools/cibadmin.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ main(int argc, char **argv)

if (the_cib->cmds->query(the_cib, NULL, &obj,
options.cmd_options) == pcmk_ok) {
pcmk__update_schema(&obj, NULL, true, false);
pcmk__update_schema(&obj, NULL, true); // todo: to_logs was false
}
pcmk__xml_free(obj);

Expand Down