Skip to content

Commit 4379cbf

Browse files
authored
Merge pull request #8486 from romayalon/romy-config-restructure-upgrade-script
NC | Online Upgrade | Config directory restructure upgrade script
2 parents a7c133e + 6b3f7d6 commit 4379cbf

File tree

9 files changed

+361
-45
lines changed

9 files changed

+361
-45
lines changed

src/sdk/config_fs.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ class ConfigFS {
660660
async create_account_config_file(account_data) {
661661
await this._throw_if_config_dir_locked();
662662
const { _id, name, owner = undefined } = account_data;
663-
const { parsed_account_data, string_account_data} = await this._prepare_for_account_schema(account_data);
663+
const { parsed_account_data, string_account_data } = await this._prepare_for_account_schema(account_data);
664664
const account_path = this.get_identity_path_by_id(_id);
665665
const account_dir_path = this.get_identity_dir_path_by_id(_id);
666666

@@ -762,7 +762,7 @@ class ConfigFS {
762762
* link_account_name_index links the access key to the relative path of the account id config file
763763
* @param {string} account_id
764764
* @param {string} account_name
765-
* @param {string} owner_account_id
765+
* @param {string} [owner_account_id]
766766
* @returns {Promise<void>}
767767
*/
768768
async link_account_name_index(account_id, account_name, owner_account_id) {
@@ -821,22 +821,22 @@ class ConfigFS {
821821
/**
822822
* unlink_access_key_index unlinks the access key from the config directory
823823
* 1. get the account access_key path
824-
* 2. check realpath on the account access_key path to make sure it belongs to the account id we meant to delete
825-
* 3. check if the account id path is the same as the account name path
826-
* 4. unlink the account name path
827-
* 5. else, do nothing as the name path might already point to a new identity/deleted by concurrent calls
824+
* 2. check realpath on the account access_key path to make sure it belongs to the account id (or account_name on versions older than 5.18) we meant to delete
825+
* 3. check if the account id path is the same as the account access_key path
826+
* 4. unlink the account access_key path
827+
* 5. else, do nothing as the access_key path might already point to a new identity/deleted by concurrent calls
828828
* @param {string} access_key
829829
* @returns {Promise<void>}
830830
*/
831-
async unlink_access_key_index(access_key, account_id_config_path) {
831+
async unlink_access_key_index(access_key, account_config_path) {
832832
const access_key_path = this.get_account_or_user_path_by_access_key(access_key);
833-
const should_unlink = await this._is_symlink_pointing_to_identity(access_key_path, account_id_config_path);
833+
const should_unlink = await this._is_symlink_pointing_to_identity(access_key_path, account_config_path);
834834
if (should_unlink) {
835835
try {
836836
await nb_native().fs.unlink(this.fs_context, access_key_path);
837837
} catch (err) {
838838
if (err.code === 'ENOENT') {
839-
dbg.warn(`config_fs.unlink_access_key_index: account access_key already unlinked ${access_key} ${account_id_config_path}`);
839+
dbg.warn(`config_fs.unlink_access_key_index: account access_key already unlinked ${access_key} ${account_config_path}`);
840840
return;
841841
}
842842
throw err;

src/test/system_tests/test_utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const { NodeHttpHandler } = require("@smithy/node-http-handler");
1818
const GPFS_ROOT_PATH = process.env.GPFS_ROOT_PATH;
1919
const IS_GPFS = !_.isUndefined(GPFS_ROOT_PATH);
2020
const TMP_PATH = get_tmp_path();
21+
const TEST_TIMEOUT = 60 * 1000;
2122

2223
/**
2324
* TMP_PATH is a path to the tmp path based on the process platform
@@ -382,7 +383,7 @@ async function create_redirect_file(config_fs, custom_config_root_path) {
382383
*/
383384
async function delete_redirect_file(config_fs) {
384385
const redirect_file_path = path.join(config.NSFS_NC_DEFAULT_CONF_DIR, config.NSFS_NC_CONF_DIR_REDIRECT_FILE);
385-
await nb_native().fs.unlink(config_fs.fs_context, redirect_file_path);
386+
await fs_utils.file_delete(redirect_file_path);
386387
}
387388

388389
function generate_anon_s3_client(endpoint) {
@@ -590,7 +591,7 @@ async function clean_config_dir(config_fs, custom_config_dir_path) {
590591
const accounts_by_name = '/accounts_by_name/';
591592
const access_keys_dir_name = '/access_keys/';
592593
const system_json = '/system.json';
593-
for (const dir of [buckets_dir_name, identities_dir_name, access_keys_dir_name, accounts_by_name]) {
594+
for (const dir of [buckets_dir_name, identities_dir_name, access_keys_dir_name, accounts_by_name, config.NSFS_TEMP_CONF_DIR_NAME]) {
594595
const default_path = path.join(config.NSFS_NC_DEFAULT_CONF_DIR, dir);
595596
await fs_utils.folder_delete(default_path);
596597
const custom_path = path.join(custom_config_dir_path, dir);
@@ -622,6 +623,7 @@ exports.generate_anon_s3_client = generate_anon_s3_client;
622623
exports.TMP_PATH = TMP_PATH;
623624
exports.IS_GPFS = IS_GPFS;
624625
exports.is_nc_coretest = is_nc_coretest;
626+
exports.TEST_TIMEOUT = TEST_TIMEOUT;
625627
exports.generate_nsfs_account = generate_nsfs_account;
626628
exports.get_new_buckets_path_by_test_env = get_new_buckets_path_by_test_env;
627629
exports.write_manual_config_file = write_manual_config_file;

src/test/unit_tests/jest_tests/test_cli_upgrade.test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
// disabling init_rand_seed as it takes longer than the actual test execution
55
process.env.DISABLE_INIT_RANDOM_SEED = 'true';
66

7-
87
const os = require('os');
98
const path = require('path');
9+
const config = require('../../../../config');
1010
const pkg = require('../../../../package.json');
1111
const fs_utils = require('../../../util/fs_utils');
1212
const { ConfigFS } = require('../../../sdk/config_fs');
13-
const { TMP_PATH, exec_manage_cli } = require('../../system_tests/test_utils');
13+
const { TMP_PATH, exec_manage_cli, clean_config_dir, fail_test_if_default_config_dir_exists, TEST_TIMEOUT } = require('../../system_tests/test_utils');
1414
const { ManageCLIError } = require('../../../manage_nsfs/manage_nsfs_cli_errors');
1515
const { ManageCLIResponse } = require('../../../manage_nsfs/manage_nsfs_cli_responses');
1616
const { TYPES, UPGRADE_ACTIONS } = require('../../../manage_nsfs/manage_nsfs_constants');
@@ -242,8 +242,17 @@ const invalid_hostname_system_json = {
242242
};
243243

244244
describe('noobaa cli - upgrade', () => {
245+
beforeAll(async () => {
246+
await fail_test_if_default_config_dir_exists('test_cli_upgrade');
247+
await fs_utils.create_fresh_path(config.NSFS_NC_DEFAULT_CONF_DIR);
248+
});
249+
245250
afterEach(async () => await fs_utils.file_delete(config_fs.system_json_path));
246251

252+
afterAll(async () => {
253+
await clean_config_dir(config_fs, config_root);
254+
}, TEST_TIMEOUT);
255+
247256
it('upgrade start - should fail on no system', async () => {
248257
const options = { config_root, expected_version: pkg.version, expected_hosts };
249258
const res = await exec_manage_cli(TYPES.UPGRADE, UPGRADE_ACTIONS.START, options, true);

src/test/unit_tests/jest_tests/test_config_dir_structure.js renamed to src/test/unit_tests/jest_tests/test_config_dir_structure.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require('path');
55
const config = require('../../../../config');
66
const { ConfigFS } = require('../../../sdk/config_fs');
77
const { TMP_PATH, create_redirect_file, create_config_dir, clean_config_dir,
8-
fail_test_if_default_config_dir_exists } = require('../../system_tests/test_utils');
8+
fail_test_if_default_config_dir_exists, TEST_TIMEOUT } = require('../../system_tests/test_utils');
99
const { get_process_fs_context, is_path_exists } = require('../../../util/native_fs_utils');
1010

1111
const tmp_fs_path = path.join(TMP_PATH, 'test_config_fs');
@@ -35,7 +35,7 @@ describe('create_config_dirs_if_missing', () => {
3535

3636
afterEach(async () => {
3737
await clean_config_dir(config_fs, CUSTOM_CONF_DIR_PATH);
38-
});
38+
}, TEST_TIMEOUT);
3939

4040
it('create_config_dirs_if_missing() first time - nothing exists - everything should be created', async () => {
4141
await default_config_fs.create_config_dirs_if_missing();

src/test/unit_tests/jest_tests/test_config_fs_backward_compatibility.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const path = require('path');
55
const fs_utils = require('../../../util/fs_utils');
66
const { ConfigFS, CONFIG_TYPES } = require('../../../sdk/config_fs');
7-
const { TMP_PATH, write_manual_config_file, write_manual_old_account_config_file } = require('../../system_tests/test_utils');
7+
const { TMP_PATH, TEST_TIMEOUT, write_manual_config_file, write_manual_old_account_config_file } = require('../../system_tests/test_utils');
88

99

1010
const tmp_fs_path = path.join(TMP_PATH, 'test_config_fs_backward_compatibility');
@@ -38,7 +38,7 @@ describe('ConfigFS Backwards Compatibility', () => {
3838

3939
afterAll(async () => {
4040
await fs_utils.folder_delete(config_root);
41-
});
41+
}, TEST_TIMEOUT);
4242

4343
afterEach(async () => {
4444
await clean_accounts();

src/test/unit_tests/jest_tests/test_nc_upgrade_manager.test.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { NCUpgradeManager, DEFAULT_NC_UPGRADE_SCRIPTS_DIR, OLD_DEFAULT_PACKAGE_VE
1616
OLD_DEFAULT_CONFIG_DIR_VERSION, CONFIG_DIR_UNLOCKED, CONFIG_DIR_LOCKED } = require('../../../upgrade/nc_upgrade_manager');
1717
const { ConfigFS } = require('../../../sdk/config_fs');
1818
const { TMP_PATH, create_redirect_file, create_config_dir,
19-
fail_test_if_default_config_dir_exists, clean_config_dir } = require('../../system_tests/test_utils');
19+
fail_test_if_default_config_dir_exists, clean_config_dir, TEST_TIMEOUT } = require('../../system_tests/test_utils');
2020

2121
const config_root = path.join(TMP_PATH, 'config_root_nc_upgrade_manager_test');
2222
const config_fs = new ConfigFS(config_root);
@@ -185,7 +185,7 @@ describe('nc upgrade manager - upgrade RPM', () => {
185185

186186
afterEach(async () => {
187187
await clean_config_dir(config_fs, config_root);
188-
});
188+
}, TEST_TIMEOUT);
189189

190190
it('upgrade rpm - nothing to upgrade - no changes in system.json', async () => {
191191
await config_fs.create_system_config_file(JSON.stringify(current_expected_system_json));
@@ -234,6 +234,10 @@ describe('nc upgrade manager - upgrade config directory', () => {
234234
await fail_test_if_default_config_dir_exists('test_config_dir_nc_upgrade_manager', config_fs);
235235
});
236236

237+
afterEach(async () => {
238+
await clean_config_dir(config_fs, config_root);
239+
}, TEST_TIMEOUT);
240+
237241
describe('nc upgrade manager - config_directory_defaults', () => {
238242

239243
it('config_directory_defaults - hostname from_version exists - 5.16.0', () => {
@@ -323,7 +327,7 @@ describe('nc upgrade manager - upgrade config directory', () => {
323327

324328
describe('nc upgrade manager - _run_nc_upgrade_scripts', () => {
325329
const from_version = '0.0.0';
326-
const to_version = '1.0.0';
330+
const to_version = '0.0.9';
327331
const custom_upgrade_scripts_dir = path.join(TMP_PATH, 'custom_upgrade_scripts_dir');
328332
const custom_upgrade_scripts_dir_version_path = path.join(TMP_PATH, 'custom_upgrade_scripts_dir', to_version);
329333
const default_upgrade_script_dir_version_path = path.join(DEFAULT_NC_UPGRADE_SCRIPTS_DIR, to_version);
@@ -419,13 +423,13 @@ describe('nc upgrade manager - upgrade config directory', () => {
419423

420424
afterEach(async () => {
421425
await clean_config_dir(config_fs, config_root);
422-
});
426+
}, TEST_TIMEOUT);
423427

424428
it('_update_config_dir_upgrade_start - system_data doesn\'t contain old config_directory data', async () => {
425429
const system_data = old_expected_system_json;
426430
const options = {
427431
config_dir_from_version: '0.0.0',
428-
config_dir_to_version: '1.0.0',
432+
config_dir_to_version: '0.0.9',
429433
package_from_version: '5.16.0',
430434
package_to_version: '5.17.0',
431435
};
@@ -484,7 +488,7 @@ describe('nc upgrade manager - upgrade config directory', () => {
484488

485489
afterEach(async () => {
486490
await clean_config_dir(config_fs, config_root);
487-
});
491+
}, TEST_TIMEOUT);
488492

489493
it('_update_config_dir_upgrade_finish - system_data doesn\'t contain old successful_upgrades data', async () => {
490494
const system_data = _.cloneDeep(old_expected_system_json_empty_successful_upgrades);
@@ -527,7 +531,7 @@ describe('nc upgrade manager - upgrade config directory', () => {
527531
'running_host': hostname,
528532
'completed_scripts': [],
529533
'config_dir_from_version': '0.0.0',
530-
'config_dir_to_version': '1.0.0',
534+
'config_dir_to_version': '0.0.9',
531535
'package_from_version': '5.17.0',
532536
'package_to_version': '5.18.0',
533537
'error': new Error('this is a last failure error').stack
@@ -575,7 +579,7 @@ describe('nc upgrade manager - upgrade config directory', () => {
575579

576580
afterEach(async () => {
577581
await clean_config_dir(config_fs, config_root);
578-
});
582+
}, TEST_TIMEOUT);
579583

580584
it('_update_config_dir_upgrade_failed - system_data doesn\'t contain old upgrade_history data', async () => {
581585
const system_data = _.cloneDeep(old_expected_system_json_empty_successful_upgrades);
@@ -622,7 +626,7 @@ describe('nc upgrade manager - upgrade config directory', () => {
622626
'running_host': hostname,
623627
'completed_scripts': [],
624628
'config_dir_from_version': '0.0.0',
625-
'config_dir_to_version': '1.0.0',
629+
'config_dir_to_version': '0.0.9',
626630
'package_from_version': '5.17.0',
627631
'package_to_version': '5.18.0',
628632
'error': new Error('this is a last failure error').stack

src/test/unit_tests/jest_tests/test_versioning_concurrency.test.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ const P = require('../../../util/promise');
77
const fs_utils = require('../../../util/fs_utils');
88
const NamespaceFS = require('../../../sdk/namespace_fs');
99
const buffer_utils = require('../../../util/buffer_utils');
10-
const { TMP_PATH, IS_GPFS } = require('../../system_tests/test_utils');
10+
const { TMP_PATH, IS_GPFS, TEST_TIMEOUT } = require('../../system_tests/test_utils');
1111
const { crypto_random_string } = require('../../../util/string_utils');
1212
const endpoint_stats_collector = require('../../../sdk/endpoint_stats_collector');
13-
const SECONDS = 1000;
14-
const test_timeout = SECONDS * 60;
1513

1614
function make_dummy_object_sdk(nsfs_config, uid, gid) {
1715
return {
@@ -71,7 +69,7 @@ describe('test versioning concurrency', () => {
7169
expect(failed_operations).toHaveLength(0);
7270
const versions = await nsfs.list_object_versions({ bucket: bucket }, DUMMY_OBJECT_SDK);
7371
expect(versions.objects.length).toBe(num_of_concurrency);
74-
}, test_timeout);
72+
}, TEST_TIMEOUT);
7573

7674
it('multiple delete version id and key', async () => {
7775
const bucket = 'bucket1';
@@ -91,7 +89,7 @@ describe('test versioning concurrency', () => {
9189
await P.delay(1000);
9290
expect(successful_operations).toHaveLength(num_of_concurrency);
9391
expect(failed_operations).toHaveLength(0);
94-
}, test_timeout);
92+
}, TEST_TIMEOUT);
9593

9694
// same as s3tests_boto3/functional/test_s3.py::test_versioning_concurrent_multi_object_delete,
9795
// this test has a bug, it tries to create the bucket twice and fails
@@ -133,7 +131,7 @@ describe('test versioning concurrency', () => {
133131
}
134132
const list_res = await nsfs.list_objects({ bucket: bucket }, DUMMY_OBJECT_SDK);
135133
expect(list_res.objects.length).toBe(0);
136-
}, test_timeout);
134+
}, TEST_TIMEOUT);
137135

138136
it('concurrent delete of latest version', async () => {
139137
const bucket = 'bucket1';
@@ -157,7 +155,7 @@ describe('test versioning concurrency', () => {
157155
expect(versions.objects.length).toBe(8); // 5 versions before + 3 delete markers concurrent
158156
const delete_marker_arr = versions.objects.filter(object => object.delete_marker === true);
159157
expect(delete_marker_arr.length).toBe(3);
160-
}, test_timeout);
158+
}, TEST_TIMEOUT);
161159

162160
it('concurrent put object and head object latest version', async () => {
163161
const bucket = 'bucket1';
@@ -185,7 +183,7 @@ describe('test versioning concurrency', () => {
185183
expect(successful_head_operations.length).toBe(number_of_iterations);
186184
const versions = await nsfs.list_object_versions({ bucket: bucket }, DUMMY_OBJECT_SDK);
187185
expect(versions.objects.length).toBe(number_of_iterations + 1); // 1 version before + 10 versions concurrent
188-
}, test_timeout);
186+
}, TEST_TIMEOUT);
189187

190188
it('concurrent puts & delete latest objects', async () => {
191189
const bucket = 'bucket1';
@@ -219,7 +217,7 @@ describe('test versioning concurrency', () => {
219217
expect(num_of_delete_markers).toBe(num_of_concurrency);
220218
const num_of_latest_versions = (versions.objects.filter(version => version.is_latest === true)).length;
221219
expect(num_of_latest_versions).toBe(1);
222-
}, test_timeout);
220+
}, TEST_TIMEOUT);
223221

224222
it('concurrent puts & delete objects by version id', async () => {
225223
const bucket = 'bucket1';
@@ -253,7 +251,7 @@ describe('test versioning concurrency', () => {
253251
expect(num_of_delete_markers).toBe(0);
254252
const num_of_latest_versions = (versions.objects.filter(version => version.is_latest === true)).length;
255253
expect(num_of_latest_versions).toBe(1);
256-
}, test_timeout);
254+
}, TEST_TIMEOUT);
257255

258256
it('concurrent delete objects by version id/latest', async () => {
259257
const bucket = 'bucket1';
@@ -286,7 +284,7 @@ describe('test versioning concurrency', () => {
286284
expect(num_of_delete_markers).toBe(num_of_concurrency);
287285
const num_of_latest_versions = (versions.objects.filter(version => version.is_latest === true)).length;
288286
expect(num_of_latest_versions).toBe(1);
289-
}, test_timeout);
287+
}, TEST_TIMEOUT);
290288

291289
it('nested key - concurrent delete multiple objects', async () => {
292290
const bucket = 'bucket1';
@@ -323,7 +321,7 @@ describe('test versioning concurrency', () => {
323321
}
324322
const list_res = await nsfs.list_objects({ bucket: bucket }, DUMMY_OBJECT_SDK);
325323
expect(list_res.objects).toHaveLength(0);
326-
}, test_timeout);
324+
}, TEST_TIMEOUT);
327325

328326
it('nested key - concurrent puts & deletes', async () => {
329327
const bucket = 'bucket1';
@@ -351,7 +349,7 @@ describe('test versioning concurrency', () => {
351349
expect(upload_failed_operations).toHaveLength(0);
352350
expect(delete_successful_operations).toHaveLength(num_of_concurrency);
353351
expect(delete_failed_operations).toHaveLength(0);
354-
}, test_timeout);
352+
}, TEST_TIMEOUT);
355353

356354
it('concurrent puts & list versions', async () => {
357355
const bucket = 'bucket1';
@@ -391,7 +389,7 @@ describe('test versioning concurrency', () => {
391389
expect(num_of_delete_markers).toBe(0);
392390
const num_of_latest_versions = (versions.objects.filter(version => version.is_latest === true)).length;
393391
expect(num_of_latest_versions).toBe(initial_num_of_objects);
394-
}, test_timeout);
392+
}, TEST_TIMEOUT);
395393

396394
it('concurrent puts & list versions - version id paging', async () => {
397395
const bucket = 'bucket1';
@@ -434,7 +432,7 @@ describe('test versioning concurrency', () => {
434432
expect(num_of_delete_markers).toBe(0);
435433
const num_of_latest_versions = (merged_versions.filter(version => version.is_latest === true)).length;
436434
expect(num_of_latest_versions).toBe(initial_num_of_objects);
437-
}, test_timeout);
435+
}, TEST_TIMEOUT);
438436

439437
it('multiple puts of the same key - suspended', async () => {
440438
const bucket = 'bucket-s';
@@ -455,7 +453,7 @@ describe('test versioning concurrency', () => {
455453
expect(failed_operations).toHaveLength(0);
456454
const versions = await nsfs.list_object_versions({ bucket: bucket }, DUMMY_OBJECT_SDK);
457455
expect(versions.objects.length).toBe(1); // save only the null version
458-
}, test_timeout);
456+
}, TEST_TIMEOUT);
459457

460458
it('multiple puts of the same key - enabled and suspended', async () => {
461459
const bucket = 'bucket-es';
@@ -489,7 +487,7 @@ describe('test versioning concurrency', () => {
489487
expect(failed_operations1).toHaveLength(0);
490488
const versions = await nsfs.list_object_versions({ bucket: bucket }, DUMMY_OBJECT_SDK);
491489
expect(versions.objects.length).toBe(num_of_concurrency1 + 1); // num_of_concurrency1 is the number of versions uploaded when versioning was enabled + 1 null version
492-
}, test_timeout);
490+
}, TEST_TIMEOUT);
493491

494492
it('multiple delete different keys', async () => {
495493
const bucket = 'bucket1';
@@ -523,7 +521,7 @@ describe('test versioning concurrency', () => {
523521
});
524522
expect(num_objs).toBe(num_objects - num_deletes);
525523

526-
}, test_timeout);
524+
}, TEST_TIMEOUT);
527525

528526
it('copy-object to same target', async () => {
529527
const num_copies = 5;
@@ -555,7 +553,7 @@ describe('test versioning concurrency', () => {
555553
}
556554
});
557555
expect(num_versions).toBe(num_copies);
558-
}, test_timeout);
556+
}, TEST_TIMEOUT);
559557
});
560558

561559
/**

0 commit comments

Comments
 (0)