Skip to content

Commit

Permalink
Merge pull request #2135 from ogayot/associate-os-to-existing-partitions
Browse files Browse the repository at this point in the history
Only associate os information to existing partitions
  • Loading branch information
ogayot authored Jan 16, 2025
2 parents ac1ba1b + 7c0037c commit d10e97d
Show file tree
Hide file tree
Showing 2 changed files with 47 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
42 changes: 42 additions & 0 deletions subiquity/models/tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,48 @@ def test_is_logical(self):
self.assertTrue(p6.is_logical)
self.assertTrue(p7.is_logical)

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

p1 = make_partition(m, d, preserve=True)
p2 = make_partition(m, d, preserve=True)

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

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

self.assertEqual("Ubuntu", p1.os.label)
self.assertEqual("Ubuntu 22.04.1 LTS", p1.os.long)
self.assertEqual("linux", p1.os.type)
self.assertEqual("22.04.1", p1.os.version)
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 d10e97d

Please sign in to comment.