diff --git a/packages/lime-mesh-upgrade/files/usr/etc/config/mesh-upgrade b/packages/lime-mesh-upgrade/files/usr/etc/config/mesh-upgrade index aeaf3ffc5..9a689517d 100644 --- a/packages/lime-mesh-upgrade/files/usr/etc/config/mesh-upgrade +++ b/packages/lime-mesh-upgrade/files/usr/etc/config/mesh-upgrade @@ -1,13 +1,13 @@ config mesh-upgrade 'main' - option id '1' - option firmware_ver "xxxx" - option repo_url 'http://10.13.156.241:8000/web_test/releases/api/' # TODO: provide a saner default - option upgrade_state 'downloading' + option id '' + option firmware_ver '' + option repo_url '' + option upgrade_state '' option safe_upgrade_status '' option eup_STATUS '' - option error 'CODE' - option timestamp '231354654' - option transaction_state 'aborted' - option master_node 'primero' + option error '0' + option timestamp '0' + option transaction_state 'no_transaction' + option master_node '' #option notset "" \ No newline at end of file diff --git a/packages/lime-mesh-upgrade/files/usr/lib/lua/lime-mesh-upgrade.lua b/packages/lime-mesh-upgrade/files/usr/lib/lua/lime-mesh-upgrade.lua index 28074c4b1..5e3657eed 100644 --- a/packages/lime-mesh-upgrade/files/usr/lib/lua/lime-mesh-upgrade.lua +++ b/packages/lime-mesh-upgrade/files/usr/lib/lua/lime-mesh-upgrade.lua @@ -1,21 +1,18 @@ #!/usr/bin/env lua - -local libuci = require "uci" local eupgrade = require 'eupgrade' local config = require "lime.config" - - local mesh_upgrade = { --posible tranactin states transaction_states = { NO_TRANSACTION="no_transaction", - STARTED = "started", --ther is a transaction in progress + STARTED = "started", --there is a transaction in progress ABORTED = "aborted", FINISHED = "finished" }, --psible upgrade states enumeration upgrade_states = { + STARTING="starting", DOWNLOADING= "downloading", READY_FOR_UPGRADE="ready_for_upgrade", UPGRADE_SCHELUDED="upgrade_scheluded", @@ -73,13 +70,13 @@ end -- Validate if the upgrade has already started function mesh_upgrade.mesh_upgrade_is_started() - local uci = libuci.cursor() + local uci = config.get_uci_cursor() return uci:get('mesh-upgrade', 'main', 'transaction_state') == 'started' --todo: what happens if a mesh_upgrade has started more than an hour ago ? should this node abort it ? end function mesh_upgrade.mesh_upgrade_abort() - local uci = libuci.cursor() + local uci = config.get_uci_cursor() uci:set('mesh-upgrade', 'main', 'transaction_state', mesh_upgrade.transaction_states.ABORTED) uci:save('mesh-upgrade') uci:commit('mesh-upgrade') @@ -93,14 +90,14 @@ function mesh_upgrade.set_mesh_upgrade_info(upgrade_data) local uci = config.get_uci_cursor() if (type(upgrade_data.id) == "number") and string.match(upgrade_data.data.repo_url, "https?://[%w-_%.%?%.:/%+=&]+") ~= nil - --perform aditional checks - then + --perform aditional checks + then uci:get('mesh-upgrade', 'main','repo_url') uci:set('mesh-upgrade', 'main', "mesh-upgrade") uci:set('mesh-upgrade', 'main', 'id', upgrade_data.id) uci:set('mesh-upgrade', 'main', 'repo_url', upgrade_data.data.repo_url) uci:set('mesh-upgrade', 'main', 'firmware_ver', upgrade_data.data.firmware_ver) - uci:set('mesh-upgrade', 'main', 'upgrade_state', mesh_upgrade.upgrade_states.starting) + uci:set('mesh-upgrade', 'main', 'upgrade_state', mesh_upgrade.upgrade_states.STARTING) uci:set('mesh-upgrade', 'main', 'error', 0) uci:set('mesh-upgrade', 'main', 'timestamp', upgrade_data.timestamp) uci:set('mesh-upgrade', 'main', 'master_node', upgrade_data.master_node) @@ -110,8 +107,7 @@ function mesh_upgrade.set_mesh_upgrade_info(upgrade_data) --wait for the download to be ready to trigger the shared state upgrade. --trigger firmware download from master_node url else - utils.log("upgrade not started input data errors") - print("upgrade not started input data errors") + config.log("upgrade not started input data errors") end end @@ -147,6 +143,10 @@ function mesh_upgrade.get_mesh_upgrade_status() upgrade_data.timestamp = uci:get('mesh-upgrade', 'main', 'timestamp') upgrade_data.master_node = uci:get('mesh-upgrade', 'main', 'master_node') upgrade_data.transaction_state = uci:get('mesh-upgrade', 'main', 'transaction_state') + if(upgrade_data.transaction_state==nil) then + uci:set('mesh-upgrade', 'main', 'transaction_state', mesh_upgrade.transaction_states.NO_TRANSACTION) + upgrade_data.transaction_state = uci:get('mesh-upgrade', 'main', 'transaction_state') + end return upgrade_data end diff --git a/packages/lime-mesh-upgrade/tests/test_lime-mesh-upgrade.lua b/packages/lime-mesh-upgrade/tests/test_lime-mesh-upgrade.lua index 0e068c636..7b57a9e70 100644 --- a/packages/lime-mesh-upgrade/tests/test_lime-mesh-upgrade.lua +++ b/packages/lime-mesh-upgrade/tests/test_lime-mesh-upgrade.lua @@ -32,33 +32,40 @@ local upgrade_data = } describe('LiMe mesh upgrade', function() - it('test set mesh config', function() + + it('test set mesh config fresh start', function() local status = lime_mesh_upgrade.get_mesh_upgrade_status() utils.printJson(status) assert.is.equal(status.transaction_state, lime_mesh_upgrade.transaction_states.NO_TRANSACTION) + assert.is.equal(lime_mesh_upgrade.mesh_upgrade_is_started(),false) + end) + + + it('test set mesh config', function() + + config.log("test set mesh config.... ") lime_mesh_upgrade.set_mesh_upgrade_info(upgrade_data) status = lime_mesh_upgrade.get_mesh_upgrade_status() utils.printJson(status) - - assert.is.equal(status.master_node, lime_mesh_upgrade.upgrade_states.STARTING) + assert.is.equal(status.master_node, upgrade_data.master_node) assert.is.equal(status.data.repo_url,upgrade_data.data.repo_url ) - - assert.is.equal(status.upgrade_state, lime_mesh_upgrade.upgrade_states.STARTING) + assert.is.equal(status.data.upgrade_state, lime_mesh_upgrade.upgrade_states.STARTING) assert.is.equal(status.transaction_state, lime_mesh_upgrade.transaction_states.STARTED) + end) it('test config 2', function() - config.log("pruebaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaa2") + config.log("") end) before_each('', function() - config.log("pruebaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1") uci = test_utils.setup_test_uci() + config.log (uci:set('mesh-upgrade', 'main', "mesh-upgrade")) + uci:save('mesh-upgrade') + uci:commit('mesh-upgrade') end) after_each('', function() - config.log("pruebaaaaaaaaaaaaaaaaaaaaaaaaaa3") - test_utils.teardown_test_uci(uci) end) end) \ No newline at end of file