Skip to content

Commit 321d8b4

Browse files
committed
Upgrade utils | change variables, errors and log prints to be general to both Containerized and NC environments
Signed-off-by: Romy <35330373+romayalon@users.noreply.github.com>
1 parent 873a00c commit 321d8b4

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/test/unit_tests/jest_tests/test_nc_upgrade_manager.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ describe('nc upgrade manager - upgrade config directory', () => {
795795
const expected_version = pkg.version;
796796
const hosts_list = [hostname];
797797
await config_fs.create_system_config_file(JSON.stringify(system_data));
798-
const expected_err_msg = 'attempt to run old container version with newer server version';
798+
const expected_err_msg = 'attempt to upgrade to an older version while server\'s version is newer';
799799
await expect(nc_upgrade_manager.upgrade_config_dir(expected_version, hosts_list))
800800
.rejects.toThrow(expected_err_msg);
801801
});

src/upgrade/upgrade_utils.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,39 @@ function version_compare(ver1, ver2) {
3535
}
3636

3737
/**
38-
* @param {string} server_version
39-
* @param {string} container_version
38+
* @param {string} current_version
39+
* @param {string} new_version
4040
*/
41-
function should_upgrade(server_version, container_version) {
42-
if (!server_version) {
41+
function should_upgrade(current_version, new_version) {
42+
if (!current_version) {
4343
dbg.log('system does not exist. no need for an upgrade');
4444
return false;
4545
}
46-
const ver_comparison = version_compare(container_version, server_version);
46+
const ver_comparison = version_compare(new_version, current_version);
4747
if (ver_comparison === 0) {
48-
if (server_version !== container_version) {
49-
dbg.warn(`the container and server appear to be the same version but different builds. (container: ${container_version}), (server: ${server_version})`);
48+
if (current_version !== new_version) {
49+
dbg.warn(`the new_version and current_version (server) appear to be the same version but different builds. (new_version: ${new_version}), (current_version: ${current_version})`);
5050
dbg.warn(`upgrade is not supported for different builds of the same version!!`);
5151
}
52-
dbg.log0('the versions of the container and the server match. no need to upgrade');
52+
dbg.log0('the versions of the new_version and the current_version match. no need to upgrade');
5353
return false;
5454
} else if (ver_comparison < 0) {
55-
// container version is older than the server version - can't downgrade
56-
dbg.error(`the container version (${container_version}) appear to be older than the current server version (${server_version}). cannot downgrade`);
57-
throw new Error('attempt to run old container version with newer server version');
55+
// new_version is older than the current server version - can't downgrade
56+
dbg.error(`the new_version (${new_version}) appears to be older than the current_version (server) (${current_version}). cannot downgrade`);
57+
throw new Error('attempt to upgrade to an older version while server\'s version is newer');
5858
} else {
59-
dbg.log0(`container version is ${container_version} and server version is ${server_version}. will upgrade`);
59+
dbg.log0(`new_version is ${new_version} and current server version is ${current_version}. will upgrade`);
6060
return true;
6161
}
6262
}
6363

6464
/**
6565
* load_required_scripts loads all scripts that should be run according to the given versions
66-
* @param {string} server_version
67-
* @param {string} container_version
66+
* @param {string} current_version
67+
* @param {string} new_version
6868
* @param {string} upgrade_scripts_dir
6969
*/
70-
async function load_required_scripts(server_version, container_version, upgrade_scripts_dir) {
70+
async function load_required_scripts(current_version, new_version, upgrade_scripts_dir) {
7171
// expecting scripts directories to be in a semver format. e.g. ./upgrade_scripts/5.0.1
7272
let upgrade_dir_content = [];
7373
try {
@@ -79,12 +79,12 @@ async function load_required_scripts(server_version, container_version, upgrade_
7979
throw err;
8080
}
8181
}
82-
// get all dirs for versions newer than server_version
82+
// get all dirs for versions newer than current_version
8383
const newer_versions = upgrade_dir_content.filter(ver =>
84-
version_compare(ver, server_version) > 0 &&
85-
version_compare(ver, container_version) <= 0)
84+
version_compare(ver, current_version) > 0 &&
85+
version_compare(ver, new_version) <= 0)
8686
.sort(version_compare);
87-
dbg.log0(`found the following versions with upgrade scripts which are newer than server version (${server_version}):`, newer_versions);
87+
dbg.log0(`found the following versions with upgrade scripts which are newer than server version (${current_version}):`, newer_versions);
8888
// get all scripts under new_versions
8989
const upgrade_scripts = _.flatMap(newer_versions, ver => {
9090
const full_path = path.join(upgrade_scripts_dir, ver);

0 commit comments

Comments
 (0)