1
0

test_napalm.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: :email:`Anthony Shaw <anthonyshaw@apache.org>`
  4. '''
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  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. patch
  13. )
  14. import tests.support.napalm as napalm_test_support
  15. import salt.proxy.napalm as napalm_proxy # NOQA
  16. TEST_OPTS = {
  17. 'proxytype': 'napalm',
  18. 'driver': 'junos',
  19. 'host': 'core05.nrt02'
  20. }
  21. def mock_get_device(opts, *args, **kwargs):
  22. assert opts == TEST_OPTS
  23. return {
  24. 'DRIVER': napalm_test_support.MockNapalmDevice(),
  25. 'UP': True
  26. }
  27. @patch('salt.utils.napalm.get_device', mock_get_device)
  28. class NapalmProxyTestCase(TestCase, LoaderModuleMockMixin):
  29. def setup_loader_modules(self):
  30. module_globals = {
  31. '__salt__': {
  32. 'config.option': MagicMock(return_value={
  33. 'test': {
  34. 'driver': 'test',
  35. 'key': '2orgk34kgk34g'
  36. }
  37. })
  38. }
  39. }
  40. module_globals['napalm_base'] = MagicMock()
  41. return {napalm_proxy: module_globals}
  42. def test_init(self):
  43. ret = napalm_proxy.init(TEST_OPTS)
  44. assert ret is True
  45. def test_alive(self):
  46. ret = napalm_proxy.alive(TEST_OPTS)
  47. assert ret is True
  48. def test_ping(self):
  49. napalm_proxy.init(TEST_OPTS)
  50. ret = napalm_proxy.ping()
  51. assert ret is True
  52. def test_initialized(self):
  53. napalm_proxy.init(TEST_OPTS)
  54. ret = napalm_proxy.initialized()
  55. assert ret is True
  56. def test_get_device(self):
  57. napalm_proxy.init(TEST_OPTS)
  58. ret = napalm_proxy.get_device()
  59. assert ret['UP'] is True
  60. def test_get_grains(self):
  61. napalm_proxy.init(TEST_OPTS)
  62. ret = napalm_proxy.get_grains()
  63. assert ret['out'] == napalm_test_support.TEST_FACTS
  64. def test_grains_refresh(self):
  65. napalm_proxy.init(TEST_OPTS)
  66. ret = napalm_proxy.grains_refresh()
  67. assert ret['out'] == napalm_test_support.TEST_FACTS
  68. def test_fns(self):
  69. ret = napalm_proxy.fns()
  70. assert 'details' in ret.keys()
  71. def test_shutdown(self):
  72. ret = napalm_proxy.shutdown(TEST_OPTS)
  73. assert ret is True
  74. def test_call(self):
  75. napalm_proxy.init(TEST_OPTS)
  76. ret = napalm_proxy.call('get_arp_table')
  77. assert ret['out'] == napalm_test_support.TEST_ARP_TABLE