1
0

test_network.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. URL = 'google-public-dns-a.google.com'
  11. class NetworkTest(ModuleCase):
  12. '''
  13. Validate network module
  14. '''
  15. def test_network_ping(self):
  16. '''
  17. network.ping
  18. '''
  19. ret = self.run_function('network.ping', [URL])
  20. exp_out = ['ping', URL, 'ttl', '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. def test_network_netstat(self):
  25. '''
  26. network.netstat
  27. '''
  28. ret = self.run_function('network.netstat')
  29. exp_out = ['proto', 'local-address']
  30. for val in ret:
  31. for out in exp_out:
  32. self.assertIn(out, val)
  33. def test_network_traceroute(self):
  34. '''
  35. network.traceroute
  36. '''
  37. if not salt.utils.path.which('traceroute') and not salt.utils.platform.is_windows():
  38. self.skipTest('traceroute not installed')
  39. ret = self.run_function('network.traceroute', [URL])
  40. exp_out = ['hostname', 'ip']
  41. for out in exp_out:
  42. self.assertIn(out, exp_out)
  43. @skipIf(not salt.utils.platform.is_windows(), 'windows only test')
  44. def test_network_nslookup(self):
  45. '''
  46. network.nslookup
  47. '''
  48. ret = self.run_function('network.nslookup', [URL])
  49. exp_out = ['Server', 'Address']
  50. for out in exp_out:
  51. self.assertIn(out, exp_out)