@@ -14,8 +14,15 @@ const { CONFIG_SUBDIRS, JSON_SUFFIX, SYMLINK_SUFFIX, ConfigFS } = require('../..
1414const { get_process_fs_context } = require ( '../../../../util/native_fs_utils' ) ;
1515const { ManageCLIError } = require ( '../../../../manage_nsfs/manage_nsfs_cli_errors' ) ;
1616const { ManageCLIResponse } = require ( '../../../../manage_nsfs/manage_nsfs_cli_responses' ) ;
17- const { exec_manage_cli, generate_s3_policy, create_fs_user_by_platform, delete_fs_user_by_platform,
18- set_path_permissions_and_owner, TMP_PATH , set_nc_config_dir_in_config } = require ( '../../../system_tests/test_utils' ) ;
17+ const {
18+ exec_manage_cli,
19+ generate_s3_policy,
20+ create_fs_user_by_platform,
21+ delete_fs_user_by_platform,
22+ set_path_permissions_and_owner,
23+ TMP_PATH ,
24+ set_nc_config_dir_in_config
25+ } = require ( '../../../system_tests/test_utils' ) ;
1926const { TYPES , ACTIONS } = require ( '../../../../manage_nsfs/manage_nsfs_constants' ) ;
2027
2128const tmp_fs_path = path . join ( TMP_PATH , 'test_bucketspace_fs' ) ;
@@ -133,10 +140,10 @@ mocha.describe('manage_nsfs cli', function() {
133140 // try to create a bucket
134141 try {
135142 const bucket_options_with_owner_of_account_cannot_create_bucket = {
136- config_root,
137- name,
138- owner : account_name_for_account_cannot_create_bucket ,
139- path : bucket_path
143+ config_root,
144+ name,
145+ owner : account_name_for_account_cannot_create_bucket ,
146+ path : bucket_path
140147 } ;
141148 await fs_utils . create_fresh_path ( bucket_path ) ;
142149 await fs_utils . file_must_exist ( bucket_path ) ;
@@ -192,7 +199,7 @@ mocha.describe('manage_nsfs cli', function() {
192199
193200 mocha . it ( 'cli bucket create - should fail invalid option' , async function ( ) {
194201 const action = ACTIONS . ADD ;
195- const bucket_options_with_invalid_option = { ...bucket_options , lala : 'lala' } ; // lala invalid option
202+ const bucket_options_with_invalid_option = { ...bucket_options , lala : 'lala' } ; // lala invalid option
196203 try {
197204 add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
198205 assert . fail ( 'should have failed with invalid option' ) ;
@@ -211,7 +218,7 @@ mocha.describe('manage_nsfs cli', function() {
211218
212219 mocha . it ( 'cli bucket status - should fail invalid option' , async function ( ) {
213220 const action = ACTIONS . STATUS ;
214- const bucket_options_with_invalid_option = { ...bucket_options , lala : 'lala' } ; // lala invalid option
221+ const bucket_options_with_invalid_option = { ...bucket_options , lala : 'lala' } ; // lala invalid option
215222 try {
216223 add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
217224 assert . fail ( 'should have failed with invalid option' ) ;
@@ -274,7 +281,7 @@ mocha.describe('manage_nsfs cli', function() {
274281
275282 mocha . it ( 'cli bucket list - should fail invalid option' , async function ( ) {
276283 const action = ACTIONS . LIST ;
277- const bucket_options_with_invalid_option = { config_root, lala : 'lala' } ; // lala invalid option
284+ const bucket_options_with_invalid_option = { config_root, lala : 'lala' } ; // lala invalid option
278285 try {
279286 add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
280287 assert . fail ( 'should have failed with invalid option' ) ;
@@ -286,7 +293,7 @@ mocha.describe('manage_nsfs cli', function() {
286293 mocha . it ( 'cli bucket list wide - should fail invalid string value' , async function ( ) {
287294 const action = ACTIONS . LIST ;
288295 const invalid_wide = 'not-boolean' ; // we accept true and false strings
289- const bucket_options_with_invalid_option = { config_root, wide : invalid_wide } ;
296+ const bucket_options_with_invalid_option = { config_root, wide : invalid_wide } ;
290297 try {
291298 add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
292299 assert . fail ( 'should have failed with invalid boolean value' ) ;
@@ -298,7 +305,7 @@ mocha.describe('manage_nsfs cli', function() {
298305 mocha . it ( 'cli bucket list wide - should fail invalid type' , async function ( ) {
299306 const action = ACTIONS . LIST ;
300307 const invalid_wide = 1234 ;
301- const bucket_options_with_invalid_option = { config_root, wide : invalid_wide } ;
308+ const bucket_options_with_invalid_option = { config_root, wide : invalid_wide } ;
302309 try {
303310 add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
304311 assert . fail ( 'should have failed with invalid option type' ) ;
@@ -339,7 +346,7 @@ mocha.describe('manage_nsfs cli', function() {
339346
340347 mocha . it ( 'cli bucket update - should fail invalid option' , async function ( ) {
341348 const action = ACTIONS . UPDATE ;
342- const bucket_options_with_invalid_option = { config_root, name, lala : 'lala' } ; // lala invalid option
349+ const bucket_options_with_invalid_option = { config_root, name, lala : 'lala' } ; // lala invalid option
343350 try {
344351 add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
345352 assert . fail ( 'should have failed with invalid option' ) ;
@@ -358,7 +365,7 @@ mocha.describe('manage_nsfs cli', function() {
358365 new_buckets_path : account . nsfs_account_config . new_buckets_path ,
359366 } ;
360367 await set_path_permissions_and_owner ( bucket_path , account_options , 0o700 ) ;
361- const update_options = { config_root, name, owner : account_name2 } ;
368+ const update_options = { config_root, name, owner : account_name2 } ;
362369 const update_res = await exec_manage_cli ( type , action , update_options ) ;
363370 bucket_options = { ...bucket_options , ...update_options } ;
364371 const bucket = await config_fs . get_bucket_by_name ( name ) ;
@@ -436,7 +443,7 @@ mocha.describe('manage_nsfs cli', function() {
436443
437444 mocha . it ( 'cli bucket delete - should fail invalid option' , async function ( ) {
438445 const action = ACTIONS . UPDATE ;
439- const bucket_options_with_invalid_option = { config_root, name, lala : 'lala' } ; // lala invalid option
446+ const bucket_options_with_invalid_option = { config_root, name, lala : 'lala' } ; // lala invalid option
440447 try {
441448 add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
442449 assert . fail ( 'should have failed with invalid option' ) ;
@@ -547,8 +554,11 @@ mocha.describe('manage_nsfs cli', function() {
547554 const gpfs_secret_key = 'U2AYaMpU3zRDcRFWmvzgQr9MoHIAsDy3oEXAMPLE' ;
548555 let account_options = { config_root, name, new_buckets_path, uid, gid, access_key, secret_key } ;
549556 const gpfs_account_options = {
550- ...account_options , access_key : gpfs_access_key , secret_key : gpfs_secret_key ,
551- name : gpfs_account , fs_backend : 'GPFS'
557+ ...account_options ,
558+ access_key : gpfs_access_key ,
559+ secret_key : gpfs_secret_key ,
560+ name : gpfs_account ,
561+ fs_backend : 'GPFS'
552562 } ;
553563 let updating_options = account_options ;
554564 let compare_details ; // we will use it for update account and compare the results
@@ -1023,7 +1033,7 @@ mocha.describe('manage_nsfs cli', function() {
10231033 mocha . it ( 'should fail - cli whitelist has invalid IP address (one item in the list)' , async function ( ) {
10241034 const ip_list_with_invalid_ip_address = [ '10.1.11' ] ; // missing a class in the IP address
10251035 try {
1026- await exec_manage_cli ( type , '' , { config_root, ips : ip_list_with_invalid_ip_address } ) ;
1036+ await exec_manage_cli ( type , '' , { config_root, ips : ip_list_with_invalid_ip_address } ) ;
10271037 assert . fail ( 'should have failed with whitelist ips with invalid ip address' ) ;
10281038 } catch ( err ) {
10291039 assert_error ( err , ManageCLIError . InvalidWhiteListIPFormat ) ;
@@ -1035,7 +1045,7 @@ mocha.describe('manage_nsfs cli', function() {
10351045 const ips = [ '127.0.0.1' , '::ffff:7f00:3' , '0000:0000:0000:0000:0000:ffff:7f00:0002' ] ;
10361046 ips . push ( invalid_ip_address ) ;
10371047 try {
1038- await exec_manage_cli ( type , '' , { config_root, ips : ips } ) ;
1048+ await exec_manage_cli ( type , '' , { config_root, ips : ips } ) ;
10391049 assert . fail ( 'should have failed with whitelist ips with invalid ip address' ) ;
10401050 } catch ( err ) {
10411051 assert_error ( err , ManageCLIError . InvalidWhiteListIPFormat ) ;
@@ -1064,14 +1074,110 @@ mocha.describe('manage_nsfs cli', function() {
10641074 const ips = [ '127.0.0.1' ] ; // IPV4 format
10651075 const res = await exec_manage_cli ( type , '' , { config_root, ips : JSON . stringify ( ips ) } ) ;
10661076 await assert_response ( '' , type , res , ips ) ;
1067- const new_config_options = { S3_SERVER_IP_WHITELIST : ips } ;
1077+ const new_config_options = { S3_SERVER_IP_WHITELIST : ips } ;
10681078 const config_data = await config_fs . get_config_json ( ) ;
10691079 console . log ( config_data ) ;
10701080 assert_whitelist ( config_data , new_config_options ) ;
10711081 } ) ;
10721082
10731083 } ) ;
10741084
1085+ mocha . describe ( 'cli lifecycle flow' , async function ( ) {
1086+ this . timeout ( 50000 ) ; // eslint-disable-line no-invalid-this
1087+ const type = TYPES . LIFECYCLE ;
1088+ let now = new Date ( ) ;
1089+ let format_time = `${ now . getHours ( ) . toString ( ) . padStart ( 2 , '0' ) } :${ now . getMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) } ` ;
1090+ const config_options = { NC_LIFECYCLE_RUN_TIME : format_time , NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS : 5 , NC_LIFECYCLE_TZ : 'LOCAL' } ;
1091+ mocha . before ( async ( ) => {
1092+ await config_fs . create_config_json_file ( JSON . stringify ( config_options ) ) ;
1093+ } ) ;
1094+ mocha . after ( async ( ) => {
1095+ const config_file_path = config_fs . get_config_json_path ( ) ;
1096+ await fs_utils . file_delete ( config_file_path ) ;
1097+ } ) ;
1098+
1099+ mocha . it ( 'cli lifecycle should run with LOCAL TZ' , async function ( ) {
1100+ now = new Date ( ) ;
1101+ format_time = `${ now . getHours ( ) . toString ( ) . padStart ( 2 , '0' ) } :${ now . getMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) } ` ;
1102+ const new_config_options = { NC_LIFECYCLE_RUN_TIME : format_time , NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS : 5 , NC_LIFECYCLE_TZ : 'LOCAL' } ;
1103+ await config_fs . update_config_json_file ( JSON . stringify ( new_config_options ) ) ;
1104+ const res = await exec_manage_cli ( type , '' , { config_root, disable_service_validation : true } ) ;
1105+ const parsed = JSON . parse ( res ) ;
1106+ assert . equal ( parsed . response . code , ManageCLIResponse . LifecycleSuccessful . code ) ;
1107+ } ) ;
1108+
1109+ mocha . it ( 'cli lifecycle shouldn\'t run twice with LOCAL TZ' , async function ( ) {
1110+ const new_config_options = { NC_LIFECYCLE_RUN_TIME : format_time , NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS : 5 , NC_LIFECYCLE_TZ : 'LOCAL' } ;
1111+ await config_fs . update_config_json_file ( JSON . stringify ( new_config_options ) ) ;
1112+ const res = await exec_manage_cli ( type , '' , { config_root, disable_service_validation : true } ) ;
1113+ const parsed = JSON . parse ( res ) ;
1114+ assert . equal ( parsed . response . code , ManageCLIResponse . LifecycleWorkerNotRunning . code ) ;
1115+ // remove the timestamp file to allow next tests to run
1116+ const timestampfile = path . join ( config_fs . config_root , config . NC_LIFECYCLE_CONFIG_DIR_NAME , 'lifecycle.timestamp' ) ;
1117+ await fs_utils . file_delete ( timestampfile ) ;
1118+ } ) ;
1119+
1120+ mocha . it ( 'cli lifecycle shouldn\'t run before NC_LIFECYCLE_RUN_TIME with LOCAL TZ' , async function ( ) {
1121+ now = new Date ( ) ;
1122+ const in_one_minute = new Date ( now ) ;
1123+ in_one_minute . setMinutes ( now . getMinutes ( ) + 1 ) ;
1124+ format_time = `${ in_one_minute . getHours ( ) . toString ( ) . padStart ( 2 , '0' ) } :${ in_one_minute . getMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) } ` ;
1125+ const new_config_options = { NC_LIFECYCLE_RUN_TIME : format_time , NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS : 5 , NC_LIFECYCLE_TZ : 'LOCAL' } ;
1126+ await config_fs . update_config_json_file ( JSON . stringify ( new_config_options ) ) ;
1127+ const res = await exec_manage_cli ( type , '' , { config_root, disable_service_validation : true } ) ;
1128+ const parsed = JSON . parse ( res ) ;
1129+ assert . equal ( parsed . response . code , ManageCLIResponse . LifecycleWorkerNotRunning . code ) ;
1130+ } ) ;
1131+
1132+ mocha . it ( 'cli lifecycle shouldn\'t run after NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS with LOCAL TZ' , async function ( ) {
1133+ now = new Date ( ) ;
1134+ const ten_minute_ago = new Date ( now ) ;
1135+ ten_minute_ago . setMinutes ( now . getMinutes ( ) - 10 ) ;
1136+ format_time = `${ ten_minute_ago . getHours ( ) . toString ( ) . padStart ( 2 , '0' ) } :${ ten_minute_ago . getMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) } ` ;
1137+ const new_config_options = { NC_LIFECYCLE_RUN_TIME : format_time , NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS : 5 , NC_LIFECYCLE_TZ : 'LOCAL' } ;
1138+ await config_fs . update_config_json_file ( JSON . stringify ( new_config_options ) ) ;
1139+ const res = await exec_manage_cli ( type , '' , { config_root, disable_service_validation : true } ) ;
1140+ const parsed = JSON . parse ( res ) ;
1141+ assert . equal ( parsed . response . code , ManageCLIResponse . LifecycleWorkerNotRunning . code ) ;
1142+ } ) ;
1143+
1144+ mocha . it ( 'cli lifecycle should run with UTC TZ' , async function ( ) {
1145+ now = new Date ( ) ;
1146+ const utc_now = new Date ( now ) ;
1147+ format_time = `${ utc_now . getUTCHours ( ) . toString ( ) . padStart ( 2 , '0' ) } :${ utc_now . getUTCMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) } ` ;
1148+ const new_config_options = { NC_LIFECYCLE_RUN_TIME : format_time , NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS : 5 , NC_LIFECYCLE_TZ : 'UTC' } ;
1149+ await config_fs . update_config_json_file ( JSON . stringify ( new_config_options ) ) ;
1150+ const res = await exec_manage_cli ( type , '' , { config_root, disable_service_validation : true } ) ;
1151+ const parsed = JSON . parse ( res ) ;
1152+ assert . equal ( parsed . response . code , ManageCLIResponse . LifecycleSuccessful . code ) ;
1153+ } ) ;
1154+
1155+ mocha . it ( 'cli lifecycle shouldn\'t run before NC_LIFECYCLE_RUN_TIME with UTC TZ' , async function ( ) {
1156+ now = new Date ( ) ;
1157+ const in_one_minute = new Date ( now ) ; // Create a copy to avoid modifying 'now'
1158+ in_one_minute . setUTCMinutes ( now . getUTCMinutes ( ) + 1 ) ;
1159+ format_time = `${ in_one_minute . getUTCHours ( ) . toString ( ) . padStart ( 2 , '0' ) } :${ in_one_minute . getUTCMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) } ` ;
1160+ const new_config_options = { NC_LIFECYCLE_RUN_TIME : format_time , NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS : 5 , NC_LIFECYCLE_TZ : 'UTC' } ;
1161+ await config_fs . update_config_json_file ( JSON . stringify ( new_config_options ) ) ;
1162+ const res = await exec_manage_cli ( type , '' , { config_root, disable_service_validation : true } ) ;
1163+ const parsed = JSON . parse ( res ) ;
1164+ assert . equal ( parsed . response . code , ManageCLIResponse . LifecycleWorkerNotRunning . code ) ;
1165+ } ) ;
1166+
1167+ mocha . it ( 'cli lifecycle shouldn\'t run after NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS with UTC TZ' , async function ( ) {
1168+ now = new Date ( ) ;
1169+ const ten_minute_ago = new Date ( now ) ;
1170+ ten_minute_ago . setUTCMinutes ( now . getUTCMinutes ( ) - 10 ) ;
1171+ format_time = `${ ten_minute_ago . getUTCHours ( ) . toString ( ) . padStart ( 2 , '0' ) } :${ ten_minute_ago . getUTCMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) } ` ;
1172+ const new_config_options = { NC_LIFECYCLE_RUN_TIME : format_time , NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS : 5 , NC_LIFECYCLE_TZ : 'UTC' } ;
1173+ await config_fs . update_config_json_file ( JSON . stringify ( new_config_options ) ) ;
1174+ const res = await exec_manage_cli ( type , '' , { config_root, disable_service_validation : true } ) ;
1175+ const parsed = JSON . parse ( res ) ;
1176+ assert . equal ( parsed . response . code , ManageCLIResponse . LifecycleWorkerNotRunning . code ) ;
1177+ } ) ;
1178+
1179+ } ) ;
1180+
10751181} ) ;
10761182
10771183
0 commit comments