test_config.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Validate the config system
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import
  7. # Import Salt Testing libs
  8. from tests.support.case import ModuleCase
  9. import pytest
  10. @pytest.mark.windows_whitelisted
  11. class ConfigTest(ModuleCase):
  12. '''
  13. Test config routines
  14. '''
  15. def test_valid_file_proto(self):
  16. '''
  17. test config.valid_file_proto
  18. '''
  19. self.assertTrue(
  20. self.run_function('config.valid_fileproto', ['salt://']))
  21. self.assertTrue(
  22. self.run_function('config.valid_fileproto', ['http://']))
  23. self.assertTrue(
  24. self.run_function('config.valid_fileproto', ['https://']))
  25. self.assertTrue(
  26. self.run_function('config.valid_fileproto', ['ftp://']))
  27. self.assertFalse(
  28. self.run_function('config.valid_fileproto', ['cheese://']))
  29. def test_backup_mode(self):
  30. '''
  31. test config.backup_mode
  32. '''
  33. self.assertEqual(
  34. self.run_function('config.backup_mode', ['minion']), 'minion')
  35. def test_manage_mode(self):
  36. '''
  37. test config.manage_mode
  38. '''
  39. # This function is generally only used with cross calls, the yaml
  40. # interpreter is breaking it for remote calls
  41. # The correct standard is the four digit form.
  42. self.assertEqual(
  43. self.run_function('config.manage_mode', ['"775"']), '0775')
  44. self.assertEqual(
  45. self.run_function('config.manage_mode', ['"1775"']), '1775')
  46. self.assertEqual(
  47. self.run_function('config.manage_mode', ['"0775"']), '0775')
  48. self.assertEqual(
  49. self.run_function('config.manage_mode', ['"01775"']), '1775')
  50. self.assertEqual(
  51. self.run_function('config.manage_mode', ['"0"']), '0000')
  52. self.assertEqual(
  53. self.run_function('config.manage_mode', ['775']), '0775')
  54. self.assertEqual(
  55. self.run_function('config.manage_mode', ['1775']), '1775')
  56. self.assertEqual(
  57. self.run_function('config.manage_mode', ['0']), '0000')
  58. def test_option(self):
  59. '''
  60. test config.option
  61. '''
  62. # Minion opt
  63. self.assertEqual(
  64. self.run_function(
  65. 'config.option',
  66. ['master_port']),
  67. self.get_config('minion')['master_port'])
  68. # pillar conf opt
  69. self.assertEqual(
  70. self.run_function(
  71. 'config.option',
  72. ['ext_spam']),
  73. 'eggs')
  74. def test_get(self):
  75. '''
  76. Test option.get
  77. '''
  78. # Check pillar get
  79. self.assertEqual(
  80. self.run_function(
  81. 'config.get',
  82. ['level1:level2']),
  83. 'foo')
  84. # Check master config
  85. self.assertEqual(
  86. self.run_function(
  87. 'config.get',
  88. ['config_opt:layer2']),
  89. 'kosher')
  90. # Check minion config
  91. self.assertEqual(
  92. self.run_function(
  93. 'config.get',
  94. ['config_test:spam']),
  95. 'eggs')