Skip to content

Commit

Permalink
[change] Handle autonaming of network devices #199
Browse files Browse the repository at this point in the history
Maintain consistency with the naming used on OpenWISP.

Closes #199
  • Loading branch information
nemesifier committed May 25, 2024
1 parent 9ad45d9 commit 985f300
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openwisp-config/files/sbin/openwisp-uci-autoname.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ for file in lfs.dir(standard_path) do
new_name = 'defaults'
elseif file == 'network' and section['.type'] == 'globals' then
new_name = 'globals'
elseif file == 'network' and section['.type'] == 'device' then
new_name = 'device_' .. section['name']:gsub('br%-', '')
elseif file == 'network' and
(section['.type'] == 'route' or section['.type'] == 'route6') then
new_name = nextAvailableName('route')
Expand Down
9 changes: 9 additions & 0 deletions openwisp-config/tests/config/network
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ config interface 'wan'
option proto 'none'
option test_restore '1'

config device
option name 'br-lan2'
list ports 'lan2'
option type 'bridge'

config interface 'lan2'
option device 'br-lan2'
option proto 'dhcp'

config interface 'wlan0'
option ifname 'wlan0'
list ipaddr '172.27.254.251/16'
Expand Down
2 changes: 2 additions & 0 deletions openwisp-config/tests/test_uci_autoname.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function TestUciAutoname.test_default_behaviour()
luaunit.assertNotNil(string.find(networkContents,
"config switch_port 'switch0_port1"))
luaunit.assertNotNil(string.find(networkContents, "config globals 'globals"))
luaunit.assertNotNil(string.find(networkContents,
"config device 'device_lan2"))
luaunit.assertNotNil(string.find(networkContents, "config route 'route1"))
luaunit.assertNotNil(string.find(networkContents, "config route 'route2"))
-- ensure rest of config options are present
Expand Down

0 comments on commit 985f300

Please sign in to comment.