Skip to content

Commit c22f40b

Browse files
authored
Merge pull request #9200 from jackyalbo/jacky-nc-fix2
Fix get_tz_date for UTC
2 parents eaaaa4e + b7f0b6e commit c22f40b

File tree

2 files changed

+127
-21
lines changed

2 files changed

+127
-21
lines changed

src/manage_nsfs/manage_nsfs_cli_utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async function get_bucket_owner_account_by_name(config_fs, bucket_owner) {
4848
} catch (err) {
4949
if (err.code === 'ENOENT') {
5050
const detail_msg = `bucket owner name ${bucket_owner} does not exist`;
51-
throw_cli_error(ManageCLIError.BucketSetForbiddenBucketOwnerNotExists, detail_msg, {bucket_owner: bucket_owner});
51+
throw_cli_error(ManageCLIError.BucketSetForbiddenBucketOwnerNotExists, detail_msg, { bucket_owner: bucket_owner });
5252
}
5353
throw err;
5454
}
@@ -270,7 +270,7 @@ function get_tz_date(hours, mins, secs, tz) {
270270

271271
if (tz === 'UTC') {
272272
date.setUTCHours(hours);
273-
date.setUTCMinutes(hours);
273+
date.setUTCMinutes(mins);
274274
date.setUTCSeconds(secs);
275275
date.setUTCMilliseconds(0);
276276
} else {

src/test/integration_tests/nc/cli/test_nc_cli.js

Lines changed: 125 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ const { CONFIG_SUBDIRS, JSON_SUFFIX, SYMLINK_SUFFIX, ConfigFS } = require('../..
1414
const { get_process_fs_context } = require('../../../../util/native_fs_utils');
1515
const { ManageCLIError } = require('../../../../manage_nsfs/manage_nsfs_cli_errors');
1616
const { ManageCLIResponse } = require('../../../../manage_nsfs/manage_nsfs_cli_responses');
17-
const { exec_manage_cli, generate_s3_policy, create_fs_user_by_platform, delete_fs_user_by_platform,
18-
set_path_permissions_and_owner, TMP_PATH, set_nc_config_dir_in_config } = require('../../../system_tests/test_utils');
17+
const {
18+
exec_manage_cli,
19+
generate_s3_policy,
20+
create_fs_user_by_platform,
21+
delete_fs_user_by_platform,
22+
set_path_permissions_and_owner,
23+
TMP_PATH,
24+
set_nc_config_dir_in_config
25+
} = require('../../../system_tests/test_utils');
1926
const { TYPES, ACTIONS } = require('../../../../manage_nsfs/manage_nsfs_constants');
2027

2128
const tmp_fs_path = path.join(TMP_PATH, 'test_bucketspace_fs');
@@ -133,10 +140,10 @@ mocha.describe('manage_nsfs cli', function() {
133140
// try to create a bucket
134141
try {
135142
const bucket_options_with_owner_of_account_cannot_create_bucket = {
136-
config_root,
137-
name,
138-
owner: account_name_for_account_cannot_create_bucket,
139-
path: bucket_path
143+
config_root,
144+
name,
145+
owner: account_name_for_account_cannot_create_bucket,
146+
path: bucket_path
140147
};
141148
await fs_utils.create_fresh_path(bucket_path);
142149
await fs_utils.file_must_exist(bucket_path);
@@ -192,7 +199,7 @@ mocha.describe('manage_nsfs cli', function() {
192199

193200
mocha.it('cli bucket create - should fail invalid option', async function() {
194201
const action = ACTIONS.ADD;
195-
const bucket_options_with_invalid_option = {...bucket_options, lala: 'lala'}; // lala invalid option
202+
const bucket_options_with_invalid_option = { ...bucket_options, lala: 'lala' }; // lala invalid option
196203
try {
197204
add_res = await exec_manage_cli(type, action, bucket_options_with_invalid_option);
198205
assert.fail('should have failed with invalid option');
@@ -211,7 +218,7 @@ mocha.describe('manage_nsfs cli', function() {
211218

212219
mocha.it('cli bucket status - should fail invalid option', async function() {
213220
const action = ACTIONS.STATUS;
214-
const bucket_options_with_invalid_option = {...bucket_options, lala: 'lala'}; // lala invalid option
221+
const bucket_options_with_invalid_option = { ...bucket_options, lala: 'lala' }; // lala invalid option
215222
try {
216223
add_res = await exec_manage_cli(type, action, bucket_options_with_invalid_option);
217224
assert.fail('should have failed with invalid option');
@@ -274,7 +281,7 @@ mocha.describe('manage_nsfs cli', function() {
274281

275282
mocha.it('cli bucket list - should fail invalid option', async function() {
276283
const action = ACTIONS.LIST;
277-
const bucket_options_with_invalid_option = {config_root, lala: 'lala'}; // lala invalid option
284+
const bucket_options_with_invalid_option = { config_root, lala: 'lala' }; // lala invalid option
278285
try {
279286
add_res = await exec_manage_cli(type, action, bucket_options_with_invalid_option);
280287
assert.fail('should have failed with invalid option');
@@ -286,7 +293,7 @@ mocha.describe('manage_nsfs cli', function() {
286293
mocha.it('cli bucket list wide - should fail invalid string value', async function() {
287294
const action = ACTIONS.LIST;
288295
const invalid_wide = 'not-boolean'; // we accept true and false strings
289-
const bucket_options_with_invalid_option = {config_root, wide: invalid_wide};
296+
const bucket_options_with_invalid_option = { config_root, wide: invalid_wide };
290297
try {
291298
add_res = await exec_manage_cli(type, action, bucket_options_with_invalid_option);
292299
assert.fail('should have failed with invalid boolean value');
@@ -298,7 +305,7 @@ mocha.describe('manage_nsfs cli', function() {
298305
mocha.it('cli bucket list wide - should fail invalid type', async function() {
299306
const action = ACTIONS.LIST;
300307
const invalid_wide = 1234;
301-
const bucket_options_with_invalid_option = {config_root, wide: invalid_wide};
308+
const bucket_options_with_invalid_option = { config_root, wide: invalid_wide };
302309
try {
303310
add_res = await exec_manage_cli(type, action, bucket_options_with_invalid_option);
304311
assert.fail('should have failed with invalid option type');
@@ -339,7 +346,7 @@ mocha.describe('manage_nsfs cli', function() {
339346

340347
mocha.it('cli bucket update - should fail invalid option', async function() {
341348
const action = ACTIONS.UPDATE;
342-
const bucket_options_with_invalid_option = { config_root, name, lala: 'lala'}; // lala invalid option
349+
const bucket_options_with_invalid_option = { config_root, name, lala: 'lala' }; // lala invalid option
343350
try {
344351
add_res = await exec_manage_cli(type, action, bucket_options_with_invalid_option);
345352
assert.fail('should have failed with invalid option');
@@ -358,7 +365,7 @@ mocha.describe('manage_nsfs cli', function() {
358365
new_buckets_path: account.nsfs_account_config.new_buckets_path,
359366
};
360367
await set_path_permissions_and_owner(bucket_path, account_options, 0o700);
361-
const update_options = { config_root, name, owner: account_name2};
368+
const update_options = { config_root, name, owner: account_name2 };
362369
const update_res = await exec_manage_cli(type, action, update_options);
363370
bucket_options = { ...bucket_options, ...update_options };
364371
const bucket = await config_fs.get_bucket_by_name(name);
@@ -436,7 +443,7 @@ mocha.describe('manage_nsfs cli', function() {
436443

437444
mocha.it('cli bucket delete - should fail invalid option', async function() {
438445
const action = ACTIONS.UPDATE;
439-
const bucket_options_with_invalid_option = { config_root, name, lala: 'lala'}; // lala invalid option
446+
const bucket_options_with_invalid_option = { config_root, name, lala: 'lala' }; // lala invalid option
440447
try {
441448
add_res = await exec_manage_cli(type, action, bucket_options_with_invalid_option);
442449
assert.fail('should have failed with invalid option');
@@ -547,8 +554,11 @@ mocha.describe('manage_nsfs cli', function() {
547554
const gpfs_secret_key = 'U2AYaMpU3zRDcRFWmvzgQr9MoHIAsDy3oEXAMPLE';
548555
let account_options = { config_root, name, new_buckets_path, uid, gid, access_key, secret_key };
549556
const gpfs_account_options = {
550-
...account_options, access_key: gpfs_access_key, secret_key: gpfs_secret_key,
551-
name: gpfs_account, fs_backend: 'GPFS'
557+
...account_options,
558+
access_key: gpfs_access_key,
559+
secret_key: gpfs_secret_key,
560+
name: gpfs_account,
561+
fs_backend: 'GPFS'
552562
};
553563
let updating_options = account_options;
554564
let compare_details; // we will use it for update account and compare the results
@@ -1023,7 +1033,7 @@ mocha.describe('manage_nsfs cli', function() {
10231033
mocha.it('should fail - cli whitelist has invalid IP address (one item in the list)', async function() {
10241034
const ip_list_with_invalid_ip_address = ['10.1.11']; // missing a class in the IP address
10251035
try {
1026-
await exec_manage_cli(type, '', { config_root, ips: ip_list_with_invalid_ip_address});
1036+
await exec_manage_cli(type, '', { config_root, ips: ip_list_with_invalid_ip_address });
10271037
assert.fail('should have failed with whitelist ips with invalid ip address');
10281038
} catch (err) {
10291039
assert_error(err, ManageCLIError.InvalidWhiteListIPFormat);
@@ -1035,7 +1045,7 @@ mocha.describe('manage_nsfs cli', function() {
10351045
const ips = ['127.0.0.1', '::ffff:7f00:3', '0000:0000:0000:0000:0000:ffff:7f00:0002'];
10361046
ips.push(invalid_ip_address);
10371047
try {
1038-
await exec_manage_cli(type, '', { config_root, ips: ips});
1048+
await exec_manage_cli(type, '', { config_root, ips: ips });
10391049
assert.fail('should have failed with whitelist ips with invalid ip address');
10401050
} catch (err) {
10411051
assert_error(err, ManageCLIError.InvalidWhiteListIPFormat);
@@ -1064,14 +1074,110 @@ mocha.describe('manage_nsfs cli', function() {
10641074
const ips = ['127.0.0.1']; // IPV4 format
10651075
const res = await exec_manage_cli(type, '', { config_root, ips: JSON.stringify(ips) });
10661076
await assert_response('', type, res, ips);
1067-
const new_config_options = { S3_SERVER_IP_WHITELIST: ips};
1077+
const new_config_options = { S3_SERVER_IP_WHITELIST: ips };
10681078
const config_data = await config_fs.get_config_json();
10691079
console.log(config_data);
10701080
assert_whitelist(config_data, new_config_options);
10711081
});
10721082

10731083
});
10741084

1085+
mocha.describe('cli lifecycle flow', async function() {
1086+
this.timeout(50000); // eslint-disable-line no-invalid-this
1087+
const type = TYPES.LIFECYCLE;
1088+
let now = new Date();
1089+
let format_time = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`;
1090+
const config_options = { NC_LIFECYCLE_RUN_TIME: format_time, NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS: 5, NC_LIFECYCLE_TZ: 'LOCAL' };
1091+
mocha.before(async () => {
1092+
await config_fs.create_config_json_file(JSON.stringify(config_options));
1093+
});
1094+
mocha.after(async () => {
1095+
const config_file_path = config_fs.get_config_json_path();
1096+
await fs_utils.file_delete(config_file_path);
1097+
});
1098+
1099+
mocha.it('cli lifecycle should run with LOCAL TZ', async function() {
1100+
now = new Date();
1101+
format_time = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`;
1102+
const new_config_options = { NC_LIFECYCLE_RUN_TIME: format_time, NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS: 5, NC_LIFECYCLE_TZ: 'LOCAL' };
1103+
await config_fs.update_config_json_file(JSON.stringify(new_config_options));
1104+
const res = await exec_manage_cli(type, '', { config_root, disable_service_validation: true });
1105+
const parsed = JSON.parse(res);
1106+
assert.equal(parsed.response.code, ManageCLIResponse.LifecycleSuccessful.code);
1107+
});
1108+
1109+
mocha.it('cli lifecycle shouldn\'t run twice with LOCAL TZ', async function() {
1110+
const new_config_options = { NC_LIFECYCLE_RUN_TIME: format_time, NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS: 5, NC_LIFECYCLE_TZ: 'LOCAL' };
1111+
await config_fs.update_config_json_file(JSON.stringify(new_config_options));
1112+
const res = await exec_manage_cli(type, '', { config_root, disable_service_validation: true });
1113+
const parsed = JSON.parse(res);
1114+
assert.equal(parsed.response.code, ManageCLIResponse.LifecycleWorkerNotRunning.code);
1115+
// remove the timestamp file to allow next tests to run
1116+
const timestampfile = path.join(config_fs.config_root, config.NC_LIFECYCLE_CONFIG_DIR_NAME, 'lifecycle.timestamp');
1117+
await fs_utils.file_delete(timestampfile);
1118+
});
1119+
1120+
mocha.it('cli lifecycle shouldn\'t run before NC_LIFECYCLE_RUN_TIME with LOCAL TZ', async function() {
1121+
now = new Date();
1122+
const in_one_minute = new Date(now);
1123+
in_one_minute.setMinutes(now.getMinutes() + 1);
1124+
format_time = `${in_one_minute.getHours().toString().padStart(2, '0')}:${in_one_minute.getMinutes().toString().padStart(2, '0')}`;
1125+
const new_config_options = { NC_LIFECYCLE_RUN_TIME: format_time, NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS: 5, NC_LIFECYCLE_TZ: 'LOCAL' };
1126+
await config_fs.update_config_json_file(JSON.stringify(new_config_options));
1127+
const res = await exec_manage_cli(type, '', { config_root, disable_service_validation: true });
1128+
const parsed = JSON.parse(res);
1129+
assert.equal(parsed.response.code, ManageCLIResponse.LifecycleWorkerNotRunning.code);
1130+
});
1131+
1132+
mocha.it('cli lifecycle shouldn\'t run after NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS with LOCAL TZ', async function() {
1133+
now = new Date();
1134+
const ten_minute_ago = new Date(now);
1135+
ten_minute_ago.setMinutes(now.getMinutes() - 10);
1136+
format_time = `${ten_minute_ago.getHours().toString().padStart(2, '0')}:${ten_minute_ago.getMinutes().toString().padStart(2, '0')}`;
1137+
const new_config_options = { NC_LIFECYCLE_RUN_TIME: format_time, NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS: 5, NC_LIFECYCLE_TZ: 'LOCAL' };
1138+
await config_fs.update_config_json_file(JSON.stringify(new_config_options));
1139+
const res = await exec_manage_cli(type, '', { config_root, disable_service_validation: true });
1140+
const parsed = JSON.parse(res);
1141+
assert.equal(parsed.response.code, ManageCLIResponse.LifecycleWorkerNotRunning.code);
1142+
});
1143+
1144+
mocha.it('cli lifecycle should run with UTC TZ', async function() {
1145+
now = new Date();
1146+
const utc_now = new Date(now);
1147+
format_time = `${utc_now.getUTCHours().toString().padStart(2, '0')}:${utc_now.getUTCMinutes().toString().padStart(2, '0')}`;
1148+
const new_config_options = { NC_LIFECYCLE_RUN_TIME: format_time, NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS: 5, NC_LIFECYCLE_TZ: 'UTC' };
1149+
await config_fs.update_config_json_file(JSON.stringify(new_config_options));
1150+
const res = await exec_manage_cli(type, '', { config_root, disable_service_validation: true });
1151+
const parsed = JSON.parse(res);
1152+
assert.equal(parsed.response.code, ManageCLIResponse.LifecycleSuccessful.code);
1153+
});
1154+
1155+
mocha.it('cli lifecycle shouldn\'t run before NC_LIFECYCLE_RUN_TIME with UTC TZ', async function() {
1156+
now = new Date();
1157+
const in_one_minute = new Date(now); // Create a copy to avoid modifying 'now'
1158+
in_one_minute.setUTCMinutes(now.getUTCMinutes() + 1);
1159+
format_time = `${in_one_minute.getUTCHours().toString().padStart(2, '0')}:${in_one_minute.getUTCMinutes().toString().padStart(2, '0')}`;
1160+
const new_config_options = { NC_LIFECYCLE_RUN_TIME: format_time, NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS: 5, NC_LIFECYCLE_TZ: 'UTC' };
1161+
await config_fs.update_config_json_file(JSON.stringify(new_config_options));
1162+
const res = await exec_manage_cli(type, '', { config_root, disable_service_validation: true });
1163+
const parsed = JSON.parse(res);
1164+
assert.equal(parsed.response.code, ManageCLIResponse.LifecycleWorkerNotRunning.code);
1165+
});
1166+
1167+
mocha.it('cli lifecycle shouldn\'t run after NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS with UTC TZ', async function() {
1168+
now = new Date();
1169+
const ten_minute_ago = new Date(now);
1170+
ten_minute_ago.setUTCMinutes(now.getUTCMinutes() - 10);
1171+
format_time = `${ten_minute_ago.getUTCHours().toString().padStart(2, '0')}:${ten_minute_ago.getUTCMinutes().toString().padStart(2, '0')}`;
1172+
const new_config_options = { NC_LIFECYCLE_RUN_TIME: format_time, NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS: 5, NC_LIFECYCLE_TZ: 'UTC' };
1173+
await config_fs.update_config_json_file(JSON.stringify(new_config_options));
1174+
const res = await exec_manage_cli(type, '', { config_root, disable_service_validation: true });
1175+
const parsed = JSON.parse(res);
1176+
assert.equal(parsed.response.code, ManageCLIResponse.LifecycleWorkerNotRunning.code);
1177+
});
1178+
1179+
});
1180+
10751181
});
10761182

10771183

0 commit comments

Comments
 (0)