Skip to content

Commit

Permalink
Merge pull request #25244 from rallytime/parted_deprecations
Browse files Browse the repository at this point in the history
Remove parted deprecations and fix failing tests
  • Loading branch information
s0undt3ch committed Jul 8, 2015
2 parents 810b109 + 138c4f1 commit 631cee1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 73 deletions.
29 changes: 1 addition & 28 deletions salt/modules/parted.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _validate_partition_boundary(boundary):
)


def probe(*devices, **kwargs):
def probe(*devices):
'''
Ask the kernel to update its local partition data. When no args are
specified all block devices are tried.
Expand All @@ -113,13 +113,6 @@ def probe(*devices, **kwargs):
salt '*' partition.probe /dev/sda
salt '*' partition.probe /dev/sda /dev/sdb
'''
salt.utils.kwargs_warn_until(kwargs, 'Beryllium')
if 'device' in kwargs:
devices = tuple([kwargs['device']] + list(devices))
del kwargs['device']
if kwargs:
raise TypeError("probe() takes no keyword arguments")

for device in devices:
_validate_device(device)

Expand All @@ -128,26 +121,6 @@ def probe(*devices, **kwargs):
return out


def part_list(device, unit=None):
'''
Deprecated. Calls partition.list.
CLI Examples:
.. code-block:: bash
salt '*' partition.part_list /dev/sda
salt '*' partition.part_list /dev/sda unit=s
salt '*' partition.part_list /dev/sda unit=kB
'''
salt.utils.warn_until(
'Beryllium',
'''The \'part_list\' function has been deprecated in favor of
\'list_\'. Please update your code and configs to reflect this.''')

return list_(device, unit)


def list_(device, unit=None):
'''
partition.list device unit
Expand Down
46 changes: 1 addition & 45 deletions tests/unit/modules/parted_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,58 +84,14 @@ def test_probe_wo_args(self):

@patch('salt.modules.parted._validate_device', MagicMock())
def test_probe_w_single_arg(self):
parted.probe("/dev/sda")
parted.probe('/dev/sda')
self.cmdrun.assert_called_once_with('partprobe -- /dev/sda')

@patch('salt.modules.parted._validate_device', MagicMock())
def test_probe_w_multiple_args(self):
parted.probe('/dev/sda', '/dev/sdb')
self.cmdrun.assert_called_once_with('partprobe -- /dev/sda /dev/sdb')

@staticmethod
def check_kwargs_warn_until_devices(device_kwargs):
def check_args(kwargs, version):
assert kwargs == device_kwargs
assert version == 'Beryllium'
parted.salt.utils.kwargs_warn_until.side_effect = check_args

@patch('salt.utils.kwargs_warn_until')
@patch('salt.modules.parted._validate_device', MagicMock())
def test_probe_w_device_kwarg(self, *args, **kwargs):
device_kwargs = {'device': '/dev/sda'}
parted.probe(**device_kwargs)
self.check_kwargs_warn_until_devices(device_kwargs)
self.cmdrun.assert_called_once_with('partprobe -- /dev/sda')

@patch('salt.utils.kwargs_warn_until')
@patch('salt.modules.parted._validate_device', MagicMock())
def test_probe_w_device_kwarg_and_arg(self, *args, **kwargs):
'''device arg is concatenated with positional args'''
device_kwargs = {'device': '/dev/sda'}
parted.probe("/dev/sdb", **device_kwargs)
self.check_kwargs_warn_until_devices(device_kwargs)
self.cmdrun.assert_called_once_with('partprobe -- /dev/sda /dev/sdb')

@patch('salt.utils.kwargs_warn_until')
def test_probe_w_extra_kwarg(self, *args, **kwargs):
device_kwargs = {'foo': 'bar'}
self.assertRaises(TypeError, parted.probe, **device_kwargs)
self.check_kwargs_warn_until_devices(device_kwargs)
self.assertFalse(self.cmdrun.called)

# Test part_list function

@patch('salt.modules.parted.list_')
@patch('salt.utils.warn_until')
def test_part_list(self, *args, **kwargs):
'''Function should call new function and raise deprecation warning'''
parted.part_list("foo", "bar")
parted.list_.assert_called_once_with("foo", "bar")
parted.salt.utils.warn_until.assert_called_once_with(
'Beryllium',
'''The \'part_list\' function has been deprecated in favor of
\'list_\'. Please update your code and configs to reflect this.''')

# Test _list function

@staticmethod
Expand Down

0 comments on commit 631cee1

Please sign in to comment.