Skip to content

Commit c21ce16

Browse files
committed
[fix] Skip connection check when firmware image unchanged
1 parent 9cd4f01 commit c21ce16

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

openwisp_firmware_upgrader/base/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def clean(self):
409409
)
410410
}
411411
)
412-
if self.device.deviceconnection_set.count() < 1:
412+
if self.image_has_changed and self.device.deviceconnection_set.count() < 1:
413413
raise ValidationError(
414414
_(
415415
"This device does not have a related connection object defined "

openwisp_firmware_upgrader/tests/test_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ def test_device_firmware_detail_400(self):
13091309

13101310
with self.subTest("Test device and image model validation"):
13111311
url = reverse("upgrader:api_devicefirmware_detail", args=[device1.pk])
1312-
with self.assertNumQueries(18):
1312+
with self.assertNumQueries(17):
13131313
# Try to make a request when the
13141314
# device model does not match the image model
13151315
data = {"image": image1a.pk}
@@ -1490,7 +1490,7 @@ def test_device_firmware_detail_update(self):
14901490
self.assertEqual(DeviceFirmware.objects.count(), 2)
14911491
self.assertEqual(UpgradeOperation.objects.count(), 0)
14921492

1493-
with self.assertNumQueries(27):
1493+
with self.assertNumQueries(26):
14941494
data = {"image": image2a.pk}
14951495
r = self.client.put(
14961496
f"{url}?format=api", data, content_type="application/json"
@@ -1529,7 +1529,7 @@ def test_device_firmware_detail_partial_update(self):
15291529
self.assertEqual(DeviceFirmware.objects.count(), 2)
15301530
self.assertEqual(UpgradeOperation.objects.count(), 0)
15311531

1532-
with self.assertNumQueries(27):
1532+
with self.assertNumQueries(26):
15331533
data = {"image": image2a.pk}
15341534
r = self.client.patch(
15351535
f"{url}?format=api", data, content_type="application/json"

openwisp_firmware_upgrader/tests/test_models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,14 @@ def test_device_fw_no_connection(self):
177177
else:
178178
self.fail("ValidationError not raised")
179179

180-
def test_device_fw_credentials_removed_after_assignment(self):
180+
def test_device_fw_save_after_credentials_removed(self):
181181
"""Regression test for #250."""
182182
device_fw = self._create_device_firmware()
183-
device_fw.upgrade_options = {"n": True}
184183
device_fw.device.deviceconnection_set.all().delete()
185-
with self.assertRaises(ValidationError) as ctx:
186-
device_fw.full_clean()
187-
self.assertIn("connection", str(ctx.exception).lower())
184+
device_fw.full_clean()
185+
uo_count = UpgradeOperation.objects.count()
186+
device_fw.save(upgrade=False)
187+
self.assertEqual(UpgradeOperation.objects.count(), uo_count)
188188

189189
def test_invalid_board(self):
190190
image = FIRMWARE_IMAGE_MAP[self.TPLINK_4300_IMAGE]

0 commit comments

Comments
 (0)