Skip to content

Commit

Permalink
Add new parameters to argparse
Browse files Browse the repository at this point in the history
  • Loading branch information
yngvar-antonsson committed May 24, 2023
1 parent 7f7e78d commit 473d8d4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 84 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Added

- Allow to list several instances (comma-separated) in ``bootstrap_from``.

- New argparse type ``json`` and several new parameters from Tarantool 2.11
(`#2102 <https://github.com/tarantool/cartridge/issues/2102>`_).

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fixed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
34 changes: 32 additions & 2 deletions cartridge/argparse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

local fio = require('fio')
local yaml = require('yaml')
local json = require('json')
local checks = require('checks')
local errors = require('errors')
-- local base_dir = fio.abspath(fio.dirname(arg[0]))
Expand Down Expand Up @@ -143,13 +144,25 @@ local box_opts = {
log = 'string', -- **string**
log_nonblock = 'boolean', -- **boolean**
log_level = 'string|number', -- **string|number**
log_modules = 'json', -- **json**
log_format = 'string', -- **string**

audit_log = 'string', -- **string**
audit_nonblock = 'boolean', -- **boolean**
audit_format = 'string', -- **string**
audit_filter = 'string', -- **string**

auth_type = 'string', -- **string**
auth_delay = 'number', -- **number**
disable_guest = 'boolean', -- **boolean**
password_lifetime_days = 'number', -- **number**
password_min_length = 'number', -- **number**
password_enforce_uppercase = 'boolean', -- **boolean**
password_enforce_lowercase = 'boolean', -- **boolean**
password_enforce_digits = 'boolean', -- **boolean**
password_enforce_specialchars = 'boolean', -- **boolean**
password_history_length = 'number', -- **number**

flightrec_enabled = 'boolean', -- **boolean**
flightrec_logs_size = 'number', -- **number**
flightrec_logs_max_msg_size = 'number', -- **number**
Expand All @@ -170,6 +183,7 @@ local box_opts = {
wal_queue_max_size = 'number', -- **number**
wal_dir_rescan_delay = 'number', -- **number**
wal_cleanup_delay = 'number', -- **number**
wal_ext = 'json', -- **json**
force_recovery = 'boolean', -- **boolean**
replication = 'string', -- **string**
instance_uuid = 'string', -- **string**
Expand Down Expand Up @@ -198,13 +212,17 @@ local box_opts = {
feedback_host = 'string', -- **string**
feedback_interval = 'number', -- **number**
feedback_crashinfo = 'boolean', -- **boolean**
feedback_send_metrics = 'boolean', -- **boolean**
feedback_metrics_collect_interval = 'number', -- **number**
feedback_metrics_limit = 'number', -- **number**
net_msg_max = 'number', -- **number**
iproto_threads = 'number', -- **number**
sql_cache_size = 'number', -- **number**
txn_timeout = 'number', -- **number**
election_mode = 'string', -- **string**
election_timeout = 'number', -- **number**
election_fencing_mode = 'string', -- **string**
metrics = 'json', -- **json**
}

local function load_file(filename)
Expand Down Expand Up @@ -454,13 +472,16 @@ local function get_opts(opts)
local opttype_str = false
local opttype_num = false
local opttype_bool = false
local opttype_json = false
for _, _opttype in pairs(string.split(opttype, '|')) do
if _opttype == 'string' then
opttype_str = true
elseif _opttype == 'number' then
opttype_num = true
elseif _opttype == 'boolean' then
opttype_bool = true
elseif _opttype == 'json' then
opttype_json = true
else
return nil, TypeCastError:new(
"can't typecast %s to %s (unsupported type)",
Expand All @@ -487,9 +508,18 @@ local function get_opts(opts)
end
if _value == nil and opttype_str then
_value = value
elseif _value == nil and opttype_json then
local ok, res = pcall(json.decode, value)
if ok then
_value = res
else
return nil, TypeCastError:new(
"invalid json parameter %s: %q",
optname, value
)
end
end

if not opttype_num and not opttype_bool and not opttype_str then
if not opttype_num and not opttype_bool and not opttype_str and not opttype_json then
return nil, TypeCastError:new(
"can't typecast %s to %s (unsupported type)",
optname, opttype
Expand Down
82 changes: 0 additions & 82 deletions test/integration/master_restart_test.lua

This file was deleted.

9 changes: 9 additions & 0 deletions test/unit/argparse_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ g.test_box_opts = function()
memtx_memory = 100, -- number -> number
listen = 13301, -- number -> number
read_only = true, -- bool -> bool
wal_ext = '{"old": true, "new": true}', -- json -> table
},
boolean_to_string = {
feedback_host = false,
Expand All @@ -325,6 +326,9 @@ g.test_box_opts = function()
boolean_to_number = {
readahead = false,
},
json_to_invalid = {
wal_ext = 'error',
}
})
)

Expand All @@ -337,6 +341,7 @@ g.test_box_opts = function()
memtx_memory = 100,
listen = 13301,
read_only = true,
wal_ext = {old = true, new = true},
})

local function check_err(cmd_args, expected)
Expand Down Expand Up @@ -376,6 +381,10 @@ g.test_box_opts = function()
check_err('--cfg ./cfg.yml --instance-name boolean_to_number',
[[TypeCastError: invalid configuration parameter readahead (number expected, got boolean)]]
)

check_err('--cfg ./cfg.yml --instance-name json_to_invalid',
[[TypeCastError: invalid json parameter wal_ext: "error"]]
)
end

g.test_replication_quorum_opts = function()
Expand Down

0 comments on commit 473d8d4

Please sign in to comment.