From 4e95bdc816ff439fa8453475c12724e8e11866f7 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 18 Sep 2019 17:30:59 -0700 Subject: [PATCH 1/3] Porting PR #51074 to 2019.2.1 --- salt/modules/disk.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/salt/modules/disk.py b/salt/modules/disk.py index 0e0f6eef5537..7b2756ff6c0b 100644 --- a/salt/modules/disk.py +++ b/salt/modules/disk.py @@ -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 @@ -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 @@ -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') From 05983ce828605850522fc0d0e83091cb64b5f7f5 Mon Sep 17 00:00:00 2001 From: ch3ll Date: Tue, 3 Dec 2019 10:10:38 -0500 Subject: [PATCH 2/3] Add disk test for fat argument --- tests/unit/modules/test_disk.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/modules/test_disk.py b/tests/unit/modules/test_disk.py index d6d1253a30e1..0541d840cb5a 100644 --- a/tests/unit/modules/test_disk.py +++ b/tests/unit/modules/test_disk.py @@ -151,6 +151,18 @@ 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) + assert expected == mock.call_args_list[0].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): From 9437276c079bb05b7881f8040fef5e921289a012 Mon Sep 17 00:00:00 2001 From: ch3ll Date: Tue, 3 Dec 2019 16:12:20 -0500 Subject: [PATCH 3/3] Fix mock tuple call_args_list --- tests/unit/modules/test_disk.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/modules/test_disk.py b/tests/unit/modules/test_disk.py index 0541d840cb5a..5ee1ae93105b 100644 --- a/tests/unit/modules/test_disk.py +++ b/tests/unit/modules/test_disk.py @@ -161,7 +161,8 @@ def test_fat_format(self): 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) - assert expected == mock.call_args_list[0].args[0] + 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')