|
| 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 | +} |
0 commit comments