Tests - IP allocation - allow more interesting node states to be specified
authorMartin Schwenke <martin@meltin.net>
Thu, 15 Sep 2011 07:08:18 +0000 (17:08 +1000)
committerMartin Schwenke <martin@meltin.net>
Sun, 25 Sep 2011 04:45:48 +0000 (14:45 +1000)
Node states on the command line are now comma-separated hex numbers,
so all flag states can be expressed.

Signed-off-by: Martin Schwenke <martin@meltin.net>
tests/src/ctdb_takeover_tests.c

index 5fd23320a3d6742629c964cccfb4d0370fd47bfe..a150018f11e618542c68ffd4782fa12d52862813 100644 (file)
@@ -183,11 +183,23 @@ void ctdb_test_init(const char nodestates[],
        struct ctdb_public_ip_list *t;
        struct ctdb_all_public_ips *available_public_ips;
        int i, numips, numnodes;
-
-       numnodes = strlen(nodestates);
+       /* This is test code and this is unreasonably big... :-) */
+       uint32_t nodeflags[256];
+       char *tok, *ns;
 
        *ctdb = talloc_zero(NULL, struct ctdb_context);
 
+       /* Avoid that const */
+       ns = talloc_strdup(*ctdb, nodestates);
+
+       numnodes = 0;
+       tok = strtok(ns, ",");
+       while (tok != NULL) {
+               nodeflags[numnodes] = (uint32_t) strtol(tok, NULL, 16);
+               numnodes++;
+               tok = strtok(NULL, ",");
+       }
+       
        /* Fake things up... */
        (*ctdb)->num_nodes = numnodes;
 
@@ -206,12 +218,6 @@ void ctdb_test_init(const char nodestates[],
        *nodemap =  talloc_array(*ctdb, struct ctdb_node_map, numnodes);
        (*nodemap)->num = numnodes;
 
-       for (i=0; i < numnodes; i++) {
-               (*nodemap)->nodes[i].pnn = i;
-               (*nodemap)->nodes[i].flags = nodestates[i] - '0';
-               /* *nodemap->nodes[i].sockaddr is uninitialised */
-       }
-
        *all_ips = read_ctdb_public_ip_list(*ctdb);
        numips = 0;
        for (t = *all_ips; t != NULL; t = t->next) {
@@ -230,14 +236,13 @@ void ctdb_test_init(const char nodestates[],
        /* Setup both nodemap and ctdb->nodes.  Mark all nodes as
         * healthy - change this later. */
        for (i=0; i < numnodes; i++) {
-               uint32_t flags = nodestates[i] - '0' ? NODE_FLAGS_UNHEALTHY : 0;
                (*nodemap)->nodes[i].pnn = i;
-               (*nodemap)->nodes[i].flags = flags;
+               (*nodemap)->nodes[i].flags = nodeflags[i];
                /* nodemap->nodes[i].sockaddr is uninitialised */
 
                (*ctdb)->nodes[i] = talloc(*ctdb, struct ctdb_node);
                (*ctdb)->nodes[i]->pnn = i;
-               (*ctdb)->nodes[i]->flags = flags;
+               (*ctdb)->nodes[i]->flags = nodeflags[i];
                (*ctdb)->nodes[i]->available_public_ips = available_public_ips;
                (*ctdb)->nodes[i]->known_public_ips = available_public_ips;
        }