Skip to content

Commit 910a24e

Browse files
committed
clusterer_controller: netns T44 - an MI reload of the DB clusters beside controller clusters
A node with cluster 901 in a db_text DB, controller clusters 741/742 and tm on 741 runs clusterer:reload: the controller clusters, their nodes and tm's capability must stay, and a DB that moves the node from 901 to 741 must make the reload fail and leave every cluster as it was. It moves rather than adds: db_text matches a query's keys with AND only, so it can load one DB cluster per node.
1 parent f067347 commit 910a24e

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎modules-contrib/clusterer_controller/test/netns_tests.sh‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,39 @@ check "n2 founded 900 under the controller as node 2" $(grep -q 'cluster_id=900,
10301030
check "the natives no longer see n2 Up, and still see each other" $(! up900 1 2 && ! up900 3 2 && ! up900 4 2 && up900 1 3 && up900 3 1 && up900 1 4 && echo 1 || echo 0) "n1: $(links900 1) / stock n3: $(links900 3) / n4: $(links900 4)"
10311031
W=$(since 2 $M2 | grep -ac "membership is the controller's"); I=$(since 2 $M2 | grep -ac "unknown source id"); E=$(since 2 $M2 | grep -ac "ERROR:")
10321032
check "n2 warned about the natives once, logging no line per packet and no error" $([ "$W" = 1 ] && [ "$I" = 0 ] && [ "$E" = 0 ] && echo 1 || echo 0) "warnings $W, per-packet $I, errors $E"
1033+
1034+
echo "=== T44 an MI reload of the DB clusters keeps the controller clusters ==="
1035+
# n1 restarted with cluster 901 in a db_text DB beside the controller's 741/742
1036+
# and tm on 741; n4 is 741's master since T40
1037+
stop_graceful 1; rm -f $R/n1.pid
1038+
D=$R/db1; mkdir -p $D
1039+
printf 'table_name(string) table_version(int) \nclusterer:4\nclusterer_bridge:1\n' > $D/version
1040+
printf 'id(int,auto) cluster_a(int) cluster_b(int) send_shtag(string) dst_node_csv(string,null) \n' > $D/clusterer_bridge
1041+
printf 'id(int,auto) cluster_id(int) node_id(int) url(string) state(int) no_ping_retries(int) priority(int) sip_addr(string,null) flags(string,null) description(string,null) \n%s\n%s\n' \
1042+
'1:901:1:bin\:10.74.0.11\:5588:1:3:50::seed:' '2:901:9:bin\:10.74.0.19\:5588:1:3:50:::' > $D/clusterer
1043+
RIG_NODE_ID=1 RIG_TM=1 mkcfg 1 $NEW
1044+
# db_text before the module, which initialises its DB connection in mod_init
1045+
sed -i -e 's|^loadmodule "clusterer_controller.so"$|loadmodule "db_text.so"\n&|' \
1046+
-e "s|^modparam(\"clusterer\", \"db_mode\", 0)\$|modparam(\"db_text\", \"db_mode\", 1)\nmodparam(\"clusterer\", \"db_url\", \"text://$D\")|" $R/n1.cfg
1047+
nx 1 $NEW/sbin/opensips -f $R/n1.cfg -m 64 -M 16 -w $R -P $R/n1.pid 2>>$R/n1.log; sleep 15
1048+
# clusters <node>: "<cluster_id>:<node ids> ..." from clusterer:list, sorted
1049+
clusters() { mi $1 clusterer:list | python3 -c '
1050+
import json,sys
1051+
print(" ".join(sorted("%s:%s" % (c["cluster_id"], ",".join(sorted(str(n["node_id"]) for n in c.get("Nodes",[]))))
1052+
for c in json.load(sys.stdin).get("result",{}).get("Clusters",[]))))'; }
1053+
tmcap() { mi $1 clusterer:list_cap | python3 -c '
1054+
import json,sys
1055+
print(sum(1 for c in json.load(sys.stdin).get("result",{}).get("Clusters",[]) if c["cluster_id"]==741
1056+
for k in c.get("Capabilities",[]) if k["name"]=="tm-repl"))'; }
1057+
C0="741:4 742:4 901:9"; M0=$(members 1 741)
1058+
check "n1 has the DB's 901 and the controller's 741 (with n4) and 742, and tm's capability on 741" $([ "$(clusters 1)" = "$C0" ] && [ "$(echo $M0 | wc -w)" = 2 ] && [ "$(tmcap 1)" = 1 ] && echo 1 || echo 0) "clusters '$(clusters 1)', 741 members '$M0', tm-repl on 741: $(tmcap 1)"
1059+
RL=$(mi 1 clusterer:reload)
1060+
check "clusterer:reload succeeds and keeps 741 and 742, their nodes and tm's capability" $(echo "$RL" | grep -q '"result"' && [ "$(clusters 1)" = "$C0" ] && [ "$(tmcap 1)" = 1 ] && [ "$(members 1 741)" = "$M0" ] && echo 1 || echo 0) "reload: $(echo $RL | cut -c1-80) / clusters '$(clusters 1)', tm-repl $(tmcap 1)"
1061+
# the DB now has n1 in 741 instead of 901 (db_text ANDs a query's keys, so
1062+
# it loads one DB cluster per node: no second row)
1063+
sleep 1; sed -i 's/^\([12]\):901:/\1:741:/' $D/clusterer
1064+
RL=$(mi 1 clusterer:reload)
1065+
check "the DB defining the controller's 741 makes the reload fail, every cluster left as it was" $(echo "$RL" | grep -q '"error"' && [ "$(clusters 1)" = "$C0" ] && [ "$(members 1 741)" = "$M0" ] && echo 1 || echo 0) "reload: $(echo $RL | cut -c1-80) / clusters '$(clusters 1)'"
10331066
fi
10341067

10351068
# groups 1 and 2 run before T10/T11 and are not checked

0 commit comments

Comments
 (0)