Merge ~dbungert/curtin:lp-2004609-swap-size-dropped into curtin:master

Proposed by Dan Bungert
Status: Merged
Approved by: Dan Bungert
Approved revision: ae78301728d0c9e1982da24cf8fd39a8496ebb94
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~dbungert/curtin:lp-2004609-swap-size-dropped
Merge into: curtin:master
Diff against target: 138 lines (+77/-6)
4 files modified
curtin/commands/block_meta.py (+5/-3)
curtin/swap.py (+3/-3)
tests/integration/test_block_meta.py (+13/-0)
tests/unittests/test_commands_block_meta.py (+56/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Michael Hudson-Doyle Approve
Review via email: mp+436862@code.launchpad.net

Commit message

block/v1: handle msdos+swap

To post a comment you must log in.
Revision history for this message
Dan Bungert (dbungert) wrote :

I needed to revert ebff651 to be able to run the integration tests.

@mwhudson, what's going on with losetup --partscan, I couldn't find mention of a conflict with --sector-size.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
ae78301... by Dan Bungert

swap: clarify debug message

This log message is shown, among other scenarios, if a swap partition is
used, which is very confusing.
Clarify that we're talking about swap file.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

> I needed to revert ebff651 to be able to run the integration tests.

Hmm on which version of Ubuntu? It works for me on kinetic. What goes wrong?

> @mwhudson, what's going on with losetup --partscan, I couldn't find mention of
> a conflict with --sector-size.

losetup with --partscan and --sector-size used to do this:

1) tell the kernel to create a device backed by the supplied file
2) tell the kernel what sector size to use
3) tell the kernel to scan for partitions

At some point, a shiny new ioctl was added that let you do all of this at once but unfortunately losetup was changed to actually do this:

1) tell the kernel to create a device backed by the supplied file and scan for partitions
2) tell the kernel what sector size to use

As you need to know the sector size to interpret the partition table, this doesn't work.

losetup has been fixed to include the sector size in the ioctl to set everything up (https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=854abba0dd9b45b4f40a9c934694b3f14052eceb) but this hasn't been released yet it seems.

Revision history for this message
Dan Bungert (dbungert) wrote :

> Hmm on which version of Ubuntu? It works for me on kinetic.

Up-to-date Lunar

> What goes wrong?

5 tests, all msdos ptable but not every msdos ptable test, fail. I don't have to revert the full commit listed above to make them 'pass', but commenting out the partprobe done by loop_dev() is enough to make them pass. Which doesn't give me high confidence.

FAILED tests/integration/test_block_meta.py::TestBlockMeta::test_delete_logical_partition
FAILED tests/integration/test_block_meta.py::TestBlockMeta::test_logical_v2
FAILED tests/integration/test_block_meta.py::TestBlockMeta::test_mix_of_operations_msdos
FAILED tests/integration/test_block_meta.py::TestBlockMeta::test_resize_extended
FAILED tests/integration/test_block_meta.py::TestBlockMeta::test_resize_logical

This is unrelated to this PR, master does so as well. This seems to be in the realm of 'sysfs is giving unexpected results', as sfdisk -J output looks reasonable if run just before the partprobe.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

So the lesson here is that we should use v2 partitioning for everything?

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/curtin/commands/block_meta.py b/curtin/commands/block_meta.py
2index 74c491c..c0e595d 100644
3--- a/curtin/commands/block_meta.py
4+++ b/curtin/commands/block_meta.py
5@@ -1097,9 +1097,11 @@ def partition_handler(info, storage_config, context):
6 partition_type = flag
7 else:
8 partition_type = "primary"
9- cmd = ["parted", disk, "--script", "mkpart", partition_type,
10- "%ss" % offset_sectors, "%ss" % str(offset_sectors +
11- length_sectors)]
12+ cmd = ["parted", disk, "--script", "mkpart", partition_type]
13+ if flag == 'swap':
14+ cmd.append("linux-swap")
15+ cmd.append("%ss" % offset_sectors)
16+ cmd.append("%ss" % (offset_sectors + length_sectors))
17 if flag == 'boot':
18 cmd.extend(['set', str(partnumber), 'boot', 'on'])
19
20diff --git a/curtin/swap.py b/curtin/swap.py
21index 7a0128d..5aea0b8 100644
22--- a/curtin/swap.py
23+++ b/curtin/swap.py
24@@ -113,7 +113,7 @@ def setup_swapfile(target, fstab=None, swapfile=None, size=None, maxsize=None,
25 size = suggested_swapsize(fsys=target, maxsize=maxsize)
26
27 if size == 0:
28- LOG.debug("Not creating swap: suggested size was 0")
29+ LOG.debug("Not creating swapfile: suggested size was 0")
30 return
31
32 if swapfile is None:
33@@ -130,7 +130,7 @@ def setup_swapfile(target, fstab=None, swapfile=None, size=None, maxsize=None,
34 if force:
35 LOG.warning('swapfile may not work: %s', err)
36 else:
37- LOG.debug('Not creating swap: %s', err)
38+ LOG.debug('Not creating swapfile: %s', err)
39 return
40
41 allocate_cmd = 'fallocate -l "${2}M" "$1"'
42@@ -142,7 +142,7 @@ def setup_swapfile(target, fstab=None, swapfile=None, size=None, maxsize=None,
43 allocate_cmd = 'dd if=/dev/zero "of=$1" bs=1M "count=$2"'
44
45 mbsize = str(int(size / (2 ** 20)))
46- msg = "creating swap file '%s' of %sMB" % (swapfile, mbsize)
47+ msg = "creating swapfile '%s' of %sMB" % (swapfile, mbsize)
48 fpath = os.path.sep.join([target, swapfile])
49 try:
50 util.ensure_dir(os.path.dirname(fpath))
51diff --git a/tests/integration/test_block_meta.py b/tests/integration/test_block_meta.py
52index 38b188a..ead1698 100644
53--- a/tests/integration/test_block_meta.py
54+++ b/tests/integration/test_block_meta.py
55@@ -1230,3 +1230,16 @@ table-length: 256'''.encode()
56 self.run_bm(config.render())
57 self.assertPartitions(
58 PartData(number=1, offset=1 << 20, size=1 << 20))
59+
60+ @parameterized.expand(((1,), (2,)))
61+ def test_swap(self, sv):
62+ self.img = self.tmp_path('image.img')
63+ config = StorageConfigBuilder(version=sv)
64+ config.add_image(path=self.img, create=True, size='20M',
65+ ptable='msdos')
66+ config.add_part(number=1, offset=1 << 20, size=1 << 20, flag='swap')
67+ self.run_bm(config.render())
68+
69+ self.assertPartitions(
70+ PartData(number=1, offset=1 << 20, size=1 << 20, boot=False,
71+ partition_type='82'))
72diff --git a/tests/unittests/test_commands_block_meta.py b/tests/unittests/test_commands_block_meta.py
73index 7067bc0..0c198e6 100644
74--- a/tests/unittests/test_commands_block_meta.py
75+++ b/tests/unittests/test_commands_block_meta.py
76@@ -654,6 +654,62 @@ class TestBlockMeta(CiTestCase):
77 'mkpart', 'primary', '2048s', '1001471s',
78 'set', '1', 'boot', 'on'], capture=True)])
79
80+ def test_partition_handler_creates_swap(self):
81+ """ Create a swap partition if the flag has requested as much """
82+ self.config = {
83+ 'storage': {
84+ 'version': 1,
85+ 'config': [
86+ {'grub_device': True,
87+ 'id': 'sda',
88+ 'name': 'sda',
89+ 'path': '/wark/xxx',
90+ 'ptable': 'msdos',
91+ 'type': 'disk',
92+ 'wipe': 'superblock'},
93+ {'device': 'sda',
94+ 'flag': 'swap',
95+ 'id': 'sda-part1',
96+ 'name': 'sda-part1',
97+ 'number': 1,
98+ 'offset': '4194304B',
99+ 'size': '511705088B',
100+ 'type': 'partition',
101+ 'wipe': 'superblock'},
102+ {'id': 'sda1-root',
103+ 'type': 'format',
104+ 'fstype': 'swap',
105+ 'volume': 'sda-part1'},
106+ ],
107+ }
108+ }
109+ self.storage_config = (
110+ block_meta.extract_storage_ordered_dict(self.config))
111+
112+ disk_info = self.storage_config.get('sda')
113+ part_info = self.storage_config.get('sda-part1')
114+ disk_kname = disk_info.get('path')
115+ part_kname = disk_kname + '1'
116+ self.mock_getpath.side_effect = iter([
117+ disk_kname,
118+ part_kname,
119+ ])
120+ self.mock_block_get_part_table_type.return_value = 'dos'
121+ kname = 'xxx'
122+ self.mock_block_path_to_kname.return_value = kname
123+ self.mock_block_sys_block_path.return_value = '/sys/class/block/xxx'
124+ self.mock_block_sector_size.return_value = (512, 512)
125+
126+ block_meta.partition_handler(
127+ part_info, self.storage_config, empty_context)
128+ part_offset = 2048 * 512
129+ self.mock_block_zero_file.assert_called_with(disk_kname, [part_offset],
130+ exclusive=False)
131+ self.mock_subp.assert_has_calls(
132+ [call(['parted', disk_kname, '--script',
133+ 'mkpart', 'primary', 'linux-swap', '2048s', '1001471s',
134+ ], capture=True)])
135+
136 @patch('curtin.util.write_file')
137 def test_mount_handler_defaults(self, mock_write_file):
138 """Test mount_handler has defaults to 'defaults' for mount options"""

Subscribers

People subscribed via source and target branches