]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
Mount image as loop device in test mode
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 8 May 2021 12:43:02 +0000 (12:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 8 May 2021 12:43:02 +0000 (12:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/disk.py

index 714ff098070b90f9d983c84beeda8ed55f66a15f..a239b403d8e692fd9a32d5596b2110408d8c2866 100644 (file)
@@ -75,13 +75,28 @@ class Disks(object):
                """
                path = util.create_sparse_file("disk", TEST_DISK_SIZE)
 
+               # Connect to a loop device
+               loop_device = self._losetup(path)
+
                # Open the file with parted
-               device = parted.Device(path)
+               device = parted.Device(loop_device)
 
                # Create a Disk object
                disk = Disk(self.bricklayer, device)
                self.disks.append(disk)
 
+       def _losetup(self, path):
+               # Find a free loop device
+               device = self.bricklayer.command(["losetup", "-f"])
+
+               device = device.rstrip()
+
+               # Connect the image to the loop device
+               self.bricklayer.command(["losetup", device, path])
+
+               # Return the name of the loop device
+               return device
+
        @property
        def supported(self):
                """