1 /*
2    Copyright (c) 2015, 2021, Oracle and/or its affiliates.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #include <util/NdbTap.hpp>
26 
27 #include <mgmapi/mgmapi.h>
28 #include <mgmapi/mgmapi_debug.h>
29 #include "mgmapi_internal.h"
30 
31 
TAPTEST(mgmapi)32 TAPTEST(mgmapi)
33 {
34   // Check behaviour of error translation functions with NULL handle
35   OK(ndb_mgm_get_latest_error(NULL) == NDB_MGM_ILLEGAL_SERVER_HANDLE);
36   OK(strcmp(ndb_mgm_get_latest_error_msg(NULL),
37             "Illegal server handle") == 0);
38   OK(strcmp(ndb_mgm_get_latest_error_desc(NULL), "") == 0);
39   OK(ndb_mgm_get_latest_error_line(NULL) == 0);
40 
41   // Check behaviour of functions with NULL handle
42   // and not connected handle
43   NdbMgmHandle h = NULL;
44   for (int lap = 1 ; lap <= 2; lap++)
45   {
46     switch(lap)
47     {
48     case 1:
49       // Test with NULL handle
50       assert(h == NULL);
51       break;
52 
53     case 2:
54       // Create handle but don't connect
55       h = ndb_mgm_create_handle();
56       break;
57 
58     default:
59       assert(false);
60       break;
61     }
62 
63     OK(ndb_mgm_disconnect(h) == -1);
64     OK(ndb_mgm_get_status(h) == NULL);
65     OK(ndb_mgm_get_status2(h, NULL) == NULL);
66     OK(ndb_mgm_enter_single_user(h, 1, NULL) == -1);
67     OK(ndb_mgm_exit_single_user(h, NULL) == -1);
68     OK(ndb_mgm_stop(h, 1, NULL) == -1);
69     OK(ndb_mgm_stop2(h, 1, NULL, 1) == -1);
70     OK(ndb_mgm_stop3(h, 1, NULL, 2, NULL) == -1);
71     OK(ndb_mgm_stop4(h, 1, NULL, 2, 3, NULL) == -1);
72     OK(ndb_mgm_restart(h, 1, NULL) == -1);
73     OK(ndb_mgm_restart2(h, 1, NULL, 2, 3, 4) == -1);
74     OK(ndb_mgm_restart3(h, 1, NULL, 2, 3, 4, NULL) == -1);
75     OK(ndb_mgm_restart4(h, 1, NULL, 2, 3, 4, 5, NULL) == -1);
76     OK(ndb_mgm_get_clusterlog_severity_filter(h, NULL, 1) == -1);
77     OK(ndb_mgm_get_clusterlog_severity_filter_old(h) == NULL);
78     OK(ndb_mgm_set_clusterlog_severity_filter(h, NDB_MGM_EVENT_SEVERITY_ON,
79                                               1, NULL ) == -1);
80     OK(ndb_mgm_get_clusterlog_loglevel(h, NULL, 1) == -1);
81     OK(ndb_mgm_get_clusterlog_loglevel_old(h) == NULL);
82     OK(ndb_mgm_set_clusterlog_loglevel(h, 1, NDB_MGM_EVENT_CATEGORY_STARTUP,
83                                        2, NULL) == -1);
84     OK(ndb_mgm_set_loglevel_node(h, 1, NDB_MGM_EVENT_CATEGORY_BACKUP,
85                                  2, NULL) == -1);
86     OK(ndb_mgm_dump_state(h, 1, NULL, 2, NULL) == -1);
87     OK(ndb_mgm_get_configuration_from_node(h, 1) == NULL);
88     OK(ndb_mgm_start_signallog(h, 1, NULL) == -1);
89     OK(ndb_mgm_stop_signallog(h, 1, NULL) == -1);
90     OK(ndb_mgm_log_signals(h, 1, NDB_MGM_SIGNAL_LOG_MODE_IN,
91                            NULL, NULL) == -1);
92     OK(ndb_mgm_set_trace(h, 1, 2, NULL) == -1);
93     OK(ndb_mgm_insert_error(h, 1, 2, NULL) == -1);
94     OK(ndb_mgm_insert_error2(h, 1, 2, 3, NULL) == -1);
95     OK(ndb_mgm_start(h, 1, NULL) == -1);
96     OK(ndb_mgm_start_backup3(h, 1, NULL, NULL, 2, 3) == -1);
97     OK(ndb_mgm_start_backup2(h, 1, NULL, NULL, 2) == -1);
98     OK(ndb_mgm_start_backup(h, 1, NULL, NULL) == -1);
99     OK(ndb_mgm_abort_backup(h, 1, NULL) == -1);
100     OK(ndb_mgm_get_configuration2(h, 1, NDB_MGM_NODE_TYPE_API, 2) == NULL);
101     OK(ndb_mgm_get_configuration(h, 1) == NULL);
102 
103     OK(ndb_mgm_alloc_nodeid(h, 1, 2, 3) == -1);
104     OK(ndb_mgm_set_int_parameter(h, 1, 2, 3, NULL) == -1);
105     OK(ndb_mgm_set_int64_parameter(h, 1, 2, 3, NULL) == -1);
106     OK(ndb_mgm_set_string_parameter(h, 1, 2, NULL, NULL) == -1);
107     OK(ndb_mgm_purge_stale_sessions(h, NULL) == -1);
108     OK(ndb_mgm_check_connection(h) == -1);
109     OK(ndb_mgm_set_connection_int_parameter(h, 1, 2, 3, 4, NULL) == -1);
110     OK(ndb_mgm_get_connection_int_parameter(h, 1, 2, 3, NULL, NULL) == -1);
111     OK(ndb_mgm_get_mgmd_nodeid(h) == 0); // Zero is an invalid nodeid
112     OK(ndb_mgm_report_event(h, NULL, 1) == -1);
113     OK(ndb_mgm_end_session(h) == -1);
114     OK(ndb_mgm_get_version(h, NULL, NULL, NULL, 1, NULL) == -1);
115     OK(ndb_mgm_get_session_id(h) == 0); // Zero is invalid zession id
116     OK(ndb_mgm_get_session(h, 1, NULL, NULL) == -1);
117     OK(ndb_mgm_set_configuration(h, NULL) == -1);
118     OK(ndb_mgm_create_nodegroup(h, NULL, NULL, NULL) == -1);
119     OK(ndb_mgm_drop_nodegroup(h, 1, NULL) == -1);
120     OK(ndb_mgm_dump_events(h, NDB_LE_Connected, 1, NULL) == NULL);
121     OK(ndb_mgm_set_dynamic_ports(h, 1, NULL, 2) == -1);
122 
123   }
124 
125   // Exceptions are these functions which does not check connected
126   // since they don't communicate with the server, test only
127   // with NULL handle
128   OK(ndb_mgm_set_configuration_nodeid(NULL, 1) == -1);
129   OK(ndb_mgm_get_configuration_nodeid(NULL) == 0); // Zero is an invalid nodeid
130 
131   // Destroy handle
132   ndb_mgm_destroy_handle(&h);
133 
134   return 1; // OK
135 }
136 
137