19 #include <NDBT_Test.hpp>
20 #include "NdbMgmd.hpp"
22 #include <mgmapi_debug.h>
23 #include <InputStream.hpp>
24 #include <signaldata/EventReport.hpp>
25 #include <NdbRestarter.hpp>
50 session_id= ndb_mgm_get_session_id(h);
51 ndbout <<
"MGM Session id: " << session_id << endl;
65 if(ndb_mgm_get_session(h,session_id,&sess,&slen))
67 ndbout <<
"Failed, session still exists" << endl;
74 ndbout <<
"SUCCESS: session is gone" << endl;
85 g_info <<
"Check connect works with timeout 3000" << endl;
86 if (!mgmd.set_timeout(3000))
91 g_err <<
"Connect failed with timeout 3000" << endl;
95 if (!mgmd.disconnect())
98 g_info <<
"Check connect to illegal host will timeout after 3000" << endl;
99 if (!mgmd.set_timeout(3000))
101 mgmd.setConnectString(
"1.1.1.1");
103 NDB_TICKS tstart= NdbTick_CurrentMillisecond();
106 g_err <<
"Connect to illegal host suceeded" << endl;
110 NDB_TICKS msecs= NdbTick_CurrentMillisecond() - tstart;
111 ndbout <<
"Took about " << msecs <<
" milliseconds"<<endl;
115 g_err <<
"The connect to illegal host timedout after much longer "
116 <<
"time than was expected, expected <= 6000, got " << msecs << endl;
126 int result= NDBT_FAILED;
135 ndbout <<
"TEST timout check_connection" << endl;
136 int errs[] = { 1, 2, 3, -1};
138 for(
int error_ins_no=0; errs[error_ins_no]!=-1; error_ins_no++)
140 int error_ins= errs[error_ins_no];
141 ndbout <<
"trying error " << error_ins << endl;
144 if(ndb_mgm_check_connection(h) < 0)
153 ndbout <<
"Failed to get mgmd node id to insert error" << endl;
160 if(ndb_mgm_insert_error(h, mgmd_nodeid, error_ins, &reply)< 0)
162 ndbout <<
"failed to insert error " << endl;
169 cc= ndb_mgm_check_connection(h);
177 ndbout <<
"FAILED: still connected" << endl;
182 ndbout <<
"TEST get_mgmd_nodeid" << endl;
185 if(ndb_mgm_insert_error(h, mgmd_nodeid, 0, &reply)< 0)
187 ndbout <<
"failed to remove inserted error " << endl;
193 ndbout <<
"got node id: " << cc << endl;
196 ndbout <<
"FAILED: didn't get node id" << endl;
202 ndbout <<
"TEST end_session" << endl;
205 if(ndb_mgm_insert_error(h, mgmd_nodeid, 4, &reply)< 0)
207 ndbout <<
"FAILED: insert error 1" << endl;
215 ndbout <<
"FAILED: success in calling end_session" << endl;
221 <<
" != expected " << ETIMEDOUT <<
") desc: "
233 ndbout <<
"FAILED: is still connected after error" << endl;
253 int errs[] = { 0, 5, 6, 7, 8, 9, -1 };
255 for(
int error_ins_no=0; errs[error_ins_no]!=-1; error_ins_no++)
257 int error_ins= errs[error_ins_no];
260 if(ndb_mgm_check_connection(h) < 0)
269 ndbout <<
"Failed to get mgmd node id to insert error" << endl;
277 if(ndb_mgm_insert_error(h, mgmd_nodeid, error_ins, &reply)< 0)
279 ndbout <<
"failed to insert error " << error_ins << endl;
283 ndbout <<
"trying error: " << error_ins << endl;
299 if(error_ins!=0 && error_ins!=9 && cl!=NULL)
301 ndbout <<
"FAILED: got a ndb_mgm_cluster_state back" << endl;
307 ndbout <<
"FAILED: is still connected after error" << endl;
314 <<
" != expected " << ETIMEDOUT <<
") desc: "
340 int errs[] = { 0, 1, 2, 3, -1 };
342 for(
int error_ins_no=0; errs[error_ins_no]!=-1; error_ins_no++)
344 int error_ins= errs[error_ins_no];
347 if(ndb_mgm_check_connection(h) < 0)
356 ndbout <<
"Failed to get mgmd node id to insert error" << endl;
364 if(ndb_mgm_insert_error(h, mgmd_nodeid, error_ins, &reply)< 0)
366 ndbout <<
"failed to insert error " << error_ins << endl;
370 ndbout <<
"trying error: " << error_ins << endl;
379 if(error_ins!=0 && c!=NULL)
381 ndbout <<
"FAILED: got a ndb_mgm_configuration back" << endl;
387 ndbout <<
"FAILED: is still connected after error" << endl;
394 <<
" != expected " << ETIMEDOUT <<
") desc: "
420 int errs[] = { 10000, 0, -1 };
422 for(
int error_ins_no=0; errs[error_ins_no]!=-1; error_ins_no++)
424 int error_ins= errs[error_ins_no];
427 if(ndb_mgm_check_connection(h) < 0)
436 ndbout <<
"Failed to get mgmd node id to insert error" << endl;
444 if(ndb_mgm_insert_error(h, mgmd_nodeid, error_ins, &reply)< 0)
446 ndbout <<
"failed to insert error " << error_ins << endl;
450 ndbout <<
"trying error: " << error_ins << endl;
458 NDB_SOCKET_TYPE my_fd;
467 if(!my_socket_valid(my_fd))
469 ndbout <<
"FAILED: could not listen to event" << endl;
479 fake_event->setNodeId(42);
485 ndb_mgm_report_event(h, theData, 6);
491 for(
int i=0;
i<20;
i++)
493 if((tmp = in.gets(buf,
sizeof(buf))))
497 if(tmp && strlen(tmp))
504 ndbout <<
"TIMED OUT READING EVENT at iteration " <<
i << endl;
518 ndbout <<
"FAILED: is still connected after error" << endl;
542 int errs[] = { 10000, 0, -1 };
544 for(
int error_ins_no=0; errs[error_ins_no]!=-1; error_ins_no++)
546 int error_ins= errs[error_ins_no];
549 if(ndb_mgm_check_connection(h) < 0)
558 ndbout <<
"Failed to get mgmd node id to insert error" << endl;
566 if(ndb_mgm_insert_error(h, mgmd_nodeid, error_ins, &reply)< 0)
568 ndbout <<
"failed to insert error " << error_ins << endl;
572 ndbout <<
"trying error: " << error_ins << endl;
582 for(
int i=0;
i<20;
i++)
584 if(error_ins==0 || (error_ins!=0 &&
i<5))
592 fake_event->setNodeId(42);
598 ndb_mgm_report_event(h, theData, 6);
603 ndbout <<
"Receieved event" << endl;
607 ndbout <<
"ERROR" << endl;
611 ndbout <<
"TIMED OUT READING EVENT at iteration " <<
i << endl;
628 ndbout <<
"FAILED: is still connected after error" << endl;
642 #include <mgmapi_internal.h>
651 int loops= ctx->getNumLoops();
652 for (
int l= 0; l < loops; l++){
659 g_err <<
"ndb_mgm_get_configuration failed, error: "
664 int r= ndb_mgm_set_configuration(mgmd.handle(), conf);
669 g_err <<
"ndb_mgm_set_configuration failed, error: "
681 while(!ctx->isTestStopped() &&
682 (result= runSetConfig(ctx, step)) == NDBT_OK)
695 int loops= ctx->getNumLoops();
696 for (
int l= 0; l < loops; l++){
711 while(!ctx->isTestStopped() &&
712 (result= runGetConfig(ctx, step)) == NDBT_OK)
724 node_types[2] = {
type,
725 NDB_MGM_NODE_TYPE_UNKNOWN };
730 g_err <<
"ndb_mgm_get_status2 failed, error: "
737 int randomnode = myRandom48(noOfNodes);
743 g_info <<
"Got node id " << *nodeId <<
" of type " << type << endl;
754 get_config_from_illegal_node(
NdbMgmd& mgmd,
int nodeId)
762 g_err <<
"ndb_mgm_get_configuration from illegal node "
763 << nodeId <<
" not failed, error: "
772 g_err <<
"ndb_mgm_get_configuration from illegal node: "
773 << nodeId <<
", error: "
786 check_get_config_illegal_node(
NdbMgmd& mgmd)
790 if (!mgmd.get_config(conf))
794 for(Uint32
i= 1;
i < MAX_NODES;
i++){
796 if (iter.find(CFG_NODE_ID,
i) != 0){
804 return get_config_from_illegal_node(mgmd, nodeId);
812 check_get_config_wrong_type(
NdbMgmd& mgmd)
818 return get_config_from_illegal_node(mgmd, nodeId);
835 if (!check_get_config_wrong_type(mgmd) ||
836 !check_get_config_illegal_node(mgmd) ||
837 !get_config_from_illegal_node(mgmd, MAX_NODES + 2))
842 int loops= ctx->getNumLoops();
843 for (
int l= 0; l < loops; l++)
848 int myChoice = myRandom48(2);
853 if (get_nodeid_of_type(mgmd, randomAllowedType, &nodeId))
859 g_err <<
"ndb_mgm_get_configuration_from_node "
860 << nodeId <<
" failed, error: "
879 while(!ctx->isTestStopped() &&
880 (result= runGetConfigFromNode(ctx, step)) == NDBT_OK)
890 NDB_MGM_NODE_TYPE_UNKNOWN
895 int iterations = ctx->getNumLoops();
901 while (iterations-- != 0 && result == NDBT_OK)
905 ndbout_c(
"Could not get status!");
913 ndbout_c(
"Could not get status2!");
921 ndbout_c(
"Could not get status2 second time!");
934 while(!ctx->isTestStopped() &&
935 (result= runTestStatus(ctx, step)) == NDBT_OK)
948 if (!call_args.contains(
"version"))
949 call_args.put(
"version", 1);
950 if (!call_args.contains(
"nodetype"))
951 call_args.put(
"nodetype", 1);
952 if (!call_args.contains(
"nodeid"))
953 call_args.put(
"nodeid", 1);
954 if (!call_args.contains(
"user"))
955 call_args.put(
"user",
"mysqld");
956 if (!call_args.contains(
"password"))
957 call_args.put(
"password",
"mysqld");
958 if (!call_args.contains(
"public key"))
959 call_args.put(
"public key",
"a public key");
960 if (!call_args.contains(
"name"))
961 call_args.put(
"name",
"testMgm");
962 if (!call_args.contains(
"log_event"))
963 call_args.put(
"log_event", 1);
964 if (!call_args.contains(
"timeout"))
965 call_args.put(
"timeout", 100);
967 if (!call_args.contains(
"endian"))
969 union {
long l;
char c[
sizeof(long)]; } endian_check;
971 call_args.put(
"endian", (endian_check.c[
sizeof(
long)-1])?
"big":
"little");
974 if (!mgmd.call(
"get nodeid", call_args,
975 "get nodeid reply", reply))
977 g_err <<
"get_nodeid: mgmd.call failed" << endl;
990 if (!reply.get(
"result", &result)){
991 ndbout_c(
"result: no 'result' found in reply");
998 static bool result_contains(
const Properties& reply,
999 const char* expected_result)
1002 if (strstr(result.c_str(), expected_result) == NULL){
1003 ndbout_c(
"result_contains: result string '%s' "
1004 "didn't contain expected result '%s'",
1005 result.c_str(), expected_result);
1008 g_info <<
" result: " << result << endl;
1024 if (result ==
"Failed")
1033 if (!reply.get(
"message", &message)){
1034 ndbout_c(
"message: no 'message' found in reply");
1041 static bool message_contains(
const Properties& reply,
1042 const char* expected_message)
1045 if (strstr(message.c_str(), expected_message) == NULL){
1046 ndbout_c(
"message_contains: message string '%s' "
1047 "didn't contain expected message '%s'",
1048 message.c_str(), expected_message);
1051 g_info <<
" message: " << message << endl;
1056 static bool get_nodeid_result_contains(
NdbMgmd& mgmd,
1058 const char* expected_result)
1061 if (!get_nodeid(mgmd, args, reply))
1063 return result_contains(reply, expected_result);
1069 check_get_nodeid_invalid_endian1(
NdbMgmd& mgmd)
1071 union {
long l;
char c[
sizeof(long)]; } endian_check;
1075 args.
put(
"endian", (endian_check.c[
sizeof(
long)-1])?
"little":
"big");
1076 return get_nodeid_result_contains(mgmd, args,
1077 "Node does not have the same endian");
1082 check_get_nodeid_invalid_endian2(
NdbMgmd& mgmd)
1086 args.
put(
"endian",
"hepp");
1087 return get_nodeid_result_contains(mgmd, args,
1088 "Node does not have the same endian");
1093 check_get_nodeid_invalid_nodetype1(
NdbMgmd& mgmd)
1096 args.
put(
"nodetype", 37);
1097 return get_nodeid_result_contains(mgmd, args,
1098 "unknown nodetype 37");
1102 check_get_nodeid_invalid_nodeid(
NdbMgmd& mgmd)
1104 for (
int nodeId = MAX_NODES; nodeId < MAX_NODES+2; nodeId++){
1105 g_info <<
"Testing invalid node " << nodeId << endl;;
1108 args.
put(
"nodeid", nodeId);
1110 expected.
assfmt(
"illegal nodeid %d", nodeId);
1111 if (!get_nodeid_result_contains(mgmd, args, expected.
c_str()))
1118 check_get_nodeid_dynamic_nodeid(
NdbMgmd& mgmd)
1122 for (
int nodeType = NDB_MGM_NODE_TYPE_MIN;
1123 nodeType < NDB_MGM_NODE_TYPE_MAX; nodeType++){
1126 g_info <<
"Testing dynamic nodeid " << nodeId
1127 <<
", nodeType: " << nodeType << endl;
1130 args.
put(
"nodeid", nodeId);
1131 args.
put(
"nodetype", nodeType);
1133 if (!get_nodeid(mgmd, args, reply))
1142 expected1.
assfmt(
"No free node id found for %s",
1143 NdbMgmd::NodeType(nodeType).c_str());
1145 expected2.
assfmt(
"Connection done from wrong host");
1146 if (!(result_contains(reply, expected1.
c_str()) ||
1147 result_contains(reply, expected2.
c_str())))
1158 check_get_nodeid_nonode(
NdbMgmd& mgmd)
1162 if (!mgmd.get_config(conf))
1166 for(Uint32
i= 1;
i < MAX_NODES;
i++){
1168 if (iter.find(CFG_NODE_ID,
i) != 0){
1176 g_info <<
"Testing nonexisting node " << nodeId << endl;;
1179 args.
put(
"nodeid", nodeId);
1181 expected.
assfmt(
"No node defined with id=%d", nodeId);
1182 return get_nodeid_result_contains(mgmd, args, expected.
c_str());
1187 check_get_nodeid_nodeid1(
NdbMgmd& mgmd)
1191 if (!mgmd.get_config(conf))
1195 Uint32 nodeType = NDB_MGM_NODE_TYPE_UNKNOWN;
1196 for(Uint32
i= 1;
i < MAX_NODES;
i++){
1198 if (iter.find(CFG_NODE_ID,
i) == 0){
1200 iter.get(CFG_TYPE_OF_SECTION, &nodeType);
1205 assert(nodeType != (Uint32)NDB_MGM_NODE_TYPE_UNKNOWN);
1208 args.
put(
"nodeid",nodeId);
1209 args.
put(
"nodetype",nodeType);
1210 if (!get_nodeid(mgmd, args, reply))
1212 g_err <<
"check_get_nodeid_nodeid1: failed for "
1213 <<
"nodeid: " << nodeId <<
", nodetype: " << nodeType << endl;
1222 check_get_nodeid_wrong_nodetype(
NdbMgmd& mgmd)
1226 if (!mgmd.get_config(conf))
1230 Uint32 nodeType = NDB_MGM_NODE_TYPE_UNKNOWN;
1231 for(Uint32
i= 1;
i < MAX_NODES;
i++){
1233 if (iter.find(CFG_NODE_ID,
i) == 0){
1235 iter.get(CFG_TYPE_OF_SECTION, &nodeType);
1239 assert(nodeId && nodeType != (Uint32)NDB_MGM_NODE_TYPE_UNKNOWN);
1241 nodeType = (nodeType + 1) / NDB_MGM_NODE_TYPE_MAX;
1242 assert((
int)nodeType >= (
int)NDB_MGM_NODE_TYPE_MIN &&
1243 (
int)nodeType <= (
int)NDB_MGM_NODE_TYPE_MAX);
1246 args.
put(
"nodeid",nodeId);
1247 args.
put(
"nodeid",nodeType);
1248 if (!get_nodeid(mgmd, args, reply))
1250 g_err <<
"check_get_nodeid_nodeid1: failed for "
1251 <<
"nodeid: " << nodeId <<
", nodetype: " << nodeType << endl;
1255 expected.
assfmt(
"Id %d configured as", nodeId);
1256 return result_contains(reply, expected.
c_str());
1265 if (!mgmd.connect())
1268 int result= NDBT_FAILED;
1270 check_get_nodeid_invalid_endian1(mgmd) &&
1271 check_get_nodeid_invalid_endian2(mgmd) &&
1272 check_get_nodeid_invalid_nodetype1(mgmd) &&
1273 check_get_nodeid_invalid_nodeid(mgmd) &&
1274 check_get_nodeid_dynamic_nodeid(mgmd) &&
1275 check_get_nodeid_nonode(mgmd) &&
1277 check_get_nodeid_wrong_nodetype(mgmd) &&
1281 if (!mgmd.end_session())
1282 result= NDBT_FAILED;
1290 int result= NDBT_OK;
1291 while(!ctx->isTestStopped() &&
1292 (result= runTestGetNodeId(ctx, step)) == NDBT_OK)
1300 int counter= 3*ctx->getNumLoops();
1302 while(!ctx->isTestStopped() && counter--)
1303 NdbSleep_SecSleep(1);;
1310 check_connection(
NdbMgmd& mgmd)
1313 mgmd.verbose(
false);
1314 bool result= mgmd.call(
"check connection", args,
1315 "check connection reply", reply);
1322 check_transporter_connect(
NdbMgmd& mgmd,
const char * hello)
1327 if (out.println(
"transporter connect\n"))
1329 g_err <<
"Send failed" << endl;
1334 g_info <<
"Client hello: '" << hello <<
"'" << endl;
1335 if (out.println(
"%s", hello))
1337 g_err <<
"Send hello '" << hello <<
"' failed" << endl;
1343 if (check_connection(mgmd)){
1344 g_err <<
"not disconnected" << endl;
1349 if (!mgmd.disconnect())
1351 if (!mgmd.connect())
1362 if (!mgmd.connect())
1365 int result = NDBT_FAILED;
1368 check_transporter_connect(mgmd,
"hello") &&
1369 check_transporter_connect(mgmd,
"hello again") &&
1372 check_transporter_connect(mgmd,
"string_longer_than_buf_1234567890") &&
1375 check_transporter_connect(mgmd,
"-1") &&
1376 check_transporter_connect(mgmd,
"-2 2") &&
1377 check_transporter_connect(mgmd,
"10000") &&
1378 check_transporter_connect(mgmd,
"99999 8") &&
1397 if (!mgmd.call(
"show config", args,
1398 "show config reply", reply, NULL,
false))
1400 g_err <<
"show_config: mgmd.call failed" << endl;
1414 if (!mgmd.connect())
1419 if (!show_config(mgmd, args1, config1))
1424 if (!mgmd.get_config(conf))
1429 conf.getConnectString(connectstring,
";");
1432 connectstring.
split(mgmds,
";");
1436 for (
size_t i = 0;
i < mgmds.size();
i++)
1439 g_info <<
"Connecting to " << mgmds[
i].c_str() << endl;
1440 if (!mgmd2.connect(mgmds[
i].c_str()))
1445 if (!show_config(mgmd, args2, config2))
1454 if (config1.get(
"line", line, &value1))
1457 if (config2.get(
"line", line, &value2))
1460 if (strcmp(value1, value2) != 0)
1462 g_err <<
"the value on line " << line <<
"didn't match!" << endl;
1463 g_err <<
"config1, value: " << value1 << endl;
1464 g_err <<
"config2, value: " << value2 << endl;
1471 g_err <<
"config2 didn't have line " << line <<
"!" << endl;
1478 if (config2.get(
"line", line, &value2))
1480 g_err <<
"config2 had line " << line <<
" not in config1!" << endl;
1485 g_info <<
"There was " << line <<
" lines in config" << endl;
1492 g_err <<
"FAIL: config should have lines!" << endl;
1498 if (!mgmd.get_config(conf2))
1501 if (!conf.equal(&conf2))
1503 g_err <<
"The binary config was different! host: " << mgmds[
i] << endl;
1518 if (!mgmd.call(
"reload config", args,
1519 "reload config reply", reply))
1521 g_err <<
"reload config: mgmd.call failed" << endl;
1530 static bool reload_config_result_contains(
NdbMgmd& mgmd,
1532 const char* expected_result)
1535 if (!reload_config(mgmd, args, reply))
1537 return result_contains(reply, expected_result);
1542 check_reload_config_both_config_and_mycnf(
NdbMgmd& mgmd)
1546 args.
put(
"config_filename",
"some filename");
1547 args.
put(
"mycnf", 1);
1548 return reload_config_result_contains(mgmd, args,
1549 "ERROR: Both mycnf and config_filename");
1556 if (!mgmd.call(
"show variables",
"",
1557 "show variables reply", reply))
1559 g_err <<
"show_variables: mgmd.call failed" << endl;
1567 check_reload_config_invalid_config_filename(
NdbMgmd& mgmd,
bool mycnf)
1570 BaseString expected(
"Could not load configuration from 'nonexisting_file");
1574 expected.
assign(
"Can't switch to use config.ini 'nonexisting_file' "
1575 "when node was started from my.cnf");
1580 args.
put(
"config_filename",
"nonexisting_file");
1581 return reload_config_result_contains(mgmd, args, expected.
c_str());
1589 if (!mgmd.connect())
1593 if (!show_variables(mgmd, variables))
1598 const char* mycnf_str;
1599 if (!variables.get(
"mycnf", &mycnf_str))
1601 bool uses_mycnf = (strcmp(mycnf_str,
"yes") == 0);
1603 int result= NDBT_FAILED;
1605 check_reload_config_both_config_and_mycnf(mgmd) &&
1606 check_reload_config_invalid_config_filename(mgmd, uses_mycnf) &&
1610 if (!mgmd.end_session())
1611 result= NDBT_FAILED;
1626 if (!call_args.contains(
"Content-Type"))
1627 call_args.put(
"Content-Type",
"ndbconfig/octet-stream");
1628 if (!call_args.contains(
"Content-Transfer-Encoding"))
1629 call_args.put(
"Content-Transfer-Encoding",
"base64");
1630 if (!call_args.contains(
"Content-Length"))
1631 call_args.put(
"Content-Length",
1632 encoded_config.
length() ? encoded_config.
length() - 1 : 1);
1634 if (!mgmd.call(
"set config", call_args,
1635 "set config reply", reply,
1636 encoded_config.
c_str()))
1638 g_err <<
"set config: mgmd.call failed" << endl;
1647 static bool set_config_result_contains(
NdbMgmd& mgmd,
1650 const char* expected_result)
1653 if (!set_config(mgmd, args, encoded_config, reply))
1655 return result_contains(reply, expected_result);
1659 static bool set_config_result_contains(
NdbMgmd& mgmd,
1661 const char* expected_result)
1667 if (!conf.pack64(encoded_config))
1670 if (!set_config(mgmd, args, encoded_config, reply))
1672 return result_contains(reply, expected_result);
1677 check_set_config_invalid_content_type(
NdbMgmd& mgmd)
1680 args.
put(
"Content-Type",
"illegal type");
1681 return set_config_result_contains(mgmd, args,
BaseString(
""),
1682 "Unhandled content type 'illegal type'");
1686 check_set_config_invalid_content_encoding(
NdbMgmd& mgmd)
1689 args.
put(
"Content-Transfer-Encoding",
"illegal encoding");
1690 return set_config_result_contains(mgmd, args,
BaseString(
""),
1691 "Unhandled content encoding "
1692 "'illegal encoding'");
1696 check_set_config_too_large_content_length(
NdbMgmd& mgmd)
1699 args.
put(
"Content-Length", 1024*1024 + 1);
1700 return set_config_result_contains(mgmd, args,
BaseString(
""),
1701 "Illegal config length size 1048577");
1705 check_set_config_too_small_content_length(
NdbMgmd& mgmd)
1708 args.
put(
"Content-Length", (Uint32)0);
1709 return set_config_result_contains(mgmd, args,
BaseString(
""),
1710 "Illegal config length size 0");
1714 check_set_config_wrong_config_length(
NdbMgmd& mgmd)
1719 if (!mgmd.get_config(conf))
1723 if (!conf.pack64(encoded_config))
1727 args.
put(
"Content-Length", encoded_config.
length() - 20);
1728 bool res = set_config_result_contains(mgmd, args, encoded_config,
1729 "Failed to unpack config");
1736 if (!mgmd.disconnect())
1738 if (!mgmd.connect())
1750 if (!mgmd.get_config(conf))
1755 conf.getConnectString(connectstring,
";");
1758 connectstring.
split(mgmds,
";");
1762 for (
size_t i = 0;
i < mgmds.size();
i++)
1765 g_info <<
"Connecting to " << mgmds[
i].c_str() << endl;
1766 if (!mgmd2.connect(mgmds[
i].c_str()))
1771 if (!mgmd2.get_config(conf2))
1776 if (!conf2.setValue(CFG_SECTION_NODE, 0,
1777 CFG_NODE_ARBIT_DELAY,
1781 if (!mgmd2.set_config(conf2))
1785 if (runCheckConfig(ctx, step) != NDBT_OK)
1794 check_set_config_fail_wrong_generation(
NdbMgmd& mgmd)
1798 if (!mgmd.get_config(conf))
1802 if (!conf.setGeneration(conf.getGeneration() + 10))
1806 return set_config_result_contains(mgmd, conf,
1807 "Invalid generation in");
1811 check_set_config_fail_wrong_name(
NdbMgmd& mgmd)
1815 if (!mgmd.get_config(conf))
1819 if (!conf.setName(
"NEWNAME"))
1823 return set_config_result_contains(mgmd, conf,
1824 "Invalid configuration name");
1828 check_set_config_fail_wrong_primary(
NdbMgmd& mgmd)
1832 if (!mgmd.get_config(conf))
1836 if (!conf.setPrimaryMgmNode(conf.getPrimaryMgmNode()+10))
1840 return set_config_result_contains(mgmd, conf,
1841 "Not primary mgm node");
1848 if (!mgmd.connect())
1851 int result= NDBT_FAILED;
1853 check_set_config_invalid_content_type(mgmd) &&
1854 check_set_config_invalid_content_encoding(mgmd) &&
1855 check_set_config_too_large_content_length(mgmd) &&
1856 check_set_config_too_small_content_length(mgmd) &&
1857 check_set_config_wrong_config_length(mgmd) &&
1858 check_set_config_any_node(ctx, step, mgmd) &&
1859 check_set_config_fail_wrong_generation(mgmd) &&
1860 check_set_config_fail_wrong_name(mgmd) &&
1861 check_set_config_fail_wrong_primary(mgmd) &&
1865 if (!mgmd.end_session())
1866 result= NDBT_FAILED;
1875 if (!mgmd.connect())
1878 int result = NDBT_OK;
1879 int loops = ctx->getNumLoops();
1882 int invalid_generation = 0, config_change_ongoing = 0;
1888 while (sucessful < loops &&
1889 !ctx->isTestStopped() &&
1894 if (!mgmd.get_config(conf))
1898 mgmd.verbose(
false);
1899 if (mgmd.set_config(conf))
1907 if (mgmd.last_error() != NDB_MGM_CONFIG_CHANGE_FAILED)
1909 g_err <<
"Config change failed with unexpected error: "
1910 << mgmd.last_error() << endl;
1911 result = NDBT_FAILED;
1916 if (error ==
"Invalid generation in configuration")
1917 invalid_generation++;
1919 if (error ==
"Config change ongoing")
1920 config_change_ongoing++;
1923 g_err <<
"Config change failed with unexpected error: '"
1924 << error <<
"'" << endl;
1925 result = NDBT_FAILED;
1931 ndbout <<
"Thread " << step->getStepNo()
1932 <<
", sucess: " << sucessful
1933 <<
", ongoing: " << config_change_ongoing
1934 <<
", invalid_generation: " << invalid_generation << endl;
1940 int result= NDBT_OK;
1941 while(!ctx->isTestStopped() &&
1942 (result= runTestSetConfigParallel(ctx, step)) == NDBT_OK)
1950 get_connection_parameter(
NdbMgmd& mgmd,
1957 if (!call_args.contains(
"node1"))
1958 call_args.put(
"node1", 1);
1959 if (!call_args.contains(
"node2"))
1960 call_args.put(
"node2", 1);
1961 if (!call_args.contains(
"param"))
1962 call_args.put(
"param", CFG_CONNECTION_SERVER_PORT);
1964 if (!mgmd.call(
"get connection parameter", call_args,
1965 "get connection parameter reply", reply))
1967 g_err <<
"get_connection_parameter: mgmd.call failed" << endl;
1975 set_connection_parameter(
NdbMgmd& mgmd,
1982 if (!call_args.contains(
"node1"))
1983 call_args.put(
"node1", 1);
1984 if (!call_args.contains(
"node2"))
1985 call_args.put(
"node2", 1);
1986 if (!call_args.contains(
"param"))
1987 call_args.put(
"param", CFG_CONNECTION_SERVER_PORT);
1988 if (!call_args.contains(
"value"))
1989 call_args.put(
"value", 37);
1991 if (!mgmd.call(
"set connection parameter", call_args,
1992 "set connection parameter reply", reply))
1994 g_err <<
"set_connection_parameter: mgmd.call failed" << endl;
2002 check_connection_parameter_invalid_nodeid(
NdbMgmd& mgmd)
2004 for (
int nodeId = MAX_NODES; nodeId < MAX_NODES+2; nodeId++){
2005 g_info <<
"Testing invalid node " << nodeId << endl;;
2008 args.
put(
"node1", nodeId);
2009 args.
put(
"node2", nodeId);
2012 if (!get_connection_parameter(mgmd, args, get_result))
2015 if (!result_contains(get_result,
2016 "Unable to find connection between nodes"))
2020 if (!set_connection_parameter(mgmd, args, set_result))
2023 if (!failed(set_result))
2026 if (!message_contains(set_result,
2027 "Unable to find connection between nodes"))
2035 check_connection_parameter(
NdbMgmd& mgmd)
2039 if (!mgmd.get_config(conf))
2043 for(Uint32
i= 1;
i < MAX_NODES;
i++){
2046 if (iter.find(CFG_NODE_ID,
i) == 0 &&
2047 iter.get(CFG_TYPE_OF_SECTION, &nodeType) == 0 &&
2054 NodeId otherNodeId = 0;
2058 for (
int nodeId = 1; nodeId < MAX_NODES; nodeId++){
2060 g_info <<
"Checking if connection between " << nodeId1
2061 <<
" and " << nodeId <<
" exists" << endl;
2064 args.
put(
"node1", nodeId1);
2065 args.
put(
"node2", nodeId);
2068 if (!get_connection_parameter(mgmd, args, result))
2076 otherNodeId = nodeId;
2079 if (!result.get(
"value", original_value))
2081 g_err <<
"Failed to get original value" << endl;
2087 if (otherNodeId == 0)
2089 g_err <<
"Could not find a suitable connection for test" << endl;
2094 get_args.
put(
"node1", nodeId1);
2095 get_args.
put(
"node2", otherNodeId);
2098 g_info <<
"Set new value(37 by default)" << endl;
2102 if (!set_connection_parameter(mgmd, set_args, set_result))
2105 if (!
ok(set_result))
2110 g_info <<
"Check new value" << endl;
2113 if (!get_connection_parameter(mgmd, get_args, get_result))
2116 if (!
ok(get_result))
2120 if (!get_result.get(
"value", new_value))
2122 g_err <<
"Failed to get new value" << endl;
2126 g_info <<
"new_value: " << new_value << endl;
2127 if (new_value !=
"37")
2129 g_err <<
"New value was not correct, expected 37, got "
2130 << new_value << endl;
2136 g_info <<
"Restore old value" << endl;
2139 if (!set_args.put(
"value", original_value.
c_str()))
2141 g_err <<
"Failed to put original_value" << endl;
2146 if (!set_connection_parameter(mgmd, set_args, set_result))
2149 if (!
ok(set_result))
2154 g_info <<
"Check restored value" << endl;
2156 if (!get_connection_parameter(mgmd, get_args, get_result))
2159 if (!
ok(get_result))
2163 if (!get_result.get(
"value", restored_value))
2165 g_err <<
"Failed to get restored value" << endl;
2169 if (restored_value != original_value)
2171 g_err <<
"Restored value was not correct, expected "
2172 << original_value <<
", got "
2173 << restored_value << endl;
2176 g_info <<
"restored_value: " << restored_value << endl;
2188 if (!mgmd.connect())
2191 int result= NDBT_FAILED;
2193 check_connection_parameter(mgmd) &&
2194 check_connection_parameter_invalid_nodeid(mgmd) &&
2198 if (!mgmd.end_session())
2199 result= NDBT_FAILED;
2207 int result= NDBT_OK;
2208 while(!ctx->isTestStopped() &&
2209 (result= runTestConnectionParameter(ctx, step)) == NDBT_OK)
2217 check_restart_connected(
NdbMgmd& mgmd)
2219 if (!mgmd.restart())
2228 if (!mgmd.connect())
2231 int result= NDBT_FAILED;
2233 check_restart_connected(mgmd) &&
2237 if (!mgmd.end_session())
2238 result= NDBT_FAILED;
2257 g_err <<
"set_logfilter: ndb_mgm_set_clusterlog_severity_filter failed"
2267 unsigned int* value)
2271 severity_struct.category = severity;
2276 g_err <<
"get_logfilter: ndb_mgm_get_clusterlog_severity_filter failed"
2282 *value = severity_struct.value;
2292 if (!mgmd.connect())
2297 g_info <<
"severity: " <<
i << endl;
2301 unsigned int initial_value;
2302 if (!get_logfilter(mgmd, severity, &initial_value))
2306 if (!set_logfilter(mgmd, severity, 0))
2310 unsigned int curr_value;
2311 if (!get_logfilter(mgmd, severity, &curr_value))
2314 if (curr_value != 0)
2316 g_err <<
"Failed to turn off severity: " << severity << endl;
2321 if (!set_logfilter(mgmd, severity, 1))
2325 if (!get_logfilter(mgmd, severity, &curr_value))
2328 if (curr_value == 0)
2330 g_err <<
"Filed to turn on severity: " << severity << endl;
2335 if (!set_logfilter(mgmd, severity, -1))
2339 if (!get_logfilter(mgmd, severity, &curr_value))
2342 if (curr_value != 0)
2344 g_err <<
"Failed to toggle severity : " << severity << endl;
2349 if (!set_logfilter(mgmd, severity, initial_value))
2362 if (!mgmd.connect())
2375 g_info <<
"Calling ndb_log_event_get_next" << endl;
2381 g_info <<
"ndb_log_event_get_next returned " << r << endl;
2383 int result = NDBT_FAILED;
2387 g_info <<
"ndb_logevent_get_next returned timeout" << endl;
2393 g_err <<
"ERROR: Receieved unexpected event: "
2394 << le_event.type << endl;
2396 g_err <<
"ERROR: ndb_logevent_get_next returned error: "
2400 ndb_mgm_destroy_logevent_handle(&le_handle);
2408 int result = NDBT_OK;
2409 int loops = ctx->getNumLoops();
2417 if (!mgmd->set_timeout(1000))
2419 result = NDBT_FAILED;
2423 if (mgmd->connect())
2425 mgmds.push_back(mgmd);
2426 g_info <<
"connections: " << mgmds.size() << endl;
2430 g_err <<
"Failed to make another connection, connections: "
2431 << mgmds.size() << endl;
2435 int to_disconnect = 10;
2436 while(mgmds.size() && to_disconnect--)
2438 g_info <<
"disconnnect, connections: " << mgmds.size() << endl;
2465 if (!mgmd.connect())
2469 int major, minor, build;
2471 &major, &minor, &build,
2472 sizeof(verStr), verStr) != 1)
2474 g_err <<
"ndb_mgm_get_version failed,"
2480 g_info <<
"Using major: " << major
2481 <<
" minor: " << minor
2482 <<
" build: " << build
2483 <<
" string: " << verStr << endl;
2486 int loops = ctx->getNumLoops();
2490 int major2, minor2, build2;
2492 &major2, &minor2, &build2,
2493 sizeof(verStr2), verStr2) != 1)
2495 g_err <<
"ndb_mgm_get_version failed,"
2501 if (major != major2)
2503 g_err <<
"Got different major: " << major2
2504 <<
" excpected: " << major << endl;
2508 if (minor != minor2)
2510 g_err <<
"Got different minor: " << minor2
2511 <<
" excpected: " << minor << endl;
2515 if (build != build2)
2517 g_err <<
"Got different build: " << build2
2518 <<
" excpected: " << build << endl;
2522 if (strcmp(verStr, verStr2) != 0)
2524 g_err <<
"Got different verStr: " << verStr2
2525 <<
" excpected: " << verStr << endl;
2539 int result= NDBT_OK;
2540 while(!ctx->isTestStopped() &&
2541 (result= runTestGetVersion(ctx, step)) == NDBT_OK)
2551 if (!mgmd.connect())
2557 g_info <<
"ndb_mgm_dump_events(" << unsupported <<
")" << endl;
2563 g_err <<
"ndb_mgm_dump_events returned events "
2564 <<
"for unsupported Ndb_logevent_type" << endl;
2569 strcmp(
"ndb_logevent_type 59 not supported",
2572 g_err <<
"Unexpected error for unsupported logevent type, "
2581 for (
int i = MAX_NDB_NODES;
i < MAX_NDB_NODES + 3;
i++)
2583 g_info <<
"ndb_mgm_dump_events(NDB_LE_MemoryUsage, 1, "
2584 <<
i <<
")" << endl;
2590 g_err <<
"ndb_mgm_dump_events returned events "
2591 <<
"for too large nodeid" << endl;
2598 "invalid nodes: '%d'", &invalid_nodeid) != 1 ||
2599 invalid_nodeid !=
i)
2601 g_err <<
"Unexpected error for too large nodeid, "
2611 int loops = ctx->getNumLoops();
2622 for (
int i = 0; supported[
i];
i++)
2624 g_info <<
"ndb_mgm_dump_events(" << supported[
i] <<
")" << endl;
2630 g_err <<
"ndb_mgm_dump_events failed, type: " << supported[
i]
2639 g_err <<
"ndb_mgm_dump_events returned a negative number of events: "
2645 g_info <<
"Got " << events->
no_of_events <<
" events" << endl;
2658 mgmd.set_timeout(50);
2660 if (!mgmd.connect())
2665 NDB_MGM_NODE_TYPE_UNKNOWN };
2668 printf(
"Getting status\n");
2688 printf(
"Stopping data node\n");
2690 int nodes[1] = { nodeId };
2691 int stopped =
ndb_mgm_restart2(mgmd.handle(), NDB_ARRAY_SIZE(nodes), nodes,
2695 printf(
"ndb_mgm_stop failed, '%s' (%d)\n",
2701 printf(
"Stopped %d data node(s)\n", stopped);
2703 printf(
"Getting status\n");
2720 res.waitClusterStarted();
2725 NDBT_TESTSUITE(testMgm);
2726 DRIVER(DummyDriver);
2727 TESTCASE(
"ApiSessionFailure",
2728 "Test failures in MGMAPI session"){
2729 INITIALIZER(runTestApiSession);
2732 TESTCASE(
"ApiConnectTimeout",
2733 "Connect timeout tests for MGMAPI"){
2734 INITIALIZER(runTestApiConnectTimeout);
2737 TESTCASE(
"ApiTimeoutBasic",
2738 "Basic timeout tests for MGMAPI"){
2739 INITIALIZER(runTestApiTimeoutBasic);
2742 TESTCASE(
"ApiGetStatusTimeout",
2743 "Test timeout for MGMAPI getStatus"){
2744 INITIALIZER(runTestApiGetStatusTimeout);
2747 TESTCASE(
"ApiGetConfigTimeout",
2748 "Test timeouts for mgmapi get_configuration"){
2749 INITIALIZER(runTestMgmApiGetConfigTimeout);
2752 TESTCASE(
"ApiMgmEventTimeout",
2753 "Test timeouts for mgmapi get_configuration"){
2754 INITIALIZER(runTestMgmApiEventTimeout);
2757 TESTCASE(
"ApiMgmStructEventTimeout",
2758 "Test timeouts for mgmapi get_configuration"){
2759 INITIALIZER(runTestMgmApiStructEventTimeout);
2762 TESTCASE(
"SetConfig",
2763 "Tests the ndb_mgm_set_configuration function"){
2764 INITIALIZER(runSetConfig);
2766 TESTCASE(
"CheckConfig",
2767 "Connect to each ndb_mgmd and check they have the same configuration"){
2768 INITIALIZER(runCheckConfig);
2770 TESTCASE(
"TestReloadConfig",
2771 "Test of 'reload config'"){
2772 INITIALIZER(runTestReloadConfig);
2774 TESTCASE(
"TestSetConfig",
2775 "Test of 'set config'"){
2776 INITIALIZER(runTestSetConfig);
2778 TESTCASE(
"TestSetConfigParallel",
2779 "Test of 'set config' from 5 threads"){
2780 STEPS(runTestSetConfigParallel, 5);
2782 TESTCASE(
"GetConfig",
"Run ndb_mgm_get_configuration in parallel"){
2783 STEPS(runGetConfig, 100);
2785 TESTCASE(
"TestStatus",
2786 "Test status and status2"){
2787 INITIALIZER(runTestStatus);
2790 TESTCASE(
"TestStatus200",
2791 "Test status and status2 with 200 threads"){
2792 STEPS(runTestStatus, 200);
2795 TESTCASE(
"TestGetNodeId",
2796 "Test 'get nodeid'"){
2797 INITIALIZER(runTestGetNodeId);
2799 TESTCASE(
"TestGetVersion",
2800 "Test 'get version' and 'ndb_mgm_get_version'"){
2801 STEPS(runTestGetVersion, 20);
2803 TESTCASE(
"TestTransporterConnect",
2804 "Test 'transporter connect'"){
2805 INITIALIZER(runTestTransporterConnect);
2807 TESTCASE(
"TestConnectionParameter",
2808 "Test 'get/set connection parameter'"){
2809 INITIALIZER(runTestConnectionParameter);
2811 TESTCASE(
"TestSetLogFilter",
2812 "Test 'set logfilter' and 'get info clusterlog'"){
2813 INITIALIZER(runTestSetLogFilter);
2816 TESTCASE(
"TestRestartMgmd",
2817 "Test restart of ndb_mgmd(s)"){
2818 INITIALIZER(runTestRestartMgmd);
2821 TESTCASE(
"Bug40922",
2822 "Make sure that ndb_logevent_get_next returns when "
2823 "called with a timeout"){
2824 INITIALIZER(runTestBug40922);
2827 "Run everything while changing config"){
2828 STEP(runTestGetNodeIdUntilStopped);
2829 STEP(runSetConfigUntilStopped);
2830 STEPS(runGetConfigUntilStopped, 10);
2831 STEPS(runGetConfigFromNodeUntilStopped, 10);
2832 STEPS(runTestStatusUntilStopped, 10);
2833 STEPS(runTestGetVersionUntilStopped, 5);
2834 STEP(runSleepAndStop);
2837 "Run everything while changing config in parallel"){
2838 STEP(runTestGetNodeIdUntilStopped);
2839 STEPS(runTestSetConfigParallelUntilStopped, 5);
2840 STEPS(runGetConfigUntilStopped, 10);
2841 STEPS(runGetConfigFromNodeUntilStopped, 10);
2842 STEPS(runTestStatusUntilStopped, 10);
2843 STEPS(runTestGetVersionUntilStopped, 5);
2844 STEP(runSleepAndStop);
2846 TESTCASE(
"Bug45497",
2847 "Connect to ndb_mgmd until it can't handle more connections"){
2848 STEP(runTestBug45497);
2850 TESTCASE(
"TestGetVersion",
2851 "Test 'get version' and 'ndb_mgm_get_version'"){
2852 STEPS(runTestGetVersion, 20);
2854 TESTCASE(
"TestDumpEvents",
2855 "Test 'dump events'"){
2856 STEPS(runTestDumpEvents, 1);
2858 TESTCASE(
"TestStatusAfterStop",
2859 "Test get status after stop "){
2860 STEPS(runTestStatusAfterStop, 1);
2862 NDBT_TESTSUITE_END(testMgm);
2864 int main(
int argc,
const char** argv){
2866 NDBT_TESTSUITE_INSTANCE(testMgm);
2867 testMgm.setCreateTable(
false);
2868 testMgm.setRunAllTables(
true);
2869 return testMgm.execute(argc, argv);