Skip to content

Commit

Permalink
[fix] Fixed issues in reconnecting to device after firmware upgrade #235
Browse files Browse the repository at this point in the history


Fixes #235
  • Loading branch information
pandafy committed Jun 9, 2023
1 parent 7018e65 commit c88fddf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
22 changes: 22 additions & 0 deletions openwisp_firmware_upgrader/tests/test_openwrt_upgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from time import sleep
from unittest.mock import patch

import swapper
from billiard import Queue
from celery.exceptions import Retry
from django.test import TransactionTestCase
Expand All @@ -21,6 +22,7 @@
from .base import TestUpgraderMixin, spy_mock

DeviceFirmware = load_model('DeviceFirmware')
DeviceConnection = swapper.load_model('connection', 'DeviceConnection')

TEST_CHECKSUM = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'

Expand Down Expand Up @@ -271,6 +273,26 @@ def test_cant_reconnect_on_write_checksum(self, exec_command, putfo, *args):
self.assertIn('Giving up', device_conn.failure_reason)
self.assertTrue(device_conn.last_attempt > start_time)

@patch.object(OpenWrt, '_call_reflash_command')
@patch('scp.SCPClient.putfo')
@patch('paramiko.SSHClient.connect')
@patch.object(OpenWrt, 'RECONNECT_DELAY', 0)
@patch.object(OpenWrt, 'RECONNECT_RETRY_DELAY', 0)
@patch('billiard.Process.is_alive', return_value=True)
@patch.object(OpenWrt, 'exec_command', side_effect=mocked_exec_upgrade_success)
@patch.object(OpenWrtSshConnector, 'upload')
@patch.object(
DeviceConnection,
'get_addresses',
side_effect=[['127.0.0.1'], [], ['127.0.0.1']],
)
def test_device_does_not_have_ip_after_reflash(self, *args):
_, _, upgrade_op, _, _ = self._trigger_upgrade()
self.assertIn(
'No valid IP addresses to initiate connections found', upgrade_op.log
)
self.assertEqual(upgrade_op.status, 'success')

@patch('scp.SCPClient.putfo')
@patch.object(OpenWrt, 'RECONNECT_DELAY', 0)
@patch.object(OpenWrt, 'RECONNECT_RETRY_DELAY', 0)
Expand Down
7 changes: 6 additions & 1 deletion openwisp_firmware_upgrader/upgraders/openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,12 @@ def _write_checksum(self, checksum):
)
try:
self.connect()
except (NoValidConnectionsError, socket.timeout, SSHException) as error:
except (
NoValidConnectionsError,
socket.timeout,
SSHException,
ValueError,
) as error:
self.log(
_(
'Device not reachable yet, ({0}).\n'
Expand Down

0 comments on commit c88fddf

Please sign in to comment.