Skip to content

Commit

Permalink
f_mu: comments cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
javierbrk committed Nov 25, 2024
1 parent 6e0e715 commit 7fd8d38
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 55 deletions.
21 changes: 3 additions & 18 deletions packages/lime-mesh-upgrade/files/usr/lib/lua/lime-mesh-upgrade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ mesh_upgrade.set_workdir("/tmp/mesh_upgrade")

function mesh_upgrade.create_local_latest_json(latest_data)
for _, im in pairs(latest_data['images']) do
-- im['download-urls'] = string.gsub(im['download-urls'], upgrade_url, "test")
im['download-urls'] = {mesh_upgrade.get_repo_base_url() .. im['name']}
end
utils.write_file(mesh_upgrade.LATEST_JSON_PATH, json.stringify(latest_data))
Expand Down Expand Up @@ -133,15 +132,13 @@ function mesh_upgrade.start_main_node_repository(latest_data)
mesh_upgrade.change_state(mesh_upgrade.upgrade_states.DOWNLOADING)
end

--- Function that check if tihs node have all things needed to became a main node
--- Function that check if this node is able to became a main node
--- Then, call update shared state with the proper info
-- @url optional new url to get the firmware for local repo
function mesh_upgrade.become_main_node(url)
if url then
eupgrade.set_custom_api_url(url)
end
-- todo(kon): check if main node is already set or we are on mesh_upgrade status
-- todo(kon): dont start again if status is started and eupgrade is downloaded for example
-- Check if there are a new version available (cached only)
-- 1. Check if new version is available and download it demonized using eupgrade
local latest = eupgrade.is_new_version_available(false)
Expand All @@ -167,7 +164,7 @@ function mesh_upgrade.become_main_node(url)
}
end

-- Update the state witth an error if eupgrade download failed
-- Update the state with an error if eupgrade download failed
-- It returns the download status
function mesh_upgrade.check_eupgrade_download_failed()
local download_status = eupgrade.get_download_status()
Expand All @@ -192,9 +189,6 @@ function mesh_upgrade.check_safeupgrade_is_working()
end

function mesh_upgrade.start_firmware_upgrade_transaction()
-- todo(kon): do all needed checks also with the main node state etc..
-- Expose eupgrade folder to uhttp (this is the best place to do it since
-- all the files are present)
if mesh_upgrade.main_node_state() ~= mesh_upgrade.main_node_states.STARTING then
return {
code = "BAD_NODE_STATE",
Expand Down Expand Up @@ -340,8 +334,6 @@ function mesh_upgrade.mesh_upgrade_abort(silent_abortion)
if silent_abortion == nil or silent_abortion == false then
mesh_upgrade.trigger_sheredstate_publish()
end
-- todo(javi): stop and delete everything
--os.execute("rm ".. eupgrade.WORKDIR .." -r >/dev/null 2>&1")
-- kill posible safe upgrade command
utils.unsafe_shell("kill $(ps| grep 'sh -c (( sleep " .. mesh_upgrade.su_start_time_out ..
"; safe-upgrade upgrade'| awk '{print $1}')")
Expand All @@ -364,11 +356,6 @@ end

function mesh_upgrade.change_main_node_state(newstate)
local main_node_state = mesh_upgrade.main_node_state()
-- if newstate == main_node_state then return false end

-- if newstate == mesh_upgrade.main_node_states.STARTING and
-- main_node_state ~= mesh_upgrade.main_node_states.NO then
-- return false
if newstate == mesh_upgrade.main_node_states.MAIN_NODE and main_node_state ~= mesh_upgrade.main_node_states.STARTING then
return false
end
Expand Down Expand Up @@ -405,16 +392,14 @@ function mesh_upgrade.change_state(newstate)
mesh_upgrade.upgrade_states.CONFIRMATION_PENDING then
return false
end
-- todo(javi): verify other states and return false if it is not possible
-- lets allow all types of state changes.
local uci = config.get_uci_cursor()
uci:set('mesh-upgrade', 'main', 'upgrade_state', newstate)
uci:save('mesh-upgrade')
uci:commit('mesh-upgrade')
return true
end

-- this function will retry max_retry_conunt tymes in case of error
-- this function will retry max_retry_conunt times in case of error
-- It will only fetch new information if main node has aborted or main node is
-- ready for upgraade
function mesh_upgrade.become_bot_node(main_node_upgrade_data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,3 @@ local hostname = utils.hostname()
local indata = io.stdin:read("*all")
utils.printJson(JSON.parse(indata))
mesh_upgrade.verify_network_consistency(JSON.parse(indata))

--if already involved in an upgrade transaction do nothing
--[[
if not mesh_upgrade.started() then
utils.log("async: starting an upgrade process")
for node, s_s_data in pairs(JSON.parse(indata)) do
--if any node has started an upgrade process and start one too?
--only fetch the info from the master node publication?
if node ~= hostname and s_s_data.main_node == mesh_upgrade.main_node_states.MAIN_NODE then
utils.unsafe_shell('logger -p daemon.info -t "async: mesh upgrade" "mesh upgrade detected upgrade from ' ..
s_s_data.repo_url .. " and masternode node " .. node .. " with this data " .. JSON.stringify(s_s_data)..'"')
mesh_upgrade.become_bot_node(s_s_data)
else
utils.unsafe_shell('logger -p daemon.info -t "async: mesh upgrade" "status "' ..
JSON.stringify(s_s_data) .. " from node " .. node)
end
end
else
--if started check that a main node has not aborted
for node, s_s_data in pairs(JSON.parse(indata)) do
utils.unsafe_shell('logger -p daemon.info -t "async: mesh upgrade" "mesh upgrade detected upgrade from "' ..
s_s_data.main_node .. " and masternode node " .. node .. " with this data " .. JSON.stringify(s_s_data.data))
utils.unsafe_shell('logger -p daemon.info -t "async: mesh upgrade" "mesh upgrade detected upgrade from "' ..
s_s_data.main_node .. " and masternode node " .. node .. " with this data " .. JSON.stringify(s_s_data.data))
if node ~= hostname and
s_s_data.main_node == mesh_upgrade.main_node_states.MAIN_NODE and
s_s_data.upgrade_state == mesh_upgrade.upgrade_states.ABORTED
then
mesh_upgrade.mesh_upgrade_abort()
utils.unsafe_shell('logger -p daemon.info -t "async: mesh upgrade" "aborting, main has aborted"')
end
end
utils.unsafe_shell('logger -p daemon.info -t "async: mesh upgrade" "already started an upgrade process"')
utils.log("already started an upgrade process")
end
]]--

0 comments on commit 7fd8d38

Please sign in to comment.