From 97752bf6dc3fc151fd1f6e33a8993b220cc77391 Mon Sep 17 00:00:00 2001 From: Vladislav Shpilevoy Date: Tue, 7 Nov 2023 21:55:35 +0100 Subject: [PATCH] test: introduce test_user_grant_range cfg option 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 --- test/luatest_helpers/vtest.lua | 17 ++++++++++++++++- test/replicaset-luatest/replicaset_3_test.lua | 3 ++- test/router-luatest/router_test.lua | 6 +++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/test/luatest_helpers/vtest.lua b/test/luatest_helpers/vtest.lua index e14971d4..b19ea3ca 100644 --- a/test/luatest_helpers/vtest.lua +++ b/test/luatest_helpers/vtest.lua @@ -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. @@ -218,8 +222,14 @@ 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}) @@ -227,6 +237,7 @@ local function cluster_new(g, cfg) 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 @@ -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') @@ -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') @@ -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 @@ -834,4 +848,5 @@ return { wait_for_nil = wait_for_nil, sourcedir = sourcedir, vardir = vardir, + clear_test_cfg_options = clear_test_cfg_options, } diff --git a/test/replicaset-luatest/replicaset_3_test.lua b/test/replicaset-luatest/replicaset_3_test.lua index 3e5b5038..46b1a226 100644 --- a/test/replicaset-luatest/replicaset_3_test.lua +++ b/test/replicaset-luatest/replicaset_3_test.lua @@ -20,7 +20,8 @@ local cfg_template = { }, }, }, - bucket_count = 20 + bucket_count = 20, + test_user_grant_range = 'super', } local global_cfg diff --git a/test/router-luatest/router_test.lua b/test/router-luatest/router_test.lua index 28a36857..6019bb32 100644 --- a/test/router-luatest/router_test.lua +++ b/test/router-luatest/router_test.lua @@ -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) @@ -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)) @@ -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)) @@ -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)