Skip to content

Commit ab624de

Browse files
committed
[FIX] hw_drivers: drivers deleted on bad response
Before this commit, if the IoT box was connected a DB which then went offline (e.g. expired runbot), and it tried to download drivers, the request would fail but it would still delete the old handlers. After this commit, we avoid this problem in two ways. Firstly, we check that we received an OK HTTP status before trying to process the response body. Secondly, we check that the reponse we have received is a valid zip file BEFORE deleting the old handlers. This way we only delete them if we are sure we have something to replace them with. task-4933638 closes odoo#218661 X-original-commit: 63d5ab8 Signed-off-by: Max Whale (mawh) <mawh@odoo.com> Signed-off-by: Yaroslav Soroko (yaso) <yaso@odoo.com>
1 parent 143ad2e commit ab624de

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

addons/hw_drivers/tools/helpers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,17 @@ def download_iot_handlers(auto=True):
446446
server = server + '/iot/get_handlers'
447447
try:
448448
resp = pm.request('POST', server, fields={'mac': get_mac_address(), 'auto': auto}, timeout=8)
449+
if resp.status != 200:
450+
_logger.error('Bad IoT handlers response received: status %s', resp.status)
451+
return
449452
if resp.data:
453+
zip_file = zipfile.ZipFile(io.BytesIO(resp.data))
450454
delete_iot_handlers()
455+
path = path_file('odoo', 'addons', 'hw_drivers', 'iot_handlers')
451456
with writable():
452-
path = path_file('odoo', 'addons', 'hw_drivers', 'iot_handlers')
453-
zip_file = zipfile.ZipFile(io.BytesIO(resp.data))
454457
zip_file.extractall(path)
458+
except zipfile.BadZipFile:
459+
_logger.exception('Bad IoT handlers response received: not a zip file')
455460
except Exception:
456461
_logger.exception('Could not reach configured server to download IoT handlers')
457462

0 commit comments

Comments
 (0)