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

[master] Porting #51074 to master #54613

Merged
merged 9 commits into from
Jan 2, 2020
8 changes: 8 additions & 0 deletions salt/modules/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ def format_(device,
fs_type='ext4',
inode_size=None,
lazy_itable_init=None,
fat=None,
force=False):
'''
Format a filesystem onto a device
Expand Down Expand Up @@ -449,6 +450,10 @@ def format_(device,

This option is only enabled for ext filesystems

fat
FAT size option. Can be 12, 16 or 32, and can only be used on
fat or vfat filesystems.

force
Force mke2fs to create a filesystem, even if the specified device is
not a partition on a block special device. This option is only enabled
Expand All @@ -471,6 +476,9 @@ def format_(device,
if lazy_itable_init is not None:
if fs_type[:3] == 'ext':
cmd.extend(['-E', 'lazy_itable_init={0}'.format(lazy_itable_init)])
if fat is not None and fat in (12, 16, 32):
if fs_type[-3:] == 'fat':
cmd.extend(['-F', fat])
if force:
if fs_type[:3] == 'ext':
cmd.append('-F')
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/modules/test_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ def test_format(self):
patch('salt.utils.path.which', MagicMock(return_value=True)):
self.assertEqual(disk.format_(device), True)

def test_fat_format(self):
'''
unit tests for disk.format when using fat argument
'''
device = '/dev/sdX1'
expected = ['mkfs', '-t', 'fat', '-F', 12, '/dev/sdX1']
mock = MagicMock(return_value=0)
with patch.dict(disk.__salt__, {'cmd.retcode': mock}),\
patch('salt.utils.path.which', MagicMock(return_value=True)):
self.assertEqual(disk.format_(device, fs_type='fat', fat=12), True)
args, kwargs = mock.call_args_list[0]
assert expected == args[0]

@skipIf(not salt.utils.path.which('lsblk') and not salt.utils.path.which('df'),
'lsblk or df not found')
def test_fstype(self):
Expand Down