test_napalm_ntp.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: :email:`Anthony Shaw <anthonyshaw@apache.org>`
  4. '''
  5. # Import Python Libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  7. # Import Salt Testing Libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase
  10. from tests.support.mock import (
  11. MagicMock,
  12. )
  13. import tests.support.napalm as napalm_test_support
  14. import salt.modules.napalm_ntp as napalm_ntp # NOQA
  15. def mock_net_load_template(template, *args, **kwargs):
  16. if template == 'set_ntp_peers' or template == 'delete_ntp_peers':
  17. assert '1.2.3.4' in kwargs['peers']
  18. if template == 'set_ntp_servers' or template == 'delete_ntp_servers':
  19. assert '2.2.3.4' in kwargs['servers']
  20. class NapalmNtpModuleTestCase(TestCase, LoaderModuleMockMixin):
  21. def setup_loader_modules(self):
  22. module_globals = {
  23. '__salt__': {
  24. 'config.option': MagicMock(return_value={
  25. 'test': {
  26. 'driver': 'test',
  27. 'key': '2orgk34kgk34g'
  28. }
  29. }),
  30. 'file.file_exists': napalm_test_support.true,
  31. 'file.join': napalm_test_support.join,
  32. 'file.get_managed': napalm_test_support.get_managed_file,
  33. 'random.hash': napalm_test_support.random_hash,
  34. 'net.load_template': mock_net_load_template
  35. }
  36. }
  37. return {napalm_ntp: module_globals}
  38. def test_peers(self):
  39. ret = napalm_ntp.peers()
  40. assert '172.17.17.1' in ret['out']
  41. def test_servers(self):
  42. ret = napalm_ntp.servers()
  43. assert '172.17.17.1' in ret['out']
  44. def test_stats(self):
  45. ret = napalm_ntp.stats()
  46. assert ret['out'][0]['reachability'] == 377
  47. def test_set_peers(self):
  48. ret = napalm_ntp.set_peers('1.2.3.4', '5.6.7.8')
  49. assert ret is None
  50. def test_set_servers(self):
  51. ret = napalm_ntp.set_servers('2.2.3.4', '6.6.7.8')
  52. assert ret is None
  53. def test_delete_servers(self):
  54. ret = napalm_ntp.delete_servers('2.2.3.4', '6.6.7.8')
  55. assert ret is None
  56. def test_delete_peers(self):
  57. ret = napalm_ntp.delete_peers('1.2.3.4', '5.6.7.8')
  58. assert ret is None