Skip to content

Commit 2cf48bc

Browse files
authored
Merge pull request #8790 from romayalon/romy-expected-hosts-optional
NC | Online upgrade | convert --expected_hosts flag from required to optional
2 parents aef9956 + f0841ff commit 2cf48bc

File tree

6 files changed

+29
-24
lines changed

6 files changed

+29
-24
lines changed

docs/NooBaaNonContainerized/NooBaaCLI.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ The `upgrade start` command is used to start a config directory upgrade run.
483483

484484
#### Usage
485485
```sh
486-
noobaa-cli upgrade start --expected_version <expected-version> --expected_hosts <expected-hosts> [--skip-verification] [--custom_upgrade_scripts_dir]
486+
noobaa-cli upgrade start --expected_version <expected-version> [--expected_hosts] <expected-hosts> [--skip-verification] [--custom_upgrade_scripts_dir]
487487
```
488488

489489
#### Flags -
@@ -492,7 +492,7 @@ noobaa-cli upgrade start --expected_version <expected-version> --expected_hosts
492492
- Description: Specifies the upgrade's expected target version.
493493
- Example - `--expected_version 5.18.0`
494494

495-
- `expected_hosts` (Required)
495+
- `expected_hosts`
496496
- Type: String
497497
- Description: Specifies the upgrade's expected hosts. String of hostnames separated by comma (,).
498498
- Example - `--expected_hosts hostname1,hostname2,hostname3`

docs/NooBaaNonContainerized/Upgrade.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ Online Upgrade Algorithm commands examples -
103103
2. Stop NooBaa service - `systemctl stop noobaa`
104104
3. RPM upgrade on a specific node - `rpm -Uvh /path/to/new_noobaa_rpm_version.rpm`
105105
4. Restart NooBaa service - `systemctl restart noobaa`
106-
5. `noobaa-cli upgrade start --expected_version=5.18.0 --expected_hosts=hostname1,hostname2,hostname3`
106+
5. Check that each node has NooBaa service running with the new code - `curl -k https://localhost:6443/_/version` or `curl http://${host_address}:6001/_/version`
107+
6. `noobaa-cli upgrade start --expected_version=5.18.0`
108+
107109

108110
### Additional Upgrade Properties of `system.json`
109111

src/manage_nsfs/manage_nsfs_help_utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ Usage:
437437
Flags:
438438
439439
--expected_version <string> The expected target version of the upgrade
440-
--expected_hosts <string> The expected hosts running NooBaa NC, a string of hosts separated by ,
440+
--expected_hosts <string> (optional) The expected hosts running NooBaa NC, a string of hosts separated by ,
441441
--skip_verification <boolean> (optional) skip upgrade verification
442442
WARNING: can cause corrupted config dir files created by hosts running old code.
443443
this should generally not be used and is intended exclusively for NooBaa team support.

src/manage_nsfs/upgrade.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function start_config_dir_upgrade(user_input, config_fs) {
4949
new NoobaaEvent(NoobaaEvent.CONFIG_DIR_UPGRADE_STARTED).create_event(undefined, { expected_version, expected_hosts }, undefined);
5050

5151
if (!expected_version) throw new Error('expected_version flag is required');
52-
if (!expected_hosts) throw new Error('expected_hosts flag is required');
52+
if (!expected_hosts) dbg.warn('expected_hosts flag is empty, config dir upgrade will be performed without hosts version verification');
5353

5454
const nc_upgrade_manager = new NCUpgradeManager(config_fs, { custom_upgrade_scripts_dir });
5555
const upgrade_res = await nc_upgrade_manager.upgrade_config_dir(expected_version, expected_hosts, { skip_verification });

src/test/unit_tests/jest_tests/test_cli_upgrade.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,11 @@ describe('noobaa cli - upgrade', () => {
270270
expect(parsed_res.error.cause).toContain('expected_version flag is required');
271271
});
272272

273-
it('upgrade start - should fail on no expected_hosts', async () => {
273+
it('upgrade start - should succeed although missing expected hosts', async () => {
274274
await fs_utils.replace_file(config_fs.system_json_path, JSON.stringify(old_rpm_expected_system_json));
275275
const res = await exec_manage_cli(TYPES.UPGRADE, UPGRADE_ACTIONS.START, { config_root, expected_version: pkg.version }, true);
276-
const parsed_res = JSON.parse(res.stdout);
277-
expect(parsed_res.error.message).toBe(ManageCLIError.UpgradeFailed.message);
278-
expect(parsed_res.error.cause).toContain('expected_hosts flag is required');
276+
const parsed_res = JSON.parse(res);
277+
expect(parsed_res.response.code).toBe(ManageCLIResponse.UpgradeSuccessful.code);
279278
});
280279

281280
it('upgrade start - should fail on missing expected_hosts in system.json', async () => {

src/upgrade/nc_upgrade_manager.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class NCUpgradeManager {
9393
* 4.4. moves the current upgrade from in_progress_upgrade to the upgrade_history.successful_upgrades
9494
* 4.5. is 5.17.0 is a good default for from_version?
9595
* @param {string} expected_version
96-
* @param {[string]} hosts_list
96+
* @param {[string]} [hosts_list]
9797
* @param {{skip_verification?: boolean}} [options]
9898
* @returns {Promise<Object>}
9999
*/
@@ -159,7 +159,7 @@ class NCUpgradeManager {
159159
* therefore we can not treat the system.json as the source of truth of the hosts information
160160
* @param {Object} system_data
161161
* @param {String} expected_version
162-
* @param {[String]} expected_hosts
162+
* @param {[String]} [expected_hosts]
163163
* @returns {Promise<Void>}
164164
*/
165165
async _verify_config_dir_upgrade(system_data, expected_version, expected_hosts) {
@@ -175,23 +175,27 @@ class NCUpgradeManager {
175175
err_message = `config dir upgrade can not be started missing hosts_data hosts_data=${util.inspect(hosts_data)}`;
176176
}
177177

178-
const all_hostnames_exist_in_expected_hosts = hostnames.every(item => expected_hosts.includes(item));
179-
if (!all_hostnames_exist_in_expected_hosts) {
180-
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)}`);
181-
}
178+
if (expected_hosts) {
179+
const all_hostnames_exist_in_expected_hosts = hostnames.every(item => expected_hosts.includes(item));
180+
if (!all_hostnames_exist_in_expected_hosts) {
181+
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)}`);
182+
}
182183

183-
const all_expected_hosts_exist_in_system_json = expected_hosts.every(item => hostnames.includes(item));
184-
if (!err_message && !all_expected_hosts_exist_in_system_json) {
185-
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)}`;
186-
}
184+
const all_expected_hosts_exist_in_system_json = expected_hosts.every(item => hostnames.includes(item));
185+
if (!err_message && !all_expected_hosts_exist_in_system_json) {
186+
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)}`;
187+
}
187188

188-
if (!err_message) {
189-
for (const cur_hostname of expected_hosts) {
190-
const host_data = hosts_data[cur_hostname];
191-
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 expected hosts have the expected version=${new_version}, host=${cur_hostname} host's current_version=${host_data.current_version}`;
189+
if (!err_message) {
190+
for (const cur_hostname of expected_hosts) {
191+
const host_data = hosts_data[cur_hostname];
192+
if (!host_data.current_version || version_compare(host_data.current_version, new_version) !== 0) {
193+
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}`;
194+
}
193195
}
194196
}
197+
} else {
198+
dbg.warn('expected_hosts is empty, config dir upgrade will be performed without hosts version verification');
195199
}
196200

197201
if (!err_message && system_data.config_directory?.in_progress_upgrade) {

0 commit comments

Comments
 (0)