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 29, 2024
1 parent cfe9731 commit 88a512c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 18 deletions.
49 changes: 35 additions & 14 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,47 @@ local function get_reboot_info(path, input)
}
end

local function reset_state(path, input)
local delay = input["delay"]
apteryx.set("/t4:test/state/age", delay)
return true
local function get_rpcs()
if _RPCS ~= nil then
return { paths=_RPCS }
end
return { paths={} }
end

local function get_reset_time(path, input)
local function reset_state(input, _, method)
if method == "GET" then
return { ["delay"] = apteryx.get("/t4:test/state/age") }
elseif method == "POST" then
local delay = input["delay"]
apteryx.set("/t4:test/state/age", delay)
return true
end
return false, "unsupported operation"
end

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", "POST"}, handler=get_reboot_info },
{ path="/operations/t4:get-rpcs", methods={"GET", "POST"}, handler=get_rpcs },
{ path="/t4:test/state/reset", methods={"GET", "POST"}, handler=reset_state },
{ path="/t4:test/state/get-last-reset-time", methods={"GET", "POST"}, handler=get_reset_time },
{ path="/t4:test/state/get-reset-history", methods={"GET", "POST"}, handler=get_reset_history },
{ path="/t4:test/state/users/*/set-age", methods={"POST"}, handler=set_age },
}
37 changes: 33 additions & 4 deletions models/test4:rpc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,38 @@
<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="reset" mode="wx" help="Reset state">
<NODE name="history" help="List of last reset times">
<NODE name="*" help="Reset time" range="0..4294967295"/>
</NODE>
<NODE name="reset" mode="rwx" 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"/>
</NODE>
<NODE name="output" help="Output parameters">
<NODE name="delay" mode="r" help="Last number of seconds waited before reset" range="0..4294967295"/>
</NODE>
</NODE>
<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">
<NODE name="*" help="The user entry with key name">
<NODE name="name" mode="rw" help="This is the name of the user"/>
<NODE name="age" mode="rw" help="Age of the user" range="0..4294967295"/>
<NODE name="set-age" mode="wx" help="Set the users age">
<NODE name="set-age" mode="rwx" help="Set the users age">
<NODE name="input" help="Input parameters">
<NODE name="age" mode="w" help="New age" range="0..4294967295"/>
</NODE>
Expand All @@ -32,19 +49,31 @@
</NODE>
</NODE>
<test:NODE name="operations" help="Container for all operation resources.">
<NODE name="reboot" mode="wx" help="Reboot operation.">
<NODE name="reboot" mode="rwx" help="Reboot operation.">
<NODE name="input" help="Input parameters">
<NODE name="delay" mode="w" help="Number of seconds to wait before initiating the reboot operation." range="0..4294967295"/>
<NODE name="message" mode="w" help="Log message to display when reboot is started."/>
<NODE name="language" mode="w" help="Language identifier string."/>
</NODE>
</NODE>
<NODE name="get-reboot-info" mode="rx" help="Retrieve parameters used in the last reboot operation.">
<NODE name="get-reboot-info" mode="rwx" help="Retrieve parameters used in the last reboot operation.">
<NODE name="output" help="Output parameters">
<NODE name="reboot-time" mode="r" help="The 'delay' parameter used in the last reboot operation." range="0..4294967295"/>
<NODE name="message" mode="r" help="The 'message' parameter used in the last reboot operation."/>
<NODE name="language" mode="r" help="The 'language' parameter used in the last reboot operation."/>
</NODE>
</NODE>
<NODE name="get-rpcs" mode="rwx" 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 88a512c

Please sign in to comment.