Skip to content

Commit

Permalink
test: introduce test_user_grant_range cfg option
Browse files Browse the repository at this point in the history
This is a vtest option which is used only by vtest and is not
propagated into vshard.

The purpose is not to grant 'super' privileges to the vshard user
when it is not needed. It allows to ensure that vshard can work
fine with fully automatic user management without any external
intervention (such as via vtest).

It will be used in a next commit for testing of non-automatic
user management.

Needed for #435

NO_DOC=internal
  • Loading branch information
Gerold103 committed Nov 28, 2023
1 parent fa3acbc commit 16bbae3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
17 changes: 16 additions & 1 deletion test/luatest_helpers/vtest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ local function error_is_timeout(err)
err.message == 'Timeout exceeded') or err.type == 'TimedOut'
end

local function clear_test_cfg_options(cfg)
cfg.test_user_grant_range = nil
end

--
-- Build a valid vshard config by a template. A template does not specify
-- anything volatile such as URIs, UUIDs - these are installed at runtime.
Expand Down Expand Up @@ -218,15 +222,22 @@ local function cluster_new(g, cfg)
local user = box.session.user()
box.session.su('admin')

local grant_range = cfg.test_user_grant_range
ivtest.clear_test_cfg_options(cfg)
ivshard.storage.cfg(cfg, box.info.uuid)
box.schema.user.grant('storage', 'super')

if grant_range ~= nil then
box.schema.user.grant('storage', grant_range, nil, nil,
{if_not_exists = true})
end

box.session.su(user)
end, {cfg})
end
for _, replica in pairs(replicas) do
replica:wait_for_readiness()
replica:exec(function(cfg)
ivtest.clear_test_cfg_options(cfg)
ivshard.storage.cfg(cfg, box.info.uuid)
end, {cfg})
end
Expand Down Expand Up @@ -413,6 +424,7 @@ end
local function cluster_cfg(g, cfg)
-- No support yet for dynamic node addition and removal. Only reconfig.
local _, err = cluster_exec_each(g, function(cfg)
ivtest.clear_test_cfg_options(cfg)
return ivshard.storage.cfg(cfg, box.info.uuid)
end, {cfg})
t.assert_equals(err, nil, 'storage reconfig')
Expand Down Expand Up @@ -587,6 +599,7 @@ end
local function storage_start(storage, cfg)
storage:start()
local _, err = storage:exec(function(cfg)
ivtest.clear_test_cfg_options(cfg)
return ivshard.storage.cfg(cfg, box.info.uuid)
end, {cfg})
t.assert_equals(err, nil, 'storage cfg on start')
Expand All @@ -597,6 +610,7 @@ end
--
local function router_cfg(router, cfg)
router:exec(function(cfg)
ivtest.clear_test_cfg_options(cfg)
ivshard.router.cfg(cfg)
end, {cfg})
end
Expand Down Expand Up @@ -834,4 +848,5 @@ return {
wait_for_nil = wait_for_nil,
sourcedir = sourcedir,
vardir = vardir,
clear_test_cfg_options = clear_test_cfg_options,
}
3 changes: 2 additions & 1 deletion test/replicaset-luatest/replicaset_3_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ local cfg_template = {
},
},
},
bucket_count = 20
bucket_count = 20,
test_user_grant_range = 'super',
}
local global_cfg

Expand Down
6 changes: 5 additions & 1 deletion test/router-luatest/router_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ local cfg_template = {
},
},
},
bucket_count = 100
bucket_count = 100,
test_user_grant_range = 'super',
}
local global_cfg = vtest.config_new(cfg_template)

Expand Down Expand Up @@ -462,6 +463,7 @@ g.test_enable_disable = function(g)
_G.ivshard.router.internal.errinj.ERRINJ_CFG_DELAY = true
end)
router:exec(function(cfg)
ivtest.clear_test_cfg_options(cfg)
rawset(_G, 'fiber_static', ifiber.new(ivshard.router.cfg, cfg))
rawset(_G, 'fiber_new', ifiber.new(ivshard.router.new,
'new_router', cfg))
Expand Down Expand Up @@ -581,6 +583,7 @@ g.test_simultaneous_cfg = function()

router:exec(function(cfg)
ivshard.router.internal.errinj.ERRINJ_CFG_DELAY = true
ivtest.clear_test_cfg_options(cfg)
rawset(_G, 'fiber_cfg_static', ifiber.new(ivshard.router.cfg, cfg))
rawset(_G, 'fiber_cfg_new', ifiber.new(ivshard.router.new,
'new_router', cfg))
Expand All @@ -590,6 +593,7 @@ g.test_simultaneous_cfg = function()

local function routers_cfg()
return router:exec(function(cfg)
ivtest.clear_test_cfg_options(cfg)
local static_router = ivshard.router.internal.routers._static_router
local new_router = ivshard.router.internal.routers.new_router
local _, err1 = pcall(ivshard.router.cfg, cfg)
Expand Down

0 comments on commit 16bbae3

Please sign in to comment.