Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
box: set box.cfg options via environment variables
Add ability to set box.cfg options via environment variables. These variables should have name `TT_<OPTION>`. When Tarantool instance is started under tarantoolctl utility, environment variables have higher priority than tarantoolctl configuration file. Closes #5602 Co-authored-by: Leonid Vasiliev <lvasiliev@tarantool.org> Co-authored-by: Alexander Turenko <alexander.turenko@tarantool.org> @TarantoolBot document Title: Set box.cfg options via environment variables Now, it is possible to set box.cfg options via environment variables. The name of variable should correspond the following pattern: `TT_<NAME>`, where `<NAME>` is uppercase box.cfg option name. For example: `TT_LISTEN`, `TT_READAHEAD`. Array values are separated by comma. Example: ```sh export TT_REPLICATION=localhost:3301,localhost:3302 ``` An empty variable is the same as unset one.
- Loading branch information
1 parent
8d1a4bd
commit 1b33012
Showing
6 changed files
with
285 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## feature/core | ||
|
||
* Now, it is possible to set box.cfg options with environment variables | ||
(gh-5602). | ||
|
||
The priority of sources of configuration options is the following (from low | ||
to high): default, tarantoolctl, environment, box.cfg{}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
local tap = require('tap') | ||
|
||
local test = tap.test('gh-5602') | ||
|
||
local status, err = pcall(box.cfg, {background = false, vinyl_timeout = 70.1}) | ||
|
||
-- Check that environment cfg values are set correctly. | ||
if arg[1] == '1' then | ||
test:plan(6) | ||
test:ok(status, 'box.cfg is successful') | ||
test:is(box.cfg['listen'], '3301', 'listen') | ||
test:is(box.cfg['readahead'], 10000, 'readahead') | ||
test:is(box.cfg['strip_core'], false, 'strip_core') | ||
test:is(box.cfg['log_format'], 'json', 'log_format is not set') | ||
test:is(box.cfg['log_nonblock'], false, 'log_nonblock') | ||
end | ||
if arg[1] == '2' then | ||
test:plan(7) | ||
test:ok(status, 'box.cfg is successful') | ||
test:is(box.cfg['listen'], '3301', 'listen') | ||
local replication = box.cfg['replication'] | ||
test:is(type(replication), 'table', 'replication is table') | ||
test:ok(replication[1] == '0.0.0.0:12345' or | ||
replication[1] == '1.1.1.1:12345', 'replication URI 1') | ||
test:ok(replication[2] == '0.0.0.0:12345' or | ||
replication[2] == '1.1.1.1:12345', 'replication URI 2') | ||
test:is(box.cfg['replication_connect_timeout'], 0.01, | ||
'replication_connect_timeout') | ||
test:is(box.cfg['replication_synchro_quorum'], '4 + 1', | ||
'replication_synchro_quorum') | ||
end | ||
|
||
-- Check that box.cfg{} values are more prioritized than | ||
-- environment cfg values. | ||
if arg[1] == '3' then | ||
test:plan(3) | ||
test:ok(status, 'box.cfg is successful') | ||
test:is(box.cfg['background'], false, | ||
'box.cfg{} background value is prioritized') | ||
test:is(box.cfg['vinyl_timeout'], 70.1, | ||
'box.cfg{} vinyl_timeout value is prioritized') | ||
end | ||
|
||
local err_msg_fmt = 'Environment variable TT_%s has incorrect value for ' .. | ||
'option "%s": should be %s' | ||
|
||
-- Check bad environment cfg values. | ||
if arg[1] == '4' then | ||
test:plan(2) | ||
test:ok(not status, 'box.cfg is not successful') | ||
local exp_err = err_msg_fmt:format('SQL_CACHE_SIZE', 'sql_cache_size', | ||
'convertible to a number') | ||
local err_msg = tostring(err) | ||
while err_msg:find('^.-:.-: ') do | ||
err_msg = err_msg:gsub('^.-:.-: ', '') | ||
end | ||
test:is(err_msg, exp_err, 'bad sql_cache_size value') | ||
end | ||
if arg[1] == '5' then | ||
test:plan(2) | ||
test:ok(not status, 'box.cfg is not successful') | ||
local exp_err = err_msg_fmt:format('STRIP_CORE', 'strip_core', | ||
'"true" or "false"') | ||
local err_msg = tostring(err) | ||
while err_msg:find('^.-:.-: ') do | ||
err_msg = err_msg:gsub('^.-:.-: ', '') | ||
end | ||
test:is(err_msg, exp_err, 'bad strip_core value') | ||
end | ||
|
||
os.exit(test:check() and 0 or 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
TAP version 13 | ||
1..6 | ||
ok - box.cfg is successful | ||
ok - listen | ||
ok - readahead | ||
ok - strip_core | ||
ok - log_format is not set | ||
ok - log_nonblock | ||
TAP version 13 | ||
1..7 | ||
ok - box.cfg is successful | ||
ok - listen | ||
ok - replication is table | ||
ok - replication URI 1 | ||
ok - replication URI 2 | ||
ok - replication_connect_timeout | ||
ok - replication_synchro_quorum | ||
TAP version 13 | ||
1..3 | ||
ok - box.cfg is successful | ||
ok - box.cfg{} background value is prioritized | ||
ok - box.cfg{} vinyl_timeout value is prioritized | ||
TAP version 13 | ||
1..2 | ||
ok - box.cfg is not successful | ||
ok - bad sql_cache_size value | ||
TAP version 13 | ||
1..2 | ||
ok - box.cfg is not successful | ||
ok - bad strip_core value | ||
TAP version 13 | ||
1..1 | ||
ok - exit status list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env tarantool | ||
|
||
local os = require('os') | ||
local fio = require('fio') | ||
local tap = require('tap') | ||
|
||
local test = tap.test('gh-5602') | ||
|
||
-- gh-5602: Check that environment cfg variables working. | ||
local TARANTOOL_PATH = arg[-1] | ||
local script_name = 'gh-5602-environment-cfg-test-cases.lua' | ||
local path_to_script = fio.pathjoin( | ||
os.getenv('PWD'), | ||
'box-tap', | ||
script_name) | ||
|
||
-- Generate a shell command like | ||
-- `FOO=x BAR=y /path/to/tarantool /path/to/script.lua 42`. | ||
local function shell_command(case, i) | ||
return ('%s %s %s %d'):format( | ||
case, | ||
TARANTOOL_PATH, | ||
path_to_script, | ||
i) | ||
end | ||
|
||
local cases = { | ||
('%s %s %s %s %s'):format( | ||
'TT_LISTEN=3301', | ||
'TT_READAHEAD=10000', | ||
'TT_STRIP_CORE=false', | ||
'TT_LOG_FORMAT=json', | ||
'TT_LOG_NONBLOCK=false'), | ||
('%s %s %s %s'):format( | ||
'TT_LISTEN=3301', | ||
'TT_REPLICATION=0.0.0.0:12345,1.1.1.1:12345', | ||
'TT_REPLICATION_CONNECT_TIMEOUT=0.01', | ||
'TT_REPLICATION_SYNCHRO_QUORUM=\'4 + 1\''), | ||
'TT_BACKGROUND=true TT_VINYL_TIMEOUT=60.1', | ||
'TT_SQL_CACHE_SIZE=a', | ||
'TT_STRIP_CORE=a', | ||
} | ||
|
||
test:plan(1) | ||
local exit_status_list = {} | ||
local exit_status_list_exp = {} | ||
for i, case in ipairs(cases) do | ||
local tmpdir = fio.tempdir() | ||
local new_path = fio.pathjoin(tmpdir, script_name) | ||
fio.copyfile(path_to_script, new_path) | ||
exit_status_list[i] = os.execute(shell_command(case, i)) | ||
exit_status_list_exp[i] = 0 | ||
end | ||
|
||
test:is_deeply(exit_status_list, exit_status_list_exp, 'exit status list') | ||
|
||
os.exit(test:check() and 0 or 1) |