test_network.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- encoding: utf-8 -*-
  2. '''
  3. :codeauthor: :email: `Justin Anderson <janderson@saltstack.com>`
  4. tests.integration.states.network
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. '''
  7. # Python libs
  8. from __future__ import absolute_import, unicode_literals, print_function
  9. # Import salt testing libs
  10. from tests.support.case import ModuleCase
  11. from tests.support.helpers import destructiveTest
  12. from tests.support.mixins import SaltReturnAssertsMixin
  13. @destructiveTest
  14. class NetworkTest(ModuleCase, SaltReturnAssertsMixin):
  15. '''
  16. Validate network state module
  17. '''
  18. def setUp(self):
  19. os_family = self.run_function('grains.get', ['os_family'])
  20. if os_family not in ('RedHat', 'Debian'):
  21. self.skipTest('Network state only supported on RedHat and Debian based systems')
  22. def test_managed(self):
  23. '''
  24. network.managed
  25. '''
  26. state_key = 'network_|-dummy0_|-dummy0_|-managed'
  27. ret = self.run_function('state.sls', mods='network.managed', test=True)
  28. self.assertEqual('Interface dummy0 is set to be added.', ret[state_key]['comment'])
  29. def test_routes(self):
  30. '''
  31. network.routes
  32. '''
  33. state_key = 'network_|-routes_|-dummy0_|-routes'
  34. expected_changes = 'Interface dummy0 routes are set to be added.'
  35. ret = self.run_function('state.sls', mods='network.routes', test=True)
  36. self.assertEqual(ret[state_key]['comment'], 'Interface dummy0 routes are set to be added.')
  37. def test_system(self):
  38. '''
  39. network.system
  40. '''
  41. state_key = 'network_|-system_|-system_|-system'
  42. global_settings = self.run_function('ip.get_network_settings')
  43. ret = self.run_function('state.sls', mods='network.system', test=True)
  44. self.assertIn(
  45. 'Global network settings are set to be {0}'.format(
  46. 'added' if not global_settings else 'updated'
  47. ),
  48. ret[state_key]['comment']
  49. )