mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Update mount module unit tests to reflect changes in mock_open
This commit is contained in:
parent
16c414e120
commit
71eeae1240
1 changed files with 55 additions and 48 deletions
|
@ -87,20 +87,19 @@ class MountTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.object(os.path, 'isfile', mock):
|
||||
self.assertEqual(mount.fstab(), {})
|
||||
|
||||
file_data = '\n'.join(['#', 'A B C D,E,F G H'])
|
||||
mock = MagicMock(return_value=True)
|
||||
with patch.dict(mount.__grains__, {'kernel': ''}):
|
||||
with patch.object(os.path, 'isfile', mock):
|
||||
file_data = '\n'.join(['#',
|
||||
'A B C D,E,F G H'])
|
||||
with patch('salt.utils.files.fopen',
|
||||
mock_open(read_data=file_data),
|
||||
create=True) as m:
|
||||
m.return_value.__iter__.return_value = file_data.splitlines()
|
||||
self.assertEqual(mount.fstab(), {'B': {'device': 'A',
|
||||
'dump': 'G',
|
||||
'fstype': 'C',
|
||||
'opts': ['D', 'E', 'F'],
|
||||
'pass': 'H'}})
|
||||
with patch.dict(mount.__grains__, {'kernel': ''}), \
|
||||
patch.object(os.path, 'isfile', mock), \
|
||||
patch('salt.utils.files.fopen', mock_open(read_data=file_data)):
|
||||
fstab = mount.fstab()
|
||||
assert fstab == {
|
||||
'B': {'device': 'A',
|
||||
'dump': 'G',
|
||||
'fstype': 'C',
|
||||
'opts': ['D', 'E', 'F'],
|
||||
'pass': 'H'}
|
||||
}, fstab
|
||||
|
||||
def test_vfstab(self):
|
||||
'''
|
||||
|
@ -110,21 +109,23 @@ class MountTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.object(os.path, 'isfile', mock):
|
||||
self.assertEqual(mount.vfstab(), {})
|
||||
|
||||
file_data = textwrap.dedent('''\
|
||||
#
|
||||
swap - /tmp tmpfs - yes size=2048m
|
||||
''')
|
||||
mock = MagicMock(return_value=True)
|
||||
with patch.dict(mount.__grains__, {'kernel': 'SunOS'}):
|
||||
with patch.object(os.path, 'isfile', mock):
|
||||
file_data = '\n'.join(['#',
|
||||
'swap - /tmp tmpfs - yes size=2048m'])
|
||||
with patch('salt.utils.files.fopen',
|
||||
mock_open(read_data=file_data),
|
||||
create=True) as m:
|
||||
m.return_value.__iter__.return_value = file_data.splitlines()
|
||||
self.assertEqual(mount.fstab(), {'/tmp': {'device': 'swap',
|
||||
'device_fsck': '-',
|
||||
'fstype': 'tmpfs',
|
||||
'mount_at_boot': 'yes',
|
||||
'opts': ['size=2048m'],
|
||||
'pass_fsck': '-'}})
|
||||
with patch.dict(mount.__grains__, {'kernel': 'SunOS'}), \
|
||||
patch.object(os.path, 'isfile', mock), \
|
||||
patch('salt.utils.files.fopen', mock_open(read_data=file_data)):
|
||||
vfstab = mount.vfstab()
|
||||
assert vfstab == {
|
||||
'/tmp': {'device': 'swap',
|
||||
'device_fsck': '-',
|
||||
'fstype': 'tmpfs',
|
||||
'mount_at_boot': 'yes',
|
||||
'opts': ['size=2048m'],
|
||||
'pass_fsck': '-'}
|
||||
}, vfstab
|
||||
|
||||
def test_rm_fstab(self):
|
||||
'''
|
||||
|
@ -274,30 +275,36 @@ class MountTestCase(TestCase, LoaderModuleMockMixin):
|
|||
Return a dict containing information on active swap
|
||||
'''
|
||||
|
||||
file_data = '\n'.join(['Filename Type Size Used Priority',
|
||||
'/dev/sda1 partition 31249404 4100 -1'])
|
||||
file_data = textwrap.dedent('''\
|
||||
Filename Type Size Used Priority
|
||||
/dev/sda1 partition 31249404 4100 -1
|
||||
''')
|
||||
with patch.dict(mount.__grains__, {'os': '', 'kernel': ''}):
|
||||
with patch('salt.utils.files.fopen',
|
||||
mock_open(read_data=file_data),
|
||||
create=True) as m:
|
||||
m.return_value.__iter__.return_value = file_data.splitlines()
|
||||
with patch('salt.utils.files.fopen', mock_open(read_data=file_data)):
|
||||
swaps = mount.swaps()
|
||||
assert swaps == {
|
||||
'/dev/sda1': {
|
||||
'priority': '-1',
|
||||
'size': '31249404',
|
||||
'type': 'partition',
|
||||
'used': '4100'}
|
||||
}, swaps
|
||||
|
||||
self.assertDictEqual(mount.swaps(), {'/dev/sda1':
|
||||
{'priority': '-1',
|
||||
'size': '31249404',
|
||||
'type': 'partition',
|
||||
'used': '4100'}})
|
||||
|
||||
file_data = '\n'.join(['Device Size Used Unknown Unknown Priority',
|
||||
'/dev/sda1 31249404 4100 unknown unknown -1'])
|
||||
file_data = textwrap.dedent('''\
|
||||
Device Size Used Unknown Unknown Priority
|
||||
/dev/sda1 31249404 4100 unknown unknown -1
|
||||
''')
|
||||
mock = MagicMock(return_value=file_data)
|
||||
with patch.dict(mount.__grains__, {'os': 'OpenBSD', 'kernel': 'OpenBSD'}):
|
||||
with patch.dict(mount.__salt__, {'cmd.run_stdout': mock}):
|
||||
self.assertDictEqual(mount.swaps(), {'/dev/sda1':
|
||||
{'priority': '-1',
|
||||
'size': '31249404',
|
||||
'type': 'partition',
|
||||
'used': '4100'}})
|
||||
with patch.dict(mount.__grains__, {'os': 'OpenBSD', 'kernel': 'OpenBSD'}), \
|
||||
patch.dict(mount.__salt__, {'cmd.run_stdout': mock}):
|
||||
swaps = mount.swaps()
|
||||
assert swaps == {
|
||||
'/dev/sda1': {
|
||||
'priority': '-1',
|
||||
'size': '31249404',
|
||||
'type': 'partition',
|
||||
'used': '4100'}
|
||||
}, swaps
|
||||
|
||||
def test_swapon(self):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue