Skip to content

Commit 30ee01d

Browse files
devkapilbansalnemesifier
authored andcommitted
[test] Writing tests for store and restore uci config
1 parent c735913 commit 30ee01d

5 files changed

Lines changed: 76 additions & 2 deletions

File tree

160 Bytes
Binary file not shown.

openwisp-config/tests/test_update_config.lua

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ TestUpdateConfig = {
2222
-- this file is pre-existing on the device
2323
os.execute('cp ./update/system '..config_dir..'system')
2424
os.execute('cp ./update/network '..config_dir..'network')
25+
os.execute('cp ./update/wireless '..config_dir..'wireless')
2526
-- we expect these UCI files to be removed
27+
os.execute('cp ./config/wireless-autoname '..remote_config_dir..'/wireless-autoname')
2628
os.execute('cp ./wifi/wireless '..remote_config_dir..'/wireless')
29+
-- this file will be overwrited by stored configuration and new configuration
2730
os.execute('cp ./wifi/wireless '..config_dir..'/wireless')
2831
-- we expect this file to be stored
2932
os.execute('echo original > '..write_dir..'/etc/existing')
@@ -34,6 +37,9 @@ TestUpdateConfig = {
3437
os.execute('mkdir -p ' .. openwisp_dir .. 'stored/etc/')
3538
os.execute('echo restore-me > '..openwisp_dir..'/stored/etc/restore-me')
3639
os.execute('echo /etc/restore-me > '..openwisp_dir..'/modified.list')
40+
-- this file is stored in the backup
41+
os.execute('mkdir -p ' .. openwisp_dir ..'etc/config/')
42+
os.execute("cp ./update/stored_wireless " ..openwisp_dir.. '/etc/config/wireless')
3743
end,
3844
tearDown = function()
3945
os.execute('rm -rf ' .. write_dir)
@@ -74,8 +80,30 @@ function TestUpdateConfig.test_update()
7480
local addedListContents = addedListFile:read('*all')
7581
luaunit.assertEquals(addedListContents, '/etc/test\n')
7682
-- ensure files are removed
77-
luaunit.assertNil(io.open(config_dir..'/wireless'))
78-
luaunit.assertNil(io.open(remote_config_dir..'/wireless'))
83+
luaunit.assertNil(io.open(config_dir..'/wireless-autoname'))
84+
luaunit.assertNil(io.open(remote_config_dir..'/wireless-autoname'))
85+
-- ensure file is not removed
86+
luaunit.assertNotNil(io.open(remote_config_dir..'/wireless'))
87+
-- ensure configuration is restored
88+
local wirelessFile = io.open(config_dir..'/wireless')
89+
luaunit.assertNotNil(wirelessFile)
90+
local wirelessContents = wirelessFile:read('*all')
91+
-- ensure device radio0 is stored from backup
92+
luaunit.assertNotNil(string.find(wirelessContents, "config wifi-device 'radio0'", 1, true))
93+
luaunit.assertNotNil(string.find(wirelessContents, "option path 'platform/ar934x_wmac'"))
94+
luaunit.assertNotNil(string.find(wirelessContents, "option channel '9'"))
95+
-- ensure device radio1 is removed as it is neither in backup nor in new configuration
96+
luaunit.assertNil(string.find(wirelessContents, "config wifi-device 'radio1'"))
97+
-- ensure device radio3 options are updated
98+
luaunit.assertNotNil(string.find(wirelessContents, "config wifi-device 'radio3'", 1, true))
99+
-- ensure channel is stored from backup
100+
luaunit.assertNotNil(string.find(wirelessContents, "option channel '14'"))
101+
-- ensure country value is used from new configuration
102+
luaunit.assertNotNil(string.find(wirelessContents, "option country 'IT'"))
103+
-- ensure hwmode is not stored as not available in remote config
104+
luaunit.assertNil(string.find(wirelessContents, "option hwmode '11h'"))
105+
-- ensure path has been removed
106+
luaunit.assertNil(string.find(wirelessContents, "option path 'pci0000:00/0000:00:1c.2/0000:05:00.0'"))
79107
-- ensure existing original file has been stored
80108
local modifiedListFile = io.open(openwisp_dir .. '/modified.list')
81109
luaunit.assertNotNil(modifiedListFile)
@@ -94,6 +122,16 @@ function TestUpdateConfig.test_update()
94122
luaunit.assertNotNil(restoreFile)
95123
luaunit.assertEquals(restoreFile:read('*all'), 'restore-me\n')
96124
luaunit.assertNil(io.open(openwisp_dir..'/stored/etc/restore-me'))
125+
-- ensure network configuration file is backed up
126+
local storedNetworkFile = io.open(openwisp_dir .. '/etc/config/network')
127+
luaunit.assertNotNil(storedNetworkFile)
128+
local initialNetworkFile = io.open('update/network')
129+
luaunit.assertEquals(storedNetworkFile:read('*all'), initialNetworkFile:read('*all'))
130+
-- ensure system configuration file is backed up
131+
local storedSystemFile = io.open(openwisp_dir .. '/etc/config/system')
132+
luaunit.assertNotNil(storedSystemFile)
133+
local initialSystemFile = io.open('update/system')
134+
luaunit.assertEquals(storedSystemFile:read('*all'), initialSystemFile:read('*all'))
97135
end
98136

99137
function TestUpdateConfig.test_update_conf_arg()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
config wifi-device 'radio0'
2+
option path 'platform/ar934x_wmac'
3+
option disabled '1'
4+
option country 'IT'
5+
option phy 'phy0'
6+
option hwmode '11g'
7+
option channel '9'
8+
option type 'mac80211'
9+
option htmode 'HT20'
10+
11+
config wifi-device 'radio3'
12+
option hwmode '11a'
13+
option channel '14'
14+
option country 'IN'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
config wifi-device 'radio1'
2+
option path 'pci0000:00/0000:00:00.0'
3+
option disabled '1'
4+
option country 'IT'
5+
option phy 'phy1'
6+
option hwmode '11a'
7+
option channel '48'
8+
option type 'mac80211'
9+
option htmode 'HT20'
10+
11+
config wifi-device 'radio3'
12+
option channel '9'
13+
option country 'IT'
14+
option disabled '1'
15+
option htmode 'HT20'
16+
option hwmode '11h'
17+
option path 'pci0000:00/0000:00:1c.2/0000:05:00.0'
18+
option phy 'phy0'
19+
option type 'mac80211'

openwisp-config/tests/wifi/wireless

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ config wifi-device 'radio1'
1818
option type 'mac80211'
1919
option htmode 'HT20'
2020

21+
config wifi-device 'radio3'
22+
option channel '13'
23+
2124
config wifi-iface
2225
option ssid 'LEDE'
2326
option encryption 'none'

0 commit comments

Comments
 (0)