test_network.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import
  4. # Import Salt Testing libs
  5. from tests.support.case import ModuleCase
  6. from tests.support.unit import skipIf
  7. # Import Salt Libs
  8. import salt.utils.path
  9. import salt.utils.platform
  10. import pytest
  11. URL = 'google-public-dns-a.google.com'
  12. @pytest.mark.windows_whitelisted
  13. class NetworkTest(ModuleCase):
  14. '''
  15. Validate network module
  16. '''
  17. def test_network_ping(self):
  18. '''
  19. network.ping
  20. '''
  21. ret = self.run_function('network.ping', [URL])
  22. exp_out = ['ping', URL, 'ms', 'time']
  23. for out in exp_out:
  24. self.assertIn(out, ret.lower())
  25. @skipIf(salt.utils.platform.is_darwin(), 'not supported on macosx')
  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. def test_network_traceroute(self):
  36. '''
  37. network.traceroute
  38. '''
  39. if not salt.utils.path.which('traceroute') and not salt.utils.platform.is_windows():
  40. self.skipTest('traceroute not installed')
  41. ret = self.run_function('network.traceroute', [URL])
  42. exp_out = ['hostname', 'ip']
  43. for out in exp_out:
  44. self.assertIn(out, exp_out)
  45. @skipIf(not salt.utils.platform.is_windows(), 'windows only test')
  46. def test_network_nslookup(self):
  47. '''
  48. network.nslookup
  49. '''
  50. ret = self.run_function('network.nslookup', [URL])
  51. exp_out = ['Server', 'Address']
  52. for out in exp_out:
  53. self.assertIn(out, exp_out)