Commit 02e831ba authored by rgaudin's avatar rgaudin
Browse files

Fixed #204: once process is completed, a random 4MiB are read from image and card and compared

parent c2f22eb2
......@@ -7,6 +7,9 @@
* Load/Save JSON always from the Home folder
* Admin Account now mandatory (not switch) with convenient defaults
* Fixed Windows 64b builds not being 64b
* CLI inputs checked before process starts
* Admin login/password not displayed in Logger nor kept in logs
* SD card checked after copy to ensure content was written
2.0-rc4
* Use decimal (GB) sizes for SD card selection
......
......@@ -149,7 +149,7 @@ class Emulator:
if current_size % refresh_every == 0:
self._logger.progress(current_percentage / 100)
self._logger.std(
"Copied {copied} of {total} ({pc:.2}%)"
"Copied {copied} of {total} ({pc:.2f}%)"
.format(copied=human_readable_size(current_size),
total=human_readable_size(total_size),
pc=current_percentage))
......@@ -165,6 +165,36 @@ class Emulator:
os.fsync(device)
os.close(device)
def ensure_written(self, device_name):
self._logger.step("Verify data on SD card")
# reopen image and device (read-only)
if os.name == "posix":
image = os.open(self._image, os.O_RDONLY)
device = os.open(device_name, os.O_RDONLY)
elif os.name == "nt":
image = os.open(self._image, os.O_RDONLY | os.O_BINARY)
device = os.open(device_name, os.O_RDONLY | os.O_BINARY)
else:
self._logger.err("platform not supported")
return
# read a 4MiB random part from the image
buffer_size = ONE_MiB * 4
total_size = os.lseek(image, 0, os.SEEK_END)
offset = random.randint(0, total_size - buffer_size) * .8
os.lseek(image, offset, os.SEEK_SET)
challenge = os.read(image, buffer_size)
os.close(image)
# read same part from the SD card and compare
os.lseek(device, offset, os.SEEK_SET)
sd_challenge = os.read(device, buffer_size)
os.close(device)
assert sd_challenge == challenge
class _RunningInstance:
_emulation = None
_qemu = None
......
......@@ -277,6 +277,16 @@ def run_installation(name, timezone, language, wifi_pwd, admin_account, kalite,
logger.step("Writting image to SD-card ({})".format(sd_card))
emulator.copy_image(sd_card)
# check that SD card was properly written
try:
emulator.ensure_written(sd_card)
except AssertionError:
logger.err("SD-card content is different than that of image.\n"
"Please check the content of your card and "
"verify that the card is not damaged ("
"often turns read-only silently).")
raise Exception("SD-card content differs from image.")
except Exception as e:
logger.failed(str(e))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment