diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:45:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:45:40 +0000 |
commit | 07d7f4cfa4b10de87a31b68191036ff446add675 (patch) | |
tree | 7162524d8aaf1aef62d2f4fa51f595ed113981ff /lib/pengine/tests/native | |
parent | Adding upstream version 2.1.6. (diff) | |
download | pacemaker-upstream/2.1.7.tar.xz pacemaker-upstream/2.1.7.zip |
Adding upstream version 2.1.7.upstream/2.1.7
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/pengine/tests/native')
-rw-r--r-- | lib/pengine/tests/native/Makefile.am | 4 | ||||
-rw-r--r-- | lib/pengine/tests/native/native_find_rsc_test.c | 724 | ||||
-rw-r--r-- | lib/pengine/tests/native/pe_base_name_eq_test.c | 31 |
3 files changed, 500 insertions, 259 deletions
diff --git a/lib/pengine/tests/native/Makefile.am b/lib/pengine/tests/native/Makefile.am index 5046ff1..07cc1a1 100644 --- a/lib/pengine/tests/native/Makefile.am +++ b/lib/pengine/tests/native/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2022 the Pacemaker project contributors +# Copyright 2022-2023 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -17,6 +17,6 @@ AM_TESTS_ENVIRONMENT += PCMK_CTS_CLI_DIR=$(top_srcdir)/cts/cli # Add "_test" to the end of all test program names to simplify .gitignore. check_PROGRAMS = native_find_rsc_test \ - pe_base_name_eq_test + pe_base_name_eq_test TESTS = $(check_PROGRAMS) diff --git a/lib/pengine/tests/native/native_find_rsc_test.c b/lib/pengine/tests/native/native_find_rsc_test.c index 22aaf41..b85ca24 100644 --- a/lib/pengine/tests/native/native_find_rsc_test.c +++ b/lib/pengine/tests/native/native_find_rsc_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2022 the Pacemaker project contributors + * Copyright 2022-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -10,21 +10,18 @@ #include <crm_internal.h> #include <crm/common/unittest_internal.h> +#include <crm/common/scheduler.h> #include <crm/common/xml.h> #include <crm/pengine/internal.h> #include <crm/pengine/status.h> -#include <crm/pengine/pe_types.h> - -/* Needed to access replicas inside a bundle. */ -#define PE__VARIANT_BUNDLE 1 -#include <lib/pengine/variant.h> xmlNode *input = NULL; -pe_working_set_t *data_set = NULL; +pcmk_scheduler_t *scheduler = NULL; -pe_node_t *cluster01, *cluster02, *httpd_bundle_0; -pe_resource_t *exim_group, *inactive_group, *promotable_clone, *inactive_clone; -pe_resource_t *httpd_bundle, *mysql_clone_group; +pcmk_node_t *cluster01, *cluster02, *httpd_bundle_0; +pcmk_resource_t *exim_group, *inactive_group; +pcmk_resource_t *promotable_clone, *inactive_clone; +pcmk_resource_t *httpd_bundle, *mysql_clone_group; static int setup(void **state) { @@ -40,25 +37,26 @@ setup(void **state) { return 1; } - data_set = pe_new_working_set(); + scheduler = pe_new_working_set(); - if (data_set == NULL) { + if (scheduler == NULL) { return 1; } - pe__set_working_set_flags(data_set, pe_flag_no_counts|pe_flag_no_compat); - data_set->input = input; + pe__set_working_set_flags(scheduler, + pcmk_sched_no_counts|pcmk_sched_no_compat); + scheduler->input = input; - cluster_status(data_set); + cluster_status(scheduler); /* Get references to the cluster nodes so we don't have to find them repeatedly. */ - cluster01 = pe_find_node(data_set->nodes, "cluster01"); - cluster02 = pe_find_node(data_set->nodes, "cluster02"); - httpd_bundle_0 = pe_find_node(data_set->nodes, "httpd-bundle-0"); + cluster01 = pe_find_node(scheduler->nodes, "cluster01"); + cluster02 = pe_find_node(scheduler->nodes, "cluster02"); + httpd_bundle_0 = pe_find_node(scheduler->nodes, "httpd-bundle-0"); /* Get references to several resources we use frequently. */ - for (GList *iter = data_set->resources; iter != NULL; iter = iter->next) { - pe_resource_t *rsc = (pe_resource_t *) iter->data; + for (GList *iter = scheduler->resources; iter != NULL; iter = iter->next) { + pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data; if (strcmp(rsc->id, "exim-group") == 0) { exim_group = rsc; @@ -80,14 +78,14 @@ setup(void **state) { static int teardown(void **state) { - pe_free_working_set(data_set); + pe_free_working_set(scheduler); return 0; } static void bad_args(void **state) { - pe_resource_t *rsc = (pe_resource_t *) g_list_first(data_set->resources)->data; + pcmk_resource_t *rsc = g_list_first(scheduler->resources)->data; char *id = rsc->id; char *name = NULL; @@ -117,11 +115,11 @@ bad_args(void **state) { static void primitive_rsc(void **state) { - pe_resource_t *dummy = NULL; + pcmk_resource_t *dummy = NULL; /* Find the "dummy" resource, which is the only one with that ID in the set. */ - for (GList *iter = data_set->resources; iter != NULL; iter = iter->next) { - pe_resource_t *rsc = (pe_resource_t *) iter->data; + for (GList *iter = scheduler->resources; iter != NULL; iter = iter->next) { + pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data; if (strcmp(rsc->id, "dummy") == 0) { dummy = rsc; @@ -133,20 +131,27 @@ primitive_rsc(void **state) { /* Passes because NULL was passed for node, regardless of flags. */ assert_ptr_equal(dummy, native_find_rsc(dummy, "dummy", NULL, 0)); - assert_ptr_equal(dummy, native_find_rsc(dummy, "dummy", NULL, pe_find_current)); + assert_ptr_equal(dummy, + native_find_rsc(dummy, "dummy", NULL, + pcmk_rsc_match_current_node)); /* Fails because resource is not a clone (nor cloned). */ - assert_null(native_find_rsc(dummy, "dummy", NULL, pe_find_clone)); - assert_null(native_find_rsc(dummy, "dummy", cluster02, pe_find_clone)); + assert_null(native_find_rsc(dummy, "dummy", NULL, + pcmk_rsc_match_clone_only)); + assert_null(native_find_rsc(dummy, "dummy", cluster02, + pcmk_rsc_match_clone_only)); /* Fails because dummy is not running on cluster01, even with the right flags. */ - assert_null(native_find_rsc(dummy, "dummy", cluster01, pe_find_current)); + assert_null(native_find_rsc(dummy, "dummy", cluster01, + pcmk_rsc_match_current_node)); - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(dummy, "dummy", cluster02, 0)); /* Passes because dummy is running on cluster02. */ - assert_ptr_equal(dummy, native_find_rsc(dummy, "dummy", cluster02, pe_find_current)); + assert_ptr_equal(dummy, + native_find_rsc(dummy, "dummy", cluster02, + pcmk_rsc_match_current_node)); } static void @@ -155,20 +160,27 @@ group_rsc(void **state) { /* Passes because NULL was passed for node, regardless of flags. */ assert_ptr_equal(exim_group, native_find_rsc(exim_group, "exim-group", NULL, 0)); - assert_ptr_equal(exim_group, native_find_rsc(exim_group, "exim-group", NULL, pe_find_current)); + assert_ptr_equal(exim_group, + native_find_rsc(exim_group, "exim-group", NULL, + pcmk_rsc_match_current_node)); /* Fails because resource is not a clone (nor cloned). */ - assert_null(native_find_rsc(exim_group, "exim-group", NULL, pe_find_clone)); - assert_null(native_find_rsc(exim_group, "exim-group", cluster01, pe_find_clone)); + assert_null(native_find_rsc(exim_group, "exim-group", NULL, + pcmk_rsc_match_clone_only)); + assert_null(native_find_rsc(exim_group, "exim-group", cluster01, + pcmk_rsc_match_clone_only)); /* Fails because none of exim-group's children are running on cluster01, even with the right flags. */ - assert_null(native_find_rsc(exim_group, "exim-group", cluster01, pe_find_current)); + assert_null(native_find_rsc(exim_group, "exim-group", cluster01, + pcmk_rsc_match_current_node)); - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(exim_group, "exim-group", cluster01, 0)); /* Passes because one of exim-group's children is running on cluster02. */ - assert_ptr_equal(exim_group, native_find_rsc(exim_group, "exim-group", cluster02, pe_find_current)); + assert_ptr_equal(exim_group, + native_find_rsc(exim_group, "exim-group", cluster02, + pcmk_rsc_match_current_node)); } static void @@ -177,30 +189,30 @@ inactive_group_rsc(void **state) { /* Passes because NULL was passed for node, regardless of flags. */ assert_ptr_equal(inactive_group, native_find_rsc(inactive_group, "inactive-group", NULL, 0)); - assert_ptr_equal(inactive_group, native_find_rsc(inactive_group, "inactive-group", NULL, pe_find_current)); - assert_ptr_equal(inactive_group, native_find_rsc(inactive_group, "inactive-group", NULL, pe_find_inactive)); + assert_ptr_equal(inactive_group, + native_find_rsc(inactive_group, "inactive-group", NULL, + pcmk_rsc_match_current_node)); /* Fails because resource is not a clone (nor cloned). */ - assert_null(native_find_rsc(inactive_group, "inactive-group", NULL, pe_find_clone)); - assert_null(native_find_rsc(inactive_group, "inactive-group", cluster01, pe_find_clone)); + assert_null(native_find_rsc(inactive_group, "inactive-group", NULL, + pcmk_rsc_match_clone_only)); + assert_null(native_find_rsc(inactive_group, "inactive-group", cluster01, + pcmk_rsc_match_clone_only)); /* Fails because none of inactive-group's children are running. */ - assert_null(native_find_rsc(inactive_group, "inactive-group", cluster01, pe_find_current)); - assert_null(native_find_rsc(inactive_group, "inactive-group", cluster02, pe_find_current)); - - /* Passes because of flags. */ - assert_ptr_equal(inactive_group, native_find_rsc(inactive_group, "inactive-group", cluster01, pe_find_inactive)); - /* Passes because of flags. */ - assert_ptr_equal(inactive_group, native_find_rsc(inactive_group, "inactive-group", cluster02, pe_find_inactive)); + assert_null(native_find_rsc(inactive_group, "inactive-group", cluster01, + pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(inactive_group, "inactive-group", cluster02, + pcmk_rsc_match_current_node)); } static void group_member_rsc(void **state) { - pe_resource_t *public_ip = NULL; + pcmk_resource_t *public_ip = NULL; /* Find the "Public-IP" resource, a member of "exim-group". */ for (GList *iter = exim_group->children; iter != NULL; iter = iter->next) { - pe_resource_t *rsc = (pe_resource_t *) iter->data; + pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data; if (strcmp(rsc->id, "Public-IP") == 0) { public_ip = rsc; @@ -212,29 +224,36 @@ group_member_rsc(void **state) { /* Passes because NULL was passed for node, regardless of flags. */ assert_ptr_equal(public_ip, native_find_rsc(public_ip, "Public-IP", NULL, 0)); - assert_ptr_equal(public_ip, native_find_rsc(public_ip, "Public-IP", NULL, pe_find_current)); + assert_ptr_equal(public_ip, + native_find_rsc(public_ip, "Public-IP", NULL, + pcmk_rsc_match_current_node)); /* Fails because resource is not a clone (nor cloned). */ - assert_null(native_find_rsc(public_ip, "Public-IP", NULL, pe_find_clone)); - assert_null(native_find_rsc(public_ip, "Public-IP", cluster02, pe_find_clone)); + assert_null(native_find_rsc(public_ip, "Public-IP", NULL, + pcmk_rsc_match_clone_only)); + assert_null(native_find_rsc(public_ip, "Public-IP", cluster02, + pcmk_rsc_match_clone_only)); /* Fails because Public-IP is not running on cluster01, even with the right flags. */ - assert_null(native_find_rsc(public_ip, "Public-IP", cluster01, pe_find_current)); + assert_null(native_find_rsc(public_ip, "Public-IP", cluster01, + pcmk_rsc_match_current_node)); - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(public_ip, "Public-IP", cluster02, 0)); /* Passes because Public-IP is running on cluster02. */ - assert_ptr_equal(public_ip, native_find_rsc(public_ip, "Public-IP", cluster02, pe_find_current)); + assert_ptr_equal(public_ip, + native_find_rsc(public_ip, "Public-IP", cluster02, + pcmk_rsc_match_current_node)); } static void inactive_group_member_rsc(void **state) { - pe_resource_t *inactive_dummy_1 = NULL; + pcmk_resource_t *inactive_dummy_1 = NULL; /* Find the "inactive-dummy-1" resource, a member of "inactive-group". */ for (GList *iter = inactive_group->children; iter != NULL; iter = iter->next) { - pe_resource_t *rsc = (pe_resource_t *) iter->data; + pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data; if (strcmp(rsc->id, "inactive-dummy-1") == 0) { inactive_dummy_1 = rsc; @@ -246,20 +265,21 @@ inactive_group_member_rsc(void **state) { /* Passes because NULL was passed for node, regardless of flags. */ assert_ptr_equal(inactive_dummy_1, native_find_rsc(inactive_dummy_1, "inactive-dummy-1", NULL, 0)); - assert_ptr_equal(inactive_dummy_1, native_find_rsc(inactive_dummy_1, "inactive-dummy-1", NULL, pe_find_current)); + assert_ptr_equal(inactive_dummy_1, + native_find_rsc(inactive_dummy_1, "inactive-dummy-1", NULL, + pcmk_rsc_match_current_node)); /* Fails because resource is not a clone (nor cloned). */ - assert_null(native_find_rsc(inactive_dummy_1, "inactive-dummy-1", NULL, pe_find_clone)); - assert_null(native_find_rsc(inactive_dummy_1, "inactive-dummy-1", cluster01, pe_find_clone)); + assert_null(native_find_rsc(inactive_dummy_1, "inactive-dummy-1", NULL, + pcmk_rsc_match_clone_only)); + assert_null(native_find_rsc(inactive_dummy_1, "inactive-dummy-1", cluster01, + pcmk_rsc_match_clone_only)); /* Fails because inactive-dummy-1 is not running. */ - assert_null(native_find_rsc(inactive_dummy_1, "inactive-dummy-1", cluster01, pe_find_current)); - assert_null(native_find_rsc(inactive_dummy_1, "inactive-dummy-1", cluster02, pe_find_current)); - - /* Passes because of flags. */ - assert_ptr_equal(inactive_dummy_1, native_find_rsc(inactive_dummy_1, "inactive-dummy-1", cluster01, pe_find_inactive)); - /* Passes because of flags. */ - assert_ptr_equal(inactive_dummy_1, native_find_rsc(inactive_dummy_1, "inactive-dummy-1", cluster02, pe_find_inactive)); + assert_null(native_find_rsc(inactive_dummy_1, "inactive-dummy-1", cluster01, + pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(inactive_dummy_1, "inactive-dummy-1", cluster02, + pcmk_rsc_match_current_node)); } static void @@ -268,24 +288,40 @@ clone_rsc(void **state) { /* Passes because NULL was passed for node, regardless of flags. */ assert_ptr_equal(promotable_clone, native_find_rsc(promotable_clone, "promotable-clone", NULL, 0)); - assert_ptr_equal(promotable_clone, native_find_rsc(promotable_clone, "promotable-clone", NULL, pe_find_current)); - assert_ptr_equal(promotable_clone, native_find_rsc(promotable_clone, "promotable-clone", NULL, pe_find_clone)); - - /* Fails because pe_find_current is required if a node is given. */ + assert_ptr_equal(promotable_clone, + native_find_rsc(promotable_clone, "promotable-clone", NULL, + pcmk_rsc_match_current_node)); + assert_ptr_equal(promotable_clone, + native_find_rsc(promotable_clone, "promotable-clone", NULL, + pcmk_rsc_match_clone_only)); + + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(promotable_clone, "promotable-clone", cluster01, 0)); /* Passes because one of ping-clone's children is running on cluster01. */ - assert_ptr_equal(promotable_clone, native_find_rsc(promotable_clone, "promotable-clone", cluster01, pe_find_current)); + assert_ptr_equal(promotable_clone, + native_find_rsc(promotable_clone, "promotable-clone", + cluster01, pcmk_rsc_match_current_node)); - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(promotable_clone, "promotable-clone", cluster02, 0)); /* Passes because one of ping_clone's children is running on cluster02. */ - assert_ptr_equal(promotable_clone, native_find_rsc(promotable_clone, "promotable-clone", cluster02, pe_find_current)); - - /* Passes for previous reasons, plus includes pe_find_clone check. */ - assert_ptr_equal(promotable_clone, native_find_rsc(promotable_clone, "promotable-clone", cluster01, pe_find_clone|pe_find_current)); - assert_ptr_equal(promotable_clone, native_find_rsc(promotable_clone, "promotable-clone", cluster02, pe_find_clone|pe_find_current)); + assert_ptr_equal(promotable_clone, + native_find_rsc(promotable_clone, "promotable-clone", + cluster02, pcmk_rsc_match_current_node)); + + // Passes for previous reasons, plus includes pcmk_rsc_match_clone_only + assert_ptr_equal(promotable_clone, + native_find_rsc(promotable_clone, "promotable-clone", + cluster01, + pcmk_rsc_match_clone_only + |pcmk_rsc_match_current_node)); + assert_ptr_equal(promotable_clone, + native_find_rsc(promotable_clone, "promotable-clone", + cluster02, + pcmk_rsc_match_clone_only + |pcmk_rsc_match_current_node)); } static void @@ -294,28 +330,30 @@ inactive_clone_rsc(void **state) { /* Passes because NULL was passed for node, regardless of flags. */ assert_ptr_equal(inactive_clone, native_find_rsc(inactive_clone, "inactive-clone", NULL, 0)); - assert_ptr_equal(inactive_clone, native_find_rsc(inactive_clone, "inactive-clone", NULL, pe_find_current)); - assert_ptr_equal(inactive_clone, native_find_rsc(inactive_clone, "inactive-clone", NULL, pe_find_clone)); - assert_ptr_equal(inactive_clone, native_find_rsc(inactive_clone, "inactive-clone", NULL, pe_find_inactive)); + assert_ptr_equal(inactive_clone, + native_find_rsc(inactive_clone, "inactive-clone", NULL, + pcmk_rsc_match_current_node)); + assert_ptr_equal(inactive_clone, + native_find_rsc(inactive_clone, "inactive-clone", NULL, + pcmk_rsc_match_clone_only)); /* Fails because none of inactive-clone's children are running. */ - assert_null(native_find_rsc(inactive_clone, "inactive-clone", cluster01, pe_find_current|pe_find_clone)); - assert_null(native_find_rsc(inactive_clone, "inactive-clone", cluster02, pe_find_current|pe_find_clone)); - - /* Passes because of flags. */ - assert_ptr_equal(inactive_clone, native_find_rsc(inactive_clone, "inactive-clone", cluster01, pe_find_inactive)); - /* Passes because of flags. */ - assert_ptr_equal(inactive_clone, native_find_rsc(inactive_clone, "inactive-clone", cluster02, pe_find_inactive)); + assert_null(native_find_rsc(inactive_clone, "inactive-clone", cluster01, + pcmk_rsc_match_current_node + |pcmk_rsc_match_clone_only)); + assert_null(native_find_rsc(inactive_clone, "inactive-clone", cluster02, + pcmk_rsc_match_current_node + |pcmk_rsc_match_clone_only)); } static void clone_instance_rsc(void **state) { - pe_resource_t *promotable_0 = NULL; - pe_resource_t *promotable_1 = NULL; + pcmk_resource_t *promotable_0 = NULL; + pcmk_resource_t *promotable_1 = NULL; /* Find the "promotable-rsc:0" and "promotable-rsc:1" resources, members of "promotable-clone". */ for (GList *iter = promotable_clone->children; iter != NULL; iter = iter->next) { - pe_resource_t *rsc = (pe_resource_t *) iter->data; + pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data; if (strcmp(rsc->id, "promotable-rsc:0") == 0) { promotable_0 = rsc; @@ -329,70 +367,132 @@ clone_instance_rsc(void **state) { /* Passes because NULL was passed for node, regardless of flags. */ assert_ptr_equal(promotable_0, native_find_rsc(promotable_0, "promotable-rsc:0", NULL, 0)); - assert_ptr_equal(promotable_0, native_find_rsc(promotable_0, "promotable-rsc:0", NULL, pe_find_current)); + assert_ptr_equal(promotable_0, + native_find_rsc(promotable_0, "promotable-rsc:0", NULL, + pcmk_rsc_match_current_node)); assert_ptr_equal(promotable_1, native_find_rsc(promotable_1, "promotable-rsc:1", NULL, 0)); - assert_ptr_equal(promotable_1, native_find_rsc(promotable_1, "promotable-rsc:1", NULL, pe_find_current)); + assert_ptr_equal(promotable_1, + native_find_rsc(promotable_1, "promotable-rsc:1", NULL, + pcmk_rsc_match_current_node)); - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(promotable_0, "promotable-rsc:0", cluster02, 0)); assert_null(native_find_rsc(promotable_1, "promotable-rsc:1", cluster01, 0)); /* Check that the resource is running on the node we expect. */ - assert_ptr_equal(promotable_0, native_find_rsc(promotable_0, "promotable-rsc:0", cluster02, pe_find_current)); - assert_null(native_find_rsc(promotable_0, "promotable-rsc:0", cluster01, pe_find_current)); - assert_ptr_equal(promotable_1, native_find_rsc(promotable_1, "promotable-rsc:1", cluster01, pe_find_current)); - assert_null(native_find_rsc(promotable_1, "promotable-rsc:1", cluster02, pe_find_current)); + assert_ptr_equal(promotable_0, + native_find_rsc(promotable_0, "promotable-rsc:0", + cluster02, pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(promotable_0, "promotable-rsc:0", cluster01, + pcmk_rsc_match_current_node)); + assert_ptr_equal(promotable_1, + native_find_rsc(promotable_1, "promotable-rsc:1", + cluster01, pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(promotable_1, "promotable-rsc:1", cluster02, + pcmk_rsc_match_current_node)); /* Passes because NULL was passed for node and primitive name was given, with correct flags. */ - assert_ptr_equal(promotable_0, native_find_rsc(promotable_0, "promotable-rsc", NULL, pe_find_clone)); - - /* Passes because pe_find_any matches any instance's base name. */ - assert_ptr_equal(promotable_0, native_find_rsc(promotable_0, "promotable-rsc", NULL, pe_find_any)); - assert_ptr_equal(promotable_1, native_find_rsc(promotable_1, "promotable-rsc", NULL, pe_find_any)); - - /* Passes because pe_find_anon matches. */ - assert_ptr_equal(promotable_0, native_find_rsc(promotable_0, "promotable-rsc", NULL, pe_find_anon)); - assert_ptr_equal(promotable_1, native_find_rsc(promotable_1, "promotable-rsc", NULL, pe_find_anon)); + assert_ptr_equal(promotable_0, + native_find_rsc(promotable_0, "promotable-rsc", NULL, + pcmk_rsc_match_clone_only)); + + // Passes because pcmk_rsc_match_basename matches any instance's base name + assert_ptr_equal(promotable_0, + native_find_rsc(promotable_0, "promotable-rsc", NULL, + pcmk_rsc_match_basename)); + assert_ptr_equal(promotable_1, + native_find_rsc(promotable_1, "promotable-rsc", NULL, + pcmk_rsc_match_basename)); + + // Passes because pcmk_rsc_match_anon_basename matches + assert_ptr_equal(promotable_0, + native_find_rsc(promotable_0, "promotable-rsc", NULL, + pcmk_rsc_match_anon_basename)); + assert_ptr_equal(promotable_1, + native_find_rsc(promotable_1, "promotable-rsc", NULL, + pcmk_rsc_match_anon_basename)); /* Check that the resource is running on the node we expect. */ - assert_ptr_equal(promotable_0, native_find_rsc(promotable_0, "promotable-rsc", cluster02, pe_find_any|pe_find_current)); - assert_ptr_equal(promotable_0, native_find_rsc(promotable_0, "promotable-rsc", cluster02, pe_find_anon|pe_find_current)); - assert_null(native_find_rsc(promotable_0, "promotable-rsc", cluster01, pe_find_any|pe_find_current)); - assert_null(native_find_rsc(promotable_0, "promotable-rsc", cluster01, pe_find_anon|pe_find_current)); - assert_ptr_equal(promotable_1, native_find_rsc(promotable_1, "promotable-rsc", cluster01, pe_find_any|pe_find_current)); - assert_ptr_equal(promotable_1, native_find_rsc(promotable_1, "promotable-rsc", cluster01, pe_find_anon|pe_find_current)); - assert_null(native_find_rsc(promotable_1, "promotable-rsc", cluster02, pe_find_any|pe_find_current)); - assert_null(native_find_rsc(promotable_1, "promotable-rsc", cluster02, pe_find_anon|pe_find_current)); + assert_ptr_equal(promotable_0, + native_find_rsc(promotable_0, "promotable-rsc", cluster02, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(promotable_0, + native_find_rsc(promotable_0, "promotable-rsc", cluster02, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(promotable_0, "promotable-rsc", cluster01, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(promotable_0, "promotable-rsc", cluster01, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(promotable_1, + native_find_rsc(promotable_1, "promotable-rsc", cluster01, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(promotable_1, + native_find_rsc(promotable_1, "promotable-rsc", cluster01, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(promotable_1, "promotable-rsc", cluster02, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(promotable_1, "promotable-rsc", cluster02, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); /* Fails because incorrect flags were given along with primitive name. */ - assert_null(native_find_rsc(promotable_0, "promotable-rsc", NULL, pe_find_current)); - assert_null(native_find_rsc(promotable_1, "promotable-rsc", NULL, pe_find_current)); + assert_null(native_find_rsc(promotable_0, "promotable-rsc", NULL, + pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(promotable_1, "promotable-rsc", NULL, + pcmk_rsc_match_current_node)); /* And then we check failure possibilities again, except passing promotable_clone * instead of promotable_X as the first argument to native_find_rsc. */ - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(promotable_clone, "promotable-rsc:0", cluster02, 0)); assert_null(native_find_rsc(promotable_clone, "promotable-rsc:1", cluster01, 0)); /* Check that the resource is running on the node we expect. */ - assert_ptr_equal(promotable_0, native_find_rsc(promotable_clone, "promotable-rsc:0", cluster02, pe_find_current)); - assert_ptr_equal(promotable_0, native_find_rsc(promotable_clone, "promotable-rsc", cluster02, pe_find_any|pe_find_current)); - assert_ptr_equal(promotable_0, native_find_rsc(promotable_clone, "promotable-rsc", cluster02, pe_find_anon|pe_find_current)); - assert_ptr_equal(promotable_1, native_find_rsc(promotable_clone, "promotable-rsc:1", cluster01, pe_find_current)); - assert_ptr_equal(promotable_1, native_find_rsc(promotable_clone, "promotable-rsc", cluster01, pe_find_any|pe_find_current)); - assert_ptr_equal(promotable_1, native_find_rsc(promotable_clone, "promotable-rsc", cluster01, pe_find_anon|pe_find_current)); + assert_ptr_equal(promotable_0, + native_find_rsc(promotable_clone, "promotable-rsc:0", + cluster02, pcmk_rsc_match_current_node)); + assert_ptr_equal(promotable_0, + native_find_rsc(promotable_clone, "promotable-rsc", + cluster02, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(promotable_0, + native_find_rsc(promotable_clone, "promotable-rsc", + cluster02, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(promotable_1, + native_find_rsc(promotable_clone, "promotable-rsc:1", + cluster01, pcmk_rsc_match_current_node)); + assert_ptr_equal(promotable_1, + native_find_rsc(promotable_clone, "promotable-rsc", + cluster01, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(promotable_1, + native_find_rsc(promotable_clone, "promotable-rsc", + cluster01, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); } static void renamed_rsc(void **state) { - pe_resource_t *promotable_0 = NULL; - pe_resource_t *promotable_1 = NULL; + pcmk_resource_t *promotable_0 = NULL; + pcmk_resource_t *promotable_1 = NULL; /* Find the "promotable-rsc:0" and "promotable-rsc:1" resources, members of "promotable-clone". */ for (GList *iter = promotable_clone->children; iter != NULL; iter = iter->next) { - pe_resource_t *rsc = (pe_resource_t *) iter->data; + pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data; if (strcmp(rsc->id, "promotable-rsc:0") == 0) { promotable_0 = rsc; @@ -404,9 +504,13 @@ renamed_rsc(void **state) { assert_non_null(promotable_0); assert_non_null(promotable_1); - /* Passes because pe_find_renamed means the base name matches clone_name. */ - assert_ptr_equal(promotable_0, native_find_rsc(promotable_0, "promotable-rsc", NULL, pe_find_renamed)); - assert_ptr_equal(promotable_1, native_find_rsc(promotable_1, "promotable-rsc", NULL, pe_find_renamed)); + // Passes because pcmk_rsc_match_history means base name matches clone_name + assert_ptr_equal(promotable_0, + native_find_rsc(promotable_0, "promotable-rsc", NULL, + pcmk_rsc_match_history)); + assert_ptr_equal(promotable_1, + native_find_rsc(promotable_1, "promotable-rsc", NULL, + pcmk_rsc_match_history)); } static void @@ -415,36 +519,32 @@ bundle_rsc(void **state) { /* Passes because NULL was passed for node, regardless of flags. */ assert_ptr_equal(httpd_bundle, native_find_rsc(httpd_bundle, "httpd-bundle", NULL, 0)); - assert_ptr_equal(httpd_bundle, native_find_rsc(httpd_bundle, "httpd-bundle", NULL, pe_find_current)); + assert_ptr_equal(httpd_bundle, + native_find_rsc(httpd_bundle, "httpd-bundle", NULL, + pcmk_rsc_match_current_node)); /* Fails because resource is not a clone (nor cloned). */ - assert_null(native_find_rsc(httpd_bundle, "httpd-bundle", NULL, pe_find_clone)); - assert_null(native_find_rsc(httpd_bundle, "httpd-bundle", cluster01, pe_find_clone)); + assert_null(native_find_rsc(httpd_bundle, "httpd-bundle", NULL, + pcmk_rsc_match_clone_only)); + assert_null(native_find_rsc(httpd_bundle, "httpd-bundle", cluster01, + pcmk_rsc_match_clone_only)); - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(httpd_bundle, "httpd-bundle", cluster01, 0)); /* Passes because one of httpd_bundle's children is running on cluster01. */ - assert_ptr_equal(httpd_bundle, native_find_rsc(httpd_bundle, "httpd-bundle", cluster01, pe_find_current)); + assert_ptr_equal(httpd_bundle, + native_find_rsc(httpd_bundle, "httpd-bundle", cluster01, + pcmk_rsc_match_current_node)); } -static void -bundle_replica_rsc(void **state) { - pe__bundle_variant_data_t *bundle_data = NULL; - pe__bundle_replica_t *replica_0 = NULL; - - pe_resource_t *ip_0 = NULL; - pe_resource_t *child_0 = NULL; - pe_resource_t *container_0 = NULL; - pe_resource_t *remote_0 = NULL; - - get_bundle_variant_data(bundle_data, httpd_bundle); - replica_0 = (pe__bundle_replica_t *) bundle_data->replicas->data; - - ip_0 = replica_0->ip; - child_0 = replica_0->child; - container_0 = replica_0->container; - remote_0 = replica_0->remote; +static bool +bundle_first_replica(pe__bundle_replica_t *replica, void *user_data) +{ + pcmk_resource_t *ip_0 = replica->ip; + pcmk_resource_t *child_0 = replica->child; + pcmk_resource_t *container_0 = replica->container; + pcmk_resource_t *remote_0 = replica->remote; assert_non_null(ip_0); assert_non_null(child_0); @@ -457,58 +557,109 @@ bundle_replica_rsc(void **state) { assert_ptr_equal(container_0, native_find_rsc(container_0, "httpd-bundle-docker-0", NULL, 0)); assert_ptr_equal(remote_0, native_find_rsc(remote_0, "httpd-bundle-0", NULL, 0)); - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(ip_0, "httpd-bundle-ip-192.168.122.131", cluster01, 0)); assert_null(native_find_rsc(child_0, "httpd:0", httpd_bundle_0, 0)); assert_null(native_find_rsc(container_0, "httpd-bundle-docker-0", cluster01, 0)); assert_null(native_find_rsc(remote_0, "httpd-bundle-0", cluster01, 0)); /* Check that the resource is running on the node we expect. */ - assert_ptr_equal(ip_0, native_find_rsc(ip_0, "httpd-bundle-ip-192.168.122.131", cluster01, pe_find_current)); - assert_null(native_find_rsc(ip_0, "httpd-bundle-ip-192.168.122.131", cluster02, pe_find_current)); - assert_null(native_find_rsc(ip_0, "httpd-bundle-ip-192.168.122.131", httpd_bundle_0, pe_find_current)); - assert_ptr_equal(child_0, native_find_rsc(child_0, "httpd:0", httpd_bundle_0, pe_find_current)); - assert_null(native_find_rsc(child_0, "httpd:0", cluster01, pe_find_current)); - assert_null(native_find_rsc(child_0, "httpd:0", cluster02, pe_find_current)); - assert_ptr_equal(container_0, native_find_rsc(container_0, "httpd-bundle-docker-0", cluster01, pe_find_current)); - assert_null(native_find_rsc(container_0, "httpd-bundle-docker-0", cluster02, pe_find_current)); - assert_null(native_find_rsc(container_0, "httpd-bundle-docker-0", httpd_bundle_0, pe_find_current)); - assert_ptr_equal(remote_0, native_find_rsc(remote_0, "httpd-bundle-0", cluster01, pe_find_current)); - assert_null(native_find_rsc(remote_0, "httpd-bundle-0", cluster02, pe_find_current)); - assert_null(native_find_rsc(remote_0, "httpd-bundle-0", httpd_bundle_0, pe_find_current)); - - /* Passes because pe_find_any matches any replica's base name. */ - assert_ptr_equal(child_0, native_find_rsc(child_0, "httpd", NULL, pe_find_any)); - - /* Passes because pe_find_anon matches. */ - assert_ptr_equal(child_0, native_find_rsc(child_0, "httpd", NULL, pe_find_anon)); + assert_ptr_equal(ip_0, + native_find_rsc(ip_0, "httpd-bundle-ip-192.168.122.131", + cluster01, pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(ip_0, "httpd-bundle-ip-192.168.122.131", + cluster02, pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(ip_0, "httpd-bundle-ip-192.168.122.131", + httpd_bundle_0, pcmk_rsc_match_current_node)); + assert_ptr_equal(child_0, + native_find_rsc(child_0, "httpd:0", httpd_bundle_0, + pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(child_0, "httpd:0", cluster01, + pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(child_0, "httpd:0", cluster02, + pcmk_rsc_match_current_node)); + assert_ptr_equal(container_0, + native_find_rsc(container_0, "httpd-bundle-docker-0", + cluster01, pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(container_0, "httpd-bundle-docker-0", cluster02, + pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(container_0, "httpd-bundle-docker-0", + httpd_bundle_0, pcmk_rsc_match_current_node)); + assert_ptr_equal(remote_0, + native_find_rsc(remote_0, "httpd-bundle-0", cluster01, + pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(remote_0, "httpd-bundle-0", cluster02, + pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(remote_0, "httpd-bundle-0", httpd_bundle_0, + pcmk_rsc_match_current_node)); + + // Passes because pcmk_rsc_match_basename matches any replica's base name + assert_ptr_equal(child_0, + native_find_rsc(child_0, "httpd", NULL, + pcmk_rsc_match_basename)); + + // Passes because pcmk_rsc_match_anon_basename matches + assert_ptr_equal(child_0, + native_find_rsc(child_0, "httpd", NULL, + pcmk_rsc_match_anon_basename)); /* Check that the resource is running on the node we expect. */ - assert_ptr_equal(child_0, native_find_rsc(child_0, "httpd", httpd_bundle_0, pe_find_any|pe_find_current)); - assert_ptr_equal(child_0, native_find_rsc(child_0, "httpd", httpd_bundle_0, pe_find_anon|pe_find_current)); - assert_null(native_find_rsc(child_0, "httpd", cluster01, pe_find_any|pe_find_current)); - assert_null(native_find_rsc(child_0, "httpd", cluster01, pe_find_anon|pe_find_current)); - assert_null(native_find_rsc(child_0, "httpd", cluster02, pe_find_any|pe_find_current)); - assert_null(native_find_rsc(child_0, "httpd", cluster02, pe_find_anon|pe_find_current)); + assert_ptr_equal(child_0, + native_find_rsc(child_0, "httpd", httpd_bundle_0, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(child_0, + native_find_rsc(child_0, "httpd", httpd_bundle_0, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(child_0, "httpd", cluster01, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(child_0, "httpd", cluster01, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(child_0, "httpd", cluster02, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(child_0, "httpd", cluster02, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); /* Fails because incorrect flags were given along with base name. */ - assert_null(native_find_rsc(child_0, "httpd", NULL, pe_find_current)); + assert_null(native_find_rsc(child_0, "httpd", NULL, + pcmk_rsc_match_current_node)); /* And then we check failure possibilities again, except passing httpd-bundle * instead of X_0 as the first argument to native_find_rsc. */ - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(httpd_bundle, "httpd-bundle-ip-192.168.122.131", cluster01, 0)); assert_null(native_find_rsc(httpd_bundle, "httpd:0", httpd_bundle_0, 0)); assert_null(native_find_rsc(httpd_bundle, "httpd-bundle-docker-0", cluster01, 0)); assert_null(native_find_rsc(httpd_bundle, "httpd-bundle-0", cluster01, 0)); /* Check that the resource is running on the node we expect. */ - assert_ptr_equal(ip_0, native_find_rsc(httpd_bundle, "httpd-bundle-ip-192.168.122.131", cluster01, pe_find_current)); - assert_ptr_equal(child_0, native_find_rsc(httpd_bundle, "httpd:0", httpd_bundle_0, pe_find_current)); - assert_ptr_equal(container_0, native_find_rsc(httpd_bundle, "httpd-bundle-docker-0", cluster01, pe_find_current)); - assert_ptr_equal(remote_0, native_find_rsc(httpd_bundle, "httpd-bundle-0", cluster01, pe_find_current)); + assert_ptr_equal(ip_0, + native_find_rsc(httpd_bundle, + "httpd-bundle-ip-192.168.122.131", + cluster01, pcmk_rsc_match_current_node)); + assert_ptr_equal(child_0, + native_find_rsc(httpd_bundle, "httpd:0", httpd_bundle_0, + pcmk_rsc_match_current_node)); + assert_ptr_equal(container_0, + native_find_rsc(httpd_bundle, "httpd-bundle-docker-0", + cluster01, pcmk_rsc_match_current_node)); + assert_ptr_equal(remote_0, + native_find_rsc(httpd_bundle, "httpd-bundle-0", cluster01, + pcmk_rsc_match_current_node)); + return false; // Do not iterate through any further replicas +} + +static void +bundle_replica_rsc(void **state) +{ + pe__foreach_bundle_replica(httpd_bundle, bundle_first_replica, NULL); } static void @@ -517,34 +668,50 @@ clone_group_rsc(void **rsc) { /* Passes because NULL was passed for node, regardless of flags. */ assert_ptr_equal(mysql_clone_group, native_find_rsc(mysql_clone_group, "mysql-clone-group", NULL, 0)); - assert_ptr_equal(mysql_clone_group, native_find_rsc(mysql_clone_group, "mysql-clone-group", NULL, pe_find_current)); - assert_ptr_equal(mysql_clone_group, native_find_rsc(mysql_clone_group, "mysql-clone-group", NULL, pe_find_clone)); - - /* Fails because pe_find_current is required if a node is given. */ + assert_ptr_equal(mysql_clone_group, + native_find_rsc(mysql_clone_group, "mysql-clone-group", + NULL, pcmk_rsc_match_current_node)); + assert_ptr_equal(mysql_clone_group, + native_find_rsc(mysql_clone_group, "mysql-clone-group", + NULL, pcmk_rsc_match_clone_only)); + + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(mysql_clone_group, "mysql-clone-group", cluster01, 0)); /* Passes because one of mysql-clone-group's children is running on cluster01. */ - assert_ptr_equal(mysql_clone_group, native_find_rsc(mysql_clone_group, "mysql-clone-group", cluster01, pe_find_current)); + assert_ptr_equal(mysql_clone_group, + native_find_rsc(mysql_clone_group, "mysql-clone-group", + cluster01, pcmk_rsc_match_current_node)); - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(mysql_clone_group, "mysql-clone-group", cluster02, 0)); /* Passes because one of mysql-clone-group's children is running on cluster02. */ - assert_ptr_equal(mysql_clone_group, native_find_rsc(mysql_clone_group, "mysql-clone-group", cluster02, pe_find_current)); - - /* Passes for previous reasons, plus includes pe_find_clone check. */ - assert_ptr_equal(mysql_clone_group, native_find_rsc(mysql_clone_group, "mysql-clone-group", cluster01, pe_find_clone|pe_find_current)); - assert_ptr_equal(mysql_clone_group, native_find_rsc(mysql_clone_group, "mysql-clone-group", cluster02, pe_find_clone|pe_find_current)); + assert_ptr_equal(mysql_clone_group, + native_find_rsc(mysql_clone_group, "mysql-clone-group", + cluster02, pcmk_rsc_match_current_node)); + + // Passes for previous reasons, plus includes pcmk_rsc_match_clone_only + assert_ptr_equal(mysql_clone_group, + native_find_rsc(mysql_clone_group, "mysql-clone-group", + cluster01, + pcmk_rsc_match_clone_only + |pcmk_rsc_match_current_node)); + assert_ptr_equal(mysql_clone_group, + native_find_rsc(mysql_clone_group, "mysql-clone-group", + cluster02, + pcmk_rsc_match_clone_only + |pcmk_rsc_match_current_node)); } static void clone_group_instance_rsc(void **rsc) { - pe_resource_t *mysql_group_0 = NULL; - pe_resource_t *mysql_group_1 = NULL; + pcmk_resource_t *mysql_group_0 = NULL; + pcmk_resource_t *mysql_group_1 = NULL; /* Find the "mysql-group:0" and "mysql-group:1" resources, members of "mysql-clone-group". */ for (GList *iter = mysql_clone_group->children; iter != NULL; iter = iter->next) { - pe_resource_t *rsc = (pe_resource_t *) iter->data; + pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data; if (strcmp(rsc->id, "mysql-group:0") == 0) { mysql_group_0 = rsc; @@ -558,73 +725,135 @@ clone_group_instance_rsc(void **rsc) { /* Passes because NULL was passed for node, regardless of flags. */ assert_ptr_equal(mysql_group_0, native_find_rsc(mysql_group_0, "mysql-group:0", NULL, 0)); - assert_ptr_equal(mysql_group_0, native_find_rsc(mysql_group_0, "mysql-group:0", NULL, pe_find_current)); + assert_ptr_equal(mysql_group_0, + native_find_rsc(mysql_group_0, "mysql-group:0", NULL, + pcmk_rsc_match_current_node)); assert_ptr_equal(mysql_group_1, native_find_rsc(mysql_group_1, "mysql-group:1", NULL, 0)); - assert_ptr_equal(mysql_group_1, native_find_rsc(mysql_group_1, "mysql-group:1", NULL, pe_find_current)); + assert_ptr_equal(mysql_group_1, + native_find_rsc(mysql_group_1, "mysql-group:1", NULL, + pcmk_rsc_match_current_node)); - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(mysql_group_0, "mysql-group:0", cluster02, 0)); assert_null(native_find_rsc(mysql_group_1, "mysql-group:1", cluster01, 0)); /* Check that the resource is running on the node we expect. */ - assert_ptr_equal(mysql_group_0, native_find_rsc(mysql_group_0, "mysql-group:0", cluster02, pe_find_current)); - assert_null(native_find_rsc(mysql_group_0, "mysql-group:0", cluster01, pe_find_current)); - assert_ptr_equal(mysql_group_1, native_find_rsc(mysql_group_1, "mysql-group:1", cluster01, pe_find_current)); - assert_null(native_find_rsc(mysql_group_1, "mysql-group:1", cluster02, pe_find_current)); + assert_ptr_equal(mysql_group_0, + native_find_rsc(mysql_group_0, "mysql-group:0", cluster02, + pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(mysql_group_0, "mysql-group:0", cluster01, + pcmk_rsc_match_current_node)); + assert_ptr_equal(mysql_group_1, + native_find_rsc(mysql_group_1, "mysql-group:1", cluster01, + pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(mysql_group_1, "mysql-group:1", cluster02, + pcmk_rsc_match_current_node)); /* Passes because NULL was passed for node and base name was given, with correct flags. */ - assert_ptr_equal(mysql_group_0, native_find_rsc(mysql_group_0, "mysql-group" , NULL, pe_find_clone)); - - /* Passes because pe_find_any matches any base name. */ - assert_ptr_equal(mysql_group_0, native_find_rsc(mysql_group_0, "mysql-group" , NULL, pe_find_any)); - assert_ptr_equal(mysql_group_1, native_find_rsc(mysql_group_1, "mysql-group" , NULL, pe_find_any)); - - /* Passes because pe_find_anon matches. */ - assert_ptr_equal(mysql_group_0, native_find_rsc(mysql_group_0, "mysql-group" , NULL, pe_find_anon)); - assert_ptr_equal(mysql_group_1, native_find_rsc(mysql_group_1, "mysql-group" , NULL, pe_find_anon)); + assert_ptr_equal(mysql_group_0, + native_find_rsc(mysql_group_0, "mysql-group" , NULL, + pcmk_rsc_match_clone_only)); + + // Passes because pcmk_rsc_match_basename matches any base name + assert_ptr_equal(mysql_group_0, + native_find_rsc(mysql_group_0, "mysql-group" , NULL, + pcmk_rsc_match_basename)); + assert_ptr_equal(mysql_group_1, + native_find_rsc(mysql_group_1, "mysql-group" , NULL, + pcmk_rsc_match_basename)); + + // Passes because pcmk_rsc_match_anon_basename matches + assert_ptr_equal(mysql_group_0, + native_find_rsc(mysql_group_0, "mysql-group" , NULL, + pcmk_rsc_match_anon_basename)); + assert_ptr_equal(mysql_group_1, + native_find_rsc(mysql_group_1, "mysql-group" , NULL, + pcmk_rsc_match_anon_basename)); /* Check that the resource is running on the node we expect. */ - assert_ptr_equal(mysql_group_0, native_find_rsc(mysql_group_0, "mysql-group", cluster02, pe_find_any|pe_find_current)); - assert_ptr_equal(mysql_group_0, native_find_rsc(mysql_group_0, "mysql-group", cluster02, pe_find_anon|pe_find_current)); - assert_null(native_find_rsc(mysql_group_0, "mysql-group", cluster01, pe_find_any|pe_find_current)); - assert_null(native_find_rsc(mysql_group_0, "mysql-group", cluster01, pe_find_anon|pe_find_current)); - assert_ptr_equal(mysql_group_1, native_find_rsc(mysql_group_1, "mysql-group", cluster01, pe_find_any|pe_find_current)); - assert_ptr_equal(mysql_group_1, native_find_rsc(mysql_group_1, "mysql-group", cluster01, pe_find_anon|pe_find_current)); - assert_null(native_find_rsc(mysql_group_1, "mysql-group", cluster02, pe_find_any|pe_find_current)); - assert_null(native_find_rsc(mysql_group_1, "mysql-group", cluster02, pe_find_anon|pe_find_current)); + assert_ptr_equal(mysql_group_0, + native_find_rsc(mysql_group_0, "mysql-group", cluster02, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(mysql_group_0, + native_find_rsc(mysql_group_0, "mysql-group", cluster02, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(mysql_group_0, "mysql-group", cluster01, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(mysql_group_0, "mysql-group", cluster01, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(mysql_group_1, + native_find_rsc(mysql_group_1, "mysql-group", cluster01, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(mysql_group_1, + native_find_rsc(mysql_group_1, "mysql-group", cluster01, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(mysql_group_1, "mysql-group", cluster02, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(mysql_group_1, "mysql-group", cluster02, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); /* Fails because incorrect flags were given along with base name. */ - assert_null(native_find_rsc(mysql_group_0, "mysql-group", NULL, pe_find_current)); - assert_null(native_find_rsc(mysql_group_1, "mysql-group", NULL, pe_find_current)); + assert_null(native_find_rsc(mysql_group_0, "mysql-group", NULL, + pcmk_rsc_match_current_node)); + assert_null(native_find_rsc(mysql_group_1, "mysql-group", NULL, + pcmk_rsc_match_current_node)); /* And then we check failure possibilities again, except passing mysql_clone_group * instead of mysql_group_X as the first argument to native_find_rsc. */ - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(mysql_clone_group, "mysql-group:0", cluster02, 0)); assert_null(native_find_rsc(mysql_clone_group, "mysql-group:1", cluster01, 0)); /* Check that the resource is running on the node we expect. */ - assert_ptr_equal(mysql_group_0, native_find_rsc(mysql_clone_group, "mysql-group:0", cluster02, pe_find_current)); - assert_ptr_equal(mysql_group_0, native_find_rsc(mysql_clone_group, "mysql-group", cluster02, pe_find_any|pe_find_current)); - assert_ptr_equal(mysql_group_0, native_find_rsc(mysql_clone_group, "mysql-group", cluster02, pe_find_anon|pe_find_current)); - assert_ptr_equal(mysql_group_1, native_find_rsc(mysql_clone_group, "mysql-group:1", cluster01, pe_find_current)); - assert_ptr_equal(mysql_group_1, native_find_rsc(mysql_clone_group, "mysql-group", cluster01, pe_find_any|pe_find_current)); - assert_ptr_equal(mysql_group_1, native_find_rsc(mysql_clone_group, "mysql-group", cluster01, pe_find_anon|pe_find_current)); + assert_ptr_equal(mysql_group_0, + native_find_rsc(mysql_clone_group, "mysql-group:0", + cluster02, pcmk_rsc_match_current_node)); + assert_ptr_equal(mysql_group_0, + native_find_rsc(mysql_clone_group, "mysql-group", + cluster02, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(mysql_group_0, + native_find_rsc(mysql_clone_group, "mysql-group", + cluster02, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(mysql_group_1, + native_find_rsc(mysql_clone_group, "mysql-group:1", + cluster01, pcmk_rsc_match_current_node)); + assert_ptr_equal(mysql_group_1, + native_find_rsc(mysql_clone_group, "mysql-group", + cluster01, + pcmk_rsc_match_basename + |pcmk_rsc_match_current_node)); + assert_ptr_equal(mysql_group_1, + native_find_rsc(mysql_clone_group, "mysql-group", + cluster01, + pcmk_rsc_match_anon_basename + |pcmk_rsc_match_current_node)); } static void clone_group_member_rsc(void **state) { - pe_resource_t *mysql_proxy = NULL; + pcmk_resource_t *mysql_proxy = NULL; /* Find the "mysql-proxy" resource, a member of "mysql-group". */ for (GList *iter = mysql_clone_group->children; iter != NULL; iter = iter->next) { - pe_resource_t *rsc = (pe_resource_t *) iter->data; + pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data; if (strcmp(rsc->id, "mysql-group:0") == 0) { for (GList *iter2 = rsc->children; iter2 != NULL; iter2 = iter2->next) { - pe_resource_t *child = (pe_resource_t *) iter2->data; + pcmk_resource_t *child = (pcmk_resource_t *) iter2->data; if (strcmp(child->id, "mysql-proxy:0") == 0) { mysql_proxy = child; @@ -640,24 +869,35 @@ clone_group_member_rsc(void **state) { /* Passes because NULL was passed for node, regardless of flags. */ assert_ptr_equal(mysql_proxy, native_find_rsc(mysql_proxy, "mysql-proxy:0", NULL, 0)); - assert_ptr_equal(mysql_proxy, native_find_rsc(mysql_proxy, "mysql-proxy:0", NULL, pe_find_current)); + assert_ptr_equal(mysql_proxy, + native_find_rsc(mysql_proxy, "mysql-proxy:0", NULL, + pcmk_rsc_match_current_node)); /* Passes because resource's parent is a clone. */ - assert_ptr_equal(mysql_proxy, native_find_rsc(mysql_proxy, "mysql-proxy:0", NULL, pe_find_clone)); - assert_ptr_equal(mysql_proxy, native_find_rsc(mysql_proxy, "mysql-proxy:0", cluster02, pe_find_clone|pe_find_current)); + assert_ptr_equal(mysql_proxy, + native_find_rsc(mysql_proxy, "mysql-proxy:0", NULL, + pcmk_rsc_match_clone_only)); + assert_ptr_equal(mysql_proxy, + native_find_rsc(mysql_proxy, "mysql-proxy:0", cluster02, + pcmk_rsc_match_clone_only + |pcmk_rsc_match_current_node)); /* Fails because mysql-proxy:0 is not running on cluster01, even with the right flags. */ - assert_null(native_find_rsc(mysql_proxy, "mysql-proxy:0", cluster01, pe_find_current)); + assert_null(native_find_rsc(mysql_proxy, "mysql-proxy:0", cluster01, + pcmk_rsc_match_current_node)); - /* Fails because pe_find_current is required if a node is given. */ + // Fails because pcmk_rsc_match_current_node is required if a node is given assert_null(native_find_rsc(mysql_proxy, "mysql-proxy:0", cluster02, 0)); /* Passes because mysql-proxy:0 is running on cluster02. */ - assert_ptr_equal(mysql_proxy, native_find_rsc(mysql_proxy, "mysql-proxy:0", cluster02, pe_find_current)); + assert_ptr_equal(mysql_proxy, + native_find_rsc(mysql_proxy, "mysql-proxy:0", cluster02, + pcmk_rsc_match_current_node)); } -/* TODO: Add tests for finding on allocated node (passing a node without - * pe_find_current, after scheduling, for a resource that is starting/stopping/moving. +/* TODO: Add tests for finding on assigned node (passing a node without + * pcmk_rsc_match_current_node, after scheduling, for a resource that is + * starting/stopping/moving. */ PCMK__UNIT_TEST(setup, teardown, cmocka_unit_test(bad_args), diff --git a/lib/pengine/tests/native/pe_base_name_eq_test.c b/lib/pengine/tests/native/pe_base_name_eq_test.c index 67a62f8..cb3c908 100644 --- a/lib/pengine/tests/native/pe_base_name_eq_test.c +++ b/lib/pengine/tests/native/pe_base_name_eq_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2022 the Pacemaker project contributors + * Copyright 2022-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -12,15 +12,15 @@ #include <crm/common/unittest_internal.h> #include <crm/common/xml.h> +#include <crm/common/scheduler.h> #include <crm/pengine/internal.h> #include <crm/pengine/status.h> -#include <crm/pengine/pe_types.h> xmlNode *input = NULL; -pe_working_set_t *data_set = NULL; +pcmk_scheduler_t *scheduler = NULL; -pe_resource_t *exim_group, *promotable_0, *promotable_1, *dummy; -pe_resource_t *httpd_bundle, *mysql_group_0, *mysql_group_1; +pcmk_resource_t *exim_group, *promotable_0, *promotable_1, *dummy; +pcmk_resource_t *httpd_bundle, *mysql_group_0, *mysql_group_1; static int setup(void **state) { @@ -36,20 +36,21 @@ setup(void **state) { return 1; } - data_set = pe_new_working_set(); + scheduler = pe_new_working_set(); - if (data_set == NULL) { + if (scheduler == NULL) { return 1; } - pe__set_working_set_flags(data_set, pe_flag_no_counts|pe_flag_no_compat); - data_set->input = input; + pe__set_working_set_flags(scheduler, + pcmk_sched_no_counts|pcmk_sched_no_compat); + scheduler->input = input; - cluster_status(data_set); + cluster_status(scheduler); /* Get references to several resources we use frequently. */ - for (GList *iter = data_set->resources; iter != NULL; iter = iter->next) { - pe_resource_t *rsc = (pe_resource_t *) iter->data; + for (GList *iter = scheduler->resources; iter != NULL; iter = iter->next) { + pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data; if (strcmp(rsc->id, "dummy") == 0) { dummy = rsc; @@ -59,7 +60,7 @@ setup(void **state) { httpd_bundle = rsc; } else if (strcmp(rsc->id, "mysql-clone-group") == 0) { for (GList *iter = rsc->children; iter != NULL; iter = iter->next) { - pe_resource_t *child = (pe_resource_t *) iter->data; + pcmk_resource_t *child = (pcmk_resource_t *) iter->data; if (strcmp(child->id, "mysql-group:0") == 0) { mysql_group_0 = child; @@ -69,7 +70,7 @@ setup(void **state) { } } else if (strcmp(rsc->id, "promotable-clone") == 0) { for (GList *iter = rsc->children; iter != NULL; iter = iter->next) { - pe_resource_t *child = (pe_resource_t *) iter->data; + pcmk_resource_t *child = (pcmk_resource_t *) iter->data; if (strcmp(child->id, "promotable-rsc:0") == 0) { promotable_0 = child; @@ -85,7 +86,7 @@ setup(void **state) { static int teardown(void **state) { - pe_free_working_set(data_set); + pe_free_working_set(scheduler); return 0; } |