17 #include <sys/param.h>
18 #include <sys/types.h>
31 static cib_t *fake_cib = NULL;
32 static GList *fake_resource_list = NULL;
33 static GList *fake_op_fail_list = NULL;
36 #define STATUS_PATH_MAX 512
38 #define NEW_NODE_TEMPLATE "//"XML_CIB_TAG_NODE"[@uname='%s']"
39 #define NODE_TEMPLATE "//"XML_CIB_TAG_STATE"[@uname='%s']"
40 #define RSC_TEMPLATE "//"XML_CIB_TAG_STATE"[@uname='%s']//"XML_LRM_TAG_RESOURCE"[@id='%s']"
44 inject_transient_attr(xmlNode * cib_node,
const char *
name,
const char *value)
46 xmlNode *attrs = NULL;
47 xmlNode *instance_attrs = NULL;
48 const char *node_uuid =
ID(cib_node);
50 out->
message(out,
"inject-attr", name, value, cib_node);
59 if (instance_attrs == NULL) {
68 update_failcounts(xmlNode * cib_node,
const char *resource,
const char *task,
69 guint interval_ms,
int rc)
74 }
else if ((rc == 7) && (interval_ms == 0)) {
79 char *now = pcmk__ttoa(time(NULL));
81 name = pcmk__failcount_name(resource, task, interval_ms);
82 inject_transient_attr(cib_node, name,
"value++");
85 name = pcmk__lastfailure_name(resource, task, interval_ms);
86 inject_transient_attr(cib_node, name, now);
93 create_node_entry(
cib_t * cib_conn,
const char *node)
117 create_op(xmlNode *cib_resource,
const char *task, guint interval_ms,
127 op->
t_run = (
unsigned int) time(NULL);
131 for (xop = pcmk__xe_first_child(cib_resource); xop != NULL;
132 xop = pcmk__xe_next(xop)) {
155 inject_node_state(
cib_t * cib_conn,
const char *node,
const char *uuid)
158 xmlNode *cib_object = NULL;
162 create_node_entry(cib_conn, node);
165 rc = cib_conn->
cmds->
query(cib_conn, xpath, &cib_object,
168 if (cib_object &&
ID(cib_object) == NULL) {
169 crm_err(
"Detected multiple node_state entries for xpath=%s, bailing", xpath);
177 char *found_uuid = NULL;
182 found_uuid = strdup(uuid);
193 rc = cib_conn->
cmds->
query(cib_conn, xpath, &cib_object,
195 crm_trace(
"injecting node state for %s. rc is %d", node, rc);
204 modify_node(
cib_t * cib_conn,
char *node, gboolean up)
206 xmlNode *cib_node = inject_node_state(cib_conn, node, NULL);
226 find_resource_xml(xmlNode * cib_node,
const char *resource)
228 xmlNode *match = NULL;
239 inject_resource(xmlNode * cib_node,
const char *resource,
const char *lrm_name,
240 const char *rclass,
const char *rtype,
const char *rprovider)
243 xmlNode *container = NULL;
244 xmlNode *cib_resource = NULL;
247 cib_resource = find_resource_xml(cib_node, resource);
248 if (cib_resource != NULL) {
256 if (strcmp(resource, lrm_name)) {
257 cib_resource = find_resource_xml(cib_node, lrm_name);
258 if (cib_resource != NULL) {
265 if (rclass == NULL || rtype == NULL) {
266 out->
err(out,
"Resource %s not found in the status section of %s."
267 " Please supply the class and type to continue", resource,
ID(cib_node));
273 out->
err(out,
"Invalid class for %s: %s", resource, rclass);
277 && (rprovider == NULL)) {
278 out->
err(out,
"Please specify the provider for resource %s", resource);
282 xpath = (
char *)xmlGetNodePath(cib_node);
283 crm_info(
"Injecting new resource %s into %s '%s'", lrm_name, xpath,
ID(cib_node));
288 const char *node_uuid =
ID(cib_node);
295 if (container == NULL) {
311 #define XPATH_MAX 1024
314 find_ticket_state(
cib_t * the_cib,
const char *ticket_id, xmlNode ** ticket_state_xml)
318 xmlNode *xml_search = NULL;
320 char *xpath_string = NULL;
323 *ticket_state_xml = NULL;
326 offset += snprintf(xpath_string + offset,
XPATH_MAX - offset,
"%s",
"/cib/status/tickets");
329 offset += snprintf(xpath_string + offset,
XPATH_MAX - offset,
"/%s[@id=\"%s\"]",
333 rc = the_cib->
cmds->
query(the_cib, xpath_string, &xml_search,
343 out->
err(out,
"Multiple ticket_states match ticket_id=%s", ticket_id);
345 *ticket_state_xml = xml_search;
347 *ticket_state_xml = xml_search;
356 set_ticket_state_attr(
const char *ticket_id,
const char *attr_name,
357 const char *attr_value,
cib_t * cib,
int cib_options)
360 xmlNode *xml_top = NULL;
361 xmlNode *ticket_state_xml = NULL;
363 rc = find_ticket_state(cib, ticket_id, &ticket_state_xml);
365 crm_debug(
"Found a match state for ticket: id=%s", ticket_id);
366 xml_top = ticket_state_xml;
368 }
else if (rc != -ENXIO) {
372 xmlNode *xml_obj = NULL;
380 crm_xml_add(ticket_state_xml, attr_name, attr_value);
393 const char *quorum,
const char *watchdog, GList *node_up, GList *node_down, GList *node_fail,
394 GList *op_inject, GList *ticket_grant, GList *ticket_revoke,
395 GList *ticket_standby, GList *ticket_activate)
400 xmlNode *cib_op = NULL;
401 xmlNode *cib_node = NULL;
402 xmlNode *cib_resource = NULL;
406 out = data_set->
priv;
408 out->
message(out,
"inject-modify-config", quorum, watchdog);
428 for (gIter = node_up; gIter != NULL; gIter = gIter->next) {
429 char *node = (
char *)gIter->data;
431 out->
message(out,
"inject-modify-node",
"Online", node);
433 cib_node = modify_node(cib, node, TRUE);
442 for (gIter = node_down; gIter != NULL; gIter = gIter->next) {
444 char *node = (
char *)gIter->data;
446 out->
message(out,
"inject-modify-node",
"Offline", node);
448 cib_node = modify_node(cib, node, FALSE);
467 for (gIter = node_fail; gIter != NULL; gIter = gIter->next) {
468 char *node = (
char *)gIter->data;
470 out->
message(out,
"inject-modify-node",
"Failing", node);
472 cib_node = modify_node(cib, node, TRUE);
482 for (gIter = ticket_grant; gIter != NULL; gIter = gIter->next) {
483 char *ticket_id = (
char *)gIter->data;
485 out->
message(out,
"inject-modify-ticket",
"Granting", ticket_id);
487 rc = set_ticket_state_attr(ticket_id,
"granted",
"true",
493 for (gIter = ticket_revoke; gIter != NULL; gIter = gIter->next) {
494 char *ticket_id = (
char *)gIter->data;
496 out->
message(out,
"inject-modify-ticket",
"Revoking", ticket_id);
498 rc = set_ticket_state_attr(ticket_id,
"granted",
"false",
504 for (gIter = ticket_standby; gIter != NULL; gIter = gIter->next) {
505 char *ticket_id = (
char *)gIter->data;
507 out->
message(out,
"inject-modify-ticket",
"Standby", ticket_id);
509 rc = set_ticket_state_attr(ticket_id,
"standby",
"true",
515 for (gIter = ticket_activate; gIter != NULL; gIter = gIter->next) {
516 char *ticket_id = (
char *)gIter->data;
518 out->
message(out,
"inject-modify-ticket",
"Activating", ticket_id);
520 rc = set_ticket_state_attr(ticket_id,
"standby",
"false",
526 for (gIter = op_inject; gIter != NULL; gIter = gIter->next) {
527 char *spec = (
char *)gIter->data;
531 guint interval_ms = 0;
536 char *resource = NULL;
538 const char *rtype = NULL;
539 const char *rclass = NULL;
540 const char *rprovider = NULL;
544 out->
message(out,
"inject-spec", spec);
546 key = calloc(1, strlen(spec) + 1);
547 node = calloc(1, strlen(spec) + 1);
548 rc = sscanf(spec,
"%[^@]@%[^=]=%d", key, node, &outcome);
550 out->
err(out,
"Invalid operation spec: %s. Only found %d fields", spec, rc);
560 out->
err(out,
"Invalid resource name: %s", resource);
566 cib_node = inject_node_state(cib, node, NULL);
569 update_failcounts(cib_node, resource, task, interval_ms, outcome);
571 cib_resource = inject_resource(cib_node, resource, resource,
572 rclass, rtype, rprovider);
575 op = create_op(cib_resource, task, interval_ms, outcome);
578 cib_op = inject_op(cib_resource, op, 0);
603 out->
message(out,
"inject-pseudo-action", node, task);
615 int target_outcome = 0;
617 const char *rtype = NULL;
618 const char *rclass = NULL;
619 const char *resource = NULL;
620 const char *rprovider = NULL;
621 const char *lrm_name = NULL;
625 xmlNode *cib_node = NULL;
626 xmlNode *cib_resource = NULL;
634 crm_info(
"Skipping %s op for %s", operation, node);
638 if (action_rsc == NULL) {
640 free(node); free(uuid);
660 out->
message(out,
"inject-rsc-action", resource, operation, node, (guint) 0);
673 cib_node = inject_node_state(fake_cib, node, (router_node? node : uuid));
676 cib_resource = inject_resource(cib_node, resource, lrm_name,
677 rclass, rtype, rprovider);
678 if (cib_resource == NULL) {
679 crm_err(
"invalid resource in transition");
680 free(node); free(uuid);
689 for (gIter = fake_op_fail_list; gIter != NULL; gIter = gIter->next) {
690 char *spec = (
char *)gIter->data;
692 const char *match_name = NULL;
697 if (strncasecmp(key, spec, strlen(key)) == 0) {
698 match_name = resource;
702 if ((match_name == NULL) && strcmp(resource, lrm_name)) {
705 if (strncasecmp(key, spec, strlen(key)) == 0) {
706 match_name = lrm_name;
711 if (match_name != NULL) {
713 rc = sscanf(spec,
"%*[^=]=%d", (
int *) &op->
rc);
718 "Invalid failed operation spec: %s. Result code must be integer",
724 out->
info(out,
"Pretending action %d failed with rc=%d", action->
id, op->
rc);
725 update_failcounts(cib_node, match_name, op->
op_type,
731 inject_op(cib_resource, op, target_outcome);
739 free(node); free(uuid);
754 out->
message(out,
"inject-cluster-action", node, task, rsc);
765 out->
message(out,
"inject-fencing-action", target, op);
770 xmlNode *cib_node = modify_node(fake_cib, target, FALSE);
783 snprintf(xpath,
STATUS_PATH_MAX,
"//node_state[@uname='%s']/%s", target,
810 out = data_set->
priv;
813 fake_op_fail_list = op_fail_list;
816 out->
begin_list(out, NULL, NULL,
"Executing Cluster Transition");
823 fake_resource_list = data_set->
resources;
828 fake_resource_list = NULL;
836 out->
err(out,
"An invalid transition was produced");
840 xmlNode *cib_object = NULL;
845 data_set->
input = cib_object;
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
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)
int pcmk__scan_min_int(const char *text, int *result, int minimum)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
void print_graph(unsigned int log_level, crm_graph_t *graph)
xmlNode * first_named_child(const xmlNode *parent, const char *name)
#define PCMK_RESOURCE_CLASS_SYSTEMD
#define XML_TAG_TRANSIENT_NODEATTRS
const char * crm_meta_value(GHashTable *hash, const char *field)
crm_graph_t * unpack_graph(xmlNode *xml_graph, const char *reference)
#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.
int(* message)(pcmk__output_t *out, const char *message_id,...)
#define XML_NODE_EXPECTED
int query_node_uuid(cib_t *the_cib, const char *uname, char **uuid, int *is_remote_node)
int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
pe_resource_t * pe_find_resource(GList *rsc_list, const char *id_rh)
#define CRM_LOG_ASSERT(expr)
int(* replace)(cib_t *cib, const char *section, xmlNode *data, int call_options)
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)
int(* modify)(cib_t *cib, const char *section, xmlNode *data, int call_options)
int run_simulation(pe_working_set_t *data_set, cib_t *cib, GList *op_fail_list)
#define XML_LRM_ATTR_TASK_KEY
bool(* is_quiet)(pcmk__output_t *out)
#define XML_TAG_ATTR_SETS
#define XML_LRM_ATTR_TASK
void pe_reset_working_set(pe_working_set_t *data_set)
Reset a working set to default state without freeing it.
#define CRMD_JOINSTATE_DOWN
void(* end_list)(pcmk__output_t *out)
#define PCMK_RESOURCE_CLASS_OCF
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#define XML_CIB_TAG_RESOURCE
#define XML_CIB_TAG_STATE
gboolean bringing_nodes_online
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, int level)
#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
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
#define crm_log_xml_debug(xml, text)
#define XML_AGENT_ATTR_PROVIDER
#define XML_ATTR_HAVE_QUORUM
xmlNode * create_xml_node(xmlNode *parent, const char *name)
#define crm_log_xml_warn(xml, text)
gboolean update_graph(crm_graph_t *graph, crm_action_t *action)
#define XML_LRM_ATTR_ROUTER_NODE
#define NEW_NODE_TEMPLATE
void free_xml(xmlNode *child)
gboolean xml_has_children(const xmlNode *root)
void destroy_graph(crm_graph_t *graph)
int(* remove)(cib_t *cib, const char *section, xmlNode *data, int call_options)
#define XML_LRM_ATTR_TARGET_UUID
#define PCMK_RESOURCE_CLASS_STONITH
lrmd_event_data_t * lrmd_new_event(const char *rsc_id, const char *task, guint interval_ms)
#define crm_log_xml_err(xml, text)
Cluster status and scheduling.
lrmd_event_data_t * convert_graph_action(xmlNode *resource, crm_action_t *action, int status, int rc)
#define PCMK_RESOURCE_CLASS_LSB
#define XML_LRM_TAG_RESOURCES
#define crm_err(fmt, args...)
#define XML_CIB_TAG_TICKET_STATE
#define XML_CIB_TAG_CRMCONFIG
#define PCMK_RESOURCE_CLASS_UPSTART
#define XML_ATTR_HAVE_WATCHDOG
This structure contains everything that makes up a single output formatter.
int update_attr_delegate(cib_t *the_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, gboolean to_console, const char *user_name, const char *node_type)
#define XML_LRM_ATTR_CALLID
int run_graph(crm_graph_t *graph)
#define XML_NODE_JOIN_STATE
#define XML_CIB_TAG_STATUS
int(* create)(cib_t *cib, const char *section, xmlNode *data, int call_options)
#define XML_NODE_IN_CLUSTER
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
#define XML_LRM_ATTR_TARGET
void modify_configuration(pe_working_set_t *data_set, cib_t *cib, const char *quorum, const char *watchdog, GList *node_up, GList *node_down, GList *node_fail, GList *op_inject, GList *ticket_grant, GList *ticket_revoke, GList *ticket_standby, GList *ticket_activate)
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
void set_graph_functions(crm_graph_functions_t *fns)
#define XML_CIB_TAG_TICKETS
#define crm_info(fmt, args...)
#define XML_ATTR_TE_TARGET_RC
#define XML_AGENT_ATTR_CLASS