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

[Unittesting P6] Add fake device support and lime-config test #567

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions packages/lime-system/files/usr/bin/lime-config
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,6 @@ function getopt( arg, options )
return tab
end

function main()
config.sanitize()

local modules_name = { "hardware_detection", "wireless", "network", "firewall", "system" }
local modules = {}

for i, name in pairs(modules_name) do modules[i] = require("lime."..name) end
for _,module in pairs(modules) do
xpcall(module.clean, function(errmsg) print(errmsg) ; print(debug.traceback()) end)
end

for _,module in pairs(modules) do
xpcall(module.configure, function(errmsg) print(errmsg) ; print(debug.traceback()) end)
end

local hooksDir = "/etc/hotplug.d/lime-config"
for hook in fs.dir(hooksDir) do
local hookCmd = hooksDir.."/"..hook.." after"
print("executed hook:", hookCmd, os.execute(hookCmd))
end
end


local lockFilePath = "/var/run/lime-config.pid"
local lockFile = io.open(lockFilePath,"r")
if lockFile then
Expand All @@ -79,7 +56,7 @@ else
os.remove("/etc/config/lime")
end

main()
config.main()

--! using --no-commit doesn't guarantee filesystem will not be changed
--! mainly because many config files are not uci-based
Expand Down
22 changes: 22 additions & 0 deletions packages/lime-system/files/usr/lib/lua/lime/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
--! stuff that affects parrallels database, at moment we don't need parallelism
--! as this is just some configuration stuff and is not performance critical.

local fs = require("nixio.fs")
local libuci = require("uci")

config = {}
Expand All @@ -14,6 +15,7 @@ function config.log(...)
end

config.uci = nil
config.hooksDir = "/etc/hotplug.d/lime-config"

function config.get_uci_cursor()
if config.uci == nil then
Expand Down Expand Up @@ -126,5 +128,25 @@ function config.autogenerable(section_name)
return ( (not config.get_all(section_name)) or config.get_bool(section_name, "autogenerated") )
end

function config.main()
config.sanitize()

local modules_name = { "hardware_detection", "wireless", "network", "firewall", "system" }
local modules = {}

for i, name in pairs(modules_name) do modules[i] = require("lime."..name) end
for _,module in pairs(modules) do
xpcall(module.clean, function(errmsg) print(errmsg) ; print(debug.traceback()) end)
end

for _,module in pairs(modules) do
xpcall(module.configure, function(errmsg) print(errmsg) ; print(debug.traceback()) end)
end

for hook in fs.dir(config.hooksDir) do
local hookCmd = config.hooksDir.."/"..hook.." after"
print("executed hook:", hookCmd, os.execute(hookCmd))
end
end

return config
31 changes: 18 additions & 13 deletions packages/lime-system/files/usr/lib/lua/lime/hardware_detection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@ local fs = require("nixio.fs")
local utils = require("lime.utils")


hardware_detection = {}
local hardware_detection = {}

hardware_detection.sectionNamePrefix="lm_hwd_"
hardware_detection.sectionNamePrefix = "lm_hwd_"
hardware_detection.search_paths = {"/usr/lib/lua/lime/hwd/*.lua"}

--! Hardware detection module clean()
--! Call clean() from all installed submodules
function hardware_detection.clean()
for hwd_module_path in fs.glob("/usr/lib/lua/lime/hwd/*.lua") do
local module_name = "lime.hwd." .. fs.basename(hwd_module_path):sub(1,-5)
if utils.isModuleAvailable(module_name) then
require(module_name).clean()
end
end
for _,search_path in ipairs(hardware_detection.search_paths) do
for hwd_module_path in fs.glob(search_path) do
local module_name = "lime.hwd." .. fs.basename(hwd_module_path):sub(1,-5)
if utils.isModuleAvailable(module_name) then
require(module_name).clean()
end
end
end
end

--! Hardware detection module configure()
--! Call detect_hardware() from all installed submodules
function hardware_detection.configure()
for hwd_module_path in fs.glob("/usr/lib/lua/lime/hwd/*.lua") do
local module_name = "lime.hwd." .. fs.basename(hwd_module_path):sub(1,-5)
if utils.isModuleAvailable(module_name) then
require(module_name).detect_hardware()
end
for _,search_path in ipairs(hardware_detection.search_paths) do
for hwd_module_path in fs.glob(search_path) do
local module_name = "lime.hwd." .. fs.basename(hwd_module_path):sub(1,-5)
if utils.isModuleAvailable(module_name) then
require(module_name).detect_hardware()
end
end
end
end

Expand Down
53 changes: 53 additions & 0 deletions tests/devices/librerouter-v1/board.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

isn't this file available somewhere already? can find the same one in the /etc/board.json of the librerouters...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This files is created on first boot by /bin/board_detect that I think is run by /etc/preinit that is run by procd. /etc/board.json is created with information gathered mostly by /etc/board.d/02_network so the way the information is stored on the code is in bash form.

Copy link
Member

Choose a reason for hiding this comment

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

So we can't get it from there for the tests then? (just thinking on deduplicating it because of the implications on maintenance...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure to be understanding your question. You mean from inside a LinbreRouter? Yes that is what I did (I copied the board.json file and the other two files, network and wireless) and that is what I think we should do for other devices too. I don't think there is an online database of this files so we don't have to do it. If we want to have this kind of integration test "with device emulation" then I don't think we have other options, or maybe I am not seeing it?

Copy link
Member

Choose a reason for hiding this comment

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

I mean getting that information from where it comes instead of hardcoding it...
don't worry, it is a lower priority thing. important to keep an eye on deduplication, but certainly not urgent

"model" : {
"id" : "librerouter-v1",
"name" : "LibreRouter v1"
},
"network" : {
"lan" : {
"ifname" : "eth1.2",
"protocol" : "static"
},
"wan" : {
"ifname" : "eth0.1",
"protocol" : "dhcp"
}
},
"switch" : {
"switch0" : {
"enable" : true,
"reset" : true,
"ports" : [
{
"num" : 0,
"device" : "eth0",
"need_tag" : false,
"want_untag" : false
},
{"num" : 5, "role" : "wan"},
{
"num" : 6,
"device" : "eth1",
"need_tag" : false,
"want_untag" : false
},
{"num" : 1, "role" : "lan"},
{"num" : 2, "role" : "lan"},
{"num" : 3, "role" : "lan"},
{"num" : 4, "role" : "lan"},
],
"roles" : [
{
"role" : "wan",
"ports" : "5 0t",
"device" : "eth0.1"
},
{
"role" : "lan",
"ports" : "1 2 3 4 6t",
"device" : "eth1.2"
}
]
}
}
}
39 changes: 39 additions & 0 deletions tests/devices/librerouter-v1/uci_config_network
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
config interface 'loopback'
spiccinini marked this conversation as resolved.
Show resolved Hide resolved
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'

config globals 'globals'
option ula_prefix 'auto'

config interface 'lan'
option type 'bridge'
option ifname 'eth1.2'
option proto 'static'
option ipaddr '192.168.1.1'
option netmask '255.255.255.0'
option ip6assign '60'

config interface 'wan'
option ifname 'eth0.1'
option proto 'dhcp'

config interface 'wan6'
option ifname 'eth0.1'
option proto 'dhcpv6'

config switch
option name 'switch0'
option reset '1'
option enable_vlan '1'

config switch_vlan
option device 'switch0'
option vlan '1'
option ports '5 0t'

config switch_vlan
option device 'switch0'
option vlan '2'
option ports '1 2 3 4 6t'
45 changes: 45 additions & 0 deletions tests/devices/librerouter-v1/uci_config_wireless
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
config wifi-device 'radio0'
option type 'mac80211'
option channel '11'
option hwmode '11g'
option path 'platform/qca955x_wmac'
option htmode 'HT20'
option disabled '1'

config wifi-iface 'default_radio0'
option device 'radio0'
option network 'lan'
option mode 'ap'
option ssid 'OpenWrt'
option encryption 'none'

config wifi-device 'radio1'
option type 'mac80211'
option channel '36'
option hwmode '11a'
option path 'pci0000:00/0000:00:00.0'
option htmode 'HT20'
option disabled '1'

config wifi-iface 'default_radio1'
option device 'radio1'
option network 'lan'
option mode 'ap'
option ssid 'OpenWrt'
option encryption 'none'

config wifi-device 'radio2'
option type 'mac80211'
option channel '36'
option hwmode '11a'
option path 'pci0000:01/0000:01:00.0'
option htmode 'HT20'
option disabled '1'

config wifi-iface 'default_radio2'
option device 'radio2'
option network 'lan'
option mode 'ap'
option ssid 'OpenWrt'
option encryption 'none'