Skip to content
Snippets Groups Projects
Commit dac1dbc9 authored by Mergen Imeev's avatar Mergen Imeev Committed by Alexander Turenko
Browse files

config: config section for instance config

This section describes general instance configuration options.

Part of #8778

NO_DOC=will be added later
NO_CHANGELOG=will be added later
parent 363b1264
No related branches found
No related tags found
No related merge requests found
......@@ -36,4 +36,62 @@ local schema = require('internal.config.utils.schema')
--
-- Create a parent directory for the given file before box.cfg().
return schema.new('instance_config', schema.record({}))
local CONFIG_VERSION = 'dev'
-- * In the instance config: must be present.
--
-- TODO: This check is disabled for the early config schema
-- version, because the schema is often changed and there is no
-- schema evolution support yet.
-- * In the cluster config: must be present in the global scope.
--
-- TODO: This check is disabled as well, see above.
-- * In the cluster config: must not be present in the other
-- scopes (group, replicaset, instance).
-- * If present, must correspond to one of supported config
-- versions, but is it validated by the config.version schema
-- node definition.
local function validate_config_version(data, w)
-- scope == nil means that it is the instance config.
local scope = w.schema.scope
if scope == nil or scope == 'global' then
-- Must be present.
if data.config == nil or data.config.version == nil then
-- TODO: Enable this check closer to 3.0.0 release.
-- w.error('config.version is mandatory')
return
end
else
-- Must not be present.
assert(scope == 'group' or scope == 'replicaset' or scope == 'instance')
if data.config ~= nil and data.config.version ~= nil then
w.error('config.version must not be present in the %s scope', scope)
end
end
end
return schema.new('instance_config', schema.record({
config = schema.record({
version = schema.enum({
CONFIG_VERSION,
}),
reload = schema.enum({
'auto',
'manual',
}, {
default = 'auto',
}),
}),
}, {
-- Any configuration data should contain a version of the
-- config schema for which it is written.
--
-- This annotation cannot be placed right into the
-- config.version field, because missed fields are not
-- validated.
validate = validate_config_version,
-- Store the config schema version right in the outmost schema
-- node as an annotation. It simplifies accesses from other
-- code.
config_version = CONFIG_VERSION,
}))
......@@ -3,6 +3,52 @@ local instance_config = require('internal.config.instance_config')
local g = t.group()
-- Check that all record element names can be found in the table and vice versa.
local function validate_fields(config, record)
local config_fields = {}
if type(config) == 'table' then
for k in pairs(config) do
table.insert(config_fields, k)
end
end
local record_fields = {}
for k, v in pairs(record.fields) do
table.insert(record_fields, k)
end
t.assert_items_equals(config_fields, record_fields)
end
g.test_general = function()
t.assert_equals(instance_config.name, 'instance_config')
end
g.test_config = function()
local iconfig = {
config = {
version = 'dev',
reload = 'auto',
},
}
instance_config:validate(iconfig)
validate_fields(iconfig.config, instance_config.schema.fields.config)
iconfig = {
config = {
version = '0.0.0',
reload = 'auto',
},
}
local err = '[instance_config] config.version: Got 0.0.0, but only the '..
'following values are allowed: dev'
t.assert_error_msg_equals(err, function()
instance_config:validate(iconfig)
end)
local exp = {
reload = 'auto',
}
local res = instance_config:apply_default({}).config
t.assert_equals(res, exp)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment