2017-04-29 10:48:33 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:synopsis: Base class for kernelpkg modules
|
|
|
|
:platform: Linux
|
|
|
|
:maturity: develop
|
|
|
|
versionadded:: oxygen
|
|
|
|
'''
|
2017-05-05 12:27:37 +00:00
|
|
|
from __future__ import absolute_import
|
2017-04-29 10:48:33 +00:00
|
|
|
|
2017-05-05 12:27:37 +00:00
|
|
|
# Salt testing libs
|
|
|
|
try:
|
|
|
|
from tests.support.mock import MagicMock, patch
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2017-04-29 10:48:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class KernelPkgTestCase(object):
|
|
|
|
'''
|
|
|
|
Test cases for salt.modules.yumkernelpkg
|
|
|
|
'''
|
|
|
|
|
2017-05-05 01:15:04 +00:00
|
|
|
def test_active(self):
|
2017-04-29 10:48:33 +00:00
|
|
|
'''
|
2017-05-05 01:15:04 +00:00
|
|
|
Test - Return return the active kernel version
|
2017-04-29 10:48:33 +00:00
|
|
|
'''
|
2017-05-05 01:15:04 +00:00
|
|
|
self.assertEqual(self._kernelpkg.active(), self.KERNEL_LIST[0])
|
2017-04-29 10:48:33 +00:00
|
|
|
|
|
|
|
def test_latest_available_no_results(self):
|
|
|
|
'''
|
|
|
|
Test - Return the latest available kernel version
|
|
|
|
'''
|
|
|
|
mock = MagicMock(return_value='')
|
|
|
|
with patch.dict(self._kernelpkg.__salt__, {'pkg.latest_version': mock}):
|
2017-05-05 01:15:04 +00:00
|
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]):
|
2017-05-05 01:35:30 +00:00
|
|
|
self.assertEqual(self._kernelpkg.latest_available(), self.KERNEL_LIST[-1])
|
2017-04-29 10:48:33 +00:00
|
|
|
|
|
|
|
def test_latest_available_at_latest(self):
|
|
|
|
'''
|
|
|
|
Test - Return the latest available kernel version
|
|
|
|
'''
|
|
|
|
mock = MagicMock(return_value=self.LATEST)
|
|
|
|
with patch.dict(self._kernelpkg.__salt__, {'pkg.latest_version': mock}):
|
2017-05-05 01:15:04 +00:00
|
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[-1]):
|
2017-04-29 10:48:33 +00:00
|
|
|
self.assertEqual(self._kernelpkg.latest_available(), self.KERNEL_LIST[-1])
|
|
|
|
|
|
|
|
def test_latest_available_with_updates(self):
|
|
|
|
'''
|
|
|
|
Test - Return the latest available kernel version
|
|
|
|
'''
|
|
|
|
mock = MagicMock(return_value=self.LATEST)
|
|
|
|
with patch.dict(self._kernelpkg.__salt__, {'pkg.latest_version': mock}):
|
2017-05-05 01:15:04 +00:00
|
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]):
|
2017-04-29 10:48:33 +00:00
|
|
|
self.assertEqual(self._kernelpkg.latest_available(), self.KERNEL_LIST[-1])
|
|
|
|
|
|
|
|
def test_latest_installed_with_updates(self):
|
|
|
|
'''
|
|
|
|
Test - Return the latest installed kernel version
|
|
|
|
'''
|
2017-05-05 01:15:04 +00:00
|
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]):
|
2017-04-29 10:48:33 +00:00
|
|
|
with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST):
|
|
|
|
self.assertEqual(self._kernelpkg.latest_installed(), self.KERNEL_LIST[-1])
|
|
|
|
|
|
|
|
def test_latest_installed_at_latest(self):
|
|
|
|
'''
|
|
|
|
Test - Return the latest installed kernel version
|
|
|
|
'''
|
2017-05-05 01:15:04 +00:00
|
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[-1]):
|
2017-04-29 10:48:33 +00:00
|
|
|
with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST):
|
|
|
|
self.assertEqual(self._kernelpkg.latest_installed(), self.KERNEL_LIST[-1])
|
|
|
|
|
|
|
|
def test_needs_reboot_with_update(self):
|
|
|
|
'''
|
|
|
|
Test - Return True if a new kernel is ready to be booted
|
|
|
|
'''
|
2017-05-05 01:15:04 +00:00
|
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]):
|
2017-04-29 10:48:33 +00:00
|
|
|
with patch.object(self._kernelpkg, 'latest_installed', return_value=self.KERNEL_LIST[1]):
|
|
|
|
self.assertTrue(self._kernelpkg.needs_reboot())
|
|
|
|
|
|
|
|
def test_needs_reboot_at_latest(self):
|
|
|
|
'''
|
|
|
|
Test - Return True if a new kernel is ready to be booted
|
|
|
|
'''
|
2017-05-05 01:15:04 +00:00
|
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[1]):
|
2017-04-29 10:48:33 +00:00
|
|
|
with patch.object(self._kernelpkg, 'latest_installed', return_value=self.KERNEL_LIST[1]):
|
|
|
|
self.assertFalse(self._kernelpkg.needs_reboot())
|
|
|
|
|
|
|
|
def test_needs_reboot_order_inverted(self):
|
|
|
|
'''
|
|
|
|
Test - Return True if a new kernel is ready to be booted
|
|
|
|
'''
|
2017-05-05 01:15:04 +00:00
|
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[1]):
|
2017-04-29 10:48:33 +00:00
|
|
|
with patch.object(self._kernelpkg, 'latest_installed', return_value=self.KERNEL_LIST[0]):
|
|
|
|
self.assertFalse(self._kernelpkg.needs_reboot())
|
|
|
|
|
|
|
|
def test_upgrade_not_needed_with_reboot(self):
|
|
|
|
'''
|
2017-05-12 00:09:14 +00:00
|
|
|
Test - Upgrade function when no upgrade is available and reboot has been requested
|
2017-04-29 10:48:33 +00:00
|
|
|
'''
|
2017-05-05 01:15:04 +00:00
|
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[-1]):
|
2017-04-29 10:48:33 +00:00
|
|
|
with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST):
|
|
|
|
result = self._kernelpkg.upgrade(reboot=True)
|
|
|
|
self.assertIn('upgrades', result)
|
2017-05-05 01:15:04 +00:00
|
|
|
self.assertEqual(result['active'], self.KERNEL_LIST[-1])
|
2017-04-29 10:48:33 +00:00
|
|
|
self.assertEqual(result['latest_installed'], self.KERNEL_LIST[-1])
|
|
|
|
self.assertEqual(result['reboot_requested'], True)
|
|
|
|
self.assertEqual(result['reboot_required'], False)
|
|
|
|
self._kernelpkg.__salt__['system.reboot'].assert_not_called()
|
|
|
|
|
|
|
|
def test_upgrade_not_needed_without_reboot(self):
|
|
|
|
'''
|
2017-05-12 00:09:14 +00:00
|
|
|
Test - Upgrade function when no upgrade is available and no reboot has been requested
|
2017-04-29 10:48:33 +00:00
|
|
|
'''
|
2017-05-05 01:15:04 +00:00
|
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[-1]):
|
2017-04-29 10:48:33 +00:00
|
|
|
with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST):
|
|
|
|
result = self._kernelpkg.upgrade(reboot=False)
|
|
|
|
self.assertIn('upgrades', result)
|
2017-05-05 01:15:04 +00:00
|
|
|
self.assertEqual(result['active'], self.KERNEL_LIST[-1])
|
2017-04-29 10:48:33 +00:00
|
|
|
self.assertEqual(result['latest_installed'], self.KERNEL_LIST[-1])
|
|
|
|
self.assertEqual(result['reboot_requested'], False)
|
|
|
|
self.assertEqual(result['reboot_required'], False)
|
|
|
|
self._kernelpkg.__salt__['system.reboot'].assert_not_called()
|
|
|
|
|
|
|
|
def test_upgrade_needed_with_reboot(self):
|
|
|
|
'''
|
2017-05-12 00:09:14 +00:00
|
|
|
Test - Upgrade function when an upgrade is available and reboot has been requested
|
2017-04-29 10:48:33 +00:00
|
|
|
'''
|
2017-05-05 01:15:04 +00:00
|
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]):
|
2017-04-29 10:48:33 +00:00
|
|
|
with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST):
|
|
|
|
result = self._kernelpkg.upgrade(reboot=True)
|
|
|
|
self.assertIn('upgrades', result)
|
2017-05-05 01:15:04 +00:00
|
|
|
self.assertEqual(result['active'], self.KERNEL_LIST[0])
|
2017-04-29 10:48:33 +00:00
|
|
|
self.assertEqual(result['latest_installed'], self.KERNEL_LIST[-1])
|
|
|
|
self.assertEqual(result['reboot_requested'], True)
|
|
|
|
self.assertEqual(result['reboot_required'], True)
|
2017-07-07 16:28:19 +00:00
|
|
|
self.assert_called_once(self._kernelpkg.__salt__['system.reboot'])
|
2017-04-29 10:48:33 +00:00
|
|
|
|
|
|
|
def test_upgrade_needed_without_reboot(self):
|
|
|
|
'''
|
2017-05-12 00:09:14 +00:00
|
|
|
Test - Upgrade function when an upgrade is available and no reboot has been requested
|
2017-04-29 10:48:33 +00:00
|
|
|
'''
|
2017-05-05 01:15:04 +00:00
|
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]):
|
2017-04-29 10:48:33 +00:00
|
|
|
with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST):
|
|
|
|
result = self._kernelpkg.upgrade(reboot=False)
|
|
|
|
self.assertIn('upgrades', result)
|
2017-05-05 01:15:04 +00:00
|
|
|
self.assertEqual(result['active'], self.KERNEL_LIST[0])
|
2017-04-29 10:48:33 +00:00
|
|
|
self.assertEqual(result['latest_installed'], self.KERNEL_LIST[-1])
|
|
|
|
self.assertEqual(result['reboot_requested'], False)
|
|
|
|
self.assertEqual(result['reboot_required'], True)
|
|
|
|
self._kernelpkg.__salt__['system.reboot'].assert_not_called()
|
2017-05-12 00:09:14 +00:00
|
|
|
|
|
|
|
def test_upgrade_available_true(self):
|
|
|
|
'''
|
|
|
|
Test - upgrade_available
|
|
|
|
'''
|
|
|
|
with patch.object(self._kernelpkg, 'latest_available', return_value=self.KERNEL_LIST[-1]):
|
|
|
|
with patch.object(self._kernelpkg, 'latest_installed', return_value=self.KERNEL_LIST[0]):
|
|
|
|
self.assertTrue(self._kernelpkg.upgrade_available())
|
|
|
|
|
|
|
|
def test_upgrade_available_false(self):
|
|
|
|
'''
|
|
|
|
Test - upgrade_available
|
|
|
|
'''
|
|
|
|
with patch.object(self._kernelpkg, 'latest_available', return_value=self.KERNEL_LIST[-1]):
|
|
|
|
with patch.object(self._kernelpkg, 'latest_installed', return_value=self.KERNEL_LIST[-1]):
|
|
|
|
self.assertFalse(self._kernelpkg.upgrade_available())
|
|
|
|
|
|
|
|
def test_upgrade_available_inverted(self):
|
|
|
|
'''
|
|
|
|
Test - upgrade_available
|
|
|
|
'''
|
|
|
|
with patch.object(self._kernelpkg, 'latest_available', return_value=self.KERNEL_LIST[0]):
|
|
|
|
with patch.object(self._kernelpkg, 'latest_installed', return_value=self.KERNEL_LIST[-1]):
|
|
|
|
self.assertFalse(self._kernelpkg.upgrade_available())
|