forked from libremesh/lime-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref_state: implements commons package
- Loading branch information
1 parent
e686037
commit f9054bc
Showing
8 changed files
with
197 additions
and
52 deletions.
There are no files selected for viewing
File renamed without changes.
26 changes: 0 additions & 26 deletions
26
...info/files/usr/share/shared-state/hooks/babel_links_info_ref/shared-state-update_refstate
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...info/files/usr/share/shared-state/hooks/babel_links_info_ref/shared-state-update_refstate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/usr/bin/shared-state-update_refstate |
File renamed without changes.
26 changes: 0 additions & 26 deletions
26
...s_info/files/usr/share/shared-state/hooks/bat_links_info_ref/shared-state-update_refstate
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...s_info/files/usr/share/shared-state/hooks/bat_links_info_ref/shared-state-update_refstate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/usr/bin/shared-state-update_refstate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{ | ||
"LiMe-430b0c": [ | ||
{ | ||
"dst_mac": "02:cc:4e:1f:73:aa", | ||
"last_seen_msecs": 1560, | ||
"tq": 255, | ||
"src_mac": "02:cc:4e:43:0b:0c", | ||
"iface": "wlan2-mesh_29" | ||
}, | ||
{ | ||
"dst_mac": "02:ab:46:1f:73:aa", | ||
"last_seen_msecs": 1000, | ||
"tq": 255, | ||
"src_mac": "02:ab:46:43:0b:0c", | ||
"iface": "wlan1-mesh_29" | ||
}, | ||
{ | ||
"dst_mac": "02:ab:46:dd:69:1c", | ||
"last_seen_msecs": 1670, | ||
"tq": 251, | ||
"src_mac": "02:ab:46:43:0b:0c", | ||
"iface": "wlan1-mesh_29" | ||
} | ||
], | ||
"cheche": [ | ||
{ | ||
"dst_mac": "02:ab:46:dd:69:1c", | ||
"last_seen_msecs": 20, | ||
"tq": 255, | ||
"src_mac": "02:ab:46:1f:73:aa", | ||
"iface": "wlan1-mesh_29" | ||
}, | ||
{ | ||
"dst_mac": "02:ab:46:43:0b:0c", | ||
"last_seen_msecs": 1300, | ||
"tq": 251, | ||
"src_mac": "02:ab:46:1f:73:aa", | ||
"iface": "wlan1-mesh_29" | ||
}, | ||
{ | ||
"dst_mac": "02:cc:4e:43:0b:0c", | ||
"last_seen_msecs": 900, | ||
"tq": 242, | ||
"src_mac": "02:cc:4e:1f:73:aa", | ||
"iface": "wlan2-mesh_29" | ||
}, | ||
{ | ||
"dst_mac": "02:58:47:dd:69:1c", | ||
"last_seen_msecs": 1460, | ||
"tq": 255, | ||
"src_mac": "02:58:47:1f:73:aa", | ||
"iface": "wlan0-mesh_29" | ||
}, | ||
{ | ||
"dst_mac": "02:58:47:1f:73:f6", | ||
"last_seen_msecs": 520, | ||
"tq": 255, | ||
"src_mac": "02:58:47:1f:73:aa", | ||
"iface": "wlan0-mesh_29" | ||
} | ||
], | ||
"konB-11s": [ | ||
{ | ||
"dst_mac": "02:58:47:1f:73:aa", | ||
"last_seen_msecs": 1020, | ||
"tq": 255, | ||
"src_mac": "02:58:47:dd:69:1c", | ||
"iface": "wlan0-mesh_29" | ||
}, | ||
{ | ||
"dst_mac": "02:58:47:1f:73:f6", | ||
"last_seen_msecs": 1010, | ||
"tq": 255, | ||
"src_mac": "02:58:47:dd:69:1c", | ||
"iface": "wlan0-mesh_29" | ||
}, | ||
{ | ||
"dst_mac": "02:ab:46:1f:73:aa", | ||
"last_seen_msecs": 540, | ||
"tq": 235, | ||
"src_mac": "02:ab:46:dd:69:1c", | ||
"iface": "wlan1-mesh_29" | ||
}, | ||
{ | ||
"dst_mac": "02:ab:46:43:0b:0c", | ||
"last_seen_msecs": 1140, | ||
"tq": 255, | ||
"src_mac": "02:ab:46:dd:69:1c", | ||
"iface": "wlan1-mesh_29" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# | ||
# Copyright (C) 2023 Javier Jorge <[email protected]> | ||
# Copyright (c) 2023 Instituto Nacional de Tecnología Industrial | ||
# Copyright (C) 2023 Asociación Civil Altermundi <[email protected]> | ||
# This is free software, licensed under the GNU Affero General Public License v3. | ||
# | ||
|
||
include ../../libremesh.mk | ||
|
||
define Package/$(PKG_NAME) | ||
SECTION:=lime | ||
CATEGORY:=LibreMesh | ||
TITLE:=Common components for refference satate datypes | ||
MAINTAINER:= Javier <[email protected]> | ||
DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \ | ||
+lime-system shared-state-async | ||
PKGARCH:=all | ||
endef | ||
|
||
define Package/$(PKG_NAME)/description | ||
Common components for refference satate datypes | ||
endef | ||
|
||
$(eval $(call BuildPackage,$(PKG_NAME))) |
30 changes: 30 additions & 0 deletions
30
packages/shared-state-ref_sate_commons/files/usr/bin/shared-state-update_refstate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/lua | ||
|
||
--! LibreMesh | ||
--! Copyright (C) 2024 Javier Jorge | ||
--! Copyright (C) 2024 Asociación Civil Altermundi <[email protected]> | ||
--! SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
local JSON = require("luci.jsonc") | ||
local utils = require "lime.utils" | ||
|
||
local ref_file_folder = "/etc/shared-state/ref_state/" | ||
|
||
local input = JSON.parse(io.stdin:read("*all")) | ||
|
||
local data_type = arg[0]:match(".*/([^/]+)/[^/]+$") | ||
|
||
local function write_if_diff(data_type, input) | ||
path = ref_file_folder .. data_type | ||
local acutal = JSON.parse(utils.read_file(path)) | ||
if input[utils.hostname()] then | ||
if not(utils.deepcompare(input[utils.hostname()],acutal or {})) then | ||
utils.write_file(path,JSON.stringify(input[utils.hostname()])) | ||
utils.unsafe_shell("logger -t shared-sate-ref-state "..data_type.." state changed") | ||
return true | ||
end | ||
end | ||
utils.unsafe_shell("logger -t shared-sate-ref-state "..data_type.." state did not change") | ||
return false | ||
end | ||
write_if_diff(data_type,input) |
49 changes: 49 additions & 0 deletions
49
packages/shared-state-ref_sate_commons/tests/test_shared-state_bat_links_ref.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
local utils = require 'lime.utils' | ||
local test_utils = require 'tests.utils' | ||
local JSON = require("luci.jsonc") | ||
local uci = nil | ||
|
||
--package.path = package.path .. ";packages/shared-state-bat_links_info/files/usr/share/shared-state/hooks/bat_links_info_ref/?;;" | ||
--require ("shared-state-update_refstate") | ||
|
||
|
||
|
||
describe('bat links ref state tests', function() | ||
|
||
it('test obj store', function() | ||
local function write_if_diff(data_type, input) | ||
path = ref_file_folder .. data_type | ||
local acutal = JSON.parse(utils.read_file(path)) | ||
if input[utils.hostname()] then | ||
if not(utils.deepcompare(input[utils.hostname()],acutal or {})) then | ||
utils.write_file(path,JSON.stringify(input[utils.hostname()])) | ||
utils.unsafe_shell("logger -t shared-sate-ref-state "..data_type.." state changed") | ||
return true | ||
end | ||
end | ||
utils.unsafe_shell("logger -t shared-sate-ref-state "..data_type.." state did not change") | ||
return false | ||
end | ||
|
||
local test_dir = test_utils.setup_test_dir() | ||
local testfile = test_dir .. 'mydata' | ||
assert.is.same({}, utils.read_obj_store(testfile)) | ||
|
||
local input=JSON.parse(utils.read_file("packages/shared-state-bat_links_info/tests/sample.json")) | ||
assert.is_true (write_if_diff(testfile,input)) | ||
assert.is_false (write_if_diff(testfile,input)) | ||
|
||
end) | ||
|
||
before_each('', function() | ||
uci = test_utils.setup_test_uci() | ||
stub(utils, "hostname", function () return "cheche" end) | ||
|
||
end) | ||
|
||
after_each('', function() | ||
test_utils.teardown_test_uci(uci) | ||
test_utils.teardown_test_dir() | ||
end) | ||
|
||
end) |