2014-09-22 18:16:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Dave Rawks (dave@pandora.com)`
|
|
|
|
|
|
|
|
|
|
|
|
tests.unit.modules.parted_test
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
'''
|
|
|
|
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import Python libs
|
2018-01-24 20:47:14 +00:00
|
|
|
from __future__ import absolute_import, unicode_literals, print_function
|
2014-11-21 19:05:13 +00:00
|
|
|
|
2014-09-22 18:16:37 +00:00
|
|
|
# Import Salt Testing libs
|
2017-03-31 12:42:52 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
|
|
|
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf, TestCase
|
|
|
|
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
2014-09-22 18:16:37 +00:00
|
|
|
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
# Import Salt libs
|
2014-09-23 22:44:33 +00:00
|
|
|
from salt.exceptions import CommandExecutionError
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.parted as parted
|
2014-09-22 18:16:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-03-31 12:42:52 +00:00
|
|
|
class PartedTestCase(TestCase, LoaderModuleMockMixin):
|
|
|
|
|
|
|
|
def setup_loader_modules(self):
|
|
|
|
self.cmdrun = MagicMock()
|
|
|
|
self.cmdrun_stdout = MagicMock()
|
|
|
|
self.addCleanup(delattr, self, 'cmdrun')
|
|
|
|
self.addCleanup(delattr, self, 'cmdrun_stdout')
|
|
|
|
return {
|
|
|
|
parted: {
|
|
|
|
'__salt__': {
|
|
|
|
'cmd.run': self.cmdrun,
|
|
|
|
'cmd.run_stdout': self.cmdrun_stdout
|
|
|
|
}
|
|
|
|
}
|
2015-04-28 14:50:33 +00:00
|
|
|
}
|
2014-09-22 21:44:52 +00:00
|
|
|
|
2014-09-22 18:16:37 +00:00
|
|
|
# Test __virtual__ function for module registration
|
|
|
|
|
|
|
|
def test_virtual_bails_on_windows(self):
|
2017-09-14 15:35:23 +00:00
|
|
|
'''
|
|
|
|
If running windows, __virtual__ shouldn't register module
|
|
|
|
'''
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
with patch('salt.utils.platform.is_windows', lambda: True):
|
2017-04-10 13:00:57 +00:00
|
|
|
ret = parted.__virtual__()
|
|
|
|
err = (False, 'The parted execution module failed to load Windows systems are not supported.')
|
|
|
|
self.assertEqual(err, ret)
|
2014-09-22 18:16:37 +00:00
|
|
|
|
|
|
|
def test_virtual_bails_without_parted(self):
|
2017-09-14 15:35:23 +00:00
|
|
|
'''
|
|
|
|
If parted not in PATH, __virtual__ shouldn't register module
|
|
|
|
'''
|
2017-09-11 16:55:39 +00:00
|
|
|
with patch('salt.utils.path.which', lambda exe: not exe == "parted"),\
|
2017-09-14 15:35:23 +00:00
|
|
|
patch('salt.utils.platform.is_windows', return_value=False):
|
2017-04-10 13:00:57 +00:00
|
|
|
ret = parted.__virtual__()
|
|
|
|
err = (False, 'The parted execution module failed to load parted binary is not in the path.')
|
|
|
|
self.assertEqual(err, ret)
|
2014-09-22 18:16:37 +00:00
|
|
|
|
|
|
|
def test_virtual_bails_without_lsblk(self):
|
2017-09-14 15:35:23 +00:00
|
|
|
'''
|
|
|
|
If lsblk not in PATH, __virtual__ shouldn't register module
|
|
|
|
'''
|
2017-09-11 16:55:39 +00:00
|
|
|
with patch('salt.utils.path.which', lambda exe: not exe == "lsblk"),\
|
2017-09-14 15:35:23 +00:00
|
|
|
patch('salt.utils.platform.is_windows', return_value=False):
|
2017-04-10 13:00:57 +00:00
|
|
|
ret = parted.__virtual__()
|
|
|
|
err = (False, 'The parted execution module failed to load lsblk binary is not in the path.')
|
|
|
|
self.assertEqual(err, ret)
|
2014-09-22 18:16:37 +00:00
|
|
|
|
|
|
|
def test_virtual_bails_without_partprobe(self):
|
2017-09-14 15:35:23 +00:00
|
|
|
'''
|
|
|
|
If partprobe not in PATH, __virtual__ shouldn't register module
|
|
|
|
'''
|
2017-09-11 16:55:39 +00:00
|
|
|
with patch('salt.utils.path.which', lambda exe: not exe == "partprobe"),\
|
2017-09-14 15:35:23 +00:00
|
|
|
patch('salt.utils.platform.is_windows', return_value=False):
|
2017-04-10 13:00:57 +00:00
|
|
|
ret = parted.__virtual__()
|
|
|
|
err = (False, 'The parted execution module failed to load partprobe binary is not in the path.')
|
|
|
|
self.assertEqual(err, ret)
|
|
|
|
|
2014-09-22 18:16:37 +00:00
|
|
|
def test_virtual(self):
|
2017-09-14 15:35:23 +00:00
|
|
|
'''
|
|
|
|
On expected platform with correct utils in PATH, register "partition" module
|
|
|
|
'''
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
with patch('salt.utils.platform.is_windows', lambda: False), \
|
|
|
|
patch('salt.utils.path.which', lambda exe: exe in ('parted', 'lsblk', 'partprobe')):
|
2017-04-10 13:00:57 +00:00
|
|
|
ret = parted.__virtual__()
|
|
|
|
expect = 'partition'
|
|
|
|
self.assertEqual(ret, expect)
|
2014-09-22 18:16:37 +00:00
|
|
|
|
|
|
|
# Test probe function
|
|
|
|
|
|
|
|
def test_probe_wo_args(self):
|
2014-09-22 21:44:52 +00:00
|
|
|
parted.probe()
|
2014-11-03 08:44:43 +00:00
|
|
|
self.cmdrun.assert_called_once_with('partprobe -- ')
|
2014-09-22 18:16:37 +00:00
|
|
|
|
|
|
|
def test_probe_w_single_arg(self):
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch('salt.modules.parted._validate_device', MagicMock()):
|
|
|
|
parted.probe('/dev/sda')
|
|
|
|
self.cmdrun.assert_called_once_with('partprobe -- /dev/sda')
|
2014-09-22 18:16:37 +00:00
|
|
|
|
|
|
|
def test_probe_w_multiple_args(self):
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch('salt.modules.parted._validate_device', MagicMock()):
|
|
|
|
parted.probe('/dev/sda', '/dev/sdb')
|
|
|
|
self.cmdrun.assert_called_once_with('partprobe -- /dev/sda /dev/sdb')
|
2014-09-22 18:16:37 +00:00
|
|
|
|
2014-09-22 21:44:52 +00:00
|
|
|
# Test _list function
|
|
|
|
|
2014-09-23 22:44:33 +00:00
|
|
|
@staticmethod
|
|
|
|
def parted_print_output(k):
|
|
|
|
output = {
|
|
|
|
"valid": (
|
|
|
|
'''BYT;\n'''
|
|
|
|
'''/dev/sda:4000GB:scsi:512:512:gpt:AMCC 9650SE-24M DISK:;\n'''
|
|
|
|
'''1:17.4kB:150MB:150MB:ext3::boot;\n'''
|
|
|
|
'''2:3921GB:4000GB:79.3GB:linux-swap(v1)::;\n'''
|
|
|
|
),
|
|
|
|
"valid_legacy": (
|
|
|
|
'''BYT;\n'''
|
|
|
|
'''/dev/sda:4000GB:scsi:512:512:gpt:AMCC 9650SE-24M DISK;\n'''
|
|
|
|
'''1:17.4kB:150MB:150MB:ext3::boot;\n'''
|
|
|
|
'''2:3921GB:4000GB:79.3GB:linux-swap(v1)::;\n'''
|
|
|
|
),
|
|
|
|
"empty": '',
|
|
|
|
"bad_label_info": (
|
|
|
|
'''BYT;\n'''
|
|
|
|
'''badbadbadbad\n'''
|
|
|
|
'''1:17.4kB:150MB:150MB:ext3::boot;\n'''
|
|
|
|
'''2:3921GB:4000GB:79.3GB:linux-swap(v1)::;\n'''
|
|
|
|
),
|
|
|
|
"bad_header": (
|
|
|
|
'''badbadbadbad\n'''
|
|
|
|
'''/dev/sda:4000GB:scsi:512:512:gpt:AMCC 9650SE-24M DISK:;\n'''
|
|
|
|
'''1:17.4kB:150MB:150MB:ext3::boot;\n'''
|
|
|
|
'''2:3921GB:4000GB:79.3GB:linux-swap(v1)::;\n'''
|
|
|
|
),
|
|
|
|
"bad_partition": (
|
|
|
|
'''BYT;\n'''
|
|
|
|
'''/dev/sda:4000GB:scsi:512:512:gpt:AMCC 9650SE-24M DISK:;\n'''
|
|
|
|
'''badbadbadbad\n'''
|
|
|
|
'''2:3921GB:4000GB:79.3GB:linux-swap(v1)::;\n'''
|
|
|
|
),
|
|
|
|
}
|
|
|
|
return output[k]
|
|
|
|
|
|
|
|
def test_list__without_device(self):
|
|
|
|
self.assertRaises(TypeError, parted.list_)
|
|
|
|
|
|
|
|
def test_list__empty_cmd_output(self):
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch('salt.modules.parted._validate_device', MagicMock()):
|
|
|
|
self.cmdrun_stdout.return_value = self.parted_print_output('empty')
|
|
|
|
output = parted.list_('/dev/sda')
|
|
|
|
self.cmdrun_stdout.assert_called_once_with('parted -m -s /dev/sda print')
|
|
|
|
expected = {'info': {}, 'partitions': {}}
|
|
|
|
self.assertEqual(output, expected)
|
2014-09-23 22:44:33 +00:00
|
|
|
|
|
|
|
def test_list__valid_unit_empty_cmd_output(self):
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch('salt.modules.parted._validate_device', MagicMock()):
|
|
|
|
self.cmdrun_stdout.return_value = self.parted_print_output('empty')
|
|
|
|
output = parted.list_('/dev/sda', unit='s')
|
|
|
|
self.cmdrun_stdout.assert_called_once_with('parted -m -s /dev/sda unit s print')
|
|
|
|
expected = {'info': {}, 'partitions': {}}
|
|
|
|
self.assertEqual(output, expected)
|
2014-09-23 22:44:33 +00:00
|
|
|
|
|
|
|
def test_list__invalid_unit(self):
|
|
|
|
self.assertRaises(CommandExecutionError, parted.list_, '/dev/sda',
|
|
|
|
unit='badbadbad')
|
|
|
|
self.assertFalse(self.cmdrun.called)
|
|
|
|
|
|
|
|
def test_list__bad_header(self):
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch('salt.modules.parted._validate_device', MagicMock()):
|
|
|
|
self.cmdrun_stdout.return_value = self.parted_print_output('bad_header')
|
|
|
|
self.assertRaises(CommandExecutionError, parted.list_, '/dev/sda')
|
|
|
|
self.cmdrun_stdout.assert_called_once_with('parted -m -s /dev/sda print')
|
2014-09-23 22:44:33 +00:00
|
|
|
|
|
|
|
def test_list__bad_label_info(self):
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch('salt.modules.parted._validate_device', MagicMock()):
|
|
|
|
self.cmdrun_stdout.return_value = self.parted_print_output('bad_label_info')
|
|
|
|
self.assertRaises(CommandExecutionError, parted.list_, '/dev/sda')
|
|
|
|
self.cmdrun_stdout.assert_called_once_with('parted -m -s /dev/sda print')
|
2014-09-23 22:44:33 +00:00
|
|
|
|
|
|
|
def test_list__bad_partition(self):
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch('salt.modules.parted._validate_device', MagicMock()):
|
|
|
|
self.cmdrun_stdout.return_value = self.parted_print_output('bad_partition')
|
|
|
|
self.assertRaises(CommandExecutionError, parted.list_, '/dev/sda')
|
|
|
|
self.cmdrun_stdout.assert_called_once_with('parted -m -s /dev/sda print')
|
2014-09-23 22:44:33 +00:00
|
|
|
|
|
|
|
def test_list__valid_cmd_output(self):
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch('salt.modules.parted._validate_device', MagicMock()):
|
|
|
|
self.cmdrun_stdout.return_value = self.parted_print_output('valid')
|
|
|
|
output = parted.list_('/dev/sda')
|
|
|
|
self.cmdrun_stdout.assert_called_once_with('parted -m -s /dev/sda print')
|
|
|
|
expected = {
|
|
|
|
'info': {
|
|
|
|
'logical sector': '512',
|
|
|
|
'physical sector': '512',
|
|
|
|
'interface': 'scsi',
|
|
|
|
'model': 'AMCC 9650SE-24M DISK',
|
|
|
|
'disk': '/dev/sda',
|
|
|
|
'disk flags': '',
|
|
|
|
'partition table': 'gpt',
|
|
|
|
'size': '4000GB'
|
|
|
|
},
|
|
|
|
'partitions': {
|
|
|
|
'1': {
|
|
|
|
'end': '150MB',
|
|
|
|
'number': '1',
|
|
|
|
'start': '17.4kB',
|
|
|
|
'file system': '',
|
|
|
|
'flags': 'boot',
|
|
|
|
'type': 'ext3',
|
|
|
|
'size': '150MB'},
|
|
|
|
'2': {
|
|
|
|
'end': '4000GB',
|
|
|
|
'number': '2',
|
|
|
|
'start': '3921GB',
|
|
|
|
'file system': '',
|
|
|
|
'flags': '',
|
|
|
|
'type': 'linux-swap(v1)',
|
|
|
|
'size': '79.3GB'
|
|
|
|
}
|
2014-09-23 22:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-10 13:00:57 +00:00
|
|
|
self.assertEqual(output, expected)
|
2014-09-23 22:44:33 +00:00
|
|
|
|
|
|
|
def test_list__valid_unit_valid_cmd_output(self):
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch('salt.modules.parted._validate_device', MagicMock()):
|
|
|
|
self.cmdrun_stdout.return_value = self.parted_print_output('valid')
|
|
|
|
output = parted.list_('/dev/sda', unit='s')
|
|
|
|
self.cmdrun_stdout.assert_called_once_with('parted -m -s /dev/sda unit s print')
|
|
|
|
expected = {
|
|
|
|
'info': {
|
|
|
|
'logical sector': '512',
|
|
|
|
'physical sector': '512',
|
|
|
|
'interface': 'scsi',
|
|
|
|
'model': 'AMCC 9650SE-24M DISK',
|
|
|
|
'disk': '/dev/sda',
|
|
|
|
'disk flags': '',
|
|
|
|
'partition table': 'gpt',
|
|
|
|
'size': '4000GB'
|
|
|
|
},
|
|
|
|
'partitions': {
|
|
|
|
'1': {
|
|
|
|
'end': '150MB',
|
|
|
|
'number': '1',
|
|
|
|
'start': '17.4kB',
|
|
|
|
'file system': '',
|
|
|
|
'flags': 'boot',
|
|
|
|
'type': 'ext3',
|
|
|
|
'size': '150MB'},
|
|
|
|
'2': {
|
|
|
|
'end': '4000GB',
|
|
|
|
'number': '2',
|
|
|
|
'start': '3921GB',
|
|
|
|
'file system': '',
|
|
|
|
'flags': '',
|
|
|
|
'type': 'linux-swap(v1)',
|
|
|
|
'size': '79.3GB'
|
|
|
|
}
|
2014-09-23 22:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-10 13:00:57 +00:00
|
|
|
self.assertEqual(output, expected)
|
2014-09-23 22:44:33 +00:00
|
|
|
|
|
|
|
def test_list__valid_legacy_cmd_output(self):
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch('salt.modules.parted._validate_device', MagicMock()):
|
|
|
|
self.cmdrun_stdout.return_value = self.parted_print_output('valid_legacy')
|
|
|
|
output = parted.list_('/dev/sda')
|
|
|
|
self.cmdrun_stdout.assert_called_once_with('parted -m -s /dev/sda print')
|
|
|
|
expected = {
|
|
|
|
'info': {
|
|
|
|
'logical sector': '512',
|
|
|
|
'physical sector': '512',
|
|
|
|
'interface': 'scsi',
|
|
|
|
'model': 'AMCC 9650SE-24M DISK',
|
|
|
|
'disk': '/dev/sda',
|
|
|
|
'partition table': 'gpt',
|
|
|
|
'size': '4000GB'
|
|
|
|
},
|
|
|
|
'partitions': {
|
|
|
|
'1': {
|
|
|
|
'end': '150MB',
|
|
|
|
'number': '1',
|
|
|
|
'start': '17.4kB',
|
|
|
|
'file system': '',
|
|
|
|
'flags': 'boot',
|
|
|
|
'type': 'ext3',
|
|
|
|
'size': '150MB'},
|
|
|
|
'2': {
|
|
|
|
'end': '4000GB',
|
|
|
|
'number': '2',
|
|
|
|
'start': '3921GB',
|
|
|
|
'file system': '',
|
|
|
|
'flags': '',
|
|
|
|
'type': 'linux-swap(v1)',
|
|
|
|
'size': '79.3GB'
|
|
|
|
}
|
2014-09-23 22:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-10 13:00:57 +00:00
|
|
|
self.assertEqual(output, expected)
|
2014-09-23 22:44:33 +00:00
|
|
|
|
|
|
|
def test_list__valid_unit_valid_legacy_cmd_output(self):
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch('salt.modules.parted._validate_device', MagicMock()):
|
|
|
|
self.cmdrun_stdout.return_value = self.parted_print_output('valid_legacy')
|
|
|
|
output = parted.list_('/dev/sda', unit='s')
|
|
|
|
self.cmdrun_stdout.assert_called_once_with('parted -m -s /dev/sda unit s print')
|
|
|
|
expected = {
|
|
|
|
'info': {
|
|
|
|
'logical sector': '512',
|
|
|
|
'physical sector': '512',
|
|
|
|
'interface': 'scsi',
|
|
|
|
'model': 'AMCC 9650SE-24M DISK',
|
|
|
|
'disk': '/dev/sda',
|
|
|
|
'partition table': 'gpt',
|
|
|
|
'size': '4000GB'
|
|
|
|
},
|
|
|
|
'partitions': {
|
|
|
|
'1': {
|
|
|
|
'end': '150MB',
|
|
|
|
'number': '1',
|
|
|
|
'start': '17.4kB',
|
|
|
|
'file system': '',
|
|
|
|
'flags': 'boot',
|
|
|
|
'type': 'ext3',
|
|
|
|
'size': '150MB'},
|
|
|
|
'2': {
|
|
|
|
'end': '4000GB',
|
|
|
|
'number': '2',
|
|
|
|
'start': '3921GB',
|
|
|
|
'file system': '',
|
|
|
|
'flags': '',
|
|
|
|
'type': 'linux-swap(v1)',
|
|
|
|
'size': '79.3GB'
|
|
|
|
}
|
2014-09-23 22:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-10 13:00:57 +00:00
|
|
|
self.assertEqual(output, expected)
|