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 "ctdb_takeover_run_core" "$_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"
255 [ -r "$CTDB_NATGW_NODES" ] || \
256 die
"error: missing CTDB_NATGW_NODES=${CTDB_NATGW_NODES}"
258 # Determine if the current node has the (fake) NAT gateway
259 # capability. This is only used to make sure tests are sane and
260 # don't try to use inconsistent setup.
261 if [ -r "$FAKE_CTDB_NATGW_STATE" ] ; then
262 read _state
<"$FAKE_CTDB_NATGW_STATE"
267 # Determine the master node
271 if [ "$FAKE_CTDB_NATGW_MASTER" = "$_ip" ] ; then
272 _master
="${_pnn} ${_ip}"
273 if [ "$_pnn" = "$FAKE_CTDB_PNN" -a "$_state" = "off" ] ; then
274 die
"Inconsistent test configuration - master node is slave-only"
279 done <"$CTDB_NATGW_NODES"
282 # Now print the node information - it is clearer to do this in a
283 # second pass. Any nodes before the master that have state not
284 # "off" are tagged as unhealthy, just so the output makes some
289 if [ "$FAKE_CTDB_NATGW_MASTER" = "$_ip" ] ; then
292 if $_found_master ; then
295 if [ $FAKE_CTDB_PNN -eq $_pnn -a "$_state" = "off" ] ; then
298 _outstate
="UNHEALTHY"
301 if [ $FAKE_CTDB_PNN -eq $_pnn ] ; then
302 _outstate
="${_outstate} (THIS NODE)"
304 printf "pnn:%d %-16s ${_outstate}\n" $_pnn "$_ip"
307 done <"$CTDB_NATGW_NODES"
311 ######################################################################
318 for _i
in $FAKE_CTDB_TUNABLES_OK ; do
319 if [ "$_var" = "$_i" ] ; then
324 for _i
in $FAKE_CTDB_TUNABLES_OBSOLETE ; do
325 if [ "$_var" = "$_i" ] ; then
326 echo "Setting obsolete tunable variable '${_var}'"
331 echo "Unable to set tunable variable '${_var}'"
335 ######################################################################
339 _t_dir
="$EVENTSCRIPTS_TESTS_VAR_DIR/fake-ctdb/fake-tdb/$1"
345 echo "$2" >"${_t_dir}/$1"
373 _t_get
"$3" >"$4" 2>/dev
/null
380 while IFS
="" read _line
; do
381 _k
=$
(echo "$_line" |
sed -n -e 's@^"\([^"]*\)" "[^"]*"$@\1@p')
382 _v
=$
(echo "$_line" |
sed -e 's@^"[^"]*" "\([^"]*\)"$@\1@')
383 [ -n "$_k" ] || die
"ctdb ptrans: bad line \"${line}\""
384 if [ -n "$_v" ] ; then
396 # This will break on keys with spaces but we don't have any of
399 for _i
in "${_t_dir}/"* ; do
400 [ -r "$_i" ] ||
continue
401 _k
="${_i##*/}" # basename
403 _kn
=$
(echo -n "$_k" |
wc -c)
404 _vn
=$
(echo -n "$_v" |
wc -c)
406 key(${_kn}) = "${_k}"
409 data(${_vn}) = "${_v}"
412 _count
=$
(($_count + 1))
415 echo "Dumped ${_count} records"
418 ######################################################################
423 echo "|source ip|port|destination ip|port|"
424 while read src dst
; do
425 echo "|${src}|${dst}|"
426 done <"$tickles_file"
430 echo "$2 $3" >>"$tickles_file"
434 _t
=$
(grep -F -v "$2 $3" "$tickles_file")
435 echo "$_t" >"$tickles_file"
437 pstore
) ctdb_pstore
"$@" ;;
438 pdelete
) ctdb_pdelete
"$@" ;;
439 pfetch
) ctdb_pfetch
"$@" ;;
440 ptrans
) ctdb_ptrans
"$@" ;;
441 catdb
) ctdb_catdb
"$@" ;;
444 echo "|Name|LinkStatus|References|"
445 _f
="${CTDB_PUBLIC_ADDRESSES:-${CTDB_BASE}/public_addresses}"
446 if [ -r "$_f" ] ; then
447 while read _ip _iface
; do
452 # For now assume _iface contains only 1.
453 if [ -f "{FAKE_CTDB_IFACES_DOWN}/${_iface}" ] ; then
456 # Nobody looks at references
457 echo "|${_iface}|${_status}|0|"
464 # Existence of file means CTDB thinks interface is down.
465 _f
="${FAKE_CTDB_IFACES_DOWN}/$2"
470 echo "ctdb setifacelink: unsupported interface status $3"
475 for _i
in $FAKE_TCP_LISTEN ; do
476 if [ "$2" = "${_i##*:}" ] ; then
484 $machine_readable || not_implemented
"$1, without -X"
485 [ "$2" != "all" ] || not_implemented
"scriptstatus all"
486 # For now just assume everything is good.
487 echo "|Type|Name|Code|Status|Start|End|Error Output...|"
488 for _i
in "$CTDB_BASE/events.d/"*.
* ; do
490 _b
="${_i##*/}" # basename
492 _f
="$FAKE_CTDB_SCRIPTSTATUS/$_b"
493 if [ -r "$_f" ] ; then
494 read _code _status _err_out
<"$_f"
498 if [ ! -x "$_i" ] ; then
505 echo "|${2:-monitor}|${_b}|${_code}|${_status}|${_d1}|${_d2}|${_err_out}|"
508 gratiousarp
) : ;; # Do nothing for now
509 killtcp
) ctdb_killtcp
"$@" ;;
511 pnn|xpnn
) ctdb_pnn
;;
512 enable) ctdb_enable
"$@";;
513 disable
) ctdb_disable
"$@";;
514 moveip
) ctdb_moveip
"$@";;
515 shutdown
) ctdb_shutdown
"$@";;
516 setnatgwstate
) ctdb_setnatgwstate
"$@" ;;
517 natgwlist
) ctdb_natgwlist
"$@" ;;
518 setvar
) ctdb_setvar
"$@" ;;
519 *) not_implemented
"$1" ;;