@@ -13,19 +13,29 @@ const path = require('path');
1313const fs_utils = require ( '../../../../util/fs_utils' ) ;
1414const config = require ( '../../../../../config' ) ;
1515const 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' ) ;
1822const { 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' ) ;
2131
2232const config_root = path . join ( TMP_PATH , 'config_root_nc_upgrade_manager_test' ) ;
2333const config_fs = new ConfigFS ( config_root ) ;
2434const hostname = os . hostname ( ) ;
2535const mock_higher_version_than_pkg_version = pkg . version + '.1' ;
2636
2737const dummy_upgrade_script_1 =
28- `/* Copyright (C) 2024 NooBaa */
38+ `/* Copyright (C) 2024 NooBaa */
2939'use strict';
3040async function run() {
3141 console.log('script number 1');
@@ -36,7 +46,7 @@ module.exports = {
3646};
3747` ;
3848const dummy_upgrade_script_2 =
39- `/* Copyright (C) 2024 NooBaa */
49+ `/* Copyright (C) 2024 NooBaa */
4050'use strict';
4151async function run() {
4252 console.log('script number 2');
@@ -47,7 +57,7 @@ module.exports = {
4757};` ;
4858
4959const dummy_failing_upgrade_script_3 =
50- `/* Copyright (C) 2024 NooBaa */
60+ `/* Copyright (C) 2024 NooBaa */
5161'use strict';
5262async function run() {
5363 console.log('script number 3');
@@ -353,23 +363,31 @@ describe('nc upgrade manager - upgrade config directory', () => {
353363 } ) ;
354364
355365 it ( '_verify_config_dir_upgrade - empty host current_version' , async ( ) => {
356- const system_data = { [ hostname ] : [ ] } ;
366+ const system_data = {
367+ [ hostname ] : [ ]
368+ } ;
357369 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` ;
358370 await expect ( nc_upgrade_manager . _verify_config_dir_upgrade ( system_data , pkg . version , [ hostname ] ) )
359371 . rejects . toThrow ( expected_err_msg ) ;
360372 } ) ;
361373
362374 it ( '_verify_config_dir_upgrade - host current_version < new_version should upgrade RPM' , async ( ) => {
363375 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+ } ;
365380 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 } ` ;
366381 await expect ( nc_upgrade_manager . _verify_config_dir_upgrade ( system_data , pkg . version , [ hostname , 'other_hostname' ] ) )
367382 . rejects . toThrow ( expected_err_msg ) ;
368383 } ) ;
369384
370385 it ( '_verify_config_dir_upgrade - host current_version > new_version should upgrade RPM' , async ( ) => {
371386 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+ } ;
373391 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 } ` ;
374392 await expect ( nc_upgrade_manager . _verify_config_dir_upgrade ( system_data , pkg . version , [ hostname , 'other_hostname' ] ) )
375393 . rejects . toThrow ( expected_err_msg ) ;
@@ -385,7 +403,9 @@ describe('nc upgrade manager - upgrade config directory', () => {
385403
386404 it ( '_verify_config_dir_upgrade - fail on mismatch expected_version' , async ( ) => {
387405 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+ } ;
389409 const nc_upgrade_manager_higher_version = new NCUpgradeManager ( config_fs ) ;
390410 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 } ` ;
391411 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', () => {
413433 const successful_upgrade_scripts_obj = { dummy_upgrade_script_1, dummy_upgrade_script_2 } ;
414434 const failing_upgrade_scripts_obj = { ...successful_upgrade_scripts_obj , dummy_failing_upgrade_script_3 } ;
415435 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 ,
417438 completed_scripts : [ ]
418439 } ) ;
419440 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', () => {
546567 system_data . config_directory . in_progress_upgrade = {
547568 completed_scripts : [ ] ,
548569 running_host : hostname ,
549- ...options
570+ ...options
550571 } ;
551572 assert_upgrade_start_data ( upgrade_start_data , system_data ) ;
552573 const system_json_data = await config_fs . get_system_config_file ( ) ;
@@ -773,7 +794,7 @@ describe('nc upgrade manager - upgrade config directory', () => {
773794 config_dir_version : config_fs . config_dir_version ,
774795 upgrade_package_version : expected_version ,
775796 upgrade_history : {
776- successful_upgrades : [ res ]
797+ successful_upgrades : [ res . upgrade_info ]
777798 }
778799 }
779800 } ;
@@ -785,9 +806,9 @@ describe('nc upgrade manager - upgrade config directory', () => {
785806 const expected_version = pkg . version ;
786807 const hosts_list = [ hostname ] ;
787808 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 ) ;
791812 } ) ;
792813
793814 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', () => {
825846 upgrade_package_version : expected_version ,
826847 upgrade_history : {
827848 successful_upgrades : [
828- res ,
849+ res . upgrade_info ,
829850 ...failed_expected_system_json_has_config_directory . config_directory . upgrade_history . successful_upgrades ,
830851 ]
831852 }
@@ -845,7 +866,7 @@ describe('nc upgrade manager - upgrade config directory', () => {
845866 */
846867function assert_upgrade_start_data ( actual_upgrade_start , expected_system_data ) {
847868 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 ;
849870 const expected_in_progress_upgrade = expected_system_data . config_directory ?. in_progress_upgrade ;
850871
851872 expect ( phase ) . toBe ( CONFIG_DIR_PHASES . CONFIG_DIR_LOCKED ) ;
@@ -871,8 +892,14 @@ function assert_upgrade_start_data(actual_upgrade_start, expected_system_data) {
871892 * @param {Object } expected_system_data
872893 */
873894function 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 ;
876903
877904 expect ( phase ) . toBe ( expected_system_data . config_directory ?. phase ) ;
878905 expect ( config_dir_version ) . toBe ( expected_system_data . config_directory ?. config_dir_version ) ;
0 commit comments