The branch, master has been updated via 6bd4feff7039138d435428eeded51975c44e567c (commit) via 0f0aef21a1bb2d88a8c184ef70c718e0c91acdc3 (commit) via a56ec75edd1705b0539513d396d311f0e80a3bf5 (commit) via c30ec02615183ecf9b412ad415bf1abd859aec45 (commit) via 81af67c6959fdbe0566e3f1a00e2be58dd268dc6 (commit) via a3f15d2828325bbfba5bc5c0a30429e2ce572a44 (commit) via 140fafef23050d40d66f5b5558c7efcb78f80cd2 (commit) from 7b75a3bb722dc86139b1a07a0100d08c34620b91 (commit)
http://gitweb.samba.org/?p=ctdb.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 6bd4feff7039138d435428eeded51975c44e567c Author: Martin Schwenke <mar...@meltin.net> Date: Wed Jul 18 17:05:03 2012 +1000 tests/tool: New tests for natgwlist, getcapabilities, lvs, lvsmaster Signed-off-by: Martin Schwenke <mar...@meltin.net> commit 0f0aef21a1bb2d88a8c184ef70c718e0c91acdc3 Author: Martin Schwenke <mar...@meltin.net> Date: Wed Jul 18 17:02:38 2012 +1000 tests/tool: New function setup_natgw() to setup $CTDB_NATGW_NODES Signed-off-by: Martin Schwenke <mar...@meltin.net> commit a56ec75edd1705b0539513d396d311f0e80a3bf5 Author: Martin Schwenke <mar...@meltin.net> Date: Wed Jul 18 16:59:19 2012 +1000 tools/ctdb: Clean up control_natgw() * Factor out repeated code into new function find_natgw() * Support both machine and human readable output * Use libctdb Signed-off-by: Martin Schwenke <mar...@meltin.net> commit c30ec02615183ecf9b412ad415bf1abd859aec45 Author: Martin Schwenke <mar...@meltin.net> Date: Wed Jul 18 16:57:01 2012 +1000 tools/ctdb: Convert some commands over to libctdb control_getcapabilities(), control_lvs(), control_lvsmaster() updated to use ctdb_getcapabilities(), ctdb_getnodemap() as appropriate. Signed-off-by: Martin Schwenke <mar...@meltin.net> commit 81af67c6959fdbe0566e3f1a00e2be58dd268dc6 Author: Martin Schwenke <mar...@meltin.net> Date: Wed Jul 18 15:57:13 2012 +1000 tests: libctdb stubs initial ctdb_getcapabilities() implementation Signed-off-by: Martin Schwenke <mar...@meltin.net> commit a3f15d2828325bbfba5bc5c0a30429e2ce572a44 Author: Martin Schwenke <mar...@meltin.net> Date: Wed Jul 18 15:53:39 2012 +1000 tests: libctdb stubs must copy pointers rather than just returning them Some code (e.g. NAT gateway code) modifies the returned result so was modifying the original. Signed-off-by: Martin Schwenke <mar...@meltin.net> commit 140fafef23050d40d66f5b5558c7efcb78f80cd2 Author: Martin Schwenke <mar...@meltin.net> Date: Wed Jul 18 14:24:08 2012 +1000 libctdb: add ctdb_getcapabilities() Signed-off-by: Martin Schwenke <mar...@meltin.net> ----------------------------------------------------------------------- Summary of changes: include/ctdb.h | 50 ++++++ include/ctdb_private.h | 8 - include/ctdb_protocol.h | 11 ++ libctdb/control.c | 28 +++ libctdb/sync.c | 17 ++ tests/src/libctdb_test.c | 38 ++++- tests/tool/scripts/local.sh | 20 +++ tests/tool/stubby.getcapabilities.001.sh | 30 ++++ tests/tool/stubby.getcapabilities.002.sh | 30 ++++ tests/tool/stubby.getcapabilities.003.sh | 27 +++ tests/tool/stubby.lvs.001.sh | 27 +++ tests/tool/stubby.lvsmaster.001.sh | 28 +++ tests/tool/stubby.lvsmaster.002.sh | 28 +++ ...tubby.status.001.sh => stubby.natgwlist.001.sh} | 18 +- ...tubby.status.002.sh => stubby.natgwlist.002.sh} | 16 +- ...tubby.status.002.sh => stubby.natgwlist.003.sh} | 18 +- tests/tool/stubby.natgwlist.004.sh | 37 ++++ tests/tool/stubby.natgwlist.005.sh | 37 ++++ tools/ctdb.c | 175 +++++++++++--------- 19 files changed, 520 insertions(+), 123 deletions(-) create mode 100755 tests/tool/stubby.getcapabilities.001.sh create mode 100755 tests/tool/stubby.getcapabilities.002.sh create mode 100755 tests/tool/stubby.getcapabilities.003.sh create mode 100755 tests/tool/stubby.lvs.001.sh create mode 100755 tests/tool/stubby.lvsmaster.001.sh create mode 100755 tests/tool/stubby.lvsmaster.002.sh copy tests/tool/{stubby.status.001.sh => stubby.natgwlist.001.sh} (68%) copy tests/tool/{stubby.status.002.sh => stubby.natgwlist.002.sh} (71%) copy tests/tool/{stubby.status.002.sh => stubby.natgwlist.003.sh} (61%) create mode 100755 tests/tool/stubby.natgwlist.004.sh create mode 100755 tests/tool/stubby.natgwlist.005.sh Changeset truncated at 500 lines: diff --git a/include/ctdb.h b/include/ctdb.h index 93224cb..c3da068 100644 --- a/include/ctdb.h +++ b/include/ctdb.h @@ -585,6 +585,35 @@ ctdb_check_message_handlers_recv(struct ctdb_connection *ctdb, /** + * ctdb_getcapabilities_send - read the capabilities of a node + * @ctdb: the ctdb_connection from ctdb_connect. + * @destnode: the destination node (see below) + * @callback: the callback when ctdb replies to our message (typesafe) + * @cbdata: the argument to callback() + * + * There are several special values for destnode, detailed in + * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the + * local ctdbd. + */ +struct ctdb_request * +ctdb_getcapabilities_send(struct ctdb_connection *ctdb, + uint32_t destnode, + ctdb_callback_t callback, void *cbdata); + +/** + * ctdb_getcapabilities_recv - read an ctdb_getcapabilities reply from ctdbd + * @ctdb: the ctdb_connection from ctdb_connect. + * @req: the completed request. + * @capabilities: a pointer to the capabilities to fill in + * + * This returns false if something went wrong, or otherwise fills in + * capabilities. + */ +bool ctdb_getcapabilities_recv(struct ctdb_connection *ctdb, + struct ctdb_request *handle, + uint32_t *capabilities); + +/** * ctdb_getdbseqnum_send - read the sequence number off a db * @ctdb: the ctdb_connection from ctdb_connect. * @destnode: the destination node (see below) @@ -950,6 +979,23 @@ ctdb_check_message_handlers(struct ctdb_connection *ctdb, uint8_t *result); /** + * ctdb_getcapabilities - read the capabilities of a node (synchronous) + * @ctdb: the ctdb_connection from ctdb_connect. + * @destnode: the destination node (see below) + * @capabilities: a pointer to the capabilities to fill in + * + * There are several special values for destnode, detailed in + * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the + * local ctdbd. + * + * Returns true and fills in *capabilities on success. + */ +bool ctdb_getcapabilities(struct ctdb_connection *ctdb, + uint32_t destnode, + uint32_t *capabilities); + + +/** * ctdb_getdbseqnum - read the seqnum of a database * @ctdb: the ctdb_connection from ctdb_connect. * @destnode: the destination node (see below) @@ -1145,6 +1191,10 @@ void ctdb_free_vnnmap(struct ctdb_vnn_map *vnnmap); ctdb_getpnn_send((ctdb), (destnode), \ ctdb_sendcb((cb), (cbdata)), (cbdata)) +#define ctdb_getcapabilities_send(ctdb, destnode, cb, cbdata) \ + ctdb_getcapabilities_send((ctdb), (destnode), \ + ctdb_sendcb((cb), (cbdata)), (cbdata)) + #define ctdb_getdbstat_send(ctdb, destnode, db_id, cb, cbdata) \ ctdb_getdbstat_send((ctdb), (destnode), (db_id), \ ctdb_sendcb((cb), (cbdata)), (cbdata)) diff --git a/include/ctdb_private.h b/include/ctdb_private.h index 0f9da36..984dc35 100644 --- a/include/ctdb_private.h +++ b/include/ctdb_private.h @@ -394,14 +394,6 @@ enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN #define CTDB_MONITORING_ACTIVE 0 #define CTDB_MONITORING_DISABLED 1 -/* The different capabilities of the ctdb daemon. */ -#define CTDB_CAP_RECMASTER 0x00000001 -#define CTDB_CAP_LMASTER 0x00000002 -/* This capability is set if CTDB_LVS_PUBLIC_IP is set */ -#define CTDB_CAP_LVS 0x00000004 -/* This capability is set if NATGW is enabled */ -#define CTDB_CAP_NATGW 0x00000008 - #define NUM_DB_PRIORITIES 3 /* main state of the ctdb daemon */ struct ctdb_context { diff --git a/include/ctdb_protocol.h b/include/ctdb_protocol.h index 33187c7..9682756 100644 --- a/include/ctdb_protocol.h +++ b/include/ctdb_protocol.h @@ -568,6 +568,17 @@ struct ctdb_node_map { #define NODE_FLAGS_NOIPTAKEOVER 0x01000000 /* this node can takeover any new ip addresses, this flag is ONLY valid within the recovery daemon */ +/* + * Node capabilities + */ +#define CTDB_CAP_RECMASTER 0x00000001 +#define CTDB_CAP_LMASTER 0x00000002 +/* This capability is set if CTDB_LVS_PUBLIC_IP is set */ +#define CTDB_CAP_LVS 0x00000004 +/* This capability is set if NATGW is enabled */ +#define CTDB_CAP_NATGW 0x00000008 + + struct ctdb_public_ip { uint32_t pnn; ctdb_sock_addr addr; diff --git a/libctdb/control.c b/libctdb/control.c index e8a5cd7..176c48c 100644 --- a/libctdb/control.c +++ b/libctdb/control.c @@ -33,6 +33,7 @@ #undef ctdb_getdbseqnum_send #undef ctdb_getifaces_send #undef ctdb_getvnnmap_send +#undef ctdb_getcapabilities_send bool ctdb_getrecmaster_recv(struct ctdb_connection *ctdb, struct ctdb_request *req, uint32_t *recmaster) @@ -515,3 +516,30 @@ struct ctdb_request *ctdb_getvnnmap_send(struct ctdb_connection *ctdb, NULL, 0, callback, private_data); } +bool ctdb_getcapabilities_recv(struct ctdb_connection *ctdb, + struct ctdb_request *req, uint32_t *capabilities) +{ + struct ctdb_reply_control *reply; + + reply = unpack_reply_control(req, CTDB_CONTROL_GET_CAPABILITIES); + if (!reply) { + return false; + } + if (reply->status == -1) { + DEBUG(ctdb, LOG_ERR, "ctdb_getcapabilities_recv: status -1"); + return false; + } + *capabilities = *((uint32_t *)reply->data); + return true; +} + +struct ctdb_request *ctdb_getcapabilities_send(struct ctdb_connection *ctdb, + uint32_t destnode, + ctdb_callback_t callback, + void *private_data) +{ + return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_CAPABILITIES, + destnode, + NULL, 0, callback, private_data); +} + diff --git a/libctdb/sync.c b/libctdb/sync.c index 0e175f7..9a82747 100644 --- a/libctdb/sync.c +++ b/libctdb/sync.c @@ -338,3 +338,20 @@ bool ctdb_getvnnmap(struct ctdb_connection *ctdb, return ret; } +bool ctdb_getcapabilities(struct ctdb_connection *ctdb, + uint32_t destnode, uint32_t *capabilities) +{ + struct ctdb_request *req; + bool done = false; + bool ret = false; + + req = synchronous(ctdb, + ctdb_getcapabilities_send(ctdb, destnode, set, &done), + &done); + if (req != NULL) { + ret = ctdb_getcapabilities_recv(ctdb, req, capabilities); + ctdb_request_free(req); + } + return ret; +} + diff --git a/tests/src/libctdb_test.c b/tests/src/libctdb_test.c index 56c007e..3395b42 100644 --- a/tests/src/libctdb_test.c +++ b/tests/src/libctdb_test.c @@ -313,35 +313,45 @@ static bool current_node_is_connected (struct ctdb_connection *ctdb) bool ctdb_getnodemap(struct ctdb_connection *ctdb, uint32_t destnode, struct ctdb_node_map **nodemap) { + size_t n; + if (!current_node_is_connected(ctdb)) { *nodemap = NULL; return false; } - *nodemap = ctdb->nodemap; + n = offsetof(struct ctdb_node_map, nodes) + (ctdb->nodemap->num) * sizeof(struct ctdb_node_and_flags); + *nodemap = (struct ctdb_node_map *) malloc(n); + memcpy(*nodemap, ctdb->nodemap, n); + return true; } void ctdb_free_nodemap(struct ctdb_node_map *nodemap) { - return; + free(nodemap); } bool ctdb_getifaces(struct ctdb_connection *ctdb, uint32_t destnode, struct ctdb_ifaces_list **ifaces) { + size_t n; + if (!current_node_is_connected(ctdb)) { *ifaces = NULL; return false; } - *ifaces = ctdb->ifaces; + n = offsetof(struct ctdb_ifaces_list, ifaces) + (ctdb->ifaces->num) * sizeof(struct ctdb_iface_info); + *ifaces = (struct ctdb_ifaces_list *) malloc(n); + memcpy(*ifaces, ctdb->ifaces, n); + return true; } void ctdb_free_ifaces(struct ctdb_ifaces_list *ifaces) { - return; + free(ifaces); } bool ctdb_getpnn(struct ctdb_connection *ctdb, @@ -387,18 +397,27 @@ bool ctdb_getrecmaster(struct ctdb_connection *ctdb, bool ctdb_getvnnmap(struct ctdb_connection *ctdb, uint32_t destnode, struct ctdb_vnn_map **vnnmap) { + size_t n; + if (!current_node_is_connected(ctdb)) { *vnnmap = NULL; return false; } - *vnnmap = ctdb->vnnmap; + *vnnmap = (struct ctdb_vnn_map *) malloc(sizeof(struct ctdb_vnn_map)); + n = ctdb->vnnmap->size * sizeof(uint32_t); + (*vnnmap)->map = malloc(n); + memcpy((*vnnmap)->map, ctdb->vnnmap->map, n); + (*vnnmap)->generation = ctdb->vnnmap->generation; + (*vnnmap)->size = ctdb->vnnmap->size; + return true; } void ctdb_free_vnnmap(struct ctdb_vnn_map *vnnmap) { - return; + free(vnnmap->map); + free(vnnmap); } bool @@ -504,3 +523,10 @@ void ctdb_free_dbstat(struct ctdb_db_statistics *dbstatistics) { free(dbstatistics); } + +bool ctdb_getcapabilities(struct ctdb_connection *ctdb, + uint32_t destnode, uint32_t *capabilities) +{ + *capabilities = CTDB_CAP_RECMASTER|CTDB_CAP_LMASTER|CTDB_CAP_NATGW; + return true; +} diff --git a/tests/tool/scripts/local.sh b/tests/tool/scripts/local.sh index 77c5f16..3b9670c 100644 --- a/tests/tool/scripts/local.sh +++ b/tests/tool/scripts/local.sh @@ -1,5 +1,11 @@ # Hey Emacs, this is a -*- shell-script -*- !!! :-) +if "$TEST_VERBOSE" ; then + debug () { echo "$@" ; } +else + debug () { : ; } +fi + define_test () { _f=$(basename "$0" ".sh") @@ -22,6 +28,20 @@ define_test () printf "%-28s - %s\n" "$_f" "$1" } +setup_natgw () +{ + debug "Setting up NAT gateway" + + natgw_config_dir="${TEST_VAR_DIR}/natgw_config" + mkdir -p "$natgw_config_dir" + + # These will accumulate, 1 per test... but will be cleaned up at + # the end. + export CTDB_NATGW_NODES=$(mktemp --tmpdir="$natgw_config_dir") + + cat >"$CTDB_NATGW_NODES" +} + simple_test () { # Most of the tests when the tool fails will have a date/time/pid diff --git a/tests/tool/stubby.getcapabilities.001.sh b/tests/tool/stubby.getcapabilities.001.sh new file mode 100755 index 0000000..df4a659 --- /dev/null +++ b/tests/tool/stubby.getcapabilities.001.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "3 nodes, all ok" + +required_result 0 <<EOF +RECMASTER: YES +LMASTER: YES +LVS: NO +NATGW: YES +EOF + +simple_test <<EOF +NODEMAP +0 192.168.20.41 0x0 CURRENT RECMASTER +1 192.168.20.42 0x0 +2 192.168.20.43 0x0 + +IFACES +:Name:LinkStatus:References: +:eth2:1:2: +:eth1:1:4: + +VNNMAP +654321 +0 +1 +2 +EOF diff --git a/tests/tool/stubby.getcapabilities.002.sh b/tests/tool/stubby.getcapabilities.002.sh new file mode 100755 index 0000000..9a37c4a --- /dev/null +++ b/tests/tool/stubby.getcapabilities.002.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "3 nodes, 1 disconnected" + +required_result 0 <<EOF +RECMASTER: YES +LMASTER: YES +LVS: NO +NATGW: YES +EOF + +simple_test <<EOF +NODEMAP +0 192.168.20.41 0x0 CURRENT RECMASTER +1 192.168.20.42 0x1 +2 192.168.20.43 0x0 + +IFACES +:Name:LinkStatus:References: +:eth2:1:2: +:eth1:1:4: + +VNNMAP +654321 +0 +1 +2 +EOF diff --git a/tests/tool/stubby.getcapabilities.003.sh b/tests/tool/stubby.getcapabilities.003.sh new file mode 100755 index 0000000..33b1b74 --- /dev/null +++ b/tests/tool/stubby.getcapabilities.003.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "3 nodes, current disconnected" + +required_result 10 <<EOF +DATE TIME [PID]: Unable to get nodemap from local node +EOF + +simple_test <<EOF +NODEMAP +0 192.168.20.41 0x1 CURRENT RECMASTER +1 192.168.20.42 0x0 +2 192.168.20.43 0x0 + +IFACES +:Name:LinkStatus:References: +:eth2:1:2: +:eth1:1:4: + +VNNMAP +654321 +0 +1 +2 +EOF diff --git a/tests/tool/stubby.lvs.001.sh b/tests/tool/stubby.lvs.001.sh new file mode 100755 index 0000000..29e9ce0 --- /dev/null +++ b/tests/tool/stubby.lvs.001.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "3 nodes, all ok" + +# This isn't very useful, since the stub for capabilities does set LVS :-) +required_result 0 <<EOF +EOF + +simple_test <<EOF +NODEMAP +0 192.168.20.41 0x0 CURRENT RECMASTER +1 192.168.20.42 0x0 +2 192.168.20.43 0x0 + +IFACES +:Name:LinkStatus:References: +:eth2:1:2: +:eth1:1:4: + +VNNMAP +654321 +0 +1 +2 +EOF diff --git a/tests/tool/stubby.lvsmaster.001.sh b/tests/tool/stubby.lvsmaster.001.sh new file mode 100755 index 0000000..cc4c42d --- /dev/null +++ b/tests/tool/stubby.lvsmaster.001.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "3 nodes, all ok" + +# This isn't very useful, since the stub for capabilities does set LVS :-) +required_result 255 <<EOF +There is no LVS master +EOF + +simple_test <<EOF +NODEMAP +0 192.168.20.41 0x0 CURRENT RECMASTER +1 192.168.20.42 0x0 +2 192.168.20.43 0x0 + +IFACES +:Name:LinkStatus:References: +:eth2:1:2: +:eth1:1:4: + +VNNMAP +654321 +0 +1 +2 +EOF diff --git a/tests/tool/stubby.lvsmaster.002.sh b/tests/tool/stubby.lvsmaster.002.sh new file mode 100755 index 0000000..b45f0cd --- /dev/null +++ b/tests/tool/stubby.lvsmaster.002.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "3 nodes, current disconnected" + -- CTDB repository