@@ -7,20 +7,21 @@ const path = require('path');
7
7
const mocha = require ( 'mocha' ) ;
8
8
const sinon = require ( 'sinon' ) ;
9
9
const assert = require ( 'assert' ) ;
10
- const { ConfigFS } = require ( '../../sdk/config_fs' ) ;
11
- const NSFSHealth = require ( '../../manage_nsfs/health' ) . NSFSHealth ;
12
10
const fs_utils = require ( '../../util/fs_utils' ) ;
13
- const test_utils = require ( '../system_tests/test_utils' ) ;
14
11
const nb_native = require ( '../../util/nb_native' ) ;
15
- const { TYPES , DIAGNOSE_ACTIONS , ACTIONS } = require ( '../../manage_nsfs/manage_nsfs_constants' ) ;
12
+ const { ConfigFS } = require ( '../../sdk/config_fs' ) ;
13
+ const mongo_utils = require ( '../../util/mongo_utils' ) ;
14
+ const test_utils = require ( '../system_tests/test_utils' ) ;
15
+ const NSFSHealth = require ( '../../manage_nsfs/health' ) . NSFSHealth ;
16
16
const { get_process_fs_context } = require ( '../../util/native_fs_utils' ) ;
17
- const { TMP_PATH , create_fs_user_by_platform, delete_fs_user_by_platform, exec_manage_cli } = require ( '../system_tests/test_utils' ) ;
18
17
const { ManageCLIError } = require ( '../../manage_nsfs/manage_nsfs_cli_errors' ) ;
18
+ const { TYPES , DIAGNOSE_ACTIONS , ACTIONS } = require ( '../../manage_nsfs/manage_nsfs_constants' ) ;
19
+ const { TMP_PATH , create_fs_user_by_platform, delete_fs_user_by_platform, exec_manage_cli } = require ( '../system_tests/test_utils' ) ;
19
20
20
- const tmp_fs_path = path . join ( TMP_PATH , 'test_bucketspace_fs ' ) ;
21
+ const tmp_fs_path = path . join ( TMP_PATH , 'test_nc_health ' ) ;
21
22
const DEFAULT_FS_CONFIG = get_process_fs_context ( ) ;
22
23
23
- const bucket_storage_path = path . join ( tmp_fs_path , 'account_inaccessible ' ) ;
24
+ const bucket_storage_path = path . join ( tmp_fs_path , 'bucket_storage_path ' ) ;
24
25
25
26
mocha . describe ( 'nsfs nc health' , function ( ) {
26
27
@@ -92,7 +93,7 @@ mocha.describe('nsfs nc health', function() {
92
93
} ) ;
93
94
} ) ;
94
95
95
- mocha . describe ( 'health check' , async function ( ) {
96
+ mocha . describe ( 'health check' , function ( ) {
96
97
const new_buckets_path = `${ root_path } new_buckets_path_user1/` ;
97
98
const account1_options = {
98
99
name : 'account1' ,
@@ -102,14 +103,15 @@ mocha.describe('nsfs nc health', function() {
102
103
} ;
103
104
const bucket1_options = {
104
105
name : 'bucket1' ,
105
- path : new_buckets_path + '/bucket1'
106
+ path : new_buckets_path + '/bucket1' ,
107
+ owner : account1_options . name
106
108
} ;
107
109
const account_inaccessible_options = { name : 'account_inaccessible' , uid : 999 , gid : 999 , new_buckets_path : bucket_storage_path } ;
108
110
const account_inaccessible_dn_options = { name : 'account_inaccessible_dn' , user : 'inaccessible_dn' , new_buckets_path : bucket_storage_path } ;
109
111
const invalid_account_dn_options = { name : 'invalid_account_dn' , user : 'invalid_account_dn' , new_buckets_path : bucket_storage_path } ;
110
112
const fs_users = {
111
113
other_user : {
112
- distinguished_name : account_inaccessible_dn_options . nsfs_account_config . distinguished_name ,
114
+ distinguished_name : account_inaccessible_dn_options . user ,
113
115
uid : 1312 ,
114
116
gid : 1312
115
117
}
@@ -140,6 +142,10 @@ mocha.describe('nsfs nc health', function() {
140
142
}
141
143
} ) ;
142
144
145
+ mocha . afterEach ( async ( ) => {
146
+ await fs_utils . file_delete ( config_fs . config_json_path ) ;
147
+ } ) ;
148
+
143
149
mocha . it ( 'Health all condition is success' , async function ( ) {
144
150
const get_service_state = sinon . stub ( Health , "get_service_state" ) ;
145
151
get_service_state . onFirstCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 100 } ) )
@@ -186,8 +192,9 @@ mocha.describe('nsfs nc health', function() {
186
192
mocha . it ( 'NSFS account with invalid storage path' , async function ( ) {
187
193
Health . get_service_state . restore ( ) ;
188
194
Health . get_endpoint_response . restore ( ) ;
189
- const account_invalid_options = { name : 'account_invalid' , new_buckets_path : new_buckets_path + '/invalid' } ;
190
- await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . ADD , { config_root, ...account_invalid_options } ) ;
195
+ // create it manually because we can not skip invalid storage path check on the CLI
196
+ const account_invalid_options = { _id : mongo_utils . mongoObjectId ( ) , name : 'account_invalid' , nsfs_account_config : { new_buckets_path : path . join ( new_buckets_path , '/invalid' ) } } ;
197
+ await test_utils . write_manual_config_file ( TYPES . ACCOUNT , config_fs , account_invalid_options ) ;
191
198
const get_service_state = sinon . stub ( Health , "get_service_state" ) ;
192
199
get_service_state . onFirstCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 1000 } ) )
193
200
. onSecondCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 2000 } ) ) ;
@@ -197,14 +204,15 @@ mocha.describe('nsfs nc health', function() {
197
204
assert . strictEqual ( health_status . status , 'OK' ) ;
198
205
assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts . length , 1 ) ;
199
206
assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts [ 0 ] . name , 'account_invalid' ) ;
200
- await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . DELETE , { config_root, name : account_invalid_options . name } ) ;
207
+ await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . DELETE , { config_root, name : account_invalid_options . name } ) ;
201
208
} ) ;
202
209
203
210
mocha . it ( 'NSFS bucket with invalid storage path' , async function ( ) {
204
211
Health . get_service_state . restore ( ) ;
205
212
Health . get_endpoint_response . restore ( ) ;
206
- const bucket_invalid = { name : 'bucket_invalid' , path : new_buckets_path + '/bucket1/invalid' } ;
207
- await config_fs . create_bucket_config_file ( bucket_invalid ) ;
213
+ // create it manually because we can not skip invalid storage path check on the CLI
214
+ const bucket_invalid = { _id : mongo_utils . mongoObjectId ( ) , name : 'bucket_invalid' , path : new_buckets_path + '/bucket1/invalid' , owner : account1_options . name } ;
215
+ await test_utils . write_manual_config_file ( TYPES . BUCKET , config_fs , bucket_invalid ) ;
208
216
const get_service_state = sinon . stub ( Health , "get_service_state" ) ;
209
217
get_service_state . onFirstCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 1000 } ) )
210
218
. onSecondCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 2000 } ) ) ;
@@ -213,15 +221,17 @@ mocha.describe('nsfs nc health', function() {
213
221
const health_status = await Health . nc_nsfs_health ( ) ;
214
222
assert . strictEqual ( health_status . status , 'OK' ) ;
215
223
assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets . length , 1 ) ;
216
- assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets [ 0 ] . name , ' bucket_invalid' ) ;
217
- await exec_manage_cli ( TYPES . BUCKET , ACTIONS . DELETE , { config_root, name : bucket_invalid . name } ) ;
224
+ assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets [ 0 ] . name , bucket_invalid . name ) ;
225
+ await exec_manage_cli ( TYPES . BUCKET , ACTIONS . DELETE , { config_root, name : bucket_invalid . name } ) ;
218
226
} ) ;
219
227
220
228
mocha . it ( 'NSFS invalid bucket schema json' , async function ( ) {
221
229
Health . get_service_state . restore ( ) ;
222
230
Health . get_endpoint_response . restore ( ) ;
223
- const bucket_invalid_schema = { name : 'bucket_invalid_schema' , path : new_buckets_path } ;
224
- await config_fs . create_bucket_config_file ( bucket_invalid_schema ) ;
231
+ // create it manually because we can not skip json schema check on the CLI
232
+ const bucket_invalid_schema = { _id : mongo_utils . mongoObjectId ( ) , name : 'bucket_invalid_schema' , path : new_buckets_path } ;
233
+ await test_utils . write_manual_config_file ( TYPES . BUCKET , config_fs , bucket_invalid_schema , 'invalid' ) ;
234
+
225
235
const get_service_state = sinon . stub ( Health , "get_service_state" ) ;
226
236
get_service_state . onFirstCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 1000 } ) )
227
237
. onSecondCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 2000 } ) ) ;
@@ -230,14 +240,16 @@ mocha.describe('nsfs nc health', function() {
230
240
const health_status = await Health . nc_nsfs_health ( ) ;
231
241
assert . strictEqual ( health_status . status , 'OK' ) ;
232
242
assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets . length , 1 ) ;
233
- assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets [ 0 ] . name , 'bucket_invalid_schema' ) ;
234
- await exec_manage_cli ( TYPES . BUCKET , ACTIONS . DELETE , { config_root, name : bucket_invalid_schema . name } ) ;
243
+ assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets [ 0 ] . name , bucket_invalid_schema . name ) ;
244
+ // delete it manually because we can not read non json files using the CLI
245
+ await test_utils . delete_manual_config_file ( TYPES . BUCKET , config_fs , bucket_invalid_schema ) ;
235
246
} ) ;
236
247
237
248
mocha . it ( 'NSFS invalid account schema json' , async function ( ) {
238
249
Health . get_service_state . restore ( ) ;
239
250
Health . get_endpoint_response . restore ( ) ;
240
- const account_invalid_schema = { _id : '9' , name : 'account_invalid_schema' , path : new_buckets_path , bla : 5 } ;
251
+ // create it manually because we can not skip json schema check on the CLI
252
+ const account_invalid_schema = { _id : mongo_utils . mongoObjectId ( ) , name : 'account_invalid_schema' , path : new_buckets_path , bla : 5 } ;
241
253
await test_utils . write_manual_config_file ( TYPES . ACCOUNT , config_fs , account_invalid_schema , 'invalid' ) ;
242
254
const get_service_state = sinon . stub ( Health , "get_service_state" ) ;
243
255
get_service_state . onFirstCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 1000 } ) )
@@ -248,7 +260,8 @@ mocha.describe('nsfs nc health', function() {
248
260
assert . strictEqual ( health_status . status , 'OK' ) ;
249
261
assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts . length , 1 ) ;
250
262
assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts [ 0 ] . name , account_invalid_schema . name ) ;
251
- await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . DELETE , { config_root, name : account_invalid_schema . name } ) ;
263
+ // delete it manually because we can not read non json files using the CLI
264
+ await test_utils . delete_manual_config_file ( TYPES . ACCOUNT , config_fs , account_invalid_schema ) ;
252
265
} ) ;
253
266
254
267
mocha . it ( 'Health all condition is success, all_account_details is false' , async function ( ) {
@@ -309,10 +322,10 @@ mocha.describe('nsfs nc health', function() {
309
322
//revert to config root
310
323
Health . config_root = config_root ;
311
324
Health . config_fs = old_config_fs ;
312
-
313
325
} ) ;
314
326
315
327
mocha . it ( 'Account with inaccessible path - uid gid' , async function ( ) {
328
+ await config_fs . create_config_json_file ( JSON . stringify ( { NC_DISABLE_ACCESS_CHECK : true } ) ) ;
316
329
await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . ADD , { config_root, ...account_inaccessible_options } ) ;
317
330
Health . get_service_state . restore ( ) ;
318
331
Health . get_endpoint_response . restore ( ) ;
@@ -329,10 +342,11 @@ mocha.describe('nsfs nc health', function() {
329
342
assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts . length , 1 ) ;
330
343
assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts [ 0 ] . code , "ACCESS_DENIED" ) ;
331
344
assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts [ 0 ] . name , account_inaccessible_options . name ) ;
332
- await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . DELETE , { config_root, name : account_inaccessible_options . name } ) ;
345
+ await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . DELETE , { config_root, name : account_inaccessible_options . name } ) ;
333
346
} ) ;
334
347
335
348
mocha . it ( 'Account with inaccessible path - dn' , async function ( ) {
349
+ await config_fs . create_config_json_file ( JSON . stringify ( { NC_DISABLE_ACCESS_CHECK : true } ) ) ;
336
350
await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . ADD , { config_root, ...account_inaccessible_dn_options } ) ;
337
351
Health . get_service_state . restore ( ) ;
338
352
Health . get_endpoint_response . restore ( ) ;
@@ -353,6 +367,7 @@ mocha.describe('nsfs nc health', function() {
353
367
} ) ;
354
368
355
369
mocha . it ( 'Account with invalid dn' , async function ( ) {
370
+ await config_fs . create_config_json_file ( JSON . stringify ( { NC_DISABLE_ACCESS_CHECK : true } ) ) ;
356
371
await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . ADD , { config_root, ...invalid_account_dn_options } ) ;
357
372
Health . get_service_state . restore ( ) ;
358
373
Health . get_endpoint_response . restore ( ) ;
@@ -364,6 +379,7 @@ mocha.describe('nsfs nc health', function() {
364
379
const get_endpoint_response = sinon . stub ( Health , "get_endpoint_response" ) ;
365
380
get_endpoint_response . onFirstCall ( ) . returns ( Promise . resolve ( { response : { response_code : 'RUNNING' , total_fork_count : 0 } } ) ) ;
366
381
const health_status = await Health . nc_nsfs_health ( ) ;
382
+ await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . DELETE , { config_root, name : invalid_account_dn_options . name } ) ;
367
383
assert . strictEqual ( health_status . checks . buckets_status . valid_buckets . length , 1 ) ;
368
384
assert . strictEqual ( health_status . checks . accounts_status . valid_accounts . length , 1 ) ;
369
385
assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts . length , 1 ) ;
@@ -386,8 +402,10 @@ mocha.describe('nsfs nc health', function() {
386
402
const get_endpoint_response = sinon . stub ( Health , "get_endpoint_response" ) ;
387
403
get_endpoint_response . onFirstCall ( ) . returns ( Promise . resolve ( { response : { response_code : 'RUNNING' , total_fork_count : 0 } } ) ) ;
388
404
const health_status = await Health . nc_nsfs_health ( ) ;
389
- assert . strictEqual ( health_status . checks . accounts_status . valid_accounts . length , 2 ) ;
405
+ assert . strictEqual ( health_status . checks . accounts_status . valid_accounts . length , 1 ) ;
390
406
assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts . length , 1 ) ;
407
+ assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts [ 0 ] . name , account_valid . name ) ;
408
+ await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . DELETE , { config_root, name : account_valid . name } ) ;
391
409
} ) ;
392
410
393
411
mocha . it ( 'Account with new_buckets_path missing and allow_bucket_creation true, invalid account' , async function ( ) {
@@ -403,8 +421,8 @@ mocha.describe('nsfs nc health', function() {
403
421
const get_endpoint_response = sinon . stub ( Health , "get_endpoint_response" ) ;
404
422
get_endpoint_response . onFirstCall ( ) . returns ( Promise . resolve ( { response : { response_code : 'RUNNING' , total_fork_count : 0 } } ) ) ;
405
423
const health_status = await Health . nc_nsfs_health ( ) ;
406
- assert . strictEqual ( health_status . checks . accounts_status . valid_accounts . length , 2 ) ;
407
- assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts . length , 2 ) ;
424
+ assert . strictEqual ( health_status . checks . accounts_status . valid_accounts . length , 1 ) ;
425
+ assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts . length , 1 ) ;
408
426
await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . DELETE , { config_root, name : account_invalid . name } ) ;
409
427
} ) ;
410
428
} ) ;
0 commit comments