summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_disk_setup.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-05-25 13:06:08 -0400
committerScott Moser <smoser@brickies.net>2017-05-26 13:37:41 -0400
commit1815c6d801933c47a01f1a94a8e689824f6797b4 (patch)
tree8df52d0f27cc498b1a49e55a5ce87bc84386d0ef /cloudinit/config/cc_disk_setup.py
parentd27c49391df343d25bd2e24045d2be6bf39c30d2 (diff)
downloadvyos-cloud-init-1815c6d801933c47a01f1a94a8e689824f6797b4.tar.gz
vyos-cloud-init-1815c6d801933c47a01f1a94a8e689824f6797b4.zip
disk_setup: udev settle before attempting partitioning or fs creation.
This attempts to use udevadm settle to wait until devices have been fully "realized". If a device exists, there may still be events in the udev queue that would create its partition table entries. We need to wait until those have been processed also. LP: #1692093
Diffstat (limited to 'cloudinit/config/cc_disk_setup.py')
-rw-r--r--cloudinit/config/cc_disk_setup.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py
index e1505b39..c2b83aea 100644
--- a/cloudinit/config/cc_disk_setup.py
+++ b/cloudinit/config/cc_disk_setup.py
@@ -680,14 +680,14 @@ def read_parttbl(device):
reliable way to probe the partition table.
"""
blkdev_cmd = [BLKDEV_CMD, '--rereadpt', device]
- udev_cmd = [UDEVADM_CMD, 'settle']
+ udevadm_settle()
try:
- util.subp(udev_cmd)
util.subp(blkdev_cmd)
- util.subp(udev_cmd)
except Exception as e:
util.logexc(LOG, "Failed reading the partition table %s" % e)
+ udevadm_settle()
+
def exec_mkpart_mbr(device, layout):
"""
@@ -737,6 +737,24 @@ def exec_mkpart(table_type, device, layout):
return get_dyn_func("exec_mkpart_%s", table_type, device, layout)
+def udevadm_settle():
+ util.subp(['udevadm', 'settle'])
+
+
+def assert_and_settle_device(device):
+ """Assert that device exists and settle so it is fully recognized."""
+ if not os.path.exists(device):
+ udevadm_settle()
+ if not os.path.exists(device):
+ raise RuntimeError("Device %s did not exist and was not created "
+ "with a udevamd settle." % device)
+
+ # Whether or not the device existed above, it is possible that udev
+ # events that would populate udev database (for reading by lsdname) have
+ # not yet finished. So settle again.
+ udevadm_settle()
+
+
def mkpart(device, definition):
"""
Creates the partition table.
@@ -752,6 +770,7 @@ def mkpart(device, definition):
device: the device to work on.
"""
# ensure that we get a real device rather than a symbolic link
+ assert_and_settle_device(device)
device = os.path.realpath(device)
LOG.debug("Checking values for %s definition", device)
@@ -852,6 +871,7 @@ def mkfs(fs_cfg):
overwrite = fs_cfg.get('overwrite', False)
# ensure that we get a real device rather than a symbolic link
+ assert_and_settle_device(device)
device = os.path.realpath(device)
# This allows you to define the default ephemeral or swap