@@ -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' ))
97135end
98136
99137function TestUpdateConfig .test_update_conf_arg ()
0 commit comments