ctdb-ipalloc: New function ipalloc_set_public_ips()
authorMartin Schwenke <martin@meltin.net>
Mon, 23 May 2016 10:23:18 +0000 (20:23 +1000)
committerAmitay Isaacs <amitay@samba.org>
Mon, 4 Jul 2016 13:42:25 +0000 (15:42 +0200)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_takeover.c
ctdb/server/ipalloc.c
ctdb/server/ipalloc.h
ctdb/tests/src/ctdb_takeover_tests.c

index d5a96c51bceff1654024f54618ac353eec82ad37..b40bbadbf56fe421eec74085337bac2d75a608d1 100644 (file)
@@ -1619,8 +1619,10 @@ static void takeover_run_process_failures(struct ctdb_context *ctdb,
  * - Populate NoIPTakover tunable in IP allocation state
  * - Populate NoIPHost in IP allocation state, derived from node flags
  *   and NoIPHostOnAllDisabled tunable
- * - Retrieve and populate known and available IP lists in IP
- *   allocation state
+ * - Retrieve known and available IP addresses (done separately so
+ *   values can be faked in unit testing)
+ * - Use ipalloc_set_public_ips() to set known and available IP
+     addresses for allocation
  * - If no available IP addresses then early exit
  * - Build list of (known IPs, currently assigned node)
  * - Populate list of nodes to force rebalance - internal structure,
@@ -1697,8 +1699,11 @@ int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map_old *nodem
                return -1;
        }
 
-       ipalloc_state->known_public_ips = known_ips;
-       ipalloc_state->available_public_ips = available_ips;
+       if (! ipalloc_set_public_ips(ipalloc_state, known_ips, available_ips)) {
+               DEBUG(DEBUG_ERR, ("Failed to set public IPs\n"));
+               talloc_free(tmp_ctx);
+               return -1;
+       }
 
        /* Short-circuit IP allocation if no node has available IPs */
        can_host_ips = false;
index ae9e8def2d8e160bcdb50e8dbca4d6cdb2ed5c83..fa2503db42b84b6f8828b95ca166fda4571c28ec 100644 (file)
 
 #include "server/ipalloc_private.h"
 
+bool ipalloc_set_public_ips(struct ipalloc_state *ipalloc_state,
+                           struct ctdb_public_ip_list *known_ips,
+                           struct ctdb_public_ip_list *available_ips)
+{
+       ipalloc_state->known_public_ips = known_ips;
+       ipalloc_state->available_public_ips = available_ips;
+
+       return true;
+}
+
 /* The calculation part of the IP allocation algorithm. */
 bool ipalloc(struct ipalloc_state *ipalloc_state)
 {
index 1acaf35c96c5fd221f33f9ed14d88f12db7fb557..b5a1bcc849d9cd5f68d152e8a147fb45ab765ddc 100644 (file)
@@ -56,6 +56,10 @@ struct ipalloc_state {
        uint32_t *force_rebalance_nodes;
 };
 
+bool ipalloc_set_public_ips(struct ipalloc_state *ipalloc_state,
+                           struct ctdb_public_ip_list *known_ips,
+                           struct ctdb_public_ip_list *available_ips);
+
 bool ipalloc(struct ipalloc_state *ipalloc_state);
 
 #endif /* __CTDB_IPALLOC_H__ */
index 9de3f2789f21d808a9719325d94d1dd1ef51a8b5..162de2b73599ea078ed1dd7eae32bfa4376c6711 100644 (file)
@@ -309,8 +309,10 @@ static void ctdb_test_init(const char nodestates[],
                (*ctdb)->nodes[i]->flags = nodemap->nodes[i].flags;
        }
 
-       (*ipalloc_state)->available_public_ips = avail;
-       (*ipalloc_state)->known_public_ips = known;
+       if (! ipalloc_set_public_ips(*ipalloc_state, known, avail)) {
+               DEBUG(DEBUG_ERR, ("Failed to set public IPs\n"));
+               exit(1);
+       }
 
        set_ipflags_internal(*ipalloc_state, nodemap,
                             tval_noiptakeover,