Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix passing extra mkfs options for btrfs volumes (#2036976) #1260

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions blivet/blivet.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,9 @@ def new_btrfs(self, *args, **kwargs):
fmt_args = kwargs.pop("fmt_args", {})
fmt_args.update({"mountpoint": mountpoint})

create_options = kwargs.get("create_options", None)
fmt_args.update({"create_options": create_options})

if kwargs.pop("subvol", False):
dev_class = BTRFSSubVolumeDevice

Expand Down
9 changes: 6 additions & 3 deletions blivet/devices/btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import os
import copy
import shlex
import tempfile
import uuid

Expand Down Expand Up @@ -473,10 +474,12 @@ def _create(self):
md_level = str(self.metadata_level)
else:
md_level = None

extra = []
if self.uuid:
extra = {"-U": self.uuid}
else:
extra = None
extra.append(blockdev.ExtraArg("-U", self.uuid))
if self.format and self.format._create_options:
extra.extend(blockdev.ExtraArg(arg) for arg in shlex.split(self.format._create_options))
try:
blockdev.btrfs.create_volume([d.path for d in self.parents],
label=self.format.label,
Expand Down
48 changes: 43 additions & 5 deletions tests/unit_tests/devices_test/btrfs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ def test_new_btrfs(self):
with patch.object(vol, "_pre_create"):
with patch.object(vol, "_post_create"):
vol.create()
blockdev.create_volume.assert_called_with(['/dev/bd1'],
label='testvolume',
data_level=None,
md_level=None,
extra={'-U': vol.uuid})
blockdev.create_volume.assert_called()
args = blockdev.create_volume.call_args.args
self.assertEqual(args, (['/dev/bd1'],))
kwargs = blockdev.create_volume.call_args.kwargs
self.assertEqual(kwargs['label'], 'testvolume')
self.assertEqual(kwargs['data_level'], None)
self.assertEqual(kwargs['md_level'], None)

extra = kwargs['extra']
self.assertTrue(extra)
self.assertEqual(extra[0].opt, "-U")
self.assertEqual(extra[0].val, vol.uuid)

with patch("blivet.devicetree.DeviceTree.names", []):
sub = b.new_btrfs_sub_volume(name="testsub", parents=[vol])
Expand All @@ -53,6 +60,37 @@ def test_new_btrfs(self):
self.assertEqual(sub.size, vol.size)
self.assertEqual(sub.volume, vol)

def test_new_btrfs_options(self):
b = blivet.Blivet()
bd = StorageDevice("bd1", fmt=blivet.formats.get_format("btrfs"),
size=Size("2 GiB"), exists=False)

b.devicetree._add_device(bd)

with patch("blivet.devicetree.DeviceTree.names", []):
vol = b.new_btrfs(name="testvolume", parents=[bd], create_options="--csum xxhash")

b.create_device(vol)

with patch("blivet.devices.btrfs.blockdev.btrfs") as blockdev:
with patch.object(vol, "_pre_create"):
with patch.object(vol, "_post_create"):
vol.create()
blockdev.create_volume.assert_called()
args = blockdev.create_volume.call_args.args
self.assertEqual(args, (['/dev/bd1'],))
kwargs = blockdev.create_volume.call_args.kwargs
self.assertEqual(kwargs['label'], 'testvolume')
self.assertEqual(kwargs['data_level'], None)
self.assertEqual(kwargs['md_level'], None)

extra = kwargs['extra']
self.assertTrue(extra)
self.assertEqual(extra[0].opt, "-U")
self.assertEqual(extra[0].val, vol.uuid)
self.assertEqual(extra[1].opt, "--csum")
self.assertEqual(extra[2].opt, "xxhash")

def test_device_id(self):
bd = StorageDevice("bd1", fmt=blivet.formats.get_format("btrfs"),
size=Size("2 GiB"), exists=False)
Expand Down