1
0

test_helpers.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import
  4. import copy
  5. import logging
  6. import os
  7. # Import Salt Testing libs
  8. from tests.support.case import ModuleCase
  9. from tests.support.mixins import SaltReturnAssertsMixin
  10. from tests.support.mock import MagicMock, patch
  11. from tests.support.runtests import RUNTIME_VARS
  12. # Import Salt libs
  13. import salt.utils.schedule
  14. import salt.utils.platform
  15. from salt.modules.test import ping
  16. log = logging.getLogger(__name__)
  17. ROOT_DIR = os.path.join(RUNTIME_VARS.TMP, 'schedule-unit-tests')
  18. SOCK_DIR = os.path.join(ROOT_DIR, 'test-socks')
  19. DEFAULT_CONFIG = salt.config.minion_config(None)
  20. DEFAULT_CONFIG['conf_dir'] = ROOT_DIR
  21. DEFAULT_CONFIG['root_dir'] = ROOT_DIR
  22. DEFAULT_CONFIG['sock_dir'] = SOCK_DIR
  23. DEFAULT_CONFIG['pki_dir'] = os.path.join(ROOT_DIR, 'pki')
  24. DEFAULT_CONFIG['cachedir'] = os.path.join(ROOT_DIR, 'cache')
  25. class SchedulerHelpersTest(ModuleCase, SaltReturnAssertsMixin):
  26. '''
  27. Test scheduler helper functions
  28. '''
  29. def setUp(self):
  30. with patch('salt.utils.schedule.clean_proc_dir', MagicMock(return_value=None)):
  31. functions = {'test.ping': ping}
  32. self.schedule = salt.utils.schedule.Schedule(copy.deepcopy(DEFAULT_CONFIG), functions, returners={})
  33. self.schedule.opts['loop_interval'] = 1
  34. def tearDown(self):
  35. self.schedule.reset()
  36. def test_get_schedule(self):
  37. '''
  38. verify that the _get_schedule function works
  39. when remove_hidden is True and schedule data
  40. contains enabled key
  41. '''
  42. job_name = 'test_get_schedule'
  43. job = {
  44. 'schedule': {
  45. 'enabled': True,
  46. job_name: {
  47. 'function': 'test.ping',
  48. 'seconds': 60
  49. }
  50. }
  51. }
  52. # Add the job to the scheduler
  53. self.schedule.opts.update(job)
  54. ret = self.schedule._get_schedule(remove_hidden=True)
  55. self.assertEqual(job['schedule'], ret)