1
0

test_network.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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, print_function, unicode_literals
  9. # Import salt testing libs
  10. from tests.support.case import ModuleCase
  11. from tests.support.helpers import destructiveTest, slowTest
  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(
  22. "Network state only supported on RedHat and Debian based systems"
  23. )
  24. @slowTest
  25. def test_managed(self):
  26. """
  27. network.managed
  28. """
  29. state_key = "network_|-dummy0_|-dummy0_|-managed"
  30. ret = self.run_function("state.sls", mods="network.managed", test=True)
  31. self.assertEqual(
  32. "Interface dummy0 is set to be added.", ret[state_key]["comment"]
  33. )
  34. @slowTest
  35. def test_routes(self):
  36. """
  37. network.routes
  38. """
  39. state_key = "network_|-routes_|-dummy0_|-routes"
  40. expected_changes = "Interface dummy0 routes are set to be added."
  41. ret = self.run_function("state.sls", mods="network.routes", test=True)
  42. self.assertEqual(
  43. ret[state_key]["comment"], "Interface dummy0 routes are set to be added."
  44. )
  45. @slowTest
  46. def test_system(self):
  47. """
  48. network.system
  49. """
  50. state_key = "network_|-system_|-system_|-system"
  51. global_settings = self.run_function("ip.get_network_settings")
  52. ret = self.run_function("state.sls", mods="network.system", test=True)
  53. self.assertIn(
  54. "Global network settings are set to be {0}".format(
  55. "added" if not global_settings else "updated"
  56. ),
  57. ret[state_key]["comment"],
  58. )