Commit d2437ac9 authored by Sebastian Bachmann's avatar Sebastian Bachmann
Browse files

Fix part-naming and add timeout while waiting

When installing on a blockdevice which device name ends in a number,
a 'p' is added between the device name and the partition number.
This will be the case, for example, when installing to /dev/nbd0 or

Further, added a timeout to the wait_for_file_to_exist function,
in order not to hang when a partition was not found.

Both changes should resolve #46
parent 55b4931b
......@@ -16,6 +16,8 @@
# =*= License: GPL-3+ =*=
import itertools
import logging
import os
import stat
import time
......@@ -89,16 +91,30 @@ class MkpartStepRunner(vmdb.StepRunnerInterface):
output = output.decode("UTF-8")
partitions = [line.split(":")[0] for line in output.splitlines() if ":" in line]
return [
word if word.startswith("/") else "{}{}".format(device, word)
word if word.startswith("/") else "{}{}{}".format(
# If the device name ends in a number,
# a 'p' is added between device and part number
'p' if device[-1].isnumeric() else '',
for word in partitions
def diff_partitions(self, old, new):
return [line for line in new if line not in old]
def wait_for_file_to_exist(self, filename):
while not os.path.exists(filename):
def wait_for_file_to_exist(self, filename, timeout=60):
logging.debug("Starting to wait for file %s to come to life", filename)
if timeout is not None:
logging.debug("Waiting %s second(s) before timeout", timeout)
for count in itertools.count():
if os.path.exists(filename):
if timeout is None or count < timeout:
raise TimeoutOnWaitingForFile(filename)
class MkpartError(Exception):
......@@ -117,3 +133,11 @@ class UnexpectedNewPartitions(MkpartError):
"Expected only one new partition to exist after mkpart, "
"but found {}".format(" ".join(diff))
class TimeoutOnWaitingForFile(MkpartError):
def __init__(self, part):
"Waited for file {} to come to life, but timeout was "
"reached while waiting. ".format(part)
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