Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
dparmar18 committed Apr 2, 2024
1 parent 6fb4b43 commit 53fa7b1
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions teuthology/suite/fragment-merge.lua
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
-- allow only some Lua (and lunatic) builtins for use by scripts
local lua_allowlist = {
require = require,
assert = assert,
error = error,
ipairs = ipairs,
next = next,
pairs = pairs,
tonumber = tonumber,
tostring = tostring,
py_attrgetter = python.as_attrgetter,
py_dict = python.builtins.dict,
py_list = python.builtins.list,
py_tuple = python.builtins.tuple,
py_enumerate = python.enumerate,
py_iterex = python.iterex,
py_itemgetter = python.as_itemgetter,
math = math,
}
lua_allowlist.__index = lua_allowlist

-- accept a fragment/config (or just return true from the script!)
local function accept()
coroutine.yield(true)
end

-- reject a fragment/config (or just return false from the script!)
local function reject()
coroutine.yield(false)
end

-- this implements logic for filtering (via teuthology-suite CLI flags)
local function matches(_ENV, f)
if description:find(f, 1, true) then
return true
end
if filter_fragments then
for i,path in py_enumerate(base_frag_paths) do
for i, path in pairs(py_enumerate(base_frag_paths)) do
if path:find(f) then
return true
end
Expand All @@ -43,15 +24,15 @@ end

local function check_filters(_ENV)
if filter_all then
for i,f in py_enumerate(filter_all) do
for i, f in pairs(py_enumerate(filter_all)) do
if not matches(_ENV, f) then
reject()
end
end
end
if filter_in then
local found, tried = false, false
for i,f in py_enumerate(filter_in) do
for i, f in pairs(py_enumerate(filter_in)) do
tried = true
if matches(_ENV, f) then
found = true
Expand All @@ -63,7 +44,7 @@ local function check_filters(_ENV)
end
end
if filter_out then
for i,f in py_enumerate(filter_out) do
for i, f in pairs(py_enumerate(filter_out)) do
if matches(_ENV, f) then
reject()
end
Expand All @@ -79,7 +60,16 @@ function new_script(script, log, deep_merge, yaml_load)
log = log,
reject = reject,
yaml_load = yaml_load,
}, lua_allowlist)
python = python, -- Assuming python module is available
}, {
__index = function(t, k)
-- Allow only specified Python functions
if k == "py_attrgetter" or k == "py_dict" or k == "py_list" or k == "py_tuple" or
k == "py_enumerate" or k == "py_iterex" or k == "py_itemgetter" then
return python[k]
end
end
})

-- avoid putting check_filters in _ENV
-- try to keep line numbers correct:
Expand Down

0 comments on commit 53fa7b1

Please sign in to comment.