Merge pull request #46 from flatcar-linux/kai/flatcar-build-2387.0.0-pick

Pick commits from flatcar-master for alpha branch
This commit is contained in:
Kai Lüke 2020-01-21 13:45:09 +01:00 committed by GitHub
commit b085b38ef4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ import re
import subprocess
import sys
import tempfile
import time
import uuid
# First sector we can use.
@ -433,11 +434,22 @@ def FormatFat(part, device):
def PartitionLoop(options, partition):
"""Allocate (and automatically free) loop devices for a partition."""
loop_dev = subprocess.check_output(['sudo', 'losetup',
'--offset', str(partition['first_byte']),
'--sizelimit', str(partition['bytes']),
'--find', '--show', options.disk_image])
loop_dev = loop_dev.strip()
for i in range(0,5):
try:
loop_dev = subprocess.check_output(['sudo', 'losetup',
'--offset', str(partition['first_byte']),
'--sizelimit', str(partition['bytes']),
'--find', '--show', options.disk_image])
loop_dev = loop_dev.strip()
err = None
break
except subprocess.CalledProcessError as error:
print("Failed to set up loopback, attempt %d" % i)
err = error
time.sleep(5)
if err is not None:
raise err
try:
yield loop_dev
@ -586,9 +598,22 @@ def Mount(options):
mount_opts.append('subvol=%s' % mount['fs_subvolume'])
Sudo(['mkdir', '-p', full_path])
Sudo(['mount', '-t', mount.get('fs_type', 'auto'),
'-o', ','.join(mount_opts),
options.disk_image, full_path])
# This tends to fail, retry if it does
err = None
for i in range(0,5):
try:
Sudo(['mount', '-t', mount.get('fs_type', 'auto'),
'-o', ','.join(mount_opts),
options.disk_image, full_path])
err = None
break
except subprocess.CalledProcessError as e:
print("Error mounting %s, attempt %d" % (full_path, i))
err = e
time.sleep(5)
if err is not None:
raise err
for src, dst in mount.get('binds', {}).iteritems():
# src may be relative or absolute, os.path.join handles this.