test_net.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- coding: utf-8 -*-
  2. # Import Python Libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import shutil
  5. import tempfile
  6. # Import salt libs
  7. import salt.runners.net as net
  8. # Import Salt Testing Libs
  9. from tests.support.mixins import LoaderModuleMockMixin
  10. from tests.support.mock import MagicMock
  11. from tests.support.runtests import RUNTIME_VARS
  12. from tests.support.unit import TestCase, skipIf
  13. @skipIf(not net.HAS_NAPALM, "napalm module required for this test")
  14. class NetTest(TestCase, LoaderModuleMockMixin):
  15. """
  16. Test the net runner
  17. """
  18. def setup_loader_modules(self):
  19. mock_get = MagicMock(return_value={})
  20. self.extmods_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  21. self.addCleanup(shutil.rmtree, self.extmods_dir, ignore_errors=True)
  22. return {
  23. net: {
  24. "__opts__": {
  25. "optimization_order": [0, 1, 2],
  26. "renderer": "yaml",
  27. "renderer_blacklist": [],
  28. "renderer_whitelist": [],
  29. "extension_modules": self.extmods_dir,
  30. },
  31. "__salt__": {"mine.get": mock_get},
  32. }
  33. }
  34. def test_interfaces(self):
  35. ret = net.interfaces()
  36. self.assertEqual(None, ret)
  37. def test_findarp(self):
  38. ret = net.findarp()
  39. self.assertEqual(None, ret)
  40. def test_findmac(self):
  41. ret = net.findmac()
  42. self.assertEqual(None, ret)
  43. def test_lldp(self):
  44. ret = net.lldp()
  45. self.assertEqual(None, ret)
  46. def test_find(self):
  47. ret = net.find("")
  48. self.assertEqual({}, ret)
  49. def test_multi_find(self):
  50. ret = net.multi_find()
  51. self.assertEqual(None, ret)