17 #include <sys/param.h> 18 #include <sys/types.h> 36 #define XPATH_NODE_CONFIG "//" PCMK_XE_NODE "[@" PCMK_XA_UNAME "='%s']" 37 #define XPATH_NODE_STATE "//" PCMK__XE_NODE_STATE "[@" PCMK_XA_UNAME "='%s']" 38 #define XPATH_NODE_STATE_BY_ID "//" PCMK__XE_NODE_STATE "[@" PCMK_XA_ID "='%s']" 39 #define XPATH_RSC_HISTORY XPATH_NODE_STATE \ 40 "//" PCMK__XE_LRM_RESOURCE "[@" PCMK_XA_ID "='%s']" 54 const char *
name,
const char *value)
56 xmlNode *attrs = NULL;
57 xmlNode *instance_attrs = NULL;
58 const char *node_uuid = pcmk__xe_id(cib_node);
60 out->
message(out,
"inject-attr",
name, value, cib_node);
71 if (instance_attrs == NULL) {
95 const char *resource,
const char *task,
96 guint interval_ms,
int exit_status)
102 xmlNode *output = NULL;
104 CRM_CHECK((out != NULL) && (cib_conn != NULL) && (cib_node != NULL)
105 && (resource != NULL) && (task != NULL),
return);
113 name = pcmk__failcount_name(resource, task, interval_ms);
116 pcmk__xe_id(cib_node), NULL, NULL, NULL,
name,
123 value = pcmk__itoa(failcount + 1);
124 inject_transient_attr(out, cib_node,
name, value);
130 name = pcmk__lastfailure_name(resource, task, interval_ms);
131 value = pcmk__ttoa(time(NULL));
132 inject_transient_attr(out, cib_node,
name, value);
146 create_node_entry(
cib_t *cib_conn,
const char *node)
151 rc = cib_conn->
cmds->
query(cib_conn, xpath, NULL,
184 create_op(
const xmlNode *cib_resource,
const char *task, guint interval_ms,
190 op =
lrmd_new_event(pcmk__xe_id(cib_resource), task, interval_ms);
194 op->
t_run = (
unsigned int) time(NULL);
200 xop != NULL; xop = pcmk__xe_next(xop)) {
249 xmlNode *cib_object = NULL;
251 bool duplicate =
false;
252 char *found_uuid = NULL;
255 create_node_entry(cib_conn, node);
258 rc = cib_conn->
cmds->
query(cib_conn, xpath, &cib_object,
261 if ((cib_object != NULL) && (pcmk__xe_id(cib_object) == NULL)) {
273 found_uuid = strdup(uuid);
283 rc = cib_conn->
cmds->
query(cib_conn, xpath_by_uuid, &cib_object,
286 if ((cib_object != NULL) && (pcmk__xe_id(cib_object) == NULL)) {
287 crm_err(
"Can't inject node state for %s because multiple " 288 "state entries found for ID %s", node, found_uuid);
293 }
else if (cib_object != NULL) {
313 rc = cib_conn->
cmds->
query(cib_conn, xpath, &cib_object,
315 crm_trace(
"Injecting node state for %s (rc=%d)", node, rc);
377 find_resource_xml(xmlNode *cib_node,
const char *resource)
405 const char *resource,
const char *lrm_name,
406 const char *rclass,
const char *rtype,
407 const char *rprovider)
410 xmlNode *container = NULL;
411 xmlNode *cib_resource = NULL;
413 cib_resource = find_resource_xml(cib_node, resource);
414 if (cib_resource != NULL) {
422 if (strcmp(resource, lrm_name) != 0) {
423 cib_resource = find_resource_xml(cib_node, lrm_name);
424 if (cib_resource != NULL) {
429 if ((rclass == NULL) || (rtype == NULL)) {
432 "Resource %s not found in the status section of %s " 433 "(supply class and type to continue)",
434 resource, pcmk__xe_id(cib_node));
444 out->
err(out,
"Invalid class for %s: %s", resource, rclass);
448 && (rprovider == NULL)) {
450 out->
err(out,
"Please specify the provider for resource %s", resource);
454 crm_info(
"Injecting new resource %s into node state '%s'",
455 lrm_name, pcmk__xe_id(cib_node));
459 const char *node_uuid = pcmk__xe_id(cib_node);
466 if (container == NULL) {
496 const char *attr_name,
bool attr_value,
cib_t *cib)
499 xmlNode *xml_top = NULL;
500 xmlNode *ticket_state_xml = NULL;
512 crm_debug(
"Injecting attribute into existing ticket state %s",
514 xml_top = ticket_state_xml;
516 }
else if (rc == ENXIO) {
517 xmlNode *xml_obj = NULL;
556 guint interval_ms = 0;
561 char *resource = NULL;
563 const char *rtype = NULL;
564 const char *rclass = NULL;
565 const char *rprovider = NULL;
567 xmlNode *cib_op = NULL;
568 xmlNode *cib_node = NULL;
569 xmlNode *cib_resource = NULL;
573 out->
message(out,
"inject-spec", spec);
577 rc = sscanf(spec,
"%[^@]@%[^=]=%d", key, node, &outcome);
579 out->
err(out,
"Invalid operation spec: %s. Only found %d fields",
588 out->
err(out,
"Invalid resource name: %s", resource);
604 rclass, rtype, rprovider);
607 op = create_op(cib_resource, task, interval_ms, outcome);
637 const GList *iter = NULL;
638 xmlNode *cib_node = NULL;
641 out->
message(out,
"inject-modify-config", injections->
quorum,
643 if (injections->
quorum != NULL) {
661 for (iter = injections->
node_up; iter != NULL; iter = iter->next) {
662 const char *node = (
const char *) iter->data;
664 out->
message(out,
"inject-modify-node",
"Online", node);
675 for (iter = injections->
node_down; iter != NULL; iter = iter->next) {
676 const char *node = (
const char *) iter->data;
679 out->
message(out,
"inject-modify-node",
"Offline", node);
706 for (iter = injections->
node_fail; iter != NULL; iter = iter->next) {
707 const char *node = (
const char *) iter->data;
709 out->
message(out,
"inject-modify-node",
"Failing", node);
721 for (iter = injections->
ticket_grant; iter != NULL; iter = iter->next) {
722 const char *ticket_id = (
const char *) iter->data;
724 out->
message(out,
"inject-modify-ticket",
"Granting", ticket_id);
730 for (iter = injections->
ticket_revoke; iter != NULL; iter = iter->next) {
731 const char *ticket_id = (
const char *) iter->data;
733 out->
message(out,
"inject-modify-ticket",
"Revoking", ticket_id);
740 for (iter = injections->
ticket_standby; iter != NULL; iter = iter->next) {
741 const char *ticket_id = (
const char *) iter->data;
743 out->
message(out,
"inject-modify-ticket",
"Standby", ticket_id);
745 rc = set_ticket_state_attr(out, ticket_id,
PCMK_XA_STANDBY,
true, cib);
749 for (iter = injections->
ticket_activate; iter != NULL; iter = iter->next) {
750 const char *ticket_id = (
const char *) iter->data;
752 out->
message(out,
"inject-modify-ticket",
"Activating", ticket_id);
754 rc = set_ticket_state_attr(out, ticket_id,
PCMK_XA_STANDBY,
false, cib);
758 for (iter = injections->
op_inject; iter != NULL; iter = iter->next) {
759 inject_action(out, (
const char *) iter->data, cib,
scheduler);
770 if (injections == NULL) {
774 g_list_free_full(injections->
node_up, g_free);
775 g_list_free_full(injections->
node_down, g_free);
776 g_list_free_full(injections->
node_fail, g_free);
777 g_list_free_full(injections->
op_fail, g_free);
778 g_list_free_full(injections->
op_inject, g_free);
void(* end_list)(pcmk__output_t *out)
#define CRM_CHECK(expr, failure_action)
#define PCMK__XE_LRM_RESOURCES
#define PCMK__XE_TICKET_STATE
#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,...)
pcmk_resource_t * pe_find_resource(GList *rsc_list, const char *id)
bool(* is_quiet)(pcmk__output_t *out)
#define PCMK_XA_HAVE_QUORUM
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)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
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
void pcmk__inject_scheduler_input(pcmk_scheduler_t *scheduler, cib_t *cib, const pcmk_injections_t *injections)
#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.
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
#define PCMK__XE_TRANSIENT_ATTRIBUTES
int cib__get_node_attrs(pcmk__output_t *out, cib_t *cib, 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 *user_name, xmlNode **result)
void pcmk_free_injections(pcmk_injections_t *injections)
Free a :pcmk_injections_t structure.
#define PCMK__XE_LRM_RESOURCE
#define CRMD_JOINSTATE_DOWN
#define PCMK_RESOURCE_CLASS_UPSTART
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
void pcmk__inject_failcount(pcmk__output_t *out, cib_t *cib_conn, xmlNode *cib_node, const char *resource, const char *task, guint interval_ms, int exit_status)
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)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
#define crm_trace(fmt, args...)
#define CRMD_JOINSTATE_MEMBER
#define PCMK_RESOURCE_CLASS_STONITH
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 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)
int pcmk__get_ticket_state(cib_t *cib, const char *ticket_id, xmlNode **state)
int pcmk_legacy2rc(int legacy_rc)
void free_xml(xmlNode *child)
bool pcmk__simulate_node_config
void pcmk__xe_set_props(xmlNodePtr node,...) G_GNUC_NULL_TERMINATED
#define pcmk__assert(expr)
#define PCMK_VALUE_ONLINE
Cluster status and scheduling.
#define crm_err(fmt, args...)
pcmk_scheduler_t * scheduler
void lrmd__set_result(lrmd_event_data_t *event, enum ocf_exitcode rc, int op_status, const char *exit_reason)
Synthetic cluster events that can be injected into the cluster for running simulations.
#define PCMK_RESOURCE_CLASS_LSB
void lrmd_free_event(lrmd_event_data_t *event)
Free an executor event.
This structure contains everything that makes up a single output formatter.
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, guint *interval_ms)
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 PCMK_OPT_HAVE_WATCHDOG
#define XPATH_RSC_HISTORY
#define PCMK__XE_NODE_STATE
xmlNode * pcmk__inject_node_state_change(cib_t *cib_conn, const char *node, bool up)
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.
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.
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
#define pcmk__assert_alloc(nmemb, size)
Resource agent executor events.
#define PCMK_XA_CRM_DEBUG_ORIGIN
#define PCMK_VALUE_OFFLINE
#define PCMK_XE_INSTANCE_ATTRIBUTES
#define XPATH_NODE_STATE_BY_ID
#define crm_info(fmt, args...)
xmlNode * pcmk__inject_node(cib_t *cib_conn, const char *node, const char *uuid)
#define PCMK_XE_CRM_CONFIG