Skip to content

Commit 7c70730

Browse files
authored
Merge pull request #8612 from romayalon/romy-online-upgrade-remove-nodes-verification
NC | Online Upgrade | Replace failure if system.json contains hosts that do not exist in --expected_hosts with a warning
2 parents 6bbc0c0 + 4aaf02e commit 7c70730

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

Diff for: src/test/unit_tests/jest_tests/test_cli_upgrade.test.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -282,23 +282,22 @@ describe('noobaa cli - upgrade', () => {
282282
const res = await exec_manage_cli(TYPES.UPGRADE, UPGRADE_ACTIONS.START, { config_root, expected_version: pkg.version, expected_hosts: `${hostname},bla1,bla2` }, true);
283283
const parsed_res = JSON.parse(res.stdout);
284284
expect(parsed_res.error.message).toBe(ManageCLIError.UpgradeFailed.message);
285-
expect(parsed_res.error.cause).toContain('config dir upgrade can not be started - expected_hosts missing one or more hosts specified in system.json hosts_data=');
285+
expect(parsed_res.error.cause).toContain('config dir upgrade can not be started - expected_hosts contains one or more hosts that are not specified in system.json hosts_data=');
286286
});
287287

288-
it('upgrade start - should fail on missing system.json hosts in expected_hosts', async () => {
288+
it('upgrade start - should succeed although system.json contains extra hosts than specified in expected_hosts', async () => {
289289
await fs_utils.replace_file(config_fs.system_json_path, JSON.stringify(invalid_hostname_system_json));
290290
const res = await exec_manage_cli(TYPES.UPGRADE, UPGRADE_ACTIONS.START, { config_root, expected_version: pkg.version, expected_hosts: `${hostname}` }, true);
291-
const parsed_res = JSON.parse(res.stdout);
292-
expect(parsed_res.error.message).toBe(ManageCLIError.UpgradeFailed.message);
293-
expect(parsed_res.error.cause).toContain('config dir upgrade can not be started - system.json missing one or more hosts info specified in expected_hosts hosts_data');
291+
const parsed_res = JSON.parse(res);
292+
expect(parsed_res.response.code).toBe(ManageCLIResponse.UpgradeSuccessful.code);
294293
});
295294

296-
it('upgrade start - should fail on missing system.json hosts in expected_hosts1', async () => {
295+
it('upgrade start - should succeed although on missing system.json hosts in expected_hosts with comma', async () => {
296+
// we set intentionally comma at the end so we will test we know how to parse it
297297
await fs_utils.replace_file(config_fs.system_json_path, JSON.stringify(invalid_hostname_system_json));
298298
const res = await exec_manage_cli(TYPES.UPGRADE, UPGRADE_ACTIONS.START, { config_root, expected_version: pkg.version, expected_hosts: `${hostname},` }, true);
299-
const parsed_res = JSON.parse(res.stdout);
300-
expect(parsed_res.error.message).toBe(ManageCLIError.UpgradeFailed.message);
301-
expect(parsed_res.error.cause).toContain('config dir upgrade can not be started - system.json missing one or more hosts info specified in expected_hosts hosts_data');
299+
const parsed_res = JSON.parse(res);
300+
expect(parsed_res.response.code).toBe(ManageCLIResponse.UpgradeSuccessful.code);
302301
});
303302

304303
it('upgrade start - should fail expected_version invalid', async () => {
@@ -316,7 +315,7 @@ describe('noobaa cli - upgrade', () => {
316315
const res = await exec_manage_cli(TYPES.UPGRADE, UPGRADE_ACTIONS.START, options, true);
317316
const parsed_res = JSON.parse(res.stdout);
318317
expect(parsed_res.error.message).toBe(ManageCLIError.UpgradeFailed.message);
319-
expect(parsed_res.error.cause).toContain('config dir upgrade can not be started until all nodes have the expected version');
318+
expect(parsed_res.error.cause).toContain('config dir upgrade can not be started until all expected hosts have the expected version');
320319
});
321320

322321
it('upgrade start - should fail - RPM version is higher than source code version', async () => {
@@ -326,7 +325,7 @@ describe('noobaa cli - upgrade', () => {
326325
const res = await exec_manage_cli(TYPES.UPGRADE, UPGRADE_ACTIONS.START, options, true);
327326
const parsed_res = JSON.parse(res.stdout);
328327
expect(parsed_res.error.code).toBe(ManageCLIError.UpgradeFailed.code);
329-
expect(parsed_res.error.cause).toContain('config dir upgrade can not be started until all nodes have the expected');
328+
expect(parsed_res.error.cause).toContain('config dir upgrade can not be started until all expected hosts have the expected');
330329
const system_data_after_upgrade = await config_fs.get_system_config_file();
331330
// check that in the hostname section nothing changed
332331
expect(system_data_before_upgrade[hostname]).toStrictEqual(system_data_after_upgrade[hostname]);

Diff for: src/test/unit_tests/jest_tests/test_nc_upgrade_manager.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -282,23 +282,23 @@ describe('nc upgrade manager - upgrade config directory', () => {
282282

283283
it('_verify_config_dir_upgrade - empty host current_version', async () => {
284284
const system_data = { [hostname]: []};
285-
const expected_err_msg = `config dir upgrade can not be started until all nodes have the expected version=${pkg.version}, host=${hostname} host's current_version=undefined`;
285+
const expected_err_msg = `config dir upgrade can not be started until all expected hosts have the expected version=${pkg.version}, host=${hostname} host's current_version=undefined`;
286286
await expect(nc_upgrade_manager._verify_config_dir_upgrade(system_data, pkg.version, [hostname]))
287287
.rejects.toThrow(expected_err_msg);
288288
});
289289

290290
it('_verify_config_dir_upgrade - host current_version < new_version should upgrade RPM', async () => {
291291
const old_version = '5.16.0';
292292
const system_data = { [hostname]: { current_version: old_version }, other_hostname: { current_version: pkg.version } };
293-
const expected_err_msg = `config dir upgrade can not be started until all nodes have the expected version=${pkg.version}, host=${hostname} host's current_version=${old_version}`;
293+
const expected_err_msg = `config dir upgrade can not be started until all expected hosts have the expected version=${pkg.version}, host=${hostname} host's current_version=${old_version}`;
294294
await expect(nc_upgrade_manager._verify_config_dir_upgrade(system_data, pkg.version, [hostname, 'other_hostname']))
295295
.rejects.toThrow(expected_err_msg);
296296
});
297297

298298
it('_verify_config_dir_upgrade - host current_version > new_version should upgrade RPM', async () => {
299299
const newer_version = pkg.version + '.1';
300300
const system_data = { [hostname]: { current_version: newer_version }, other_hostname: { current_version: pkg.version } };
301-
const expected_err_msg = `config dir upgrade can not be started until all nodes have the expected version=${pkg.version}, host=${hostname} host's current_version=${newer_version}`;
301+
const expected_err_msg = `config dir upgrade can not be started until all expected hosts have the expected version=${pkg.version}, host=${hostname} host's current_version=${newer_version}`;
302302
await expect(nc_upgrade_manager._verify_config_dir_upgrade(system_data, pkg.version, [hostname, 'other_hostname']))
303303
.rejects.toThrow(expected_err_msg);
304304
});

Diff for: src/upgrade/nc_upgrade_manager.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ class NCUpgradeManager {
154154
* 2. The user's expected_version is the host's package version -
155155
* expected_version is the expected source code version that the user asks to upgrade to, it's an optional verification,
156156
* if expected_version was not provided we assume that the source code on this host is
157-
* 3. TODO? - verifies a backup confirmation of the config directory received by the user/location exists
158-
* updated and that the source code version and the schema version is the one we want to upgrade to
159-
* QUESTION -
160-
* 3. should we verify a backup, by stat of the backup location just have a confirmation of the user in the CLI
161-
* 4. are there more verifications we should do?
157+
* 3. The user's expected_hosts exist in system.json
158+
* 4. If there are hosts in system.json that ere not provided in the expected_hosts we will print a warning but won't fail
159+
* we do that because of hostname can be renamed, hosts that are on maintainance and we don't want to block the upgrade becuase it might take a lot of time,
160+
* or because of hosts that used to be a part of the cluster and they were removed from the cluster, we don't get the updated info of the hosts on system.json
161+
* therefore we can not treat the system.json as the source of truth of the hosts information
162162
* @param {Object} system_data
163163
* @param {String} expected_version
164164
* @param {[String]} expected_hosts
@@ -176,20 +176,22 @@ class NCUpgradeManager {
176176
if (!err_message && !hostnames.length) {
177177
err_message = `config dir upgrade can not be started missing hosts_data hosts_data=${util.inspect(hosts_data)}`;
178178
}
179-
const missing_expected_hosts = !(expected_hosts.every(item => hostnames.includes(item)));
180-
const missing_hostnames = !(hostnames.every(item => expected_hosts.includes(item)));
181179

182-
if (!err_message && missing_expected_hosts) {
183-
err_message = `config dir upgrade can not be started - expected_hosts missing one or more hosts specified in system.json hosts_data=${util.inspect(hosts_data)}`;
180+
const all_hostnames_exist_in_expected_hosts = hostnames.every(item => expected_hosts.includes(item));
181+
if (!all_hostnames_exist_in_expected_hosts) {
182+
dbg.warn(`_verify_config_dir_upgrade - system.json contains one or more hosts info that are not specified in expected_hosts: hosts_data=${util.inspect(hosts_data)} expected_hosts=${util.inspect(expected_hosts)}`);
184183
}
185-
if (!err_message && missing_hostnames) {
186-
err_message = `config dir upgrade can not be started - system.json missing one or more hosts info specified in expected_hosts hosts_data=${util.inspect(hosts_data)}`;
184+
185+
const all_expected_hosts_exist_in_system_json = expected_hosts.every(item => hostnames.includes(item));
186+
if (!err_message && !all_expected_hosts_exist_in_system_json) {
187+
err_message = `config dir upgrade can not be started - expected_hosts contains one or more hosts that are not specified in system.json hosts_data=${util.inspect(hosts_data)} expected_hosts=${util.inspect(expected_hosts)}`;
187188
}
188189

189190
if (!err_message) {
190-
for (const [host, host_data] of Object.entries(hosts_data)) {
191+
for (const cur_hostname of expected_hosts) {
192+
const host_data = hosts_data[cur_hostname];
191193
if (!host_data.current_version || version_compare(host_data.current_version, new_version) !== 0) {
192-
err_message = `config dir upgrade can not be started until all nodes have the expected version=${new_version}, host=${host} host's current_version=${host_data.current_version}`;
194+
err_message = `config dir upgrade can not be started until all expected hosts have the expected version=${new_version}, host=${cur_hostname} host's current_version=${host_data.current_version}`;
193195
}
194196
}
195197
}

0 commit comments

Comments
 (0)