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

btrfs: add option to not set subvolumes as default #50801

Merged
merged 1 commit into from
Dec 10, 2018
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
12 changes: 10 additions & 2 deletions salt/states/btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def wrapper(*args, **kwargs):

@__mount_device
def subvolume_created(name, device, qgroupids=None, set_default=False,
copy_on_write=True, __dest=None):
copy_on_write=True, force_set_default=True,
__dest=None):
'''
Makes sure that a btrfs subvolume is present.

Expand All @@ -150,6 +151,10 @@ def subvolume_created(name, device, qgroupids=None, set_default=False,
copy_on_write
If false, set the subvolume with chattr +C

force_set_default
If false and the subvolume is already present, it will not
force it as default if ``set_default`` is True

'''
ret = {
'name': name,
Expand Down Expand Up @@ -190,7 +195,10 @@ def subvolume_created(name, device, qgroupids=None, set_default=False,

ret['changes'][name] = 'Created subvolume {}'.format(name)

if set_default and not _is_default(path, __dest, name):
# If the volume was already present, we can opt-out the check for
# default subvolume.
if (not exists or (exists and force_set_default)) and \
set_default and not _is_default(path, __dest, name):
ret['changes'][name + '_default'] = _set_default(path, __dest, name)

if not copy_on_write and _is_cow(path):
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/states/test_btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,42 @@ def test_subvolume_created_exists_set_default(self, mount, umount,
mount.assert_called_once()
umount.assert_called_once()

@patch('salt.states.btrfs._set_default')
@patch('salt.states.btrfs._is_default')
@patch('salt.states.btrfs._umount')
@patch('salt.states.btrfs._mount')
def test_subvolume_created_exists_set_default_no_force(self,
mount,
umount,
is_default,
set_default):
'''
Test creating a subvolume.
'''
mount.return_value = '/tmp/xxx'
is_default.return_value = False
set_default.return_value = True
salt_mock = {
'btrfs.subvolume_exists': MagicMock(return_value=True),
}
opts_mock = {
'test': False,
}
with patch.dict(btrfs.__salt__, salt_mock), \
patch.dict(btrfs.__opts__, opts_mock):
assert btrfs.subvolume_created(name='@/var',
device='/dev/sda1',
set_default=True,
force_set_default=False) == {
'name': '@/var',
'result': True,
'changes': {},
'comment': ['Subvolume @/var already present'],
}
salt_mock['btrfs.subvolume_exists'].assert_called_with('/tmp/xxx/@/var')
mount.assert_called_once()
umount.assert_called_once()

@patch('salt.states.btrfs._is_cow')
@patch('salt.states.btrfs._umount')
@patch('salt.states.btrfs._mount')
Expand Down