1
0

test_napalm.py 2.5 KB

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