Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrared state Async ubus interface #1086

Merged
merged 8 commits into from
Mar 15, 2024

Conversation

javierbrk
Copy link
Collaborator

@javierbrk javierbrk commented Feb 19, 2024

This pull request adds shrare-state-async ubus interface. Get method returns sharedstate "get" json data or reported error in case no json is found. Errors are bubbled up as they come from sharedstate inside a json structure with the name "error".

Since there is no Shared State async binary available in the testing environment, testing possibilities are reduced. Manual testing can be done on a router with bat-hosts package using this commands:

Get bat-hosts

# ubus -S call shared-state-async get "{'data_type': 'bat-hosts'}"
{"a8:40:41:1f:73:ab":"lrsegundo_eth1_2","02:95:39:1f:73:aa":"lrsegundo_eth0_250","a8:40:41:1c:85:c3":"lrsegundo_wlan2_mesh","a8:40:41:1c:85:16":"lrsegundo_wlan1_mesh","02:bb:ed:1f:73:aa":"lrsegundo_eth1_250","a8:40:41:1f:73:a8":"lrsegundo_wlan0_ap","aa:40:41:1f:73:a8":"lrsegundo_wlan0_apname","02:db:d6:1f:73:aa":"lrsegundo_eth0_1_250","02:29:0f:1f:73:aa":"lrsegundo_eth1_2_250","c2:10:20:5e:7f:b3":"lrsegundo_bat0","a8:40:41:1f:73:aa":"lrsegundo_eth0"}

Get an invalid data type

# ubus -S call shared-state-async get "{'data_type': 'bat-hosss'}"
{"error":53248}

Sync valid data type

# ubus -S call shared-state-async sync "{'data_type': 'bat-hosts'}"
{"error":0}

Sync invalid data type

ubus -S call shared-state-async sync "{'data_type': 'bat-hoss' }"
{"error":53248}

Sync valid data type with unreachable ipv4 addresses

# ubus -S call shared-state-async sync "{'data_type': 'bat-hosts' ,'peers_ip':['10.0.0.1','10.0.0.2']}'"
{"error":32768}

Sync valid data type with invalid ipv4 address

# ubus -S call shared-state-async sync "{'data_type': 'bat-hosts' ,'peers_ip':['10.0.0.1','10.0.2']}'"
{"error":61952}

Sync invalid data type with specified ipv4 address

ubus -S call shared-state-async sync "{'data_type': 'bat-hosdts' ,'peers_ip':['127.0.0.1','127.0.0.1']}'"
{"error":53248}

Sync valid data type with reachable ipv4 addresses

# ubus -S call shared-state-async sync "{'data_type': 'bat-hosts' ,'peers_ip':['127.0.0.1','127.0.0.1']}'"
{"error":0}

}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing new line at the end of file

Copy link
Member

@G10h4ck G10h4ck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my inline comments

@@ -0,0 +1,15 @@
{
"lime-app": {
"description": "lime-app public access",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we explicitely mention lime-app here? other components could benefit to access shared-state-async via ubus too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While logged in via ssh, you have direct, full access to ubus. This file is to enable lime app to use it. other users should enable other profiles.


local ERROR_LOG_FILE_NAME = "/tmp/shared_state_rpcd_error.log"

local function parseErrors()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way of handling errors doesn't seems robust to me :-/, what if a few calls are performed in parallel and some fails and some not?
shared-state-async command return the error code to the calling shell if some error happens, in that case the error should be bubbled up without more parsing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this prove too cumbersome to do in Lua, consider rewriting the whole ubus plugin using ucode, or ash which are supported by default by OpenWrt

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit e891527 implements a new way of handling, what do you think?

@G10h4ck G10h4ck added this to the mesh-wide milestone Feb 21, 2024
@codecov-commenter
Copy link

codecov-commenter commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 79.64%. Comparing base (63242c2) to head (5336c53).
Report is 44 commits behind head on master.

❗ Current head 5336c53 differs from pull request most recent head 5356cbd. Consider uploading reports for the commit 5356cbd to get more accurate results

Files Patch % Lines
...s/lime-system/files/usr/lib/lua/lime/proto/lan.lua 87.50% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1086      +/-   ##
==========================================
+ Coverage   79.55%   79.64%   +0.08%     
==========================================
  Files          53       53              
  Lines        4564     4579      +15     
==========================================
+ Hits         3631     3647      +16     
+ Misses        933      932       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

local function get(msg)
local error = os.execute("shared-state-async get " ..
msg.data_type .. " 2>/dev/null ")
utils.printJson({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That the error get printed only on failure happens implicitely, please add at least a comment documentig this behaviour, so we cna understand what's happening when we look at this code in a few months or years ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ! it is a weird behavior that gives a lot of headaches. Any output that is printed in the console is used as output. If its a json everything goes fine, if it is not a json you get "invalid input" as a response.

@G10h4ck G10h4ck merged commit d3d2086 into libremesh:master Mar 15, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants