Skip to content

Commit

Permalink
storage: only associate OsProber results with existing partitions
Browse files Browse the repository at this point in the history
If os-prober reports that Ubuntu is installed on sda4 (e.g., partition 4
of disk sda), then we should make that info available in the API.

However, if we remove sda4 and then create another partition with number
4, we should not assume that it contains anything of value.

refs LP: #2091172

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
  • Loading branch information
ogayot committed Jan 16, 2025
1 parent 07fb317 commit 7c0037c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions subiquity/models/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,11 @@ def ok_for_lvm_vg(self):

@property
def os(self):
if not self.preserve:
# Only associate the OS information with existing partitions.
# If /dev/sda4 was deleted and a new partition on sda with number 4
# is created, we should not pretend it contains anything of value.
return None
os_data = self._m._probe_data.get("os", {}).get(self._path())
if not os_data:
return None
Expand Down
19 changes: 19 additions & 0 deletions subiquity/models/tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,25 @@ def test_os(self):
self.assertIsNone(p1.os.subpath)
self.assertIsNone(p2.os)

def test_os__recreated_partition(self):
m = make_model(storage_version=2)
d = make_disk(m, ptable="gpt")

# We do not mark the partition preserved, which means we either
# formatted the disk or deleted / recreated the partition.
p = make_partition(m, d)

os_info = {
"label": "Ubuntu",
"long": "Ubuntu 22.04.1 LTS",
"type": "linux",
"version": "22.04.1",
}

m._probe_data["os"] = {p._path(): os_info}

self.assertIsNone(p.os)


class TestCanmount(SubiTestCase):
@parameterized.expand(
Expand Down

0 comments on commit 7c0037c

Please sign in to comment.