1
0

test_network.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import
  3. import pytest
  4. import salt.utils.path
  5. import salt.utils.platform
  6. from tests.support.case import ModuleCase
  7. from tests.support.helpers import slowTest
  8. from tests.support.unit import skipIf
  9. URL = "google-public-dns-a.google.com"
  10. @pytest.mark.windows_whitelisted
  11. class NetworkTest(ModuleCase):
  12. """
  13. Validate network module
  14. """
  15. @slowTest
  16. def test_network_ping(self):
  17. """
  18. network.ping
  19. """
  20. ret = self.run_function("network.ping", [URL])
  21. exp_out = ["ping", URL, "ms", "time"]
  22. for out in exp_out:
  23. self.assertIn(out, ret.lower())
  24. @skipIf(salt.utils.platform.is_darwin(), "not supported on macosx")
  25. @slowTest
  26. def test_network_netstat(self):
  27. """
  28. network.netstat
  29. """
  30. ret = self.run_function("network.netstat")
  31. exp_out = ["proto", "local-address"]
  32. for val in ret:
  33. for out in exp_out:
  34. self.assertIn(out, val)
  35. @slowTest
  36. def test_network_traceroute(self):
  37. """
  38. network.traceroute
  39. """
  40. if (
  41. not salt.utils.path.which("traceroute")
  42. and not salt.utils.platform.is_windows()
  43. ):
  44. self.skipTest("traceroute not installed")
  45. ret = self.run_function("network.traceroute", [URL])
  46. exp_out = ["hostname", "ip"]
  47. for out in exp_out:
  48. self.assertIn(out, exp_out)
  49. @skipIf(not salt.utils.platform.is_windows(), "windows only test")
  50. @slowTest
  51. def test_network_nslookup(self):
  52. """
  53. network.nslookup
  54. """
  55. ret = self.run_function("network.nslookup", [URL])
  56. exp_out = ["Server", "Address"]
  57. for out in exp_out:
  58. self.assertIn(out, exp_out)