Skip to content

Commit 49ad768

Browse files
authored
Merge pull request #8682 from romayalon/romy-online-upgrade-integration-tests
NC | Online Upgrade | Integration tests | Add CLI and S3 integration tests
2 parents cde9dda + 19a16d6 commit 49ad768

File tree

5 files changed

+436
-0
lines changed

5 files changed

+436
-0
lines changed

docs/NooBaaNonContainerized/CI&Tests.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ The following is a list of `NC mocha test` files -
9191
2. `test_nc_health` - Tests NooBaa Health CLI.
9292
3. `test_nsfs_glacier_backend.js` - Tests NooBaa Glacier Backend.
9393
4. `test_nc_with_a_couple_of_forks.js` - Tests the `bucket_namespace_cache` when running with a couple of forks. Please notice that it uses `nc_coretest` with setup that includes a couple of forks.
94+
5. `test_nc_online_upgrade_s3_integrations.js` - Tests S3 operations during mocked config directory upgrade.
9495

9596
#### NC Jest test files
9697
The following is a list of `NC jest tests` files -
@@ -112,6 +113,7 @@ The following is a list of `NC jest tests` files -
112113
16. `test_config_fs_backward_compatibility.test.js` - Tests of the backwards compatibility of configFS functions.
113114
17. `test_nc_upgrade_manager.test.js` - Tests of the NC upgrade manager.
114115
18. `test_cli_upgrade.test.js` - Tests of the upgrade CLI commands.
116+
19. `test_nc_online_upgrade_cli_integrations.test.js` - Tests CLI commands during mocked config directory upgrade.
115117

116118
#### nc_index.js File
117119
* 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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,32 @@ async function create_file(fs_context, file_path, file_data) {
687687
);
688688
}
689689

690+
/**
691+
* create_system_json creates the system.json file
692+
* if mock_config_dir_version it sets it before creating the file
693+
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
694+
* @param {String} [mock_config_dir_version]
695+
* @returns {Promise<Void>}
696+
*/
697+
async function create_system_json(config_fs, mock_config_dir_version) {
698+
const system_data = await config_fs._get_new_system_json_data();
699+
if (mock_config_dir_version) system_data.config_directory.config_dir_version = mock_config_dir_version;
700+
await config_fs.create_system_config_file(JSON.stringify(system_data));
701+
}
702+
703+
/**
704+
* update_system_json updates the system.json file
705+
* if mock_config_dir_version it sets it before creating the file
706+
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
707+
* @param {String} [mock_config_dir_version]
708+
* @returns {Promise<Void>}
709+
*/
710+
async function update_system_json(config_fs, mock_config_dir_version) {
711+
const system_data = await config_fs.get_system_config_file();
712+
if (mock_config_dir_version) system_data.config_directory.config_dir_version = mock_config_dir_version;
713+
await config_fs.update_system_config_file(JSON.stringify(system_data));
714+
}
715+
690716
exports.blocks_exist_on_cloud = blocks_exist_on_cloud;
691717
exports.create_hosts_pool = create_hosts_pool;
692718
exports.delete_hosts_pool = delete_hosts_pool;
@@ -717,6 +743,8 @@ exports.symlink_account_access_keys = symlink_account_access_keys;
717743
exports.create_file = create_file;
718744
exports.create_redirect_file = create_redirect_file;
719745
exports.delete_redirect_file = delete_redirect_file;
746+
exports.create_system_json = create_system_json;
747+
exports.update_system_json = update_system_json;
720748
exports.fail_test_if_default_config_dir_exists = fail_test_if_default_config_dir_exists;
721749
exports.create_config_dir = create_config_dir;
722750
exports.clean_config_dir = clean_config_dir;
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
/* Copyright (C) 2016 NooBaa */
2+
'use strict';
3+
4+
// disabling init_rand_seed as it takes longer than the actual test execution
5+
process.env.DISABLE_INIT_RANDOM_SEED = "true";
6+
7+
const path = require('path');
8+
const fs_utils = require('../../../util/fs_utils');
9+
const { exec_manage_cli, TMP_PATH, create_system_json } = require('../../system_tests/test_utils');
10+
const { folder_delete, create_fresh_path } = require('../../../util/fs_utils');
11+
const { TYPES, ACTIONS } = require('../../../manage_nsfs/manage_nsfs_constants');
12+
const { ManageCLIError } = require('../../../manage_nsfs/manage_nsfs_cli_errors');
13+
const { ManageCLIResponse } = require('../../../manage_nsfs/manage_nsfs_cli_responses');
14+
15+
const config_root = path.join(TMP_PATH, 'test_online_upgrade_cli_integrations');
16+
const { ConfigFS } = require('../../../sdk/config_fs');
17+
const config_fs = new ConfigFS(config_root);
18+
const default_new_buckets_path = path.join(TMP_PATH, 'default_new_buckets_path_online_upgrade_cli_integrations_test');
19+
const bucket_storage_path = path.join(default_new_buckets_path, 'bucket1');
20+
const old_config_dir_version = '0.0.0';
21+
22+
const default_account_options = {
23+
config_root,
24+
name: 'account1',
25+
new_buckets_path: default_new_buckets_path,
26+
uid: process.getuid(),
27+
gid: process.getgid(),
28+
};
29+
30+
const default_bucket_options = {
31+
config_root,
32+
name: 'bucket1',
33+
path: bucket_storage_path,
34+
owner: default_account_options.name
35+
};
36+
37+
describe('online upgrade CLI bucket operations tests', function() {
38+
beforeAll(async () => {
39+
await create_fresh_path(config_root);
40+
await create_fresh_path(default_new_buckets_path, 770);
41+
await fs_utils.file_must_exist(default_new_buckets_path);
42+
await create_default_account();
43+
await create_fresh_path(bucket_storage_path, 770);
44+
await fs_utils.file_must_exist(bucket_storage_path);
45+
});
46+
47+
afterAll(async () => {
48+
await folder_delete(config_root);
49+
await folder_delete(default_new_buckets_path);
50+
});
51+
52+
afterEach(async () => {
53+
await fs_utils.file_delete(config_fs.system_json_path);
54+
await exec_manage_cli(TYPES.BUCKET, ACTIONS.DELETE, { config_root, name: default_bucket_options.name }, true);
55+
});
56+
57+
it('create bucket - host is blocked for config dir updates - should fail', async function() {
58+
await create_system_json(config_fs, old_config_dir_version);
59+
const res = await exec_manage_cli(TYPES.BUCKET, ACTIONS.ADD, default_bucket_options, true);
60+
expect(JSON.parse(res.stdout).error.message).toBe(ManageCLIError.ConfigDirUpdateBlocked.message);
61+
});
62+
63+
it('create bucket - host is not blocked for config dir updates', async function() {
64+
await create_system_json(config_fs);
65+
const res = await exec_manage_cli(TYPES.BUCKET, ACTIONS.ADD, default_bucket_options, true);
66+
expect(JSON.parse(res).response.code).toBe(ManageCLIResponse.BucketCreated.code);
67+
});
68+
69+
it('update bucket - host is blocked for config dir updates - should fail', async function() {
70+
await create_default_bucket();
71+
await create_system_json(config_fs, old_config_dir_version);
72+
const update_bucket_options = { ...default_bucket_options, name: default_bucket_options.name, new_name: 'bucket2' };
73+
const update_res = await exec_manage_cli(TYPES.BUCKET, ACTIONS.UPDATE, update_bucket_options, true);
74+
expect(JSON.parse(update_res.stdout).error.message).toBe(ManageCLIError.ConfigDirUpdateBlocked.message);
75+
});
76+
77+
it('update bucket - host is not blocked for config dir updates', async function() {
78+
await create_default_bucket();
79+
await create_system_json(config_fs);
80+
const update_bucket_options = { ...default_bucket_options, name: default_bucket_options.name, new_name: 'bucket2' };
81+
const update_res = await exec_manage_cli(TYPES.BUCKET, ACTIONS.UPDATE, update_bucket_options, true);
82+
expect(JSON.parse(update_res).response.code).toBe(ManageCLIResponse.BucketUpdated.code);
83+
});
84+
85+
it('delete bucket - host is blocked for config dir updates - should fail', async function() {
86+
await create_default_bucket();
87+
await create_system_json(config_fs, old_config_dir_version);
88+
const delete_bucket_options = { config_root, name: default_bucket_options.name };
89+
const delete_res = await exec_manage_cli(TYPES.BUCKET, ACTIONS.DELETE, delete_bucket_options, true);
90+
expect(JSON.parse(delete_res.stdout).error.message).toBe(ManageCLIError.ConfigDirUpdateBlocked.message);
91+
});
92+
93+
it('delete bucket - host is not blocked for config dir updates', async function() {
94+
await create_default_bucket();
95+
await create_system_json(config_fs);
96+
const delete_bucket_options = { config_root, name: default_bucket_options.name };
97+
const delete_res = await exec_manage_cli(TYPES.BUCKET, ACTIONS.DELETE, delete_bucket_options, true);
98+
expect(JSON.parse(delete_res).response.code).toBe(ManageCLIResponse.BucketDeleted.code);
99+
});
100+
101+
it('list buckets - old config dir version - success', async function() {
102+
await create_default_bucket();
103+
await create_system_json(config_fs, old_config_dir_version);
104+
const list_bucket_options = { config_root };
105+
const list_res = await exec_manage_cli(TYPES.BUCKET, ACTIONS.LIST, list_bucket_options, true);
106+
expect(JSON.parse(list_res).response.code).toBe(ManageCLIResponse.BucketList.code);
107+
});
108+
109+
it('bucket status - old config dir version - success', async function() {
110+
await create_default_bucket();
111+
await create_system_json(config_fs, old_config_dir_version);
112+
const status_bucket_options = { config_root, name: default_bucket_options.name };
113+
const status_res = await exec_manage_cli(TYPES.BUCKET, ACTIONS.STATUS, status_bucket_options, true);
114+
expect(JSON.parse(status_res).response.code).toBe(ManageCLIResponse.BucketStatus.code);
115+
});
116+
});
117+
118+
describe('online upgrade CLI account operations tests', function() {
119+
beforeAll(async () => {
120+
await create_fresh_path(config_root);
121+
await create_fresh_path(default_new_buckets_path, 770);
122+
});
123+
124+
afterAll(async () => {
125+
await folder_delete(config_root);
126+
await folder_delete(default_new_buckets_path);
127+
});
128+
129+
afterEach(async () => {
130+
await fs_utils.file_delete(config_fs.system_json_path);
131+
await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.DELETE, { config_root, name: default_account_options.name }, true);
132+
});
133+
134+
it('create account - host is blocked for config dir updates - should fail', async function() {
135+
await create_system_json(config_fs, old_config_dir_version);
136+
const res = await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.ADD, default_account_options, true);
137+
expect(JSON.parse(res.stdout).error.message).toBe(ManageCLIError.ConfigDirUpdateBlocked.message);
138+
});
139+
140+
it('create account - host is not blocked for config dir updates', async function() {
141+
await create_system_json(config_fs);
142+
const res = await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.ADD, default_account_options, true);
143+
expect(JSON.parse(res).response.code).toBe(ManageCLIResponse.AccountCreated.code);
144+
});
145+
146+
it('update account - host is blocked for config dir updates - should fail', async function() {
147+
await create_default_account();
148+
await create_system_json(config_fs, old_config_dir_version);
149+
const update_account_options = { ...default_account_options, name: default_account_options.name, new_name: 'account2' };
150+
const update_res = await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.UPDATE, update_account_options, true);
151+
expect(JSON.parse(update_res.stdout).error.message).toBe(ManageCLIError.ConfigDirUpdateBlocked.message);
152+
});
153+
154+
it('update account - host is not blocked for config dir updates', async function() {
155+
await create_default_account();
156+
await create_system_json(config_fs);
157+
const update_account_options = { ...default_account_options, name: default_account_options.name, new_name: 'account2' };
158+
const update_res = await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.UPDATE, update_account_options, true);
159+
expect(JSON.parse(update_res).response.code).toBe(ManageCLIResponse.AccountUpdated.code);
160+
});
161+
162+
it('delete account - host is blocked for config dir updates - should fail', async function() {
163+
await create_default_account();
164+
await create_system_json(config_fs, old_config_dir_version);
165+
const delete_account_options = { config_root, name: default_account_options.name };
166+
const delete_res = await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.DELETE, delete_account_options, true);
167+
expect(JSON.parse(delete_res.stdout).error.message).toBe(ManageCLIError.ConfigDirUpdateBlocked.message);
168+
});
169+
170+
it('delete account - host is not blocked for config dir updates', async function() {
171+
await create_default_account();
172+
await create_system_json(config_fs);
173+
const delete_account_options = { config_root, name: default_account_options.name };
174+
const delete_res = await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.DELETE, delete_account_options, true);
175+
expect(JSON.parse(delete_res).response.code).toBe(ManageCLIResponse.AccountDeleted.code);
176+
});
177+
178+
it('list accounts - old config dir version - success', async function() {
179+
await create_default_account();
180+
await create_system_json(config_fs, old_config_dir_version);
181+
182+
const list_account_options = { config_root };
183+
const list_res = await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.LIST, list_account_options, true);
184+
expect(JSON.parse(list_res).response.code).toBe(ManageCLIResponse.AccountList.code);
185+
});
186+
187+
it('account status - old config dir version - success', async function() {
188+
await create_default_account();
189+
await create_system_json(config_fs, old_config_dir_version);
190+
const status_account_options = { config_root, name: default_account_options.name };
191+
const status_res = await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.STATUS, status_account_options, true);
192+
expect(JSON.parse(status_res).response.code).toBe(ManageCLIResponse.AccountStatus.code);
193+
});
194+
});
195+
196+
/**
197+
* create_default_bucket creates the default bucket for tests that require an existing bucket
198+
* @returns {Promise<Void>}
199+
*/
200+
async function create_default_bucket() {
201+
const res = await exec_manage_cli(TYPES.BUCKET, ACTIONS.ADD, default_bucket_options, true);
202+
expect(JSON.parse(res).response.code).toBe(ManageCLIResponse.BucketCreated.code);
203+
}
204+
205+
/**
206+
* create_default_bucket creates the default bucket for tests that require an existing bucket
207+
* @returns {Promise<Void>}
208+
*/
209+
async function create_default_account() {
210+
const res = await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.ADD, default_account_options, true);
211+
expect(JSON.parse(res).response.code).toBe(ManageCLIResponse.AccountCreated.code);
212+
}

src/test/unit_tests/nc_index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require('./test_s3_bucket_policy');
1919
require('./test_nsfs_versioning');
2020
require('./test_bucketspace_versioning');
2121
require('./test_nc_bucket_logging');
22+
require('./test_nc_online_upgrade_s3_integrations');
2223

2324
// running with a couple of forks - please notice and add only relevant tests here
2425
require('./test_nc_with_a_couple_of_forks.js'); // please notice that we use a different setup

0 commit comments

Comments
 (0)