test_network.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 pytest
  10. # Import salt testing libs
  11. from tests.support.case import ModuleCase
  12. from tests.support.mixins import SaltReturnAssertsMixin
  13. @pytest.mark.destructive_test
  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. )