Skip to content

Commit e57b5c3

Browse files
committed
NC | config dir restructure tests
Signed-off-by: Romy <35330373+romayalon@users.noreply.github.com>
1 parent 30ac4b2 commit e57b5c3

File tree

6 files changed

+827
-33
lines changed

6 files changed

+827
-33
lines changed

docs/NooBaaNonContainerized/CI&Tests.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,13 @@ The following is a list of `NC jest tests` files -
105105
9. `test_nc_nsfs_account_schema_validation.test.js` - Tests NC account schema validation.
106106
10. `test_nc_nsfs_new_buckets_path_validation.test.js` - Tests new_buckets_path RW access.
107107
11. `test_config_fs.test.js` - Tests ConfigFS methods.
108-
12. `test_nsfs_concurrency` - Tests concurrent operations.
109-
13. `test_versioning_concurrency` - Tests concurrent operations on versioned enabled bucket.
108+
12. `test_nsfs_concurrency.test.js` - Tests concurrent operations.
109+
13. `test_versioning_concurrency.test.js` - Tests concurrent operations on versioned enabled bucket.
110+
14. `test_config_dir_restructure_upgrade_script.test.js` - Tests of the config directory restructure upgrade script.
111+
15. `test_config_dir_structure.test.js` - Tests of the configFS functions created for the new config directory structure.
112+
16. `test_config_fs_backward_compatibility.test.js` - Tests of the backwards compatibility of configFS functions.
113+
17. `test_nc_upgrade_manager.test.js` - Tests of the NC upgrade manager.
114+
18. `test_cli_upgrade.test.js` - Tests of the upgrade CLI commands.
110115

111116
#### nc_index.js File
112117
* The `nc_index.js` is a file that runs several NC and NSFS mocha related tests.

src/test/system_tests/test_utils.js

Lines changed: 102 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -478,19 +478,26 @@ function get_new_buckets_path_by_test_env(new_buckets_full_path, new_buckets_dir
478478
/**
479479
* write_manual_config_file writes config file directly to the file system without using config FS
480480
* used for creating backward compatibility tests, invalid config files etc
481+
* 1. if it's account -
482+
* 1.1. create identity directory /{config_dir_path}/identities/{id}/
483+
* 2. create the config file -
484+
* 2.1. if it's a bucket - create it in /{config_dir_path}/buckets/{bucket_name}.json
485+
* 2.2. if it's an account - create it in /{config_dir_path}/identities/{id}/identity.json
486+
* 3. if it's an account and symlink_name is true - create /{config_dir_path}/accounts_by_name/{account_name}.symlink -> /{config_dir_path}/identities/{id}/identity.json
487+
* 4. if it's an account and symlink_access_key is true and there is access key in the account config - create /{config_dir_path}/access_keys/{access_key}.symlink -> /{config_dir_path}/identities/{id}/identity.json
481488
* @param {String} type
482489
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
483490
* @param {Object} config_data
484491
* @param {String} [invalid_str]
492+
* @param {{symlink_name?: Boolean, symlink_access_key?: Boolean}} [options]
485493
* @returns {Promise<Void>}
486494
*/
487-
async function write_manual_config_file(type, config_fs, config_data, invalid_str = '') {
495+
async function write_manual_config_file(type, config_fs, config_data, invalid_str = '', { symlink_name, symlink_access_key} = {symlink_name: true, symlink_access_key: true}) {
488496
const config_path = type === CONFIG_TYPES.BUCKET ?
489497
config_fs.get_bucket_path_by_name(config_data.name) :
490498
config_fs.get_identity_path_by_id(config_data._id);
491499
if (type === CONFIG_TYPES.ACCOUNT) {
492-
const dir_path = config_fs.get_identity_dir_path_by_id(config_data._id);
493-
await nb_native().fs.mkdir(config_fs.fs_context, dir_path, native_fs_utils.get_umasked_mode(config.BASE_MODE_DIR));
500+
await create_identity_dir_if_missing(config_fs, config_data._id);
494501
}
495502
await nb_native().fs.writeFile(
496503
config_fs.fs_context,
@@ -500,22 +507,69 @@ async function write_manual_config_file(type, config_fs, config_data, invalid_st
500507
mode: native_fs_utils.get_umasked_mode(config.BASE_MODE_FILE)
501508
}
502509
);
510+
const id_relative_path = config_fs.get_account_relative_path_by_id(config_data._id);
503511

504-
if (type === CONFIG_TYPES.ACCOUNT) {
505-
const id_relative_path = config_fs.get_account_relative_path_by_id(config_data._id);
506-
const name_symlink_path = config_fs.get_account_or_user_path_by_name(config_data.name);
507-
await nb_native().fs.symlink(config_fs.fs_context, id_relative_path, name_symlink_path);
512+
if (type === CONFIG_TYPES.ACCOUNT && symlink_name) {
513+
await symlink_account_name(config_fs, config_data.name, id_relative_path);
514+
}
515+
516+
if (type === CONFIG_TYPES.ACCOUNT && symlink_access_key && config_data.access_keys &&
517+
Object.keys(config_data.access_keys).length > 0) {
518+
await symlink_account_access_keys(config_fs, config_data.access_keys, id_relative_path);
519+
}
520+
}
521+
522+
/**
523+
* symlink_account_name symlinks the account's name path to the target link path
524+
* used for manual creation of the account name symlink
525+
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
526+
* @param {String} account_name
527+
* @param {String} link_target
528+
*/
529+
async function symlink_account_name(config_fs, account_name, link_target) {
530+
const name_symlink_path = config_fs.get_account_or_user_path_by_name(account_name);
531+
await nb_native().fs.symlink(config_fs.fs_context, link_target, name_symlink_path);
532+
}
533+
534+
/**
535+
* symlink_account_access_keys symlinks the account's access key path to the target link path
536+
* used for manual creation of the account access key symlink
537+
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
538+
* @param {Object} access_keys
539+
* @param {String} link_target
540+
*/
541+
async function symlink_account_access_keys(config_fs, access_keys, link_target) {
542+
for (const { access_key } of access_keys) {
543+
const access_key_symlink_path = config_fs.get_account_or_user_path_by_access_key(access_key);
544+
await nb_native().fs.symlink(config_fs.fs_context, link_target, access_key_symlink_path);
508545
}
509546
}
510547

548+
/**
549+
* create_identity_dir_if_missing created the identity directory if missing
550+
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
551+
* @param {String} _id
552+
* @returns {Promise<Void>}
553+
*/
554+
async function create_identity_dir_if_missing(config_fs, _id) {
555+
const dir_path = config_fs.get_identity_dir_path_by_id(_id);
556+
try {
557+
await nb_native().fs.mkdir(config_fs.fs_context, dir_path, native_fs_utils.get_umasked_mode(config.BASE_MODE_DIR));
558+
} catch (err) {
559+
if (err.code !== 'ENOENT') throw err;
560+
}
561+
}
511562

512563
/**
513564
* write_manual_old_account_config_file writes account config file directly to the old file system account path without using config FS
565+
* 1. create old json file in /config_dir_path/accounts/account.json
566+
* 2. if symlink_access_key is true - create old access key symlink /config_dir_path/access_keys/{access_key}.symlink -> /config_dir_path/accounts/account.json
514567
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
515568
* @param {Object} config_data
569+
* @param {{symlink_access_key?: Boolean}} [options]
516570
* @returns {Promise<Void>}
517571
*/
518-
async function write_manual_old_account_config_file(config_fs, config_data) {
572+
async function write_manual_old_account_config_file(config_fs, config_data, { symlink_access_key } = { symlink_access_key: false }) {
519573
const config_path = config_fs._get_old_account_path_by_name(config_data.name);
520574
await nb_native().fs.writeFile(
521575
config_fs.fs_context,
@@ -525,6 +579,12 @@ async function write_manual_old_account_config_file(config_fs, config_data) {
525579
mode: native_fs_utils.get_umasked_mode(config.BASE_MODE_FILE)
526580
}
527581
);
582+
583+
const account_name_relative_path = config_fs.get_old_account_relative_path_by_name(config_data.name);
584+
if (symlink_access_key) {
585+
const access_key_symlink_path = config_fs.get_account_or_user_path_by_access_key(config_data.access_keys[0].access_key);
586+
await nb_native().fs.symlink(config_fs.fs_context, account_name_relative_path, access_key_symlink_path);
587+
}
528588
}
529589

530590
/**
@@ -556,9 +616,9 @@ async function delete_manual_config_file(type, config_fs, config_data) {
556616

557617
/**
558618
* @param {any} test_name
559-
* @param {Object} [config_fs]
619+
* @param {import('../../sdk/config_fs').ConfigFS} [config_fs]
560620
*/
561-
async function fail_test_if_default_config_dir_exists(test_name, config_fs = {}) {
621+
async function fail_test_if_default_config_dir_exists(test_name, config_fs) {
562622
const fs_context = config_fs?.fs_context || native_fs_utils.get_process_fs_context();
563623
const config_dir_exists = await native_fs_utils.is_path_exists(fs_context, config.NSFS_NC_DEFAULT_CONF_DIR);
564624
const msg = `${test_name} found an existing default config directory ${config.NSFS_NC_DEFAULT_CONF_DIR},` +
@@ -583,6 +643,10 @@ async function create_config_dir(config_dir) {
583643

584644
/**
585645
* clean_config_dir cleans the config directory
646+
* custom_config_dir_path is created in some tests that are not using the default /etc/noobaa.conf.d/
647+
* config directory path
648+
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
649+
* @param {String} [custom_config_dir_path]
586650
* @returns {Promise<Void>}
587651
*/
588652
async function clean_config_dir(config_fs, custom_config_dir_path) {
@@ -593,17 +657,35 @@ async function clean_config_dir(config_fs, custom_config_dir_path) {
593657
const system_json = '/system.json';
594658
for (const dir of [buckets_dir_name, identities_dir_name, access_keys_dir_name, accounts_by_name, config.NSFS_TEMP_CONF_DIR_NAME]) {
595659
const default_path = path.join(config.NSFS_NC_DEFAULT_CONF_DIR, dir);
596-
await fs_utils.folder_delete(default_path);
597-
const custom_path = path.join(custom_config_dir_path, dir);
598-
await fs_utils.folder_delete(custom_path);
599-
660+
await fs_utils.folder_delete_skip_enoent(default_path);
661+
if (custom_config_dir_path) {
662+
const custom_path = path.join(custom_config_dir_path, dir);
663+
await fs_utils.folder_delete_skip_enoent(custom_path);
664+
}
600665
}
666+
601667
await delete_redirect_file(config_fs);
602668
await fs_utils.file_delete(system_json);
603-
await fs_utils.folder_delete(config.NSFS_NC_DEFAULT_CONF_DIR);
604-
await fs_utils.folder_delete(custom_config_dir_path);
669+
await fs_utils.folder_delete_skip_enoent(config.NSFS_NC_DEFAULT_CONF_DIR);
670+
await fs_utils.folder_delete_skip_enoent(custom_config_dir_path);
605671
}
606672

673+
/**
674+
* create_file creates a file in the file system
675+
* @param {nb.NativeFSContext} fs_context
676+
* @param {String} file_path
677+
* @param {Object} file_data
678+
*/
679+
async function create_file(fs_context, file_path, file_data) {
680+
await nb_native().fs.writeFile(
681+
fs_context,
682+
file_path,
683+
Buffer.from(JSON.stringify(file_data)),
684+
{
685+
mode: native_fs_utils.get_umasked_mode(config.BASE_MODE_FILE)
686+
}
687+
);
688+
}
607689

608690
exports.blocks_exist_on_cloud = blocks_exist_on_cloud;
609691
exports.create_hosts_pool = create_hosts_pool;
@@ -629,6 +711,10 @@ exports.get_new_buckets_path_by_test_env = get_new_buckets_path_by_test_env;
629711
exports.write_manual_config_file = write_manual_config_file;
630712
exports.write_manual_old_account_config_file = write_manual_old_account_config_file;
631713
exports.delete_manual_config_file = delete_manual_config_file;
714+
exports.create_identity_dir_if_missing = create_identity_dir_if_missing;
715+
exports.symlink_account_name = symlink_account_name;
716+
exports.symlink_account_access_keys = symlink_account_access_keys;
717+
exports.create_file = create_file;
632718
exports.create_redirect_file = create_redirect_file;
633719
exports.delete_redirect_file = delete_redirect_file;
634720
exports.fail_test_if_default_config_dir_exists = fail_test_if_default_config_dir_exists;

0 commit comments

Comments
 (0)