test_network.py 2.2 KB

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