fix detection of mounted partitions

Even if we are going to ignore a mountpoint, we still need to process
its children...

Add machine config where the installer is running from a partition of a
disk you might want to install to, and an api test.
This commit is contained in:
Michael Hudson-Doyle 2023-07-24 12:18:05 +12:00
parent e84b3dda8f
commit b3dafb250b
3 changed files with 1237 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1292,15 +1292,19 @@ class FilesystemModel(object):
continue
majmin_to_dev[f'{major}:{minor}'] = obj
log.debug("majmin_to_dev %s", majmin_to_dev)
mounts = list(self._probe_data.get('mount', []))
while mounts:
mount = mounts.pop(0)
mounts.extend(mount.get('children', []))
if mount['target'].startswith(self.target):
# Completely ignore mounts under /target, they are probably
# leftovers from a previous install attempt.
continue
if 'maj:min' not in mount:
continue
log.debug("considering mount of %s", mount['maj:min'])
obj = majmin_to_dev.get(mount['maj:min'])
if obj is None:
continue
@ -1312,7 +1316,6 @@ class FilesystemModel(object):
if isinstance(o, Disk):
o._has_in_use_partition = True
work.extend(dependencies(o))
mounts.extend(mount.get('children', []))
# This is a special hack for the install media. When written to a USB
# stick or similar, both the block device for the whole drive and for

View File

@ -2075,3 +2075,17 @@ class TestActiveDirectory(TestAPI):
# manager will fail to POST /shutdown.
except aiohttp.client_exceptions.ClientOSError:
pass
class TestMountDetection(TestAPI):
@timeout()
async def test_mount_detection(self):
# Test that the partition the installer is running from is
# correctly identified as mounted.
cfg = 'examples/machines/booted-from-rp.json'
async with start_server(cfg) as instance:
result = await instance.get('/storage/v2')
[disk1] = result['disks']
self.assertTrue(disk1['has_in_use_partition'])
disk1p2 = disk1['partitions'][1]
self.assertTrue(disk1p2['is_in_use'])