[FIX] hw_drivers: Don't crash if remount fails

We sometimes encountered IoT Boxes crashing because the remount failed.
As this isn't a big issue, we won't check the return value of the call
to `mount`.

closes odoo/odoo#59438

X-original-commit: 5f9874da0f5f5b27c546cd248d08299f0e65544b
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
This commit is contained in:
Antoine Prieels
2020-10-07 15:44:11 +00:00
parent 0c6d8ecfaf
commit 2f7f9095d7
+17 -17
View File
@@ -93,14 +93,14 @@ def check_git_branch():
local_branch = subprocess.check_output(git + ['symbolic-ref', '-q', '--short', 'HEAD']).decode('utf-8').rstrip()
if db_branch != local_branch:
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"])
subprocess.call(["sudo", "mount", "-o", "remount,rw", "/"])
subprocess.check_call(["rm", "-rf", "/home/pi/odoo/addons/hw_drivers/iot_handlers/drivers/*"])
subprocess.check_call(["rm", "-rf", "/home/pi/odoo/addons/hw_drivers/iot_handlers/interfaces/*"])
subprocess.check_call(git + ['branch', '-m', db_branch])
subprocess.check_call(git + ['remote', 'set-branches', 'origin', db_branch])
os.system('/home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/posbox_update.sh')
subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"])
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"])
subprocess.call(["sudo", "mount", "-o", "remount,ro", "/"])
subprocess.call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"])
except Exception as e:
_logger.error('Could not reach configured server')
@@ -200,15 +200,15 @@ def load_certificate():
result = json.loads(response.data.decode('utf8'))['result']
if result:
write_file('odoo-subject.conf', result['subject_cn'])
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"])
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/"])
subprocess.call(["sudo", "mount", "-o", "remount,rw", "/"])
subprocess.call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/"])
Path('/etc/ssl/certs/nginx-cert.crt').write_text(result['x509_pem'])
Path('/root_bypass_ramdisks/etc/ssl/certs/nginx-cert.crt').write_text(result['x509_pem'])
Path('/etc/ssl/private/nginx-cert.key').write_text(result['private_key_pem'])
Path('/root_bypass_ramdisks/etc/ssl/private/nginx-cert.key').write_text(result['private_key_pem'])
subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"])
subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/root_bypass_ramdisks/"])
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"])
subprocess.call(["sudo", "mount", "-o", "remount,ro", "/"])
subprocess.call(["sudo", "mount", "-o", "remount,ro", "/root_bypass_ramdisks/"])
subprocess.call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"])
subprocess.check_call(["sudo", "service", "nginx", "restart"])
def download_iot_handlers(auto=True):
@@ -223,12 +223,12 @@ def download_iot_handlers(auto=True):
try:
resp = pm.request('POST', server, fields={'mac': get_mac_address(), 'auto': auto})
if resp.data:
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"])
subprocess.call(["sudo", "mount", "-o", "remount,rw", "/"])
drivers_path = Path.home() / 'odoo/addons/hw_drivers/iot_handlers'
zip_file = zipfile.ZipFile(io.BytesIO(resp.data))
zip_file.extractall(drivers_path)
subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"])
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"])
subprocess.call(["sudo", "mount", "-o", "remount,ro", "/"])
subprocess.call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"])
except Exception as e:
_logger.error('Could not reach configured server')
_logger.error('A error encountered : %s ' % e)
@@ -264,16 +264,16 @@ def read_file_first_line(filename):
return ''
def unlink_file(filename):
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"])
subprocess.call(["sudo", "mount", "-o", "remount,rw", "/"])
path = Path.home() / filename
if path.exists():
path.unlink()
subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"])
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"])
subprocess.call(["sudo", "mount", "-o", "remount,ro", "/"])
subprocess.call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"])
def write_file(filename, text):
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"])
subprocess.call(["sudo", "mount", "-o", "remount,rw", "/"])
path = Path.home() / filename
path.write_text(text)
subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"])
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"])
subprocess.call(["sudo", "mount", "-o", "remount,ro", "/"])
subprocess.call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"])