Skip to content

Commit

Permalink
Merge pull request #54613 from garethgreenaway/2019_2_1_port_51074
Browse files Browse the repository at this point in the history
[master] Porting #51074 to master
  • Loading branch information
dwoz authored Jan 2, 2020
2 parents 4d8ccf3 + b74465f commit 4b1c804
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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

0 comments on commit 4b1c804

Please sign in to comment.