test_tuned.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.mock import MagicMock, patch
  6. from tests.support.unit import TestCase
  7. class TunedListTestCase(TestCase, LoaderModuleMockMixin):
  8. """
  9. Test the tuned.list_() method for different versions of tuned-adm
  10. """
  11. def setup_loader_modules(self):
  12. return {tuned: {}}
  13. def test_v_241(self):
  14. """
  15. Test the list_ function for older tuned-adm (v2.4.1)
  16. as shipped with CentOS-6
  17. """
  18. tuned_list = """Available profiles:
  19. - throughput-performance
  20. - virtual-guest
  21. - latency-performance
  22. - laptop-battery-powersave
  23. - laptop-ac-powersave
  24. - virtual-host
  25. - desktop-powersave
  26. - server-powersave
  27. - spindown-disk
  28. - sap
  29. - enterprise-storage
  30. - default
  31. Current active profile: throughput-performance"""
  32. mock_cmd = MagicMock(return_value=tuned_list)
  33. with patch.dict(tuned.__salt__, {"cmd.run": mock_cmd}):
  34. self.assertEqual(
  35. tuned.list_(),
  36. [
  37. "throughput-performance",
  38. "virtual-guest",
  39. "latency-performance",
  40. "laptop-battery-powersave",
  41. "laptop-ac-powersave",
  42. "virtual-host",
  43. "desktop-powersave",
  44. "server-powersave",
  45. "spindown-disk",
  46. "sap",
  47. "enterprise-storage",
  48. "default",
  49. ],
  50. )
  51. def test_v_271(self):
  52. """
  53. Test the list_ function for newer tuned-adm (v2.7.1)
  54. as shipped with CentOS-7
  55. """
  56. tuned_list = """Available profiles:
  57. - balanced - General non-specialized tuned profile
  58. - desktop - Optmize for the desktop use-case
  59. - latency-performance - Optimize for deterministic performance
  60. - network-latency - Optimize for deterministic performance
  61. - network-throughput - Optimize for streaming network throughput.
  62. - powersave - Optimize for low power-consumption
  63. - throughput-performance - Broadly applicable tuning that provides--
  64. - virtual-guest - Optimize for running inside a virtual-guest.
  65. - virtual-host - Optimize for running KVM guests
  66. Current active profile: virtual-guest
  67. """
  68. mock_cmd = MagicMock(return_value=tuned_list)
  69. with patch.dict(tuned.__salt__, {"cmd.run": mock_cmd}):
  70. self.assertEqual(
  71. tuned.list_(),
  72. [
  73. "balanced",
  74. "desktop",
  75. "latency-performance",
  76. "network-latency",
  77. "network-throughput",
  78. "powersave",
  79. "throughput-performance",
  80. "virtual-guest",
  81. "virtual-host",
  82. ],
  83. )
  84. def test_none(self):
  85. """
  86. """
  87. ret = {
  88. "pid": 12345,
  89. "retcode": 1,
  90. "stderr": "stderr: Cannot talk to Tuned daemon via DBus. Is Tuned daemon running?",
  91. "stdout": "No current active profile.",
  92. }
  93. mock_cmd = MagicMock(return_value=ret)
  94. with patch.dict(tuned.__salt__, {"cmd.run_all": mock_cmd}):
  95. self.assertEqual(tuned.active(), "none")