MCPcopy Create free account
hub / github.com/ClusterLabs/pacemaker / test_date_expression

Function test_date_expression

lib/pengine/rules.c:511–572  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

509}
510
511gboolean
512test_date_expression(xmlNode * time_expr, crm_time_t * now)
513{
514 crm_time_t *start = NULL;
515 crm_time_t *end = NULL;
516 const char *value = NULL;
517 const char *op = crm_element_value(time_expr, "operation");
518
519 xmlNode *duration_spec = NULL;
520 xmlNode *date_spec = NULL;
521
522 gboolean passed = FALSE;
523
524 crm_trace("Testing expression: %s", ID(time_expr));
525
526 duration_spec = first_named_child(time_expr, "duration");
527 date_spec = first_named_child(time_expr, "date_spec");
528
529 value = crm_element_value(time_expr, "start");
530 if (value != NULL) {
531 start = crm_time_new(value);
532 }
533 value = crm_element_value(time_expr, "end");
534 if (value != NULL) {
535 end = crm_time_new(value);
536 }
537
538 if (start != NULL && end == NULL && duration_spec != NULL) {
539 end = parse_xml_duration(start, duration_spec);
540 }
541 if (op == NULL) {
542 op = "in_range";
543 }
544
545 if (safe_str_eq(op, "date_spec") || safe_str_eq(op, "in_range")) {
546 if (start != NULL && crm_time_compare(start, now) > 0) {
547 passed = FALSE;
548 } else if (end != NULL && crm_time_compare(end, now) < 0) {
549 passed = FALSE;
550 } else if (safe_str_eq(op, "in_range")) {
551 passed = TRUE;
552 } else {
553 passed = cron_range_satisfied(now, date_spec);
554 }
555
556 } else if (safe_str_eq(op, "gt") && crm_time_compare(start, now) < 0) {
557 passed = TRUE;
558
559 } else if (safe_str_eq(op, "lt") && crm_time_compare(end, now) > 0) {
560 passed = TRUE;
561
562 } else if (safe_str_eq(op, "eq") && crm_time_compare(start, now) == 0) {
563 passed = TRUE;
564
565 } else if (safe_str_eq(op, "neq") && crm_time_compare(start, now) != 0) {
566 passed = TRUE;
567 }
568

Callers 1

test_expressionFunction · 0.85

Calls 7

crm_element_valueFunction · 0.85
first_named_childFunction · 0.85
crm_time_newFunction · 0.85
parse_xml_durationFunction · 0.85
crm_time_compareFunction · 0.85
cron_range_satisfiedFunction · 0.85
crm_time_freeFunction · 0.85

Tested by

no test coverage detected