Refactor update

This commit is contained in:
twangboy 2016-03-18 14:12:31 -06:00
parent d41e62b1d3
commit 182b80d67e
2 changed files with 11 additions and 14 deletions

View File

@ -324,14 +324,9 @@ def update(name):
.. code-block:: bash
salt '*' softwareupdate.install <update-name>
salt '*' softwareupdate.update <update-name>
'''
try:
updates = _get_available()
except CommandExecutionError as exc:
raise CommandExecutionError(exc)
if name not in updates:
if not update_available(name):
raise SaltInvocationError('Update not available: {0}'.format(name))
try:
@ -340,12 +335,7 @@ def update(name):
except CommandExecutionError as exc:
raise CommandExecutionError(exc)
try:
updates = _get_available()
except CommandExecutionError as exc:
raise CommandExecutionError(exc)
return name not in updates
return not update_available(name)
def update_available(name):

View File

@ -113,15 +113,22 @@ class MacSoftwareUpdateModuleTest(integration.ModuleCase):
self.assertFalse(self.run_function('softwareupdate.schedule_enabled'))
@destructiveTest
def test_update_all(self):
def test_update(self):
'''
Test softwareupdate.update_all
Test softwareupdate.update
Test softwareupdate.update_available
'''
# There's no way to know what the dictionary will contain, so all we can
# check is that the return is a dictionary
self.assertIsInstance(
self.run_function('softwareupdate.update_all'), dict)
# Test update not available
self.assertIn(
'Update not available',
self.run_function('softwareupdate.update', ['spongebob']))
@destructiveTest
def test_install(self):
'''