|  | 
|  | 1 | +/* Copyright (C) 2024 NooBaa */ | 
|  | 2 | +'use strict'; | 
|  | 3 | + | 
|  | 4 | +const path = require('path'); | 
|  | 5 | +const mocha = require('mocha'); | 
|  | 6 | +const assert = require('assert'); | 
|  | 7 | +const fs_utils = require('../../util/fs_utils'); | 
|  | 8 | +const nb_native = require('../../util/nb_native'); | 
|  | 9 | +const { get_process_fs_context } = require('../../util/native_fs_utils'); | 
|  | 10 | +const { ManageCLIResponse } = require('../../manage_nsfs/manage_nsfs_cli_responses'); | 
|  | 11 | +const { exec_manage_cli, get_coretest_path, TMP_PATH } = require('../system_tests/test_utils'); | 
|  | 12 | +const { TYPES, ACTIONS } = require('../../manage_nsfs/manage_nsfs_constants'); | 
|  | 13 | + | 
|  | 14 | +const DEFAULT_FS_CONFIG = get_process_fs_context(); | 
|  | 15 | + | 
|  | 16 | +const coretest_path = get_coretest_path(); | 
|  | 17 | +const coretest = require(coretest_path); | 
|  | 18 | +coretest.setup({}); | 
|  | 19 | + | 
|  | 20 | +mocha.describe('cli logging flow', async function() { | 
|  | 21 | +    this.timeout(50000); // eslint-disable-line no-invalid-this | 
|  | 22 | +    const bucket_path = path.join(TMP_PATH, 'log_bucket'); | 
|  | 23 | +    const pers_log_path = path.join(TMP_PATH, 'pers_logs'); | 
|  | 24 | + | 
|  | 25 | +    mocha.before(async () => { | 
|  | 26 | +        await fs_utils.create_fresh_path(pers_log_path); | 
|  | 27 | +        await fs_utils.create_fresh_path(bucket_path); | 
|  | 28 | +        await fs_utils.file_must_exist(bucket_path); | 
|  | 29 | +        await exec_manage_cli(TYPES.ACCOUNT, ACTIONS.ADD, { name: 'logbucketowner', user: 'root', new_buckets_path: bucket_path}); | 
|  | 30 | +        await exec_manage_cli(TYPES.BUCKET, ACTIONS.ADD, { name: 'logbucket', path: bucket_path, owner: 'logbucketowner'}); | 
|  | 31 | +        const data = '{"noobaa_bucket_logging":"true","op":"GET","bucket_owner":"[email protected]",' + | 
|  | 32 | +            '"source_bucket":"s3-bucket",' + | 
|  | 33 | +            '"object_key":"/s3-bucket?list-type=2&prefix=&delimiter=%2F&encoding-type=url",' + | 
|  | 34 | +            '"log_bucket":"logbucket",' + | 
|  | 35 | +            '"log_prefix":"","remote_ip":"100.64.0.2",' + | 
|  | 36 | +            '"request_uri":"/s3-bucket?list-type=2&prefix=&delimiter=%2F&encoding-type=url",' + | 
|  | 37 | +            '"http_status":102,"request_id":"lztyrl5k-7enflf-19sm"}'; | 
|  | 38 | +        await nb_native().fs.writeFile(DEFAULT_FS_CONFIG, path.join(pers_log_path + '/', 'bucket_logging.log'), | 
|  | 39 | +            Buffer.from(data + '\n')); | 
|  | 40 | +    }); | 
|  | 41 | + | 
|  | 42 | +    mocha.it('cli run logging', async function() { | 
|  | 43 | +        const res = await exec_manage_cli(TYPES.LOGGING, '', {}, false, { 'GUARANTEED_LOGS_PATH': pers_log_path}); | 
|  | 44 | +        const entries = await nb_native().fs.readdir(DEFAULT_FS_CONFIG, bucket_path); | 
|  | 45 | +        const log_objects = entries.filter(entry => !entry.name.startsWith('.')); | 
|  | 46 | +        assert.equal(log_objects.length, 1); // 1 new log_object should have been uploaded to the bucket | 
|  | 47 | +        const parsed = JSON.parse(res); | 
|  | 48 | +        assert.equal(parsed.response.code, ManageCLIResponse.LoggingExported.code); | 
|  | 49 | +    }); | 
|  | 50 | +}); | 
0 commit comments