test_config.py 3.1 KB

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