test_napalm.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 tests.support.napalm as napalm_test_support
  8. # Import Salt Testing Libs
  9. from tests.support.mixins import LoaderModuleMockMixin
  10. from tests.support.mock import MagicMock, patch
  11. from tests.support.unit import TestCase
  12. import salt.proxy.napalm as napalm_proxy # NOQA
  13. TEST_OPTS = {"proxytype": "napalm", "driver": "junos", "host": "core05.nrt02"}
  14. def mock_get_device(opts, *args, **kwargs):
  15. assert opts == TEST_OPTS
  16. return {"DRIVER": napalm_test_support.MockNapalmDevice(), "UP": True}
  17. @patch("salt.utils.napalm.get_device", mock_get_device)
  18. class NapalmProxyTestCase(TestCase, LoaderModuleMockMixin):
  19. def setup_loader_modules(self):
  20. module_globals = {
  21. "__salt__": {
  22. "config.option": MagicMock(
  23. return_value={"test": {"driver": "test", "key": "2orgk34kgk34g"}}
  24. )
  25. }
  26. }
  27. module_globals["napalm_base"] = MagicMock()
  28. return {napalm_proxy: module_globals}
  29. def test_init(self):
  30. ret = napalm_proxy.init(TEST_OPTS)
  31. assert ret is True
  32. def test_alive(self):
  33. ret = napalm_proxy.alive(TEST_OPTS)
  34. assert ret is True
  35. def test_ping(self):
  36. napalm_proxy.init(TEST_OPTS)
  37. ret = napalm_proxy.ping()
  38. assert ret is True
  39. def test_initialized(self):
  40. napalm_proxy.init(TEST_OPTS)
  41. ret = napalm_proxy.initialized()
  42. assert ret is True
  43. def test_get_device(self):
  44. napalm_proxy.init(TEST_OPTS)
  45. ret = napalm_proxy.get_device()
  46. assert ret["UP"] is True
  47. def test_get_grains(self):
  48. napalm_proxy.init(TEST_OPTS)
  49. ret = napalm_proxy.get_grains()
  50. assert ret["out"] == napalm_test_support.TEST_FACTS
  51. def test_grains_refresh(self):
  52. napalm_proxy.init(TEST_OPTS)
  53. ret = napalm_proxy.grains_refresh()
  54. assert ret["out"] == napalm_test_support.TEST_FACTS
  55. def test_fns(self):
  56. ret = napalm_proxy.fns()
  57. assert "details" in ret.keys()
  58. def test_shutdown(self):
  59. ret = napalm_proxy.shutdown(TEST_OPTS)
  60. assert ret is True
  61. def test_call(self):
  62. napalm_proxy.init(TEST_OPTS)
  63. ret = napalm_proxy.call("get_arp_table")
  64. assert ret["out"] == napalm_test_support.TEST_ARP_TABLE