test_tuned.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import
  3. from salt.modules import tuned
  4. from tests.support.mixins import LoaderModuleMockMixin
  5. from tests.support.unit import TestCase
  6. from tests.support.mock import (
  7. MagicMock,
  8. patch,
  9. )
  10. class TunedListTestCase(TestCase, LoaderModuleMockMixin):
  11. '''
  12. Test the tuned.list_() method for different versions of tuned-adm
  13. '''
  14. def setup_loader_modules(self):
  15. return {tuned: {}}
  16. def test_v_241(self):
  17. '''
  18. Test the list_ function for older tuned-adm (v2.4.1)
  19. as shipped with CentOS-6
  20. '''
  21. tuned_list = '''Available profiles:
  22. - throughput-performance
  23. - virtual-guest
  24. - latency-performance
  25. - laptop-battery-powersave
  26. - laptop-ac-powersave
  27. - virtual-host
  28. - desktop-powersave
  29. - server-powersave
  30. - spindown-disk
  31. - sap
  32. - enterprise-storage
  33. - default
  34. Current active profile: throughput-performance'''
  35. mock_cmd = MagicMock(return_value=tuned_list)
  36. with patch.dict(tuned.__salt__, {'cmd.run': mock_cmd}):
  37. self.assertEqual(
  38. tuned.list_(),
  39. ['throughput-performance', 'virtual-guest',
  40. 'latency-performance', 'laptop-battery-powersave',
  41. 'laptop-ac-powersave', 'virtual-host',
  42. 'desktop-powersave', 'server-powersave',
  43. 'spindown-disk', 'sap', 'enterprise-storage', 'default'])
  44. def test_v_271(self):
  45. '''
  46. Test the list_ function for newer tuned-adm (v2.7.1)
  47. as shipped with CentOS-7
  48. '''
  49. tuned_list = '''Available profiles:
  50. - balanced - General non-specialized tuned profile
  51. - desktop - Optmize for the desktop use-case
  52. - latency-performance - Optimize for deterministic performance
  53. - network-latency - Optimize for deterministic performance
  54. - network-throughput - Optimize for streaming network throughput.
  55. - powersave - Optimize for low power-consumption
  56. - throughput-performance - Broadly applicable tuning that provides--
  57. - virtual-guest - Optimize for running inside a virtual-guest.
  58. - virtual-host - Optimize for running KVM guests
  59. Current active profile: virtual-guest
  60. '''
  61. mock_cmd = MagicMock(return_value=tuned_list)
  62. with patch.dict(tuned.__salt__, {'cmd.run': mock_cmd}):
  63. self.assertEqual(
  64. tuned.list_(),
  65. ['balanced', 'desktop', 'latency-performance',
  66. 'network-latency', 'network-throughput', 'powersave',
  67. 'throughput-performance', 'virtual-guest',
  68. 'virtual-host'])