mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
bf45c18f9d
These tests are new to develop and need to be converted to use the new assert_called_once syntax introduced in #42084.
174 lines
8.2 KiB
Python
174 lines
8.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
'''
|
|
:synopsis: Base class for kernelpkg modules
|
|
:platform: Linux
|
|
:maturity: develop
|
|
versionadded:: oxygen
|
|
'''
|
|
from __future__ import absolute_import
|
|
|
|
# Salt testing libs
|
|
try:
|
|
from tests.support.mock import MagicMock, patch
|
|
except ImportError:
|
|
pass
|
|
|
|
|
|
class KernelPkgTestCase(object):
|
|
'''
|
|
Test cases for salt.modules.yumkernelpkg
|
|
'''
|
|
|
|
def test_active(self):
|
|
'''
|
|
Test - Return return the active kernel version
|
|
'''
|
|
self.assertEqual(self._kernelpkg.active(), self.KERNEL_LIST[0])
|
|
|
|
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}):
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]):
|
|
self.assertEqual(self._kernelpkg.latest_available(), self.KERNEL_LIST[-1])
|
|
|
|
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}):
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[-1]):
|
|
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}):
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]):
|
|
self.assertEqual(self._kernelpkg.latest_available(), self.KERNEL_LIST[-1])
|
|
|
|
def test_latest_installed_with_updates(self):
|
|
'''
|
|
Test - Return the latest installed kernel version
|
|
'''
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]):
|
|
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
|
|
'''
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[-1]):
|
|
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
|
|
'''
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]):
|
|
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
|
|
'''
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[1]):
|
|
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
|
|
'''
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[1]):
|
|
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):
|
|
'''
|
|
Test - Upgrade function when no upgrade is available and reboot has been requested
|
|
'''
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[-1]):
|
|
with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST):
|
|
result = self._kernelpkg.upgrade(reboot=True)
|
|
self.assertIn('upgrades', result)
|
|
self.assertEqual(result['active'], self.KERNEL_LIST[-1])
|
|
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):
|
|
'''
|
|
Test - Upgrade function when no upgrade is available and no reboot has been requested
|
|
'''
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[-1]):
|
|
with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST):
|
|
result = self._kernelpkg.upgrade(reboot=False)
|
|
self.assertIn('upgrades', result)
|
|
self.assertEqual(result['active'], self.KERNEL_LIST[-1])
|
|
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):
|
|
'''
|
|
Test - Upgrade function when an upgrade is available and reboot has been requested
|
|
'''
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]):
|
|
with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST):
|
|
result = self._kernelpkg.upgrade(reboot=True)
|
|
self.assertIn('upgrades', result)
|
|
self.assertEqual(result['active'], self.KERNEL_LIST[0])
|
|
self.assertEqual(result['latest_installed'], self.KERNEL_LIST[-1])
|
|
self.assertEqual(result['reboot_requested'], True)
|
|
self.assertEqual(result['reboot_required'], True)
|
|
self.assert_called_once(self._kernelpkg.__salt__['system.reboot'])
|
|
|
|
def test_upgrade_needed_without_reboot(self):
|
|
'''
|
|
Test - Upgrade function when an upgrade is available and no reboot has been requested
|
|
'''
|
|
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]):
|
|
with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST):
|
|
result = self._kernelpkg.upgrade(reboot=False)
|
|
self.assertIn('upgrades', result)
|
|
self.assertEqual(result['active'], self.KERNEL_LIST[0])
|
|
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()
|
|
|
|
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())
|