Skip to content

Commit

Permalink
Additional test model fields for RPC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlgsmith committed Jul 28, 2024
1 parent cfe9731 commit dd7fa7d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
40 changes: 28 additions & 12 deletions models/rpc.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- luacheck: globals _RPCS
local apteryx = require('apteryx')

local function reboot(path, input)
local function reboot(input)
if input["language"] ~= nil then
-- generate results for test cases
if input["language"] ~= 'en-US' then
Expand All @@ -21,7 +22,7 @@ local function reboot(path, input)
return true
end

local function get_reboot_info(path, input)
local function get_reboot_info()
local info = apteryx.get_tree("/system/reboot-info")
return {
["reboot-time"] = info["reboot-time"] or nil,
Expand All @@ -30,27 +31,42 @@ local function get_reboot_info(path, input)
}
end

local function reset_state(path, input)
local delay = input["delay"]
local function get_rpcs()
if _RPCS ~= nil then
return { paths=_RPCS }
end
return { paths={} }
end

local function reset_state(input)
local delay = input["delay"]
apteryx.set("/t4:test/state/age", delay)
return true
end

local function get_reset_time(path, input)
local function get_reset_time()
return { ["last-reset"] = apteryx.get("/t4:test/state/age") }
end

local function set_age(path, input)
local function get_reset_history()
local lasttime = apteryx.get("/t4:test/state/age")
local history = apteryx.get_tree("/t4:test/state/history")
return { ["last-reset"] = lasttime, ["history"] = history }
end

local function set_age(input, path)
local user = path:match('/t4:test/state/users/([^/]+)')
local age = input["age"]
local age = input["age"]
apteryx.set("/t4:test/state/users/" .. user .. "/age", age)
return true
end

return {
["/operations/t4:reboot"] = reboot,
["/operations/t4:get-reboot-info"] = get_reboot_info,
["/t4:test/state/reset"] = reset_state,
["/t4:test/state/get-last-reset-time"] = get_reset_time,
["/t4:test/state/users/*/set-age"] = set_age,
{ path="/operations/t4:reboot", methods={"POST"}, handler=reboot },
{ path="/operations/t4:get-reboot-info", methods={"GET"}, handler=get_reboot_info },
{ path="/operations/t4:get-rpcs", methods={"GET"}, handler=get_rpcs },
{ path="/t4:test/state/reset", methods={"POST"}, handler=reset_state },
{ path="/t4:test/state/get-last-reset-time", methods={"GET"}, handler=get_reset_time },
{ path="/t4:test/state/get-reset-history", methods={"GET"}, handler=get_reset_history },
{ path="/t4:test/state/users/*/set-age", methods={"POST"}, handler=set_age },
}
26 changes: 26 additions & 0 deletions models/test4:rpc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<NODE name="test" help="This is a test node in the testing-4 namespace">
<NODE name="state" help="State">
<NODE name="age" mode="r" help="a string"/>
<NODE name="history" help="List of last reset times">
<NODE name="*" help="Reset time" range="0..4294967295"/>
</NODE>
<NODE name="reset" mode="wx" help="Reset state">
<NODE name="input" help="Input parameters">
<NODE name="delay" mode="w" help="Number of seconds to wait before starting the reset" range="0..4294967295"/>
Expand All @@ -16,6 +19,17 @@
<NODE name="get-last-reset-time" mode="rwx" help="Retrieve the last interface reset time">
<NODE name="output" help="Output parameters">
<NODE name="last-reset" mode="r" help="Time of the last reset" range="0..4294967295"/>
<NODE name="history" help="List of last reset times">
<NODE name="*" help="Last reset time" range="0..4294967295"/>
</NODE>
</NODE>
</NODE>
<NODE name="get-reset-history" mode="rwx" help="Retrieve the history of resets">
<NODE name="output" help="Output parameters">
<NODE name="last-reset" mode="r" help="Time of the last reset" range="0..4294967295"/>
<NODE name="history" help="List of last reset times">
<NODE name="*" help="Last reset time" range="0..4294967295"/>
</NODE>
</NODE>
</NODE>
<NODE name="users" help="This is a list of users">
Expand Down Expand Up @@ -46,5 +60,17 @@
<NODE name="language" mode="r" help="The 'language' parameter used in the last reboot operation."/>
</NODE>
</NODE>
<NODE name="get-rpcs" mode="rx" help="Retrieve the list of all RPCs">
<NODE name="output" help="Output parameters">
<NODE name="paths" help="List of RPCs">
<NODE name="*" help="An RPC">
<NODE name="path" mode="r" help="RPC path"/>
<NODE name="methods" help="List of methods this RPC supports">
<NODE name="*" mode="r" help="A method" pattern="POST|GET|PUT|PATCH|DELETE|HEAD|OPTIONS"/>
</NODE>
</NODE>
</NODE>
</NODE>
</NODE>
</test:NODE>
</MODULE>

0 comments on commit dd7fa7d

Please sign in to comment.