Skip to content

Commit 6bbba15

Browse files
committed
CR
Signed-off-by: Romy <[email protected]>
1 parent 03e86aa commit 6bbba15

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

src/manage_nsfs/health.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -450,17 +450,17 @@ class NSFSHealth {
450450
*/
451451
_get_config_dir_status(system_data) {
452452
if (!system_data) return { error: 'system data is missing' };
453-
const blocked_hosts = this._get_blocked_hosts_status(this.config_fs, system_data);
453+
const blocked_hosts_status = this._get_blocked_hosts_status(this.config_fs, system_data);
454454
const config_dir_data = system_data.config_directory;
455-
if (!config_dir_data) return { error: 'config directory data is missing, must upgrade config directory', blocked_hosts };
455+
if (!config_dir_data) return { error: 'config directory data is missing, must upgrade config directory', blocked_hosts: blocked_hosts_status };
456456
const config_dir_upgrade_status = this._get_config_dir_upgrade_status(config_dir_data);
457457
return {
458458
phase: config_dir_data.phase,
459459
config_dir_version: config_dir_data.config_dir_version,
460460
upgrade_package_version: config_dir_data.upgrade_package_version,
461461
upgrade_status: config_dir_upgrade_status,
462462
error: config_dir_upgrade_status.error || undefined,
463-
blocked_hosts
463+
blocked_hosts: blocked_hosts_status
464464
};
465465
}
466466

@@ -484,26 +484,28 @@ class NSFSHealth {
484484

485485
/**
486486
* _get_blocked_hosts_status checks if there are any hosts blocked for updating the config directory
487-
* 1. when host's config_dir_version older than 5.18.0 and system's config_dit_version is 5.18.0 and higher it means it's not blocked
488-
* because the source code won't include _throw_if_config_dir_locked() but it's still can cause invalid config files, therefore including it in the blocked list
489-
* 2. when system's config_dir_version older than 5.18.0 and hosts's config_dir_version is 5.18.0 and higher
490-
* it means updated to the config directory from this host are blocked
487+
* 1. if only config dir was upgraded (>=5.18.0) - host's config_dir_version doesn not exist (<5.18.0) and system's config_dir_version exists (>=5.18.0)
488+
* it means it's not blocked because the source code won't include _throw_if_config_dir_locked() but it still can create invalid config files, therefore including it in the blocked list
489+
* 2. if system's config_dir_version wasn't upgraded yet and hosts's config_dir_version exist (>= 5.18.0)
490+
* it means updates to the config directory from this host are blocked
491+
* 3. if system's config dir version does not match the hosts's config_dir_version - updates to the config directory from this host are blocked
492+
* @param {import('../sdk/config_fs').ConfigFS} config_fs
491493
* @param {Object} system_data
492494
* @returns {Object}
493495
*/
494496
_get_blocked_hosts_status(config_fs, system_data) {
495497
const system_config_dir_version = system_data.config_directory?.config_dir_version;
496-
const hosts_data = _.omit(system_data, 'config_directory');
498+
const hosts_data = config_fs.get_hosts_data(system_data);
497499
let res;
498500
for (const host_name of Object.keys(hosts_data)) {
499501
const host_data = hosts_data[host_name];
500502
let version_compare_err;
501503
const only_config_dir_upgraded = !host_data.config_dir_version && system_config_dir_version;
502504
const only_host_upgraded = host_data.config_dir_version && !system_config_dir_version;
503505
if (only_config_dir_upgraded) {
504-
version_compare_err = `host's config_dir_version is undefined, system's config_dir_version already upgraded to ${system_config_dir_version}, updates to the config directory via the host will result with invalid config_dir files`;
506+
version_compare_err = `host's config_dir_version is undefined, system's config_dir_version already upgraded to ${system_config_dir_version}, updates to the config directory via the host will result with invalid config_dir files until the host source code upgrade`;
505507
} else if (only_host_upgraded) {
506-
version_compare_err = `host's config_dir_version is ${host_data.config_dir_version}, system's config_dir_version is undefined`;
508+
version_compare_err = `host's config_dir_version is ${host_data.config_dir_version}, system's config_dir_version is undefined, updates to the config directory will be blocked until the config dir upgrade`;
507509
} else {
508510
version_compare_err = host_data.config_dir_version && system_config_dir_version &&
509511
config_fs.compare_host_and_config_dir_version(host_data.config_dir_version, system_config_dir_version);

src/sdk/config_fs.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -1074,9 +1074,9 @@ class ConfigFS {
10741074
* if system.json does not exist (a new system) - host and config dir data will be set on the newly created file
10751075
* else -
10761076
* 1. if the host data already exist in system.json - return
1077-
* 2. set the host data on system.json data and update the file
1077+
* 2. update the host data on system.json
10781078
* Note - config directory data on upgraded systems will be set by nc_upgrade_manager
1079-
* @returns
1079+
* @returns {Promise<Object>}
10801080
*/
10811081
async register_hostname_in_system_json() {
10821082
const system_data = await this.get_system_config_file({silent_if_missing: true});
@@ -1176,6 +1176,7 @@ class ConfigFS {
11761176
const system_data = await this.get_system_config_file({ silent_if_missing: true });
11771177
// if system was never created, currently we allow using the CLI without creating system
11781178
// we should consider changing it to throw on this scenario as well
1179+
// https://github.com/noobaa/noobaa-core/issues/8468
11791180
if (!system_data) return;
11801181
if (!system_data.config_directory) {
11811182
throw new RpcError('CONFIG_DIR_VERSION_MISMATCH', `config_directory data is missing in system.json, any updates to the config directory are blocked until the config dir upgrade`);
@@ -1191,13 +1192,15 @@ class ConfigFS {
11911192
/**
11921193
* compare_host_and_config_dir_version compares the version of the config dir in the system.json file
11931194
* with the config dir version of the running host
1195+
* if compare result is 0 - undefined will be returned
1196+
* else - an appropriate error string will be returned
11941197
* @param {String} running_code_config_dir_version
11951198
* @param {String} system_config_dir_version
11961199
* @returns {String | Undefined}
11971200
*/
11981201
compare_host_and_config_dir_version(running_code_config_dir_version, system_config_dir_version) {
11991202
const ver_comparison = version_compare(running_code_config_dir_version, system_config_dir_version);
1200-
dbg.log0('config_fs.compare_host_and_config_dir_version', running_code_config_dir_version, system_config_dir_version, ver_comparison);
1203+
dbg.log0(`config_fs.compare_host_and_config_dir_version: ver_comparison ${ver_comparison} running_code_config_dir_version ${running_code_config_dir_version} system_config_dir_version ${system_config_dir_version}`);
12011204
if (ver_comparison > 0) {
12021205
return `running code config_dir_version=${running_code_config_dir_version} is higher than the config dir version ` +
12031206
`mentioned in system.json=${system_config_dir_version}, any updates to the config directory are blocked until the config dir upgrade`;
@@ -1243,6 +1246,15 @@ class ConfigFS {
12431246
}
12441247
};
12451248
}
1249+
1250+
/**
1251+
* get_hosts_data recieves system_data and returns only the hosts data
1252+
* @param {Object} system_data
1253+
* @returns {Object}
1254+
*/
1255+
get_hosts_data(system_data) {
1256+
return _.omit(system_data, 'config_directory');
1257+
}
12461258
}
12471259

12481260
// EXPORTS

src/test/unit_tests/test_nc_health.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ mocha.describe('nsfs nc health', function() {
186186

187187
mocha.it('Health all condition is success', async function() {
188188
valid_system_json.config_directory = {
189-
'config_dir_version': config_fs.config_dir_version,
190-
'upgrade_package_version': pkg.version,
191-
'phase': CONFIG_DIR_PHASES.CONFIG_DIR_UNLOCKED,
189+
config_dir_version: config_fs.config_dir_version,
190+
upgrade_package_version: pkg.version,
191+
phase: CONFIG_DIR_PHASES.CONFIG_DIR_UNLOCKED,
192192
upgrade_status: default_mock_upgrade_status
193193
};
194194
valid_system_json[hostname].config_dir_version = config_fs.config_dir_version;
@@ -640,7 +640,7 @@ mocha.describe('nsfs nc health', function() {
640640
assert_config_dir_status(health_status, valid_system_json.config_directory);
641641
});
642642

643-
mocha.it('invalid blocked hosts', async function() {
643+
mocha.it('health should report on blocked hosts - config directory data is missing, host is blocked for updates', async function() {
644644
valid_system_json.config_directory = undefined;
645645
valid_system_json[hostname].config_dir_version = config_fs.config_dir_version;
646646
await Health.config_fs.create_system_config_file(JSON.stringify(valid_system_json));
@@ -652,7 +652,7 @@ mocha.describe('nsfs nc health', function() {
652652
[hostname]: {
653653
host_version: valid_system_json[hostname].current_version,
654654
host_config_dir_version: valid_system_json[hostname].config_dir_version,
655-
error: `host's config_dir_version is ${valid_system_json[hostname].config_dir_version}, system's config_dir_version is undefined`
655+
error: `host's config_dir_version is ${valid_system_json[hostname].config_dir_version}, system's config_dir_version is undefined, updates to the config directory will be blocked until the config dir upgrade`
656656
}
657657
}
658658
});

src/upgrade/nc_upgrade_manager.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"use strict";
33

44
const os = require('os');
5-
const _ = require('lodash');
65
const path = require('path');
76
const util = require('util');
87
const pkg = require('../../package.json');
@@ -165,7 +164,7 @@ class NCUpgradeManager {
165164
*/
166165
async _verify_config_dir_upgrade(system_data, expected_version, expected_hosts) {
167166
const new_version = this.package_version;
168-
const hosts_data = _.omit(system_data, 'config_directory');
167+
const hosts_data = this.config_fs.get_hosts_data(system_data);
169168
let err_message;
170169
if (expected_version !== new_version) {
171170
err_message = `config dir upgrade can not be started - the host's package version=${new_version} does not match the user's expected version=${expected_version}`;

0 commit comments

Comments
 (0)