test_network.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.unit import skipIf
  8. URL = "google-public-dns-a.google.com"
  9. @pytest.mark.windows_whitelisted
  10. class NetworkTest(ModuleCase):
  11. """
  12. Validate network module
  13. """
  14. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  15. def test_network_ping(self):
  16. """
  17. network.ping
  18. """
  19. ret = self.run_function("network.ping", [URL])
  20. exp_out = ["ping", URL, "ms", "time"]
  21. for out in exp_out:
  22. self.assertIn(out, ret.lower())
  23. @skipIf(salt.utils.platform.is_darwin(), "not supported on macosx")
  24. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  25. def test_network_netstat(self):
  26. """
  27. network.netstat
  28. """
  29. ret = self.run_function("network.netstat")
  30. exp_out = ["proto", "local-address"]
  31. for val in ret:
  32. for out in exp_out:
  33. self.assertIn(out, val)
  34. @pytest.mark.slow_test(seconds=240) # Test takes >120 and <=240 seconds
  35. def test_network_traceroute(self):
  36. """
  37. network.traceroute
  38. """
  39. if (
  40. not salt.utils.path.which("traceroute")
  41. and not salt.utils.platform.is_windows()
  42. ):
  43. self.skipTest("traceroute not installed")
  44. ret = self.run_function("network.traceroute", [URL])
  45. exp_out = ["hostname", "ip"]
  46. for out in exp_out:
  47. self.assertIn(out, exp_out)
  48. @skipIf(not salt.utils.platform.is_windows(), "windows only test")
  49. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  50. def test_network_nslookup(self):
  51. """
  52. network.nslookup
  53. """
  54. ret = self.run_function("network.nslookup", [URL])
  55. exp_out = ["Server", "Address"]
  56. for out in exp_out:
  57. self.assertIn(out, exp_out)