Skip to content

Commit

Permalink
Merge pull request #1634 from dbungert/bootable-disks
Browse files Browse the repository at this point in the history
Bootable disks
  • Loading branch information
dbungert authored Apr 4, 2023
2 parents c8e30bc + 965a49f commit a8e2b3e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
8 changes: 1 addition & 7 deletions subiquity/common/apidef.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,10 @@ class reformat_disk:
def POST(data: Payload[ReformatDisk]) \
-> StorageResponseV2: ...

class potential_boot_disks:
"""Obtain the list of disks which can be made bootable.
This list can be empty if there are no disks or if none of them
are plausible sources of a boot disk."""
def GET() -> List[str]: ...

class add_boot_partition:
"""Mark a given disk as bootable, which may cause a partition
to be added to the disk. It is an error to call this for a
disk not in the list from potential_boot_disks."""
disk for which can_be_boot_device is False."""
def POST(disk_id: str) -> StorageResponseV2: ...

class add_partition:
Expand Down
1 change: 1 addition & 0 deletions subiquity/common/filesystem/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def _for_client_disk(disk, *, min_size=0):
usage_labels=usage_labels(disk),
partitions=[for_client(p) for p in gaps.parts_and_gaps(disk)],
boot_device=boot.is_boot_device(disk),
can_be_boot_device=boot.can_be_boot_device(disk),
ok_for_guided=disk.size >= min_size,
model=getattr(disk, 'model', None),
vendor=getattr(disk, 'vendor', None))
Expand Down
1 change: 1 addition & 0 deletions subiquity/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class Disk:
preserve: bool
path: Optional[str]
boot_device: bool
can_be_boot_device: bool
model: Optional[str] = None
vendor: Optional[str] = None

Expand Down
5 changes: 0 additions & 5 deletions subiquity/server/controllers/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,11 +780,6 @@ async def v2_reformat_disk_POST(self, data: ReformatDisk) \
self.reformat(self.model._one(id=data.disk_id), data.ptable)
return await self.v2_GET()

async def v2_potential_boot_disks_GET(self) -> List[str]:
disks = self.potential_boot_disks(check_boot=True,
with_reformatting=False)
return [disk.id for disk in disks]

async def v2_add_boot_partition_POST(self, disk_id: str) \
-> StorageResponseV2:
disk = self.model._one(id=disk_id)
Expand Down
36 changes: 20 additions & 16 deletions subiquity/server/controllers/tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,27 +545,30 @@ def _setup(self, bootloader, ptable, **kw):
self.app = make_app()
self.app.opts.bootloader = bootloader.value
self.fsc = FilesystemController(app=self.app)
self.fsc.calculate_suggested_install_min = mock.Mock()
self.fsc.calculate_suggested_install_min.return_value = 10 << 30
self.fsc.model = self.model = make_model(bootloader)
self.model.storage_version = 2
self.fsc._probe_task.task = mock.Mock()
self.fsc._get_system_task.task = mock.Mock()

@parameterized.expand(bootloaders_and_ptables)
async def test_get_boot_disks_only(self, bootloader, ptable):
self._setup(bootloader, ptable)
disk = make_disk(self.model)
self.assertEqual([disk.id],
await self.fsc.v2_potential_boot_disks_GET())

@parameterized.expand(bootloaders_and_ptables)
async def test_get_boot_disks_none(self, bootloader, ptable):
self._setup(bootloader, ptable)
self.assertEqual([], await self.fsc.v2_potential_boot_disks_GET())
make_disk(self.model)
resp = await self.fsc.v2_GET()
[d] = resp.disks
self.assertTrue(d.can_be_boot_device)

@parameterized.expand(bootloaders_and_ptables)
async def test_get_boot_disks_all(self, bootloader, ptable):
self._setup(bootloader, ptable)
d1 = make_disk(self.model)
d2 = make_disk(self.model)
self.assertEqual(set([d1.id, d2.id]),
set(await self.fsc.v2_potential_boot_disks_GET()))
make_disk(self.model)
make_disk(self.model)
resp = await self.fsc.v2_GET()
[d1, d2] = resp.disks
self.assertTrue(d1.can_be_boot_device)
self.assertTrue(d2.can_be_boot_device)

@parameterized.expand(bootloaders_and_ptables)
async def test_get_boot_disks_some(self, bootloader, ptable):
Expand All @@ -577,11 +580,12 @@ async def test_get_boot_disks_some(self, bootloader, ptable):
preserve=True)
if bootloader == Bootloader.NONE:
# NONE will always pass the boot check, even on a full disk
expected = set([d1.id, d2.id])
bootable = set([d1.id, d2.id])
else:
expected = set([d2.id])
self.assertEqual(expected,
set(await self.fsc.v2_potential_boot_disks_GET()))
bootable = set([d2.id])
resp = await self.fsc.v2_GET()
for d in resp.disks:
self.assertEqual(d.id in bootable, d.can_be_boot_device)


class TestCoreBootInstallMethods(IsolatedAsyncioTestCase):
Expand Down

0 comments on commit a8e2b3e

Please sign in to comment.