Skip to content

Commit a91b64b

Browse files
committed
cr
Signed-off-by: Romy <[email protected]>
1 parent 8a0b589 commit a91b64b

File tree

5 files changed

+37
-33
lines changed

5 files changed

+37
-33
lines changed

src/manage_nsfs/manage_nsfs_constants.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
/* Copyright (C) 2024 NooBaa */
22
'use strict';
33

4-
const TYPES = {
4+
const TYPES = Object.freeze({
55
ACCOUNT: 'account',
66
BUCKET: 'bucket',
77
IP_WHITELIST: 'whitelist',
88
GLACIER: 'glacier',
99
LOGGING: 'logging',
1010
DIAGNOSE: 'diagnose',
1111
UPGRADE: 'upgrade'
12-
};
12+
});
1313

14-
const ACTIONS = {
14+
const ACTIONS = Object.freeze({
1515
ADD: 'add',
1616
UPDATE: 'update',
1717
DELETE: 'delete',
1818
LIST: 'list',
1919
STATUS: 'status'
20-
};
20+
});
2121

22-
const GLACIER_ACTIONS = {
22+
const GLACIER_ACTIONS = Object.freeze({
2323
MIGRATE: 'migrate',
2424
RESTORE: 'restore',
2525
EXPIRY: 'expiry',
26-
};
26+
});
2727

28-
const DIAGNOSE_ACTIONS = {
28+
const DIAGNOSE_ACTIONS = Object.freeze({
2929
HEALTH: 'health',
3030
GATHER_LOGS: 'gather-logs',
3131
METRICS: 'metrics'
32-
};
32+
});
3333

34-
const UPGRADE_ACTIONS = {
34+
const UPGRADE_ACTIONS = Object.freeze({
3535
START: 'start',
3636
STATUS: 'status',
3737
HISTORY: 'history'
38-
};
39-
38+
});
4039

4140
const CONFIG_ROOT_FLAG = 'config_root';
4241
const CLI_MUTUAL_OPTIONS = new Set([CONFIG_ROOT_FLAG, 'config_root_backend', 'debug']);

src/manage_nsfs/manage_nsfs_help_utils.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,6 @@ Usage:
283283

284284

285285
const UPGRADE_OPTIONS = `
286-
Usage:
287-
288-
'upgrade' is a noobaa-core command that will return the exported metrics of the deployed NooBaa system.
289-
290286
Usage:
291287
292288
noobaa-cli upgrade <action> [flags]
@@ -300,19 +296,24 @@ List of actions supported:
300296
`;
301297

302298
const UPGRADE_START_OPTIONS = `
303-
'upgrade start' is a noobaa-core command that will start config directory upgrade run.
299+
'upgrade start' is a noobaa-cli command that will start config directory upgrade run.
304300
Run upgrade start after upgrading NooBaa RPMs on all the cluster nodes, after starting an upgrade of the config directory,
305301
S3 I/O, S3 Buckets getters and NooBaa CLI Account/Buckets/Whitelist getters operations will still be working
306302
But updates of the config directory will be blocked during the upgrade of the config directory.
303+
Upgrade start should be executed on one node, the config directory changes will be available for all the nodes of the cluster.
307304
`;
308305

309306
const UPGRADE_STATUS_OPTIONS = `
310-
'upgrade status' is a noobaa-core command that will return the status of an ongoing upgrade run.
307+
'upgrade status' is a noobaa-cli command that will return the status of an ongoing upgrade run,
308+
the available status information is upgrade start timestmp, from_version, to_version, config_dir_from_version,
309+
config_dir_to_version, running_host etc.
311310
312311
`;
313312

314313
const UPGRADE_HISTORY_OPTIONS = `
315-
'upgrade history' is a noobaa-core command that will return the history of past upgrades.
314+
'upgrade history' is a noobaa-cli command that will return the history of past upgrades,
315+
the available history information is an array of upgrade information - upgrade start timestmp, from_version, to_version, config_dir_from_version,
316+
config_dir_to_version, running_host etc.
316317
317318
`;
318319

src/manage_nsfs/upgrade.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async function exec_config_dir_upgrade() {
3838
throw new Error('Upgrade Config Directory is not implemented yet');
3939
} catch (err) {
4040
dbg.warn('could not upgrade config directory successfully - err', err);
41-
throw_cli_error({ ...ManageCLIError.UpgradeFailed, cause: err?.errors?.[0] || err });
41+
throw_cli_error({ ...ManageCLIError.UpgradeFailed, cause: err });
4242
}
4343
}
4444

@@ -49,13 +49,13 @@ async function exec_config_dir_upgrade() {
4949
*/
5050
async function get_upgrade_status(config_fs) {
5151
try {
52-
const system_config = await config_fs.get_system_config_file();
53-
const upgrade_status = system_config?.config_directory?.in_progress_upgrade;
54-
if (!upgrade_status) throw new Error('Config directory upgrade status is empty, there is no ongoing config directory upgrade or there is an error', { cause: system_config });
52+
const system_config = await config_fs.get_system_config_file({ silent_if_missing: true });
53+
let upgrade_status = system_config?.config_directory?.in_progress_upgrade;
54+
if (!upgrade_status) upgrade_status = { message: 'Config directory upgrade status is empty, there is no ongoing config directory upgrade' };
5555
write_stdout_response(ManageCLIResponse.UpgradeStatus, upgrade_status);
5656
} catch (err) {
5757
dbg.warn('could not get upgrade status response', err);
58-
throw_cli_error({ ...ManageCLIError.UpgradeStatusFailed, cause: err?.errors?.[0] || err });
58+
throw_cli_error({ ...ManageCLIError.UpgradeStatusFailed, cause: err });
5959
}
6060
}
6161

@@ -66,13 +66,13 @@ async function get_upgrade_status(config_fs) {
6666
*/
6767
async function get_upgrade_history(config_fs) {
6868
try {
69-
const system_config = await config_fs.get_system_config_file();
70-
const upgrade_history = system_config?.config_directory?.upgrade_history;
71-
if (!upgrade_history) throw new Error('Config directory upgrade history is empty', { cause: system_config });
69+
const system_config = await config_fs.get_system_config_file({ silent_if_missing: true });
70+
let upgrade_history = system_config?.config_directory?.upgrade_history;
71+
if (!upgrade_history) upgrade_history = { message: 'Config directory upgrade history is empty' };
7272
write_stdout_response(ManageCLIResponse.UpgradeHistory, upgrade_history);
7373
} catch (err) {
7474
dbg.warn('could not get upgrade history response', err);
75-
throw_cli_error({ ...ManageCLIError.UpgradeHistoryFailed, cause: err?.errors?.[0] || err });
75+
throw_cli_error({ ...ManageCLIError.UpgradeHistoryFailed, cause: err });
7676
}
7777
}
7878

src/sdk/config_fs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,10 +844,11 @@ class ConfigFS {
844844

845845
/**
846846
* get_system_config_file read system.json file
847+
* @param {{silent_if_missing?: boolean}} options
847848
* @returns {Promise<Object>}
848849
*/
849-
async get_system_config_file() {
850-
const system_data = await this.get_config_data(this.system_json_path);
850+
async get_system_config_file(options) {
851+
const system_data = await this.get_config_data(this.system_json_path, options);
851852
return system_data;
852853
}
853854

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const expected_system_json = {
4848
};
4949

5050
describe('noobaa cli - upgrade', () => {
51-
afterAll(async () => await fs_utils.file_delete(config_fs.system_json_path));
51+
afterEach(async () => await fs_utils.file_delete(config_fs.system_json_path));
5252

5353
it('upgrade start - should fail with not implemented', async () => {
5454
const res = await exec_manage_cli(TYPES.UPGRADE, UPGRADE_ACTIONS.START, { config_root }, true);
@@ -57,7 +57,9 @@ describe('noobaa cli - upgrade', () => {
5757

5858
it('upgrade status - should fail - there is no ongoing upgrade', async () => {
5959
const res = await exec_manage_cli(TYPES.UPGRADE, UPGRADE_ACTIONS.STATUS, { config_root }, true);
60-
expect(JSON.parse(res.stdout).error.message).toBe(ManageCLIError.UpgradeStatusFailed.message);
60+
const parsed_res = JSON.parse(res);
61+
expect(parsed_res.response.code).toBe(ManageCLIResponse.UpgradeStatus.code);
62+
expect(parsed_res.response.reply.message).toEqual('Config directory upgrade status is empty, there is no ongoing config directory upgrade');
6163
});
6264

6365
it('upgrade status', async () => {
@@ -66,12 +68,13 @@ describe('noobaa cli - upgrade', () => {
6668
const parsed_res = JSON.parse(res);
6769
expect(parsed_res.response.code).toBe(ManageCLIResponse.UpgradeStatus.code);
6870
expect(parsed_res.response.reply).toEqual(expected_system_json.config_directory.in_progress_upgrade);
69-
await fs_utils.file_delete(config_fs.system_json_path);
7071
});
7172

7273
it('upgrade history - should fail - there is no config directory upgrade history', async () => {
7374
const res = await exec_manage_cli(TYPES.UPGRADE, UPGRADE_ACTIONS.HISTORY, { config_root }, true);
74-
expect(JSON.parse(res.stdout).error.message).toBe(ManageCLIError.UpgradeHistoryFailed.message);
75+
const parsed_res = JSON.parse(res);
76+
expect(parsed_res.response.code).toBe(ManageCLIResponse.UpgradeHistory.code);
77+
expect(parsed_res.response.reply.message).toEqual('Config directory upgrade history is empty');
7578
});
7679

7780
it('upgrade history', async () => {

0 commit comments

Comments
 (0)