Skip to content

Commit ba57d2d

Browse files
committed
Upgrade Checker Enhancements
- Adding suggested to use targetVersion option if it was not used. - Selecting the latest version of the series in case the targetVersion option was specified but with an incomplete version. Change-Id: Ic6bc2412340d357d0bfdda47331d86d6889d66ab
1 parent 06c4853 commit ba57d2d

File tree

8 files changed

+93
-14
lines changed

8 files changed

+93
-14
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ if(HAVE_V8)
12621262
endif()
12631263
endif()
12641264

1265-
add_definitions(-DMYSH_VERSION="${MYSH_VERSION}" -DMYSH_BUILD_ID="${MYSH_BUILD_ID}" -DEXTRA_NAME_SUFFIX="${EXTRA_NAME_SUFFIX}")
1265+
add_definitions(-DMYSH_VERSION="${MYSH_VERSION}" -DLATEST_MYSH_80_VERSION="${LATEST_MYSH_80_VERSION}" -DMYSH_BUILD_ID="${MYSH_BUILD_ID}" -DEXTRA_NAME_SUFFIX="${EXTRA_NAME_SUFFIX}")
12661266
if(WIN32)
12671267
add_definitions(-DMYSH_VERSION_WIN="${MYSH_VERSION_WIN}")
12681268
endif()

modules/util/upgrade_check.cc

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@ namespace {
5353

5454
const Version ALL_VERSIONS("777.777.777");
5555

56-
}
56+
// This map should be updated with the latest version of each series to enable
57+
// gatting the latest version available in case a partial version is provided
58+
// as the taget value, so for example, not needed when patch version is 0 in
59+
// the last version of a series
60+
static std::unordered_map<std::string, Version> latest_versions = {
61+
{"8", Version(MYSH_VERSION)}, // If 8 is given, latest version
62+
// is the current shell version
63+
{"8.0", Version(LATEST_MYSH_80_VERSION)}};
64+
65+
} // namespace
5766

5867
std::string upgrade_issue_to_string(const Upgrade_issue &problem) {
5968
std::stringstream ss;
@@ -96,9 +105,17 @@ const shcore::Option_pack_def<Upgrade_check_options>
96105
return opts;
97106
}
98107

108+
mysqlshdk::utils::Version Upgrade_check_options::get_target_version() const {
109+
return target_version.value_or(mysqlshdk::utils::Version(MYSH_VERSION));
110+
}
111+
99112
void Upgrade_check_options::set_target_version(const std::string &value) {
100-
if (!value.empty() && value != "8.0") {
101-
target_version = Version(value);
113+
if (!value.empty()) {
114+
if (latest_versions.contains(value)) {
115+
target_version = latest_versions.at(value);
116+
} else {
117+
target_version = Version(value);
118+
}
102119
}
103120
}
104121

@@ -2160,7 +2177,8 @@ bool UNUSED_VARIABLE(register_get_deprecated_default_auth_check) =
21602177

21612178
Upgrade_check_config::Upgrade_check_config(const Upgrade_check_options &options)
21622179
: m_output_format(options.output_format) {
2163-
m_upgrade_info.target_version = options.target_version;
2180+
m_upgrade_info.target_version = options.get_target_version();
2181+
m_upgrade_info.explicit_target_version = options.target_version.has_value();
21642182
m_upgrade_info.config_path = options.config_path;
21652183

21662184
if (m_output_format.empty()) {
@@ -2231,7 +2249,8 @@ bool check_for_upgrade(const Upgrade_check_config &config) {
22312249

22322250
print->check_info(config.session()->get_connection_options().uri_endpoint(),
22332251
config.upgrade_info().server_version_long,
2234-
config.upgrade_info().target_version.get_base());
2252+
config.upgrade_info().target_version.get_base(),
2253+
config.upgrade_info().explicit_target_version);
22352254

22362255
const auto checklist =
22372256
Upgrade_check::create_checklist(config.upgrade_info(), config.targets());

modules/util/upgrade_check.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,17 @@ struct Upgrade_issue {
6969
struct Upgrade_check_options {
7070
static const shcore::Option_pack_def<Upgrade_check_options> &options();
7171

72-
mysqlshdk::utils::Version target_version =
73-
mysqlshdk::utils::Version(MYSH_VERSION);
72+
std::optional<mysqlshdk::utils::Version> target_version;
7473
std::string config_path;
7574
std::string output_format;
7675
std::optional<std::string> password;
7776

77+
mysqlshdk::utils::Version get_target_version() const;
78+
7879
private:
80+
#ifdef FRIEND_TEST
81+
FRIEND_TEST(Upgrade_check_options, set_target_version);
82+
#endif
7983
void set_target_version(const std::string &value);
8084
};
8185

@@ -89,6 +93,7 @@ class Upgrade_check {
8993
mysqlshdk::utils::Version target_version;
9094
std::string server_os;
9195
std::string config_path;
96+
bool explicit_target_version;
9297
};
9398

9499
enum class Target {

modules/util/upgrade_check_formatter.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,18 @@ class Text_upgrade_checker_output : public Upgrade_check_output_formatter {
6969

7070
void check_info(const std::string &server_addres,
7171
const std::string &server_version,
72-
const std::string &target_version) override {
72+
const std::string &target_version,
73+
bool explicit_target_version) override {
7374
print_paragraph(
7475
shcore::str_format(
7576
"The MySQL server at %s, version %s, will now be checked for "
76-
"compatibility issues for upgrade to MySQL %s...",
77+
"compatibility issues for upgrade to MySQL %s%s...",
7778
server_addres.c_str(), server_version.c_str(),
78-
target_version.c_str()),
79+
target_version.c_str(),
80+
explicit_target_version
81+
? ""
82+
: ". To check for a different target server version, use the "
83+
"targetVersion option"),
7984
0, 0);
8085
}
8186

@@ -170,7 +175,8 @@ class JSON_upgrade_checker_output : public Upgrade_check_output_formatter {
170175

171176
void check_info(const std::string &server_addres,
172177
const std::string &server_version,
173-
const std::string &target_version) override {
178+
const std::string &target_version,
179+
[[maybe_unused]] bool explicit_target_version) override {
174180
rapidjson::Value addr;
175181
addr.SetString(server_addres.c_str(), server_addres.length(), m_allocator);
176182
m_json_document.AddMember("serverAddress", addr, m_allocator);

modules/util/upgrade_check_formatter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2023, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License, version 2.0,
@@ -41,7 +41,8 @@ class Upgrade_check_output_formatter {
4141

4242
virtual void check_info(const std::string &server_addres,
4343
const std::string &server_version,
44-
const std::string &target_version) = 0;
44+
const std::string &target_version,
45+
bool explicit_target_version) = 0;
4546
virtual void check_results(const Upgrade_check &check,
4647
const std::vector<Upgrade_issue> &results) = 0;
4748
virtual void check_error(const Upgrade_check &check, const char *description,

unittest/modules/upgrade_check_t.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* along with this program; if not, write to the Free Software Foundation, Inc.,
2121
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222
*/
23+
#include "unittest/gprod_clean.h"
2324

2425
#include "modules/util/mod_util.h"
2526
#include "modules/util/upgrade_check.h"
@@ -179,6 +180,27 @@ class MySQL_upgrade_check_test : public Shell_core_test_wrapper {
179180
std::vector<mysqlsh::Upgrade_issue> issues;
180181
};
181182

183+
TEST(Upgrade_check_options, set_target_version) {
184+
Upgrade_check_options options;
185+
options.set_target_version("8");
186+
EXPECT_EQ(Version(MYSH_VERSION), options.target_version);
187+
188+
options.set_target_version("8.0");
189+
EXPECT_EQ(Version(LATEST_MYSH_80_VERSION), options.target_version);
190+
191+
options.set_target_version("8.1");
192+
EXPECT_EQ(Version(8, 1, 0), options.target_version);
193+
194+
options.set_target_version("8.2");
195+
EXPECT_EQ(Version(8, 2, 0), options.target_version);
196+
197+
options.set_target_version("8.3");
198+
EXPECT_EQ(Version(8, 3, 0), options.target_version);
199+
200+
options.set_target_version("8.0.34");
201+
EXPECT_EQ(Version(8, 0, 34), options.target_version);
202+
}
203+
182204
TEST_F(MySQL_upgrade_check_test, checklist_generation) {
183205
Version current(MYSH_VERSION);
184206
Version prev(current.get_major(), current.get_minor(),

unittest/shell_cli_operation_t.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,16 @@ TEST_F(Shell_cli_operation_test, integration_test) {
850850
{"--", "util", "check-for-server-upgrade", uri.c_str()}, "",
851851
env));
852852
MY_EXPECT_STDOUT_CONTAINS("will now be checked for compatibility issues");
853+
MY_EXPECT_STDOUT_CONTAINS("To check for a different target server version");
854+
output_handler.wipe_all();
855+
856+
EXPECT_NE(10,
857+
testutil->call_mysqlsh_c({"--", "util", "check-for-server-upgrade",
858+
uri.c_str(), "--target-version=8.3.0"},
859+
"", env));
860+
MY_EXPECT_STDOUT_CONTAINS("will now be checked for compatibility issues");
861+
MY_EXPECT_STDOUT_NOT_CONTAINS(
862+
"To check for a different target server version");
853863
output_handler.wipe_all();
854864

855865
MY_EXPECT_EQ_OR_DUMP(

version.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,25 @@ MACRO(GET_MYSQL_VERSION)
109109

110110
ENDMACRO()
111111

112+
MACRO(GET_LATEST_VERSIONS)
113+
# This macro ensures the following variable is kept up to date release after release
114+
SET(LATEST_MYSH_80_VERSION "8.0.36")
115+
116+
IF (NOT "${MYSH_NO_DASH_VERSION}" STREQUAL "${LATEST_MYSH_80_VERSION}")
117+
SET(VERSION_MAPPING "8.4.0/8.0.37" "8.3.0/8.0.36" "8.2.0/8.0.35")
118+
119+
LIST(FIND VERSION_MAPPING "${MYSH_NO_DASH_VERSION}/${LATEST_MYSH_80_VERSION}" POSITION)
120+
IF (${POSITION} EQUAL -1)
121+
MESSAGE(FATAL_ERROR "Unable to find latest 80 version (${MYSH_NO_DASH_VERSION}/${LATEST_MYSH_80_VERSION}), please ${VERSION_MAPPING} update the definitions of VERSION_MAPPING and LATEST_MYSH_80_VERSION.")
122+
ENDIF()
123+
ENDIF()
124+
ENDMACRO()
125+
126+
112127
# Get mysql version and other interesting variables
113128
GET_MYSH_VERSION()
114129
GET_MYSQL_VERSION()
130+
GET_LATEST_VERSIONS()
115131

116132
SET(MYSH_BUILD_ID "$ENV{PARENT_ID}")
117133
SET(MYSH_COMMIT_ID "$ENV{PUSH_REVISION}")

0 commit comments

Comments
 (0)