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) {
97 const char *resource,
const char *task,
98 guint interval_ms,
int exit_status,
bool infinity)
104 xmlNode *output = NULL;
106 CRM_CHECK((out != NULL) && (cib_conn != NULL) && (cib_node != NULL)
107 && (resource != NULL) && (task != NULL),
return);
115 name = pcmk__failcount_name(resource, task, interval_ms);
118 pcmk__xe_id(cib_node), NULL, NULL, NULL,
name,
130 value = pcmk__itoa(failcount + 1);
133 inject_transient_attr(out, cib_node,
name, value);
139 name = pcmk__lastfailure_name(resource, task, interval_ms);
140 value = pcmk__ttoa(time(NULL));
141 inject_transient_attr(out, cib_node,
name, value);
155 create_node_entry(
cib_t *cib_conn,
const char *node)
192 create_op(
const xmlNode *cib_resource,
const char *task, guint interval_ms,
198 op =
lrmd_new_event(pcmk__xe_id(cib_resource), task, interval_ms);
201 op->
t_run = time(NULL);
234 const char *node,
int target_rc)
257 xmlNode *cib_object = NULL;
259 bool duplicate =
false;
260 char *found_uuid = NULL;
263 create_node_entry(cib_conn, node);
266 rc = cib_conn->
cmds->
query(cib_conn, xpath, &cib_object,
269 if ((cib_object != NULL) && (pcmk__xe_id(cib_object) == NULL)) {
281 found_uuid = strdup(uuid);
291 rc = cib_conn->
cmds->
query(cib_conn, xpath_by_uuid, &cib_object,
294 if ((cib_object != NULL) && (pcmk__xe_id(cib_object) == NULL)) {
295 crm_err(
"Can't inject node state for %s because multiple " 296 "state entries found for ID %s", node, found_uuid);
301 }
else if (cib_object != NULL) {
320 rc = cib_conn->
cmds->
query(cib_conn, xpath, &cib_object,
322 crm_trace(
"Injecting node state for %s (rc=%d)", node, rc);
384 find_resource_xml(xmlNode *cib_node,
const char *resource)
412 const char *resource,
const char *lrm_name,
413 const char *rclass,
const char *rtype,
414 const char *rprovider)
417 xmlNode *container = NULL;
418 xmlNode *cib_resource = NULL;
420 cib_resource = find_resource_xml(cib_node, resource);
421 if (cib_resource != NULL) {
429 if (strcmp(resource, lrm_name) != 0) {
430 cib_resource = find_resource_xml(cib_node, lrm_name);
431 if (cib_resource != NULL) {
436 if ((rclass == NULL) || (rtype == NULL)) {
439 "Resource %s not found in the status section of %s " 440 "(supply class and type to continue)",
441 resource, pcmk__xe_id(cib_node));
450 out->
err(out,
"Invalid class for %s: %s", resource, rclass);
454 && (rprovider == NULL)) {
456 out->
err(out,
"Please specify the provider for resource %s", resource);
460 crm_info(
"Injecting new resource %s into node state '%s'",
461 lrm_name, pcmk__xe_id(cib_node));
465 const char *node_uuid = pcmk__xe_id(cib_node);
472 if (container == NULL) {
502 const char *attr_name,
bool attr_value,
cib_t *cib)
505 xmlNode *xml_top = NULL;
506 xmlNode *ticket_state_xml = NULL;
518 crm_debug(
"Injecting attribute into existing ticket state %s",
520 xml_top = ticket_state_xml;
522 }
else if (rc == ENXIO) {
523 xmlNode *xml_obj = NULL;
561 guint interval_ms = 0;
566 char *resource = NULL;
568 const char *rtype = NULL;
569 const char *rclass = NULL;
570 const char *rprovider = NULL;
572 xmlNode *cib_op = NULL;
573 xmlNode *cib_node = NULL;
574 xmlNode *cib_resource = NULL;
577 bool infinity =
false;
579 out->
message(out,
"inject-spec", spec);
583 rc = sscanf(spec,
"%[^@]@%[^=]=%d", key, node, &outcome);
585 out->
err(out,
"Invalid operation spec: %s. Only found %d fields",
594 out->
err(out,
"Invalid resource name: %s", resource);
619 rclass, rtype, rprovider);
622 op = create_op(cib_resource, task, interval_ms, outcome);
651 const GList *iter = NULL;
652 xmlNode *cib_node = NULL;
655 out->
message(out,
"inject-modify-config", injections->
quorum,
657 if (injections->
quorum != NULL) {
669 NULL, NULL, NULL, NULL,
675 for (iter = injections->
node_up; iter != NULL; iter = iter->next) {
676 const char *node = (
const char *) iter->data;
678 out->
message(out,
"inject-modify-node",
"Online", node);
688 for (iter = injections->
node_down; iter != NULL; iter = iter->next) {
689 const char *node = (
const char *) iter->data;
692 out->
message(out,
"inject-modify-node",
"Offline", node);
716 for (iter = injections->
node_fail; iter != NULL; iter = iter->next) {
717 const char *node = (
const char *) iter->data;
719 out->
message(out,
"inject-modify-node",
"Failing", node);
730 for (iter = injections->
ticket_grant; iter != NULL; iter = iter->next) {
731 const char *ticket_id = (
const char *) iter->data;
733 out->
message(out,
"inject-modify-ticket",
"Granting", ticket_id);
739 for (iter = injections->
ticket_revoke; iter != NULL; iter = iter->next) {
740 const char *ticket_id = (
const char *) iter->data;
742 out->
message(out,
"inject-modify-ticket",
"Revoking", ticket_id);
749 for (iter = injections->
ticket_standby; iter != NULL; iter = iter->next) {
750 const char *ticket_id = (
const char *) iter->data;
752 out->
message(out,
"inject-modify-ticket",
"Standby", ticket_id);
754 rc = set_ticket_state_attr(out, ticket_id,
PCMK_XA_STANDBY,
true, cib);
758 for (iter = injections->
ticket_activate; iter != NULL; iter = iter->next) {
759 const char *ticket_id = (
const char *) iter->data;
761 out->
message(out,
"inject-modify-ticket",
"Activating", ticket_id);
763 rc = set_ticket_state_attr(out, ticket_id,
PCMK_XA_STANDBY,
false, cib);
767 for (iter = injections->
op_inject; iter != NULL; iter = iter->next) {
768 inject_action(out, (
const char *) iter->data, cib,
scheduler);
779 if (injections == NULL) {
783 g_list_free_full(injections->
node_up, g_free);
784 g_list_free_full(injections->
node_down, g_free);
785 g_list_free_full(injections->
node_fail, g_free);
786 g_list_free_full(injections->
op_fail, g_free);
787 g_list_free_full(injections->
op_inject, g_free);
void(* end_list)(pcmk__output_t *out)
#define CRM_CHECK(expr, failure_action)
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
#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)
void pcmk__xe_set_bool_attr(xmlNodePtr node, const char *name, bool value)
#define PCMK_VALUE_INFINITY
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)
pcmk__scheduler_private_t * priv
int query_node_uuid(cib_t *the_cib, const char *uname, char **uuid, int *is_remote_node)
#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
#define XPATH_NODE_CONFIG
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
#define PCMK__XE_TRANSIENT_ATTRIBUTES
void pcmk__xml_free(xmlNode *xml)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
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
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
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.
#define crm_trace(fmt, args...)
#define CRMD_JOINSTATE_MEMBER
#define PCMK_RESOURCE_CLASS_STONITH
#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)
#define PCMK_ACTION_START
pcmk__resource_private_t * priv
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)
#define pcmk__str_copy(str)
bool pcmk__simulate_node_config
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, bool infinity)
xmlNode * pcmk__xe_next(const xmlNode *node, const char *element_name)
#define pcmk__assert(expr)
void pcmk__xe_set_props(xmlNodePtr node,...) G_GNUC_NULL_TERMINATED
#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.
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
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.
xmlNode * pcmk__inject_action_result(xmlNode *cib_resource, lrmd_event_data_t *op, const char *node, int target_rc)
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.
#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
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1