diff options
author | Ted Trask <ttrask01@yahoo.com> | 2015-12-28 16:09:52 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2015-12-28 16:09:52 +0000 |
commit | 0e9d6d88d375f3ef9226ee053db819d671582e24 (patch) | |
tree | a88f0a2c567e148292b200e97343207e275db0e7 | |
parent | f91deac776293158454217d3437762576e30d3a7 (diff) | |
download | acf-provisioning-0e9d6d88d375f3ef9226ee053db819d671582e24.tar.bz2 acf-provisioning-0e9d6d88d375f3ef9226ee053db819d671582e24.tar.xz |
Modify update_device to also validate device params (this causes update_device_params.lua to be called before update_device.lua)
-rw-r--r-- | config/update_device.lua | 16 | ||||
-rw-r--r-- | provisioning-model.lua | 12 |
2 files changed, 10 insertions, 18 deletions
diff --git a/config/update_device.lua b/config/update_device.lua index b4334cd..cd5dda5 100644 --- a/config/update_device.lua +++ b/config/update_device.lua @@ -3,18 +3,4 @@ local functions, device, olddevice, params, oldparams = ... --functions.logevent("got to update_device script") --- We'll handle the changing of the device by handling the resulting changing of the params -local f -local env = {} -setmetatable (env, {__index = _G}) -local IS_52_LOAD = pcall(load, '') -if IS_52_LOAD then - f = loadfile("/etc/provisioning/update_device_params.lua", "bt", env) -else - -- loadfile loads into the global environment - -- so we set env 0, not env 1 - setfenv (0, env) - f = loadfile("/etc/provisioning/update_device_params.lua") - setfenv (0, _G) -end -if (f) then f(functions, params, oldparams) end +-- The resulting changing of the params has already been handled, so nothing to do here diff --git a/provisioning-model.lua b/provisioning-model.lua index 3c4dfe7..2c54619 100644 --- a/provisioning-model.lua +++ b/provisioning-model.lua @@ -1257,7 +1257,7 @@ mymodule.update_group = function(self, group, action, create) -- Update the devices after databasedisconnect so device failure doesn't rollback the change if success then - -- Notify the devices that their params might have changed + -- Notify the devices that their params might have changed (this will also validate) for i,d in ipairs(devices) do local r = set_device_params(get_device_params(d.device_id, false), false) if r.errtxt then self.logevent("Failed to update params for device "..d.device_id..": "..r.errtxt) end @@ -1442,7 +1442,7 @@ mymodule.update_param = function(self, param, action, create) -- Update the devices after databasedisconnect so device failure doesn't rollback the change if success then - -- Notify the devices that their params might have changed + -- Notify the devices that their params might have changed (this will also validate) for i,d in ipairs(devices) do local r = set_device_params(get_device_params(d.device_id, false), false) if r.errtxt then self.logevent("Failed to update params for device "..d.device_id..": "..r.errtxt) end @@ -1648,8 +1648,14 @@ mymodule.update_device = function(self, device, action, create) end end + -- Notify the device that its params might have changed (this will also validate) local s = saved_device_params[device.value.device_id.value] - callscript(updatedevicescriptfile, device, saved_devices[device.value.device_id.value], get_device_params(device.value.device_id.value), s) + local r = set_device_params(get_device_params(device.value.device_id.value, false), false) + if r.errtxt then + error(r:print_errtxt()) + end + + callscript(updatedevicescriptfile, device, saved_devices[device.value.device_id.value], r, s) saved_devices[device.value.device_id.value] = device end |