Skip to content

Commit cb6beec

Browse files
authored
Merge pull request #8364 from romayalon/romy-health-tests-fix
NC | CLI | Small fixes in Health and Account Delete CLI command
2 parents 4edc2a4 + 982e878 commit cb6beec

File tree

4 files changed

+81
-38
lines changed

4 files changed

+81
-38
lines changed

src/cmd/manage_nsfs.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,7 @@ async function list_config_files(type, wide, show_secrets, filters = {}) {
635635
* @param {object} user_input
636636
*/
637637
function get_access_keys(action, user_input) {
638-
let access_keys = [{
639-
access_key: undefined,
640-
secret_key: undefined,
641-
}];
638+
let access_keys = [];
642639
let new_access_key;
643640
if (action === ACTIONS.ADD || action === ACTIONS.UPDATE || action === ACTIONS.DELETE) {
644641
manage_nsfs_validations._validate_access_keys(user_input.access_key, user_input.secret_key);

src/manage_nsfs/health.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,16 @@ class NSFSHealth {
338338
};
339339
}
340340

341-
let config_files;
341+
let config_files_names;
342342
if (type === TYPES.BUCKET) {
343-
config_files = await this.config_fs.list_buckets();
343+
config_files_names = await this.config_fs.list_buckets();
344344
} else {
345-
config_files = await this.config_fs.list_accounts();
345+
config_files_names = await this.config_fs.list_accounts();
346346
}
347-
for (const config_file of config_files) {
347+
for (const config_file_name of config_files_names) {
348348
// config_file get data or push error
349349
const { config_data = undefined, err_obj = undefined } =
350-
await this.get_config_file_data_or_error_object(type, config_file);
350+
await this.get_config_file_data_or_error_object(type, config_file_name);
351351
if (!config_data && err_obj) {
352352
invalid_storages.push(err_obj.invalid_storage);
353353
continue;
@@ -361,7 +361,7 @@ class NSFSHealth {
361361
config_data.nsfs_account_config.new_buckets_path;
362362

363363
if (type === TYPES.ACCOUNT) {
364-
const config_file_path = this.config_fs.get_account_path_by_name(config_file.name);
364+
const config_file_path = this.config_fs.get_account_path_by_name(config_file_name);
365365
res = await is_new_buckets_path_valid(config_file_path, config_data, storage_path);
366366
} else if (type === TYPES.BUCKET) {
367367
res = await is_bucket_storage_path_exists(this.config_fs.fs_context, config_data, storage_path);

src/test/system_tests/test_utils.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ function get_new_buckets_path_by_test_env(new_buckets_full_path, new_buckets_dir
435435
/**
436436
* write_manual_config_file writes config file directly to the file system without using config FS
437437
* used for creating backward compatibility tests, invalid config files etc
438+
* @param {String} type
438439
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
439440
* @param {Object} config_data
440441
* @param {String} [invalid_str]
@@ -483,6 +484,32 @@ async function write_manual_old_account_config_file(config_fs, config_data) {
483484
);
484485
}
485486

487+
/**
488+
* delete_manual_config_file deletes config file directly from the file system without using config FS
489+
* used for deleting invalid config files etc
490+
* @param {String} type
491+
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
492+
* @param {Object} config_data
493+
* @returns {Promise<Void>}
494+
*/
495+
async function delete_manual_config_file(type, config_fs, config_data) {
496+
if (type === CONFIG_TYPES.ACCOUNT) {
497+
const name_symlink_path = config_fs.get_account_or_user_path_by_name(config_data.name);
498+
await nb_native().fs.unlink(config_fs.fs_context, name_symlink_path);
499+
}
500+
501+
const config_path = type === CONFIG_TYPES.BUCKET ?
502+
config_fs.get_bucket_path_by_name(config_data.name) :
503+
config_fs.get_identity_path_by_id(config_data._id);
504+
505+
await nb_native().fs.unlink(config_fs.fs_context, config_path);
506+
507+
if (type === CONFIG_TYPES.ACCOUNT) {
508+
const dir_path = config_fs.get_identity_dir_path_by_id(config_data._id);
509+
await nb_native().fs.rmdir(config_fs.fs_context, dir_path);
510+
}
511+
}
512+
486513
exports.blocks_exist_on_cloud = blocks_exist_on_cloud;
487514
exports.create_hosts_pool = create_hosts_pool;
488515
exports.delete_hosts_pool = delete_hosts_pool;
@@ -504,4 +531,5 @@ exports.generate_nsfs_account = generate_nsfs_account;
504531
exports.get_new_buckets_path_by_test_env = get_new_buckets_path_by_test_env;
505532
exports.write_manual_config_file = write_manual_config_file;
506533
exports.write_manual_old_account_config_file = write_manual_old_account_config_file;
534+
exports.delete_manual_config_file = delete_manual_config_file;
507535

src/test/unit_tests/test_nc_nsfs_health.js

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@ const path = require('path');
77
const mocha = require('mocha');
88
const sinon = require('sinon');
99
const assert = require('assert');
10-
const { ConfigFS } = require('../../sdk/config_fs');
11-
const NSFSHealth = require('../../manage_nsfs/health').NSFSHealth;
1210
const fs_utils = require('../../util/fs_utils');
13-
const test_utils = require('../system_tests/test_utils');
1411
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;
1616
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');
1817
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');
1920

20-
const tmp_fs_path = path.join(TMP_PATH, 'test_bucketspace_fs');
21+
const tmp_fs_path = path.join(TMP_PATH, 'test_nc_health');
2122
const DEFAULT_FS_CONFIG = get_process_fs_context();
2223

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');
2425

2526
mocha.describe('nsfs nc health', function() {
2627

@@ -92,7 +93,7 @@ mocha.describe('nsfs nc health', function() {
9293
});
9394
});
9495

95-
mocha.describe('health check', async function() {
96+
mocha.describe('health check', function() {
9697
const new_buckets_path = `${root_path}new_buckets_path_user1/`;
9798
const account1_options = {
9899
name: 'account1',
@@ -102,14 +103,15 @@ mocha.describe('nsfs nc health', function() {
102103
};
103104
const bucket1_options = {
104105
name: 'bucket1',
105-
path: new_buckets_path + '/bucket1'
106+
path: new_buckets_path + '/bucket1',
107+
owner: account1_options.name
106108
};
107109
const account_inaccessible_options = { name: 'account_inaccessible', uid: 999, gid: 999, new_buckets_path: bucket_storage_path };
108110
const account_inaccessible_dn_options = { name: 'account_inaccessible_dn', user: 'inaccessible_dn', new_buckets_path: bucket_storage_path };
109111
const invalid_account_dn_options = { name: 'invalid_account_dn', user: 'invalid_account_dn', new_buckets_path: bucket_storage_path };
110112
const fs_users = {
111113
other_user: {
112-
distinguished_name: account_inaccessible_dn_options.nsfs_account_config.distinguished_name,
114+
distinguished_name: account_inaccessible_dn_options.user,
113115
uid: 1312,
114116
gid: 1312
115117
}
@@ -140,6 +142,10 @@ mocha.describe('nsfs nc health', function() {
140142
}
141143
});
142144

145+
mocha.afterEach(async () => {
146+
await fs_utils.file_delete(config_fs.config_json_path);
147+
});
148+
143149
mocha.it('Health all condition is success', async function() {
144150
const get_service_state = sinon.stub(Health, "get_service_state");
145151
get_service_state.onFirstCall().returns(Promise.resolve({ service_status: 'active', pid: 100 }))
@@ -186,8 +192,9 @@ mocha.describe('nsfs nc health', function() {
186192
mocha.it('NSFS account with invalid storage path', async function() {
187193
Health.get_service_state.restore();
188194
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);
191198
const get_service_state = sinon.stub(Health, "get_service_state");
192199
get_service_state.onFirstCall().returns(Promise.resolve({ service_status: 'active', pid: 1000 }))
193200
.onSecondCall().returns(Promise.resolve({ service_status: 'active', pid: 2000 }));
@@ -197,14 +204,15 @@ mocha.describe('nsfs nc health', function() {
197204
assert.strictEqual(health_status.status, 'OK');
198205
assert.strictEqual(health_status.checks.accounts_status.invalid_accounts.length, 1);
199206
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});
201208
});
202209

203210
mocha.it('NSFS bucket with invalid storage path', async function() {
204211
Health.get_service_state.restore();
205212
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);
208216
const get_service_state = sinon.stub(Health, "get_service_state");
209217
get_service_state.onFirstCall().returns(Promise.resolve({ service_status: 'active', pid: 1000 }))
210218
.onSecondCall().returns(Promise.resolve({ service_status: 'active', pid: 2000 }));
@@ -213,15 +221,17 @@ mocha.describe('nsfs nc health', function() {
213221
const health_status = await Health.nc_nsfs_health();
214222
assert.strictEqual(health_status.status, 'OK');
215223
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});
218226
});
219227

220228
mocha.it('NSFS invalid bucket schema json', async function() {
221229
Health.get_service_state.restore();
222230
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+
225235
const get_service_state = sinon.stub(Health, "get_service_state");
226236
get_service_state.onFirstCall().returns(Promise.resolve({ service_status: 'active', pid: 1000 }))
227237
.onSecondCall().returns(Promise.resolve({ service_status: 'active', pid: 2000 }));
@@ -230,14 +240,16 @@ mocha.describe('nsfs nc health', function() {
230240
const health_status = await Health.nc_nsfs_health();
231241
assert.strictEqual(health_status.status, 'OK');
232242
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);
235246
});
236247

237248
mocha.it('NSFS invalid account schema json', async function() {
238249
Health.get_service_state.restore();
239250
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 };
241253
await test_utils.write_manual_config_file(TYPES.ACCOUNT, config_fs, account_invalid_schema, 'invalid');
242254
const get_service_state = sinon.stub(Health, "get_service_state");
243255
get_service_state.onFirstCall().returns(Promise.resolve({ service_status: 'active', pid: 1000 }))
@@ -248,7 +260,8 @@ mocha.describe('nsfs nc health', function() {
248260
assert.strictEqual(health_status.status, 'OK');
249261
assert.strictEqual(health_status.checks.accounts_status.invalid_accounts.length, 1);
250262
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);
252265
});
253266

254267
mocha.it('Health all condition is success, all_account_details is false', async function() {
@@ -309,10 +322,10 @@ mocha.describe('nsfs nc health', function() {
309322
//revert to config root
310323
Health.config_root = config_root;
311324
Health.config_fs = old_config_fs;
312-
313325
});
314326

315327
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 }));
316329
await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.ADD, { config_root, ...account_inaccessible_options});
317330
Health.get_service_state.restore();
318331
Health.get_endpoint_response.restore();
@@ -329,10 +342,11 @@ mocha.describe('nsfs nc health', function() {
329342
assert.strictEqual(health_status.checks.accounts_status.invalid_accounts.length, 1);
330343
assert.strictEqual(health_status.checks.accounts_status.invalid_accounts[0].code, "ACCESS_DENIED");
331344
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});
333346
});
334347

335348
mocha.it('Account with inaccessible path - dn', async function() {
349+
await config_fs.create_config_json_file(JSON.stringify({ NC_DISABLE_ACCESS_CHECK: true }));
336350
await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.ADD, { config_root, ...account_inaccessible_dn_options });
337351
Health.get_service_state.restore();
338352
Health.get_endpoint_response.restore();
@@ -353,6 +367,7 @@ mocha.describe('nsfs nc health', function() {
353367
});
354368

355369
mocha.it('Account with invalid dn', async function() {
370+
await config_fs.create_config_json_file(JSON.stringify({ NC_DISABLE_ACCESS_CHECK: true }));
356371
await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.ADD, { config_root, ...invalid_account_dn_options });
357372
Health.get_service_state.restore();
358373
Health.get_endpoint_response.restore();
@@ -364,6 +379,7 @@ mocha.describe('nsfs nc health', function() {
364379
const get_endpoint_response = sinon.stub(Health, "get_endpoint_response");
365380
get_endpoint_response.onFirstCall().returns(Promise.resolve({response: {response_code: 'RUNNING', total_fork_count: 0}}));
366381
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 });
367383
assert.strictEqual(health_status.checks.buckets_status.valid_buckets.length, 1);
368384
assert.strictEqual(health_status.checks.accounts_status.valid_accounts.length, 1);
369385
assert.strictEqual(health_status.checks.accounts_status.invalid_accounts.length, 1);
@@ -386,8 +402,10 @@ mocha.describe('nsfs nc health', function() {
386402
const get_endpoint_response = sinon.stub(Health, "get_endpoint_response");
387403
get_endpoint_response.onFirstCall().returns(Promise.resolve({response: {response_code: 'RUNNING', total_fork_count: 0}}));
388404
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);
390406
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 });
391409
});
392410

393411
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() {
403421
const get_endpoint_response = sinon.stub(Health, "get_endpoint_response");
404422
get_endpoint_response.onFirstCall().returns(Promise.resolve({response: {response_code: 'RUNNING', total_fork_count: 0}}));
405423
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);
408426
await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.DELETE, { config_root, name: account_invalid.name });
409427
});
410428
});

0 commit comments

Comments
 (0)