17 #include <sys/param.h> 18 #include <sys/types.h> 36 #define XPATH_NODE_CONFIG "//" XML_CIB_TAG_NODE "[@uname='%s']" 37 #define XPATH_NODE_STATE "//" XML_CIB_TAG_STATE "[@uname='%s']" 38 #define XPATH_RSC_HISTORY XPATH_NODE_STATE "//" \ 39 XML_LRM_TAG_RESOURCE "[@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(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;
229 create_node_entry(cib_conn, node);
232 rc = cib_conn->
cmds->
query(cib_conn, xpath, &cib_object,
235 if ((cib_object != NULL) && (
ID(cib_object) == NULL)) {
236 crm_err(
"Detected multiple node_state entries for xpath=%s, bailing",
245 char *found_uuid = NULL;
250 found_uuid = strdup(uuid);
261 rc = cib_conn->
cmds->
query(cib_conn, xpath, &cib_object,
263 crm_trace(
"Injecting node state for %s (rc=%d)", node, rc);
316 find_resource_xml(xmlNode *cib_node,
const char *resource)
344 const char *resource,
const char *lrm_name,
345 const char *rclass,
const char *rtype,
346 const char *rprovider)
349 xmlNode *container = NULL;
350 xmlNode *cib_resource = NULL;
352 cib_resource = find_resource_xml(cib_node, resource);
353 if (cib_resource != NULL) {
361 if (strcmp(resource, lrm_name) != 0) {
362 cib_resource = find_resource_xml(cib_node, lrm_name);
363 if (cib_resource != NULL) {
368 if ((rclass == NULL) || (rtype == NULL)) {
370 out->
err(out,
"Resource %s not found in the status section of %s." 371 " Please supply the class and type to continue", resource,
ID(cib_node));
381 out->
err(out,
"Invalid class for %s: %s", resource, rclass);
385 && (rprovider == NULL)) {
387 out->
err(out,
"Please specify the provider for resource %s", resource);
391 crm_info(
"Injecting new resource %s into node state '%s'",
392 lrm_name,
ID(cib_node));
396 const char *node_uuid =
ID(cib_node);
403 if (container == NULL) {
419 #define XPATH_MAX 1024 423 xmlNode **ticket_state_xml)
427 xmlNode *xml_search = NULL;
429 char *xpath_string = NULL;
432 *ticket_state_xml = NULL;
435 offset += snprintf(xpath_string + offset,
XPATH_MAX - offset,
"%s",
"/cib/status/tickets");
438 offset += snprintf(xpath_string + offset,
XPATH_MAX - offset,
"/%s[@id=\"%s\"]",
442 rc = the_cib->
cmds->
query(the_cib, xpath_string, &xml_search,
452 out->
err(out,
"Multiple ticket_states match ticket_id=%s", ticket_id);
454 *ticket_state_xml = xml_search;
456 *ticket_state_xml = xml_search;
478 const char *attr_name,
bool attr_value,
cib_t *cib)
481 xmlNode *xml_top = NULL;
482 xmlNode *ticket_state_xml = NULL;
485 rc = find_ticket_state(out, cib, ticket_id, &ticket_state_xml);
489 crm_debug(
"Injecting attribute into existing ticket state %s",
491 xml_top = ticket_state_xml;
493 }
else if (rc == ENXIO) {
494 xmlNode *xml_obj = NULL;
533 guint interval_ms = 0;
538 char *resource = NULL;
540 const char *rtype = NULL;
541 const char *rclass = NULL;
542 const char *rprovider = NULL;
544 xmlNode *cib_op = NULL;
545 xmlNode *cib_node = NULL;
546 xmlNode *cib_resource = NULL;
550 out->
message(out,
"inject-spec", spec);
552 key = calloc(1, strlen(spec) + 1);
553 node = calloc(1, strlen(spec) + 1);
554 rc = sscanf(spec,
"%[^@]@%[^=]=%d", key, node, &outcome);
556 out->
err(out,
"Invalid operation spec: %s. Only found %d fields",
565 out->
err(out,
"Invalid resource name: %s", resource);
580 rclass, rtype, rprovider);
583 op = create_op(cib_resource, task, interval_ms, outcome);
614 xmlNode *cib_node = NULL;
617 out->
message(out,
"inject-modify-config", injections->
quorum,
619 if (injections->
quorum != NULL) {
637 for (iter = injections->
node_up; iter != NULL; iter = iter->next) {
638 char *node = (
char *) iter->data;
640 out->
message(out,
"inject-modify-node",
"Online", node);
651 for (iter = injections->
node_down; iter != NULL; iter = iter->next) {
652 char *node = (
char *) iter->data;
655 out->
message(out,
"inject-modify-node",
"Offline", node);
678 for (iter = injections->
node_fail; iter != NULL; iter = iter->next) {
679 char *node = (
char *) iter->data;
681 out->
message(out,
"inject-modify-node",
"Failing", node);
693 for (iter = injections->
ticket_grant; iter != NULL; iter = iter->next) {
694 char *ticket_id = (
char *) iter->data;
696 out->
message(out,
"inject-modify-ticket",
"Granting", ticket_id);
698 rc = set_ticket_state_attr(out, ticket_id,
"granted",
true, cib);
702 for (iter = injections->
ticket_revoke; iter != NULL; iter = iter->next) {
703 char *ticket_id = (
char *) iter->data;
705 out->
message(out,
"inject-modify-ticket",
"Revoking", ticket_id);
707 rc = set_ticket_state_attr(out, ticket_id,
"granted",
false, cib);
711 for (iter = injections->
ticket_standby; iter != NULL; iter = iter->next) {
712 char *ticket_id = (
char *) iter->data;
714 out->
message(out,
"inject-modify-ticket",
"Standby", ticket_id);
716 rc = set_ticket_state_attr(out, ticket_id,
"standby",
true, cib);
720 for (iter = injections->
ticket_activate; iter != NULL; iter = iter->next) {
721 char *ticket_id = (
char *) iter->data;
723 out->
message(out,
"inject-modify-ticket",
"Activating", ticket_id);
725 rc = set_ticket_state_attr(out, ticket_id,
"standby",
false, cib);
729 for (iter = injections->
op_inject; iter != NULL; iter = iter->next) {
730 inject_action(out, (
char *) iter->data, cib,
data_set);
741 if (injections == NULL) {
745 g_list_free_full(injections->
node_up, g_free);
746 g_list_free_full(injections->
node_down, g_free);
747 g_list_free_full(injections->
node_fail, g_free);
748 g_list_free_full(injections->
op_fail, g_free);
749 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)
_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,...)
xmlNode * first_named_child(const xmlNode *parent, const char *name)
#define PCMK_RESOURCE_CLASS_SYSTEMD
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)
pe_resource_t * pe_find_resource(GList *rsc_list, const char *id_rh)
#define CRM_LOG_ASSERT(expr)
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)
void pcmk__inject_scheduler_input(pe_working_set_t *data_set, cib_t *cib, pcmk_injections_t *injections)
#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_OCF
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 PCMK_RESOURCE_CLASS_SERVICE
#define crm_trace(fmt, args...)
#define CRMD_JOINSTATE_MEMBER
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)
#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
int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
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
#define PCMK_RESOURCE_CLASS_STONITH
lrmd_event_data_t * lrmd_new_event(const char *rsc_id, const char *task, guint interval_ms)
Cluster status and scheduling.
#define PCMK_RESOURCE_CLASS_LSB
#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_UPSTART
#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