@@ -14,8 +14,15 @@ const { CONFIG_SUBDIRS, JSON_SUFFIX, SYMLINK_SUFFIX, ConfigFS } = require('../..
14
14
const { get_process_fs_context } = require ( '../../../../util/native_fs_utils' ) ;
15
15
const { ManageCLIError } = require ( '../../../../manage_nsfs/manage_nsfs_cli_errors' ) ;
16
16
const { 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' ) ;
19
26
const { TYPES , ACTIONS } = require ( '../../../../manage_nsfs/manage_nsfs_constants' ) ;
20
27
21
28
const tmp_fs_path = path . join ( TMP_PATH , 'test_bucketspace_fs' ) ;
@@ -133,10 +140,10 @@ mocha.describe('manage_nsfs cli', function() {
133
140
// try to create a bucket
134
141
try {
135
142
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
140
147
} ;
141
148
await fs_utils . create_fresh_path ( bucket_path ) ;
142
149
await fs_utils . file_must_exist ( bucket_path ) ;
@@ -192,7 +199,7 @@ mocha.describe('manage_nsfs cli', function() {
192
199
193
200
mocha . it ( 'cli bucket create - should fail invalid option' , async function ( ) {
194
201
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
196
203
try {
197
204
add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
198
205
assert . fail ( 'should have failed with invalid option' ) ;
@@ -211,7 +218,7 @@ mocha.describe('manage_nsfs cli', function() {
211
218
212
219
mocha . it ( 'cli bucket status - should fail invalid option' , async function ( ) {
213
220
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
215
222
try {
216
223
add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
217
224
assert . fail ( 'should have failed with invalid option' ) ;
@@ -274,7 +281,7 @@ mocha.describe('manage_nsfs cli', function() {
274
281
275
282
mocha . it ( 'cli bucket list - should fail invalid option' , async function ( ) {
276
283
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
278
285
try {
279
286
add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
280
287
assert . fail ( 'should have failed with invalid option' ) ;
@@ -286,7 +293,7 @@ mocha.describe('manage_nsfs cli', function() {
286
293
mocha . it ( 'cli bucket list wide - should fail invalid string value' , async function ( ) {
287
294
const action = ACTIONS . LIST ;
288
295
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 } ;
290
297
try {
291
298
add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
292
299
assert . fail ( 'should have failed with invalid boolean value' ) ;
@@ -298,7 +305,7 @@ mocha.describe('manage_nsfs cli', function() {
298
305
mocha . it ( 'cli bucket list wide - should fail invalid type' , async function ( ) {
299
306
const action = ACTIONS . LIST ;
300
307
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 } ;
302
309
try {
303
310
add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
304
311
assert . fail ( 'should have failed with invalid option type' ) ;
@@ -339,7 +346,7 @@ mocha.describe('manage_nsfs cli', function() {
339
346
340
347
mocha . it ( 'cli bucket update - should fail invalid option' , async function ( ) {
341
348
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
343
350
try {
344
351
add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
345
352
assert . fail ( 'should have failed with invalid option' ) ;
@@ -358,7 +365,7 @@ mocha.describe('manage_nsfs cli', function() {
358
365
new_buckets_path : account . nsfs_account_config . new_buckets_path ,
359
366
} ;
360
367
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 } ;
362
369
const update_res = await exec_manage_cli ( type , action , update_options ) ;
363
370
bucket_options = { ...bucket_options , ...update_options } ;
364
371
const bucket = await config_fs . get_bucket_by_name ( name ) ;
@@ -436,7 +443,7 @@ mocha.describe('manage_nsfs cli', function() {
436
443
437
444
mocha . it ( 'cli bucket delete - should fail invalid option' , async function ( ) {
438
445
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
440
447
try {
441
448
add_res = await exec_manage_cli ( type , action , bucket_options_with_invalid_option ) ;
442
449
assert . fail ( 'should have failed with invalid option' ) ;
@@ -547,8 +554,11 @@ mocha.describe('manage_nsfs cli', function() {
547
554
const gpfs_secret_key = 'U2AYaMpU3zRDcRFWmvzgQr9MoHIAsDy3oEXAMPLE' ;
548
555
let account_options = { config_root, name, new_buckets_path, uid, gid, access_key, secret_key } ;
549
556
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'
552
562
} ;
553
563
let updating_options = account_options ;
554
564
let compare_details ; // we will use it for update account and compare the results
@@ -1023,7 +1033,7 @@ mocha.describe('manage_nsfs cli', function() {
1023
1033
mocha . it ( 'should fail - cli whitelist has invalid IP address (one item in the list)' , async function ( ) {
1024
1034
const ip_list_with_invalid_ip_address = [ '10.1.11' ] ; // missing a class in the IP address
1025
1035
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 } ) ;
1027
1037
assert . fail ( 'should have failed with whitelist ips with invalid ip address' ) ;
1028
1038
} catch ( err ) {
1029
1039
assert_error ( err , ManageCLIError . InvalidWhiteListIPFormat ) ;
@@ -1035,7 +1045,7 @@ mocha.describe('manage_nsfs cli', function() {
1035
1045
const ips = [ '127.0.0.1' , '::ffff:7f00:3' , '0000:0000:0000:0000:0000:ffff:7f00:0002' ] ;
1036
1046
ips . push ( invalid_ip_address ) ;
1037
1047
try {
1038
- await exec_manage_cli ( type , '' , { config_root, ips : ips } ) ;
1048
+ await exec_manage_cli ( type , '' , { config_root, ips : ips } ) ;
1039
1049
assert . fail ( 'should have failed with whitelist ips with invalid ip address' ) ;
1040
1050
} catch ( err ) {
1041
1051
assert_error ( err , ManageCLIError . InvalidWhiteListIPFormat ) ;
@@ -1064,14 +1074,110 @@ mocha.describe('manage_nsfs cli', function() {
1064
1074
const ips = [ '127.0.0.1' ] ; // IPV4 format
1065
1075
const res = await exec_manage_cli ( type , '' , { config_root, ips : JSON . stringify ( ips ) } ) ;
1066
1076
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 } ;
1068
1078
const config_data = await config_fs . get_config_json ( ) ;
1069
1079
console . log ( config_data ) ;
1070
1080
assert_whitelist ( config_data , new_config_options ) ;
1071
1081
} ) ;
1072
1082
1073
1083
} ) ;
1074
1084
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
+
1075
1181
} ) ;
1076
1182
1077
1183
0 commit comments