17 #include <sys/param.h> 18 #include <sys/types.h> 36 #define XPATH_NODE_CONFIG "//" XML_CIB_TAG_NODE "[@" XML_ATTR_UNAME "='%s']" 37 #define XPATH_NODE_STATE "//" XML_CIB_TAG_STATE "[@" XML_ATTR_UNAME "='%s']" 38 #define XPATH_RSC_HISTORY XPATH_NODE_STATE \ 39 "//" XML_LRM_TAG_RESOURCE "[@" XML_ATTR_ID "='%s']" 53 const char *
name,
const char *value)
55 xmlNode *attrs = NULL;
56 xmlNode *instance_attrs = NULL;
57 const char *node_uuid =
ID(cib_node);
59 out->
message(out,
"inject-attr",
name, value, cib_node);
68 if (instance_attrs == NULL) {
90 const char *resource,
const char *task,
91 guint interval_ms,
int rc)
96 }
else if ((rc == 7) && (interval_ms == 0)) {
101 char *now = pcmk__ttoa(time(NULL));
103 name = pcmk__failcount_name(resource, task, interval_ms);
104 inject_transient_attr(out, cib_node,
name,
"value++");
107 name = pcmk__lastfailure_name(resource, task, interval_ms);
108 inject_transient_attr(out, cib_node,
name, now);
123 create_node_entry(
cib_t *cib_conn,
const char *node)
128 rc = cib_conn->
cmds->
query(cib_conn, xpath, NULL,
161 create_op(
const xmlNode *cib_resource,
const char *task, guint interval_ms,
170 op->
t_run = (
unsigned int) time(NULL);
175 for (xop = pcmk__xe_first_child(cib_resource); xop != NULL;
176 xop = pcmk__xe_next(xop)) {
225 xmlNode *cib_object = NULL;
227 bool duplicate =
false;
228 char *found_uuid = NULL;
231 create_node_entry(cib_conn, node);
234 rc = cib_conn->
cmds->
query(cib_conn, xpath, &cib_object,
237 if ((cib_object != NULL) && (
ID(cib_object) == NULL)) {
238 crm_err(
"Detected multiple node_state entries for xpath=%s, bailing",
248 found_uuid = strdup(uuid);
256 rc = cib_conn->
cmds->
query(cib_conn, xpath_by_uuid, &cib_object,
259 if ((cib_object != NULL) && (
ID(cib_object) == NULL)) {
260 crm_err(
"Detected multiple node_state entries for xpath=%s, bailing",
266 }
else if (cib_object != NULL) {
285 rc = cib_conn->
cmds->
query(cib_conn, xpath, &cib_object,
287 crm_trace(
"Injecting node state for %s (rc=%d)", node, rc);
349 find_resource_xml(xmlNode *cib_node,
const char *resource)
377 const char *resource,
const char *lrm_name,
378 const char *rclass,
const char *rtype,
379 const char *rprovider)
382 xmlNode *container = NULL;
383 xmlNode *cib_resource = NULL;
385 cib_resource = find_resource_xml(cib_node, resource);
386 if (cib_resource != NULL) {
394 if (strcmp(resource, lrm_name) != 0) {
395 cib_resource = find_resource_xml(cib_node, lrm_name);
396 if (cib_resource != NULL) {
401 if ((rclass == NULL) || (rtype == NULL)) {
403 out->
err(out,
"Resource %s not found in the status section of %s." 404 " Please supply the class and type to continue", resource,
ID(cib_node));
414 out->
err(out,
"Invalid class for %s: %s", resource, rclass);
418 && (rprovider == NULL)) {
420 out->
err(out,
"Please specify the provider for resource %s", resource);
424 crm_info(
"Injecting new resource %s into node state '%s'",
425 lrm_name,
ID(cib_node));
429 const char *node_uuid =
ID(cib_node);
436 if (container == NULL) {
454 xmlNode **ticket_state_xml)
457 xmlNode *xml_search = NULL;
459 GString *xpath = g_string_sized_new(256);
462 *ticket_state_xml = NULL;
464 g_string_append(xpath,
473 rc = the_cib->
cmds->
query(the_cib, (
const char *) xpath->str, &xml_search,
475 g_string_free(xpath, TRUE);
483 out->
err(out,
"Multiple ticket_states match ticket_id=%s", ticket_id);
485 *ticket_state_xml = xml_search;
504 const char *attr_name,
bool attr_value,
cib_t *cib)
507 xmlNode *xml_top = NULL;
508 xmlNode *ticket_state_xml = NULL;
511 rc = find_ticket_state(out, cib, ticket_id, &ticket_state_xml);
515 crm_debug(
"Injecting attribute into existing ticket state %s",
517 xml_top = ticket_state_xml;
519 }
else if (rc == ENXIO) {
520 xmlNode *xml_obj = NULL;
559 guint interval_ms = 0;
564 char *resource = NULL;
566 const char *rtype = NULL;
567 const char *rclass = NULL;
568 const char *rprovider = NULL;
570 xmlNode *cib_op = NULL;
571 xmlNode *cib_node = NULL;
572 xmlNode *cib_resource = NULL;
576 out->
message(out,
"inject-spec", spec);
578 key = calloc(1, strlen(spec) + 1);
579 node = calloc(1, strlen(spec) + 1);
580 rc = sscanf(spec,
"%[^@]@%[^=]=%d", key, node, &outcome);
582 out->
err(out,
"Invalid operation spec: %s. Only found %d fields",
591 out->
err(out,
"Invalid resource name: %s", resource);
606 rclass, rtype, rprovider);
609 op = create_op(cib_resource, task, interval_ms, outcome);
639 const GList *iter = NULL;
640 xmlNode *cib_node = NULL;
643 out->
message(out,
"inject-modify-config", injections->
quorum,
645 if (injections->
quorum != NULL) {
663 for (iter = injections->
node_up; iter != NULL; iter = iter->next) {
664 const char *node = (
const char *) iter->data;
666 out->
message(out,
"inject-modify-node",
"Online", node);
677 for (iter = injections->
node_down; iter != NULL; iter = iter->next) {
678 const char *node = (
const char *) iter->data;
681 out->
message(out,
"inject-modify-node",
"Offline", node);
704 for (iter = injections->
node_fail; iter != NULL; iter = iter->next) {
705 const char *node = (
const char *) iter->data;
707 out->
message(out,
"inject-modify-node",
"Failing", node);
719 for (iter = injections->
ticket_grant; iter != NULL; iter = iter->next) {
720 const char *ticket_id = (
const char *) iter->data;
722 out->
message(out,
"inject-modify-ticket",
"Granting", ticket_id);
724 rc = set_ticket_state_attr(out, ticket_id,
"granted",
true, cib);
728 for (iter = injections->
ticket_revoke; iter != NULL; iter = iter->next) {
729 const char *ticket_id = (
const char *) iter->data;
731 out->
message(out,
"inject-modify-ticket",
"Revoking", ticket_id);
733 rc = set_ticket_state_attr(out, ticket_id,
"granted",
false, cib);
737 for (iter = injections->
ticket_standby; iter != NULL; iter = iter->next) {
738 const char *ticket_id = (
const char *) iter->data;
740 out->
message(out,
"inject-modify-ticket",
"Standby", ticket_id);
742 rc = set_ticket_state_attr(out, ticket_id,
"standby",
true, cib);
746 for (iter = injections->
ticket_activate; iter != NULL; iter = iter->next) {
747 const char *ticket_id = (
const char *) iter->data;
749 out->
message(out,
"inject-modify-ticket",
"Activating", ticket_id);
751 rc = set_ticket_state_attr(out, ticket_id,
"standby",
false, cib);
755 for (iter = injections->
op_inject; iter != NULL; iter = iter->next) {
756 inject_action(out, (
const char *) iter->data, cib,
data_set);
767 if (injections == NULL) {
771 g_list_free_full(injections->
node_up, g_free);
772 g_list_free_full(injections->
node_down, g_free);
773 g_list_free_full(injections->
node_fail, g_free);
774 g_list_free_full(injections->
op_fail, g_free);
775 g_list_free_full(injections->
op_inject, g_free);
void(* end_list)(pcmk__output_t *out)
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, guint *interval_ms)
#define PCMK_RESOURCE_CLASS_SERVICE
_Noreturn crm_exit_t crm_exit(crm_exit_t rc)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
int(* message)(pcmk__output_t *out, const char *message_id,...)
void pcmk__inject_scheduler_input(pe_working_set_t *data_set, cib_t *cib, const pcmk_injections_t *injections)
xmlNode * first_named_child(const xmlNode *parent, const char *name)
bool(* is_quiet)(pcmk__output_t *out)
#define XML_TAG_TRANSIENT_NODEATTRS
xmlNode * pcmk__inject_resource_history(pcmk__output_t *out, xmlNode *cib_node, const char *resource, const char *lrm_name, const char *rclass, const char *rtype, const char *rprovider)
#define XML_LRM_TAG_RESOURCE
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
void lrmd_free_event(lrmd_event_data_t *event)
Free an executor event.
#define XML_NODE_EXPECTED
int query_node_uuid(cib_t *the_cib, const char *uname, char **uuid, int *is_remote_node)
void pcmk__xe_set_bool_attr(xmlNodePtr node, const char *name, bool value)
#define PCMK_RESOURCE_CLASS_OCF
pe_resource_t * pe_find_resource(GList *rsc_list, const char *id_rh)
#define PCMK_RESOURCE_CLASS_SYSTEMD
xmlNode * pcmk__inject_action_result(xmlNode *cib_resource, lrmd_event_data_t *op, int target_rc)
#define XPATH_NODE_CONFIG
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
#define XML_CIB_TAG_NODES
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
#define XML_TAG_ATTR_SETS
void pcmk_free_injections(pcmk_injections_t *injections)
Free a :pcmk_injections_t structure.
#define CRMD_JOINSTATE_DOWN
#define PCMK_RESOURCE_CLASS_UPSTART
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#define XML_CIB_TAG_STATE
#define crm_trace(fmt, args...)
#define CRMD_JOINSTATE_MEMBER
#define PCMK_RESOURCE_CLASS_STONITH
void pcmk__g_strcat(GString *buffer,...) G_GNUC_NULL_TERMINATED
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
int(* modify)(cib_t *cib, const char *section, xmlNode *data, int call_options)
int(*) int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
#define crm_log_xml_debug(xml, text)
int(* create)(cib_t *cib, const char *section, xmlNode *data, int call_options)
#define XML_AGENT_ATTR_PROVIDER
#define XML_ATTR_HAVE_QUORUM
pe_working_set_t * data_set
xmlNode * create_xml_node(xmlNode *parent, const char *name)
#define crm_log_xml_warn(xml, text)
Action completed, result is known.
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
void pcmk__inject_failcount(pcmk__output_t *out, xmlNode *cib_node, const char *resource, const char *task, guint interval_ms, int rc)
int pcmk_legacy2rc(int legacy_rc)
void free_xml(xmlNode *child)
gboolean xml_has_children(const xmlNode *root)
bool pcmk__simulate_node_config
void pcmk__xe_set_props(xmlNodePtr node,...) G_GNUC_NULL_TERMINATED
lrmd_event_data_t * lrmd_new_event(const char *rsc_id, const char *task, guint interval_ms)
Create a new lrmd_event_data_t object.
Cluster status and scheduling.
#define XML_LRM_TAG_RESOURCES
#define crm_err(fmt, args...)
#define XML_CIB_TAG_TICKET_STATE
void lrmd__set_result(lrmd_event_data_t *event, enum ocf_exitcode rc, int op_status, const char *exit_reason)
#define XML_CIB_TAG_CRMCONFIG
Synthetic cluster events that can be injected into the cluster for running simulations.
#define PCMK_RESOURCE_CLASS_LSB
#define XML_ATTR_HAVE_WATCHDOG
This structure contains everything that makes up a single output formatter.
xmlNode * pcmk__create_history_xml(xmlNode *parent, lrmd_event_data_t *event, const char *caller_version, int target_rc, const char *node, const char *origin)
#define XML_LRM_ATTR_CALLID
int cib__update_node_attr(pcmk__output_t *out, cib_t *cib, int call_options, const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, const char *attr_value, const char *user_name, const char *node_type)
#define XPATH_RSC_HISTORY
xmlNode * pcmk__inject_node_state_change(cib_t *cib_conn, const char *node, bool up)
#define XML_NODE_JOIN_STATE
#define XML_CIB_TAG_STATUS
#define XML_NODE_IN_CLUSTER
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
int(* remove)(cib_t *cib, const char *section, xmlNode *data, int call_options)
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
#define XML_CIB_TAG_TICKETS
#define crm_info(fmt, args...)
xmlNode * pcmk__inject_node(cib_t *cib_conn, const char *node, const char *uuid)
#define XML_AGENT_ATTR_CLASS