test_napalm_probes.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_probes as napalm_probes # NOQA
  15. TEST_PROBES = {
  16. 'new_probe': {
  17. 'new_test1': {
  18. 'probe_type': 'icmp-ping',
  19. 'target': '192.168.0.1',
  20. 'source': '192.168.0.2',
  21. 'probe_count': 13,
  22. 'test_interval': 3
  23. }
  24. }
  25. }
  26. TEST_DELETE_PROBES = {
  27. 'existing_probe': {
  28. 'existing_test1': {},
  29. 'existing_test2': {}
  30. }
  31. }
  32. TEST_SCHEDULE_PROBES = {
  33. 'test_probe': {
  34. 'existing_test1': {},
  35. 'existing_test2': {}
  36. }
  37. }
  38. def mock_net_load(template, *args, **kwargs):
  39. if template == 'set_probes':
  40. assert kwargs['probes'] == TEST_PROBES
  41. return napalm_test_support.TEST_TERM_CONFIG
  42. if template == 'delete_probes':
  43. assert kwargs['probes'] == TEST_DELETE_PROBES
  44. return napalm_test_support.TEST_TERM_CONFIG
  45. if template == 'schedule_probes':
  46. assert kwargs['probes'] == TEST_SCHEDULE_PROBES
  47. return napalm_test_support.TEST_TERM_CONFIG
  48. raise ValueError("incorrect template {0}".format(template))
  49. class NapalmProbesModuleTestCase(TestCase, LoaderModuleMockMixin):
  50. def setup_loader_modules(self):
  51. module_globals = {
  52. '__salt__': {
  53. 'config.option': MagicMock(return_value={
  54. 'test': {
  55. 'driver': 'test',
  56. 'key': '2orgk34kgk34g'
  57. }
  58. }),
  59. 'file.file_exists': napalm_test_support.true,
  60. 'file.join': napalm_test_support.join,
  61. 'file.get_managed': napalm_test_support.get_managed_file,
  62. 'random.hash': napalm_test_support.random_hash,
  63. 'net.load_template': mock_net_load
  64. }
  65. }
  66. return {napalm_probes: module_globals}
  67. def test_probes_config(self):
  68. ret = napalm_probes.config()
  69. assert ret['out'] == napalm_test_support.TEST_PROBES_CONFIG
  70. def test_probes_results(self):
  71. ret = napalm_probes.results()
  72. assert ret['out'] == napalm_test_support.TEST_PROBES_RESULTS
  73. def test_set_probes(self):
  74. ret = napalm_probes.set_probes(TEST_PROBES)
  75. assert ret['result'] is True
  76. def test_delete_probes(self):
  77. ret = napalm_probes.delete_probes(TEST_DELETE_PROBES)
  78. assert ret['result'] is True
  79. def test_schedule_probes(self):
  80. ret = napalm_probes.schedule_probes(TEST_SCHEDULE_PROBES)
  81. assert ret['result'] is True