@@ -13,19 +13,29 @@ const path = require('path');
13
13
const fs_utils = require ( '../../../../util/fs_utils' ) ;
14
14
const config = require ( '../../../../../config' ) ;
15
15
const pkg = require ( '../../../../../package.json' ) ;
16
- const { NCUpgradeManager, DEFAULT_NC_UPGRADE_SCRIPTS_DIR , OLD_DEFAULT_PACKAGE_VERSION ,
17
- OLD_DEFAULT_CONFIG_DIR_VERSION } = require ( '../../../../upgrade/nc_upgrade_manager' ) ;
16
+ const {
17
+ NCUpgradeManager,
18
+ DEFAULT_NC_UPGRADE_SCRIPTS_DIR ,
19
+ OLD_DEFAULT_PACKAGE_VERSION ,
20
+ OLD_DEFAULT_CONFIG_DIR_VERSION
21
+ } = require ( '../../../../upgrade/nc_upgrade_manager' ) ;
18
22
const { ConfigFS, CONFIG_DIR_PHASES } = require ( '../../../../sdk/config_fs' ) ;
19
- const { TMP_PATH , create_redirect_file, create_config_dir,
20
- fail_test_if_default_config_dir_exists, clean_config_dir, TEST_TIMEOUT } = require ( '../../../system_tests/test_utils' ) ;
23
+ const {
24
+ TMP_PATH ,
25
+ create_redirect_file,
26
+ create_config_dir,
27
+ fail_test_if_default_config_dir_exists,
28
+ clean_config_dir,
29
+ TEST_TIMEOUT
30
+ } = require ( '../../../system_tests/test_utils' ) ;
21
31
22
32
const config_root = path . join ( TMP_PATH , 'config_root_nc_upgrade_manager_test' ) ;
23
33
const config_fs = new ConfigFS ( config_root ) ;
24
34
const hostname = os . hostname ( ) ;
25
35
const mock_higher_version_than_pkg_version = pkg . version + '.1' ;
26
36
27
37
const dummy_upgrade_script_1 =
28
- `/* Copyright (C) 2024 NooBaa */
38
+ `/* Copyright (C) 2024 NooBaa */
29
39
'use strict';
30
40
async function run() {
31
41
console.log('script number 1');
@@ -36,7 +46,7 @@ module.exports = {
36
46
};
37
47
` ;
38
48
const dummy_upgrade_script_2 =
39
- `/* Copyright (C) 2024 NooBaa */
49
+ `/* Copyright (C) 2024 NooBaa */
40
50
'use strict';
41
51
async function run() {
42
52
console.log('script number 2');
@@ -47,7 +57,7 @@ module.exports = {
47
57
};` ;
48
58
49
59
const dummy_failing_upgrade_script_3 =
50
- `/* Copyright (C) 2024 NooBaa */
60
+ `/* Copyright (C) 2024 NooBaa */
51
61
'use strict';
52
62
async function run() {
53
63
console.log('script number 3');
@@ -353,23 +363,31 @@ describe('nc upgrade manager - upgrade config directory', () => {
353
363
} ) ;
354
364
355
365
it ( '_verify_config_dir_upgrade - empty host current_version' , async ( ) => {
356
- const system_data = { [ hostname ] : [ ] } ;
366
+ const system_data = {
367
+ [ hostname ] : [ ]
368
+ } ;
357
369
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` ;
358
370
await expect ( nc_upgrade_manager . _verify_config_dir_upgrade ( system_data , pkg . version , [ hostname ] ) )
359
371
. rejects . toThrow ( expected_err_msg ) ;
360
372
} ) ;
361
373
362
374
it ( '_verify_config_dir_upgrade - host current_version < new_version should upgrade RPM' , async ( ) => {
363
375
const old_version = '5.16.0' ;
364
- const system_data = { [ hostname ] : { current_version : old_version } , other_hostname : { current_version : pkg . version } } ;
376
+ const system_data = {
377
+ [ hostname ] : { current_version : old_version } ,
378
+ other_hostname : { current_version : pkg . version }
379
+ } ;
365
380
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 } ` ;
366
381
await expect ( nc_upgrade_manager . _verify_config_dir_upgrade ( system_data , pkg . version , [ hostname , 'other_hostname' ] ) )
367
382
. rejects . toThrow ( expected_err_msg ) ;
368
383
} ) ;
369
384
370
385
it ( '_verify_config_dir_upgrade - host current_version > new_version should upgrade RPM' , async ( ) => {
371
386
const newer_version = mock_higher_version_than_pkg_version ;
372
- const system_data = { [ hostname ] : { current_version : newer_version } , other_hostname : { current_version : pkg . version } } ;
387
+ const system_data = {
388
+ [ hostname ] : { current_version : newer_version } ,
389
+ other_hostname : { current_version : pkg . version }
390
+ } ;
373
391
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 } ` ;
374
392
await expect ( nc_upgrade_manager . _verify_config_dir_upgrade ( system_data , pkg . version , [ hostname , 'other_hostname' ] ) )
375
393
. rejects . toThrow ( expected_err_msg ) ;
@@ -385,7 +403,9 @@ describe('nc upgrade manager - upgrade config directory', () => {
385
403
386
404
it ( '_verify_config_dir_upgrade - fail on mismatch expected_version' , async ( ) => {
387
405
const expected_version = mock_higher_version_than_pkg_version ;
388
- const system_data = { [ hostname ] : { current_version : pkg . version , other_hostname : { current_version : pkg . version } } } ;
406
+ const system_data = {
407
+ [ hostname ] : { current_version : pkg . version , other_hostname : { current_version : pkg . version } }
408
+ } ;
389
409
const nc_upgrade_manager_higher_version = new NCUpgradeManager ( config_fs ) ;
390
410
const expected_err_msg = `config dir upgrade can not be started - the host's package version=${ pkg . version } does not match the user's expected version=${ expected_version } ` ;
391
411
await expect ( nc_upgrade_manager_higher_version . _verify_config_dir_upgrade ( system_data , expected_version , [ hostname ] ) )
@@ -413,7 +433,8 @@ describe('nc upgrade manager - upgrade config directory', () => {
413
433
const successful_upgrade_scripts_obj = { dummy_upgrade_script_1, dummy_upgrade_script_2 } ;
414
434
const failing_upgrade_scripts_obj = { ...successful_upgrade_scripts_obj , dummy_failing_upgrade_script_3 } ;
415
435
const default_this_upgrade = Object . freeze ( {
416
- config_dir_from_version : from_version , config_dir_to_version : to_version ,
436
+ config_dir_from_version : from_version ,
437
+ config_dir_to_version : to_version ,
417
438
completed_scripts : [ ]
418
439
} ) ;
419
440
const default_upgrade_script_paths = Object . keys ( successful_upgrade_scripts_obj ) . map ( script_name =>
@@ -546,7 +567,7 @@ describe('nc upgrade manager - upgrade config directory', () => {
546
567
system_data . config_directory . in_progress_upgrade = {
547
568
completed_scripts : [ ] ,
548
569
running_host : hostname ,
549
- ...options
570
+ ...options
550
571
} ;
551
572
assert_upgrade_start_data ( upgrade_start_data , system_data ) ;
552
573
const system_json_data = await config_fs . get_system_config_file ( ) ;
@@ -773,7 +794,7 @@ describe('nc upgrade manager - upgrade config directory', () => {
773
794
config_dir_version : config_fs . config_dir_version ,
774
795
upgrade_package_version : expected_version ,
775
796
upgrade_history : {
776
- successful_upgrades : [ res ]
797
+ successful_upgrades : [ res . upgrade_info ]
777
798
}
778
799
}
779
800
} ;
@@ -785,9 +806,9 @@ describe('nc upgrade manager - upgrade config directory', () => {
785
806
const expected_version = pkg . version ;
786
807
const hosts_list = [ hostname ] ;
787
808
await config_fs . create_system_config_file ( JSON . stringify ( system_data ) ) ;
788
- const expected_err_msg = 'config_dir_version on system.json and config_fs.config_dir_version match, nothing to upgrade' ;
789
- await expect ( nc_upgrade_manager . upgrade_config_dir ( expected_version , hosts_list ) )
790
- . rejects . toThrow ( expected_err_msg ) ;
809
+ const expected_msg = 'config_dir_version on system.json and config_fs.config_dir_version match, nothing to upgrade' ;
810
+ const res = await nc_upgrade_manager . upgrade_config_dir ( expected_version , hosts_list ) ;
811
+ expect ( res . upgrade_info . detail ) . toStrictEqual ( expected_msg ) ;
791
812
} ) ;
792
813
793
814
it ( 'upgrade_config_dir - config_dir_version in system.json is newer than the hosts current config_dir_version' , async ( ) => {
@@ -825,7 +846,7 @@ describe('nc upgrade manager - upgrade config directory', () => {
825
846
upgrade_package_version : expected_version ,
826
847
upgrade_history : {
827
848
successful_upgrades : [
828
- res ,
849
+ res . upgrade_info ,
829
850
...failed_expected_system_json_has_config_directory . config_directory . upgrade_history . successful_upgrades ,
830
851
]
831
852
}
@@ -845,7 +866,7 @@ describe('nc upgrade manager - upgrade config directory', () => {
845
866
*/
846
867
function assert_upgrade_start_data ( actual_upgrade_start , expected_system_data ) {
847
868
const { config_dir_version, upgrade_package_version, phase, upgrade_history, in_progress_upgrade, current_version } =
848
- actual_upgrade_start . config_directory ;
869
+ actual_upgrade_start . config_directory ;
849
870
const expected_in_progress_upgrade = expected_system_data . config_directory ?. in_progress_upgrade ;
850
871
851
872
expect ( phase ) . toBe ( CONFIG_DIR_PHASES . CONFIG_DIR_LOCKED ) ;
@@ -871,8 +892,14 @@ function assert_upgrade_start_data(actual_upgrade_start, expected_system_data) {
871
892
* @param {Object } expected_system_data
872
893
*/
873
894
function assert_upgrade_finish_or_fail_data ( actual_system_data , expected_system_data ) {
874
- const { config_dir_version, upgrade_package_version, phase, upgrade_history, in_progress_upgrade, current_version } =
875
- actual_system_data . config_directory ;
895
+ const {
896
+ config_dir_version,
897
+ upgrade_package_version,
898
+ phase,
899
+ upgrade_history,
900
+ in_progress_upgrade,
901
+ current_version
902
+ } = actual_system_data . config_directory ;
876
903
877
904
expect ( phase ) . toBe ( expected_system_data . config_directory ?. phase ) ;
878
905
expect ( config_dir_version ) . toBe ( expected_system_data . config_directory ?. config_dir_version ) ;
0 commit comments