Skip to content

Commit 24fffed

Browse files
author
Nelson Goncalves
committed
BUG#26393614: ADDING AN INSTANCE USING 'LOCALHOST' (SANDBOX) SHOULD THROW A WARNING
This patch adds warnings regarding the limitations using MySQL sandboxes with InnoDB Cluster. New warnings are now shown in the log file after the cluster.addInstance and dba.deploySandboxInstance operations. Furthermore, the deploySandboxInstance command also got a new warning when using the interactive mode. New tests were added to verify all of the above changes.
1 parent f36d9f8 commit 24fffed

File tree

16 files changed

+570
-26
lines changed

16 files changed

+570
-26
lines changed

interactive/interactive_global_dba.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "modules/mysqlxtest_utils.h"
3131
#include "utils/utils_general.h"
3232
#include "utils/utils_file.h"
33+
#include "utils/utils_path.h"
3334
#include "utils/utils_help.h"
3435
#include <boost/format.hpp>
3536

@@ -137,13 +138,21 @@ shcore::Value Global_dba::deploy_sandbox_instance(const shcore::Argument_list &a
137138

138139
std::string message;
139140
if (prompt_password) {
141+
std::vector<std::string> paths {sandbox_dir, std::to_string(port)};
142+
std::string path = shcore::join_path(paths);
140143
if (deploying) {
141-
message = "A new MySQL sandbox instance will be created on this host in \n"\
142-
"" + sandbox_dir + "/" + std::to_string(port) + "\n\n"
144+
message = "A new MySQL sandbox instance will be created on this host "
145+
"in \n" + path + "\n\n"
146+
"Warning: Sandbox instances are only suitable for deploying and \n"
147+
"running on your local machine for testing purposes and are not \n"
148+
"accessible from external networks.\n\n"
143149
"Please enter a MySQL root password for the new instance: ";
144150
} else {
145151
message = "The MySQL sandbox instance on this host in \n"\
146-
"" + sandbox_dir + "/" + std::to_string(port) + " will be started\n\n"
152+
"" + path + " will be started\n\n"
153+
"Warning: Sandbox instances are only suitable for deploying and \n"
154+
"running on your local machine for testing purposes and are not \n"
155+
"accessible from external networks.\n\n"
147156
"Please enter the MySQL root password of the instance: ";
148157
}
149158

@@ -197,8 +206,10 @@ shcore::Value Global_dba::perform_instance_operation(const shcore::Argument_list
197206
auto options = valid_args.map_at(1);
198207

199208
std::string sandboxDir {options->get_string("sandboxDir")};
209+
std::vector<std::string> paths {sandboxDir, std::to_string(port)};
210+
std::string path = shcore::join_path(paths);
200211
std::string message = "The MySQL sandbox instance on this host in \n"\
201-
"" + sandboxDir + "/" + std::to_string(port) + " will be " + past + "\n";
212+
"" + path + " will be " + past + "\n";
202213

203214
println(message);
204215

modules/adminapi/mod_dba.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,6 @@ shcore::Value Dba::deploy_sandbox_instance(const shcore::Argument_list &args, co
10421042
auto session = std::dynamic_pointer_cast<mysqlsh::mysql::ClassicSession>(
10431043
mysqlsh::connect_session(uri, password, mysqlsh::SessionType::Classic));
10441044
assert(session);
1045-
10461045
log_info("Creating root@%s account for sandbox %i", remote_root.c_str(), port);
10471046
session->execute_sql("SET sql_log_bin = 0");
10481047
{
@@ -1062,6 +1061,10 @@ shcore::Value Dba::deploy_sandbox_instance(const shcore::Argument_list &args, co
10621061
session->close(shcore::Argument_list());
10631062
}
10641063
}
1064+
log_warning(
1065+
"Sandbox instances are only suitable for deploying and running on "
1066+
"your local machine for testing purposes and are not accessible from "
1067+
"external networks.");
10651068
}
10661069
}
10671070
CATCH_AND_TRANSLATE_FUNCTION_EXCEPTION(get_function_name(fname));

modules/adminapi/mod_dba_replicaset.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ void ReplicaSet::validate_instance_address(std::shared_ptr<mysqlsh::mysql::Class
269269
"To add an instance to the cluster, please use a valid, non-local hostname or IP. "
270270
+ hostname + " can only be used with sandbox MySQL instances.");
271271
} else {
272-
log_info("'%s' (%s) detected as local sandbox", hostname.c_str(), datadir.c_str());
272+
log_warning(
273+
"'%s' (%s) detected as local sandbox. Sandbox instances are only "
274+
"suitable for deploying and running on your local machine for "
275+
"testing purposes and are not accessible from external networks.",
276+
hostname.c_str(), datadir.c_str());
273277
}
274278
} else {
275279
auto result = session->execute_sql("select @@report_host, @@hostname");

shellcore/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ file(GLOB libmysqlshcore_SRC
5656
"${CMAKE_SOURCE_DIR}/utils/utils_time.cc"
5757
"${CMAKE_SOURCE_DIR}/utils/utils_file.h"
5858
"${CMAKE_SOURCE_DIR}/utils/utils_file.cc"
59+
"${CMAKE_SOURCE_DIR}/utils/utils_path.h"
5960
"${CMAKE_SOURCE_DIR}/utils/utils_json.h"
6061
"${CMAKE_SOURCE_DIR}/utils/utils_json.cc"
6162
"${CMAKE_SOURCE_DIR}/utils/utils_general.h"
@@ -90,6 +91,13 @@ file(GLOB libmysqlshcore_SRC
9091
"${BOOST_SOURCE_CODE}"
9192
)
9293

94+
# platform dependent implementations
95+
IF(UNIX)
96+
LIST(APPEND libmysqlshcore_SRC "${CMAKE_SOURCE_DIR}/utils/utils_path_unix.cc")
97+
ELSEIF(WIN32)
98+
LIST(APPEND libmysqlshcore_SRC "${CMAKE_SOURCE_DIR}/utils/utils_path_win32.cc")
99+
ENDIF()
100+
93101
#if(NOT WINDOWS_RUNTIME_MD)
94102
list(APPEND libmysqlshcore_SRC "${CMAKE_SOURCE_DIR}/types/ishell_core.cc")
95103
list(APPEND libmysqlshcore_SRC "${CMAKE_SOURCE_DIR}/common/logger/logger.cc")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Assumptions: smart deployment routines available
2+
//@ Initialization
3+
var connected = connect_to_sandbox([__mysql_sandbox_port1]);
4+
if (connected)
5+
cleanup_sandbox(__mysql_sandbox_port1);
6+
7+
//@<OUT> Deploy sandbox
8+
dba.deploySandboxInstance(__mysql_sandbox_port1, {sandboxDir:__sandbox_dir});
9+
10+
//@ Finalization
11+
if (!connected)
12+
// if sandbox was not available when test start, clean it
13+
cleanup_sandbox(__mysql_sandbox_port1);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ Initialization
2+
||
3+
4+
//@<OUT> Deploy sandbox
5+
A new MySQL sandbox instance will be created on this host in
6+
<<<__sandbox_dir>>><<<__mysql_sandbox_port1>>>
7+
8+
Warning: Sandbox instances are only suitable for deploying and
9+
running on your local machine for testing purposes and are not
10+
accessible from external networks.
11+
12+
Please enter a MySQL root password for the new instance: Deploying new MySQL instance...
13+
14+
Instance <<<localhost>>>:<<<__mysql_sandbox_port1>>> successfully deployed and started.
15+
Use shell.connect('root@localhost:<<<__mysql_sandbox_port1>>>'); to connect to the instance.
16+
17+
//@ Finalization
18+
||

unittest/shell_js_dba_t.cc

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ TEST_F(Shell_js_dba_tests, no_active_session_error) {
201201
TEST_F(Shell_js_dba_tests, no_interactive_sandboxes) {
202202
_options->wizards = false;
203203
reset_shell();
204-
204+
output_handler.set_log_level(ngcommon::Logger::LOG_WARNING);
205205
execute("dba.verbose = true;");
206206

207207
// Create directory with space and quotes in name to test.
@@ -226,6 +226,12 @@ TEST_F(Shell_js_dba_tests, no_interactive_sandboxes) {
226226
// Remove previously created directories.
227227
shcore::remove_directory(dir);
228228
shcore::remove_directory(dir_long);
229+
// BUG#26393614
230+
std::vector<std::string> log{
231+
"Warning: Sandbox instances are only suitable for deploying and "
232+
"running on your local machine for testing purposes and are not "
233+
"accessible from external networks."};
234+
MY_EXPECT_LOG_CONTAINS(log);
229235
}
230236

231237
TEST_F(Shell_js_dba_tests, dba_help) {
@@ -252,6 +258,22 @@ TEST_F(Shell_js_dba_tests, no_interactive_deploy_instances) {
252258
validate_interactive("dba_reset_or_deploy.js");
253259
}
254260

261+
TEST_F(Shell_js_dba_tests, interactive_deploy_instance) {
262+
_options->interactive = true;
263+
reset_shell();
264+
output_handler.set_log_level(ngcommon::Logger::LOG_WARNING);
265+
// BUG 26830224
266+
// Please enter a MySQL root password for the new instance:
267+
output_handler.passwords.push_back("root");
268+
validate_interactive("dba_deploy_sandbox.js");
269+
// BUG#26393614
270+
std::vector<std::string> log{
271+
"Warning: Sandbox instances are only suitable for deploying and "
272+
"running on your local machine for testing purposes and are not "
273+
"accessible from external networks."};
274+
MY_EXPECT_LOG_CONTAINS(log);
275+
}
276+
255277
TEST_F(Shell_js_dba_tests, no_interactive_classic_global_dba) {
256278
std::string bad_config = "[mysqld]\ngtid_mode = OFF\n";
257279
create_file("mybad.cnf", bad_config);
@@ -582,7 +604,18 @@ TEST_F(Shell_js_dba_tests, function_preconditions_interactive) {
582604
TEST_F(Shell_js_dba_tests, dba_cluster_add_instance) {
583605
_options->wizards = false;
584606
reset_shell();
607+
output_handler.set_log_level(ngcommon::Logger::LOG_WARNING);
608+
585609
validate_interactive("dba_cluster_add_instance.js");
610+
// BUG#26393614
611+
std::vector<std::string> log{
612+
"'localhost' (" + _sandbox_dir + _path_splitter + _mysql_sandbox_port2 +
613+
_path_splitter +
614+
"sandboxdata) detected as local sandbox. "
615+
"Sandbox instances are only suitable for deploying and "
616+
"running on your local machine for testing purposes and are not "
617+
"accessible from external networks."};
618+
MY_EXPECT_LOG_CONTAINS(log);
586619
}
587620

588621
TEST_F(Shell_js_dba_tests, dba_cluster_remove_instance) {

unittest/test_utils.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,6 @@ void Shell_core_test_wrapper::SetUp() {
262262
set_options();
263263
output_handler.debug = debug;
264264

265-
#ifdef _WIN32
266-
std::string _path_splitter = "\\";
267-
#else
268-
std::string _path_splitter = "/";
269-
#endif
270-
271265
// Initializes the interactive shell
272266
reset_shell();
273267

unittest/test_utils/admin_api_test.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@
2323
namespace tests {
2424
void Admin_api_test::SetUp() {
2525
Shell_core_test_wrapper::SetUp();
26-
27-
std::vector<std::string> path_components = {_sandbox_dir,
28-
_mysql_sandbox_port1, "my.cnf"};
29-
_sandbox_cnf_1 = shcore::join_strings(path_components, _path_splitter);
30-
31-
path_components[1] = _mysql_sandbox_port2;
32-
_sandbox_cnf_2 = shcore::join_strings(path_components, _path_splitter);
33-
34-
path_components[1] = _mysql_sandbox_port3;
35-
_sandbox_cnf_3 = shcore::join_strings(path_components, _path_splitter);
3626
}
3727

3828
void Admin_api_test::add_instance_type_queries

unittest/test_utils/shell_base_test.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ namespace tests {
2525

2626
void Shell_base_test::SetUp() {
2727
const char *uri = getenv("MYSQL_URI");
28+
#ifdef _WIN32
29+
_path_splitter = "\\";
30+
#else
31+
_path_splitter = "/";
32+
#endif
33+
2834
if (uri) {
2935
// Creates connection data and recreates URI, this will fix URI if no
3036
// password is defined So the UT don't prompt for password ever
@@ -95,6 +101,16 @@ void Shell_base_test::SetUp() {
95101
}
96102
}
97103

104+
std::vector<std::string> path_components = {_sandbox_dir,
105+
_mysql_sandbox_port1, "my.cnf"};
106+
_sandbox_cnf_1 = shcore::join_strings(path_components, _path_splitter);
107+
108+
path_components[1] = _mysql_sandbox_port2;
109+
_sandbox_cnf_2 = shcore::join_strings(path_components, _path_splitter);
110+
111+
path_components[1] = _mysql_sandbox_port3;
112+
_sandbox_cnf_3 = shcore::join_strings(path_components, _path_splitter);
113+
98114
_new_line_char = "\n";
99115
#ifdef WIN32
100116
_new_line_char = "\r\n";

0 commit comments

Comments
 (0)