5 # Print a message and exit.
8 echo "$1" >&2 ; exit ${2:-1}
11 not_implemented_exit_code=1
18 A fake CTDB stub that prints items depending on the variables
19 FAKE_CTDB_PNN (default 0) depending on command-line options.
26 echo "${prog}: command \"$1\" not implemented in stub" >&2
27 exit $not_implemented_exit_code
30 # Don't set $POSIXLY_CORRECT here.
31 _temp=$(getopt -n "$prog" -o "Xvhn:" -l help -- "$@") || \
37 machine_readable=false
44 -X) machine_readable=true ; shift ;;
45 -v) verbose=true ; shift ;;
46 -n) nodespec="$2" ; shift 2 ;;
48 -h|--help|*) usage ;; # * shouldn't happen, so this is reasonable.
56 # Make sure tickles file exists.
57 tickles_file="$EVENTSCRIPTS_TESTS_VAR_DIR/fake-ctdb/tickles"
58 mkdir -p $(dirname "$tickles_file")
64 while read _src _dst ; do
65 sed -i -e "/^$_dst $_src\$/d" "$FAKE_NETSTAT_TCP_ESTABLISHED_FILE"
71 if [ "$nodespec" = "all" ] ; then
72 nodes="$(seq 0 $((FAKE_CTDB_NUMNODES - 1)) )"
73 elif [ -n "$nodespec" ] ; then
74 nodes="$(echo $nodespec | sed -e 's@,@ @g')"
81 # For testing backward compatibility...
82 for i in $CTDB_NOT_IMPLEMENTED ; do
83 if [ "$i" = "$1" ] ; then
91 echo "PNN:${FAKE_CTDB_PNN:-0}"
94 ######################################################################
96 FAKE_CTDB_NODE_STATE="$FAKE_CTDB_STATE/node-state"
97 FAKE_CTDB_NODES_DISABLED="$FAKE_CTDB_NODE_STATE/0x4"
99 ######################################################################
101 # NOTE: all nodes share $CTDB_PUBLIC_ADDRESSES
103 FAKE_CTDB_IP_LAYOUT="$FAKE_CTDB_STATE/ip-layout"
107 touch "$FAKE_CTDB_IP_LAYOUT"
112 _pa="${CTDB_PUBLIC_ADDRESSES:-${CTDB_BASE}/public_addresses}"
114 if [ ! -s "$FAKE_CTDB_IP_LAYOUT" ] ; then
115 sed -n -e 's@^\([^#][^/]*\)/.*@\1 -1@p' \
116 "$_pa" >"$FAKE_CTDB_IP_LAYOUT"
119 _t="${FAKE_CTDB_IP_LAYOUT}.new"
122 for _i in $(seq 0 $((FAKE_CTDB_NUMNODES - 1)) ) ; do
123 if ls "$FAKE_CTDB_STATE/node-state/"*"/$_i" >/dev/null 2>&1 ; then
124 # Have non-zero flags
126 for _j in "$FAKE_CTDB_STATE/node-state/"*"/$_i" ; do
127 _tf="${_j%/*}" # dirname
128 _f="${_tf##*/}" # basename
129 _this=$(( $_this | $_f ))
134 _flags="${_flags}${_flags:+,}${_this}"
136 CTDB_TEST_LOGLEVEL=2 \
137 "ctdb_takeover_tests" \
138 "ipalloc" "$_flags" <"$FAKE_CTDB_IP_LAYOUT" |
140 mv "$_t" "$FAKE_CTDB_IP_LAYOUT"
141 ) <"$FAKE_CTDB_IP_LAYOUT"
146 # If nobody has done any IP-fu then generate a layout.
147 [ -f "$FAKE_CTDB_IP_LAYOUT" ] || ip_reallocate
149 _mypnn=$(ctdb_pnn | sed -e 's@PNN:@@')
151 if $machine_readable ; then
153 echo "|Public IP|Node|ActiveInterface|AvailableInterfaces|ConfiguredInterfaces|"
155 echo "|Public IP|Node|"
158 echo "Public IPs on node ${_mypnn}"
161 # Join public addresses file with $FAKE_CTDB_IP_LAYOUT, and
162 # process output line by line...
163 _pa="${CTDB_PUBLIC_ADDRESSES:-${CTDB_BASE}/public_addresses}"
164 sed -e 's@/@ @' "$_pa" | sort | join - "$FAKE_CTDB_IP_LAYOUT" |
165 while read _ip _bit _ifaces _pnn ; do
167 # If more than 1 interface, assume all addresses are on the 1st.
168 _first_iface="${_ifaces%%,*}"
169 # Only show interface if address is on this node.
171 if [ "$_pnn" = "$_mypnn" ]; then
172 _my_iface="$_first_iface"
174 if $machine_readable ; then
175 echo "|${_ip}|${_pnn}|${_my_iface}|${_first_iface}|${_ifaces}|"
177 echo "${_ip} node[${_pnn}] active[${_my_iface}] available[${_first_iface}] configured[[${_ifaces}]"
180 if $machine_readable ; then
181 echo "|${_ip}|${_pnn}|"
183 echo "${_ip} ${_pnn}"
194 ip_reallocate # should be harmless and ensures we have good state
199 _t="${FAKE_CTDB_IP_LAYOUT}.new"
201 while read _i _pnn ; do
202 if [ "$_ip" = "$_i" ] ; then
208 mv "$_t" "$FAKE_CTDB_IP_LAYOUT"
209 ) <"$FAKE_CTDB_IP_LAYOUT"
212 ######################################################################
218 for _i in $nodes ; do
219 rm -f "${FAKE_CTDB_NODES_DISABLED}/${_i}"
229 for _i in $nodes ; do
230 mkdir -p "$FAKE_CTDB_NODES_DISABLED"
231 touch "${FAKE_CTDB_NODES_DISABLED}/${_i}"
237 ######################################################################
241 echo "CTDB says BYE!"
244 ######################################################################
246 FAKE_CTDB_NATGW_STATE="${FAKE_CTDB_STATE}/natgw_state"
248 ctdb_setnatgwstate ()
250 echo "$2" >"$FAKE_CTDB_NATGW_STATE"
253 # This is only used by the NAT gateway code at the moment, so use a
254 # hack. Assume that $CTDB_NATGW_NODES contains all nodes in the
255 # cluster (which is what current tests assume). Use the PNN to find
256 # the address from this file. The NAT gateway code only used the
257 # address, so just mark the node healthy.
260 echo '|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|'
261 _line=$(( $FAKE_CTDB_PNN + 1 ))
262 _ip=$(sed -e "${_line}p" "$CTDB_NATGW_NODES")
263 echo "|${FAKE_CTDB_PNN}|${_ip}|0|0|0|0|0|0|0|Y|"
266 ######################################################################
273 for _i in $FAKE_CTDB_TUNABLES_OK ; do
274 if [ "$_var" = "$_i" ] ; then
279 for _i in $FAKE_CTDB_TUNABLES_OBSOLETE ; do
280 if [ "$_var" = "$_i" ] ; then
281 echo "Setting obsolete tunable variable '${_var}'"
286 echo "Unable to set tunable variable '${_var}'"
290 ######################################################################
294 _t_dir="$EVENTSCRIPTS_TESTS_VAR_DIR/fake-ctdb/fake-tdb/$1"
300 echo "$2" >"${_t_dir}/$1"
328 _t_get "$3" >"$4" 2>/dev/null
335 while IFS="" read _line ; do
336 _k=$(echo "$_line" | sed -n -e 's@^"\([^"]*\)" "[^"]*"$@\1@p')
337 _v=$(echo "$_line" | sed -e 's@^"[^"]*" "\([^"]*\)"$@\1@')
338 [ -n "$_k" ] || die "ctdb ptrans: bad line \"${line}\""
339 if [ -n "$_v" ] ; then
351 # This will break on keys with spaces but we don't have any of
354 for _i in "${_t_dir}/"* ; do
355 [ -r "$_i" ] || continue
356 _k="${_i##*/}" # basename
358 _kn=$(echo -n "$_k" | wc -c)
359 _vn=$(echo -n "$_v" | wc -c)
361 key(${_kn}) = "${_k}"
364 data(${_vn}) = "${_v}"
367 _count=$(($_count + 1))
370 echo "Dumped ${_count} records"
373 ######################################################################
378 echo "|source ip|port|destination ip|port|"
379 while read src dst ; do
380 echo "|${src}|${dst}|"
381 done <"$tickles_file"
385 echo "$2 $3" >>"$tickles_file"
389 _t=$(grep -F -v "$2 $3" "$tickles_file")
390 echo "$_t" >"$tickles_file"
392 pstore) ctdb_pstore "$@" ;;
393 pdelete) ctdb_pdelete "$@" ;;
394 pfetch) ctdb_pfetch "$@" ;;
395 ptrans) ctdb_ptrans "$@" ;;
396 catdb) ctdb_catdb "$@" ;;
399 echo "|Name|LinkStatus|References|"
400 _f="${CTDB_PUBLIC_ADDRESSES:-${CTDB_BASE}/public_addresses}"
401 if [ -r "$_f" ] ; then
402 while read _ip _iface ; do
407 # For now assume _iface contains only 1.
408 if [ -f "{FAKE_CTDB_IFACES_DOWN}/${_iface}" ] ; then
411 # Nobody looks at references
412 echo "|${_iface}|${_status}|0|"
419 # Existence of file means CTDB thinks interface is down.
420 _f="${FAKE_CTDB_IFACES_DOWN}/$2"
425 echo "ctdb setifacelink: unsupported interface status $3"
430 for _i in $FAKE_TCP_LISTEN ; do
431 if [ "$2" = "${_i##*:}" ] ; then
439 $machine_readable || not_implemented "$1, without -X"
440 [ "$2" != "all" ] || not_implemented "scriptstatus all"
441 # For now just assume everything is good.
442 echo "|Type|Name|Code|Status|Start|End|Error Output...|"
443 for _i in "$CTDB_BASE/events.d/"*.* ; do
445 _b="${_i##*/}" # basename
447 _f="$FAKE_CTDB_SCRIPTSTATUS/$_b"
448 if [ -r "$_f" ] ; then
449 read _code _status _err_out <"$_f"
453 if [ ! -x "$_i" ] ; then
460 echo "|${2:-monitor}|${_b}|${_code}|${_status}|${_d1}|${_d2}|${_err_out}|"
463 gratiousarp) : ;; # Do nothing for now
464 killtcp) ctdb_killtcp "$@" ;;
466 pnn|xpnn) ctdb_pnn ;;
467 enable) ctdb_enable "$@";;
468 disable) ctdb_disable "$@";;
469 moveip) ctdb_moveip "$@";;
470 shutdown) ctdb_shutdown "$@";;
471 setnatgwstate) ctdb_setnatgwstate "$@" ;;
472 setvar) ctdb_setvar "$@" ;;
473 nodestatus) ctdb_nodestatus "$@" ;;
474 *) not_implemented "$1" ;;