test_shell.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. """
  2. tests.integration.proxy.test_shell
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Test salt-call --proxyid <proxyid> commands
  5. """
  6. import logging
  7. import pytest
  8. import salt.utils.path
  9. import salt.utils.platform
  10. from tests.support.helpers import slowTest
  11. log = logging.getLogger(__name__)
  12. @pytest.fixture(scope="module")
  13. def salt_call_cli(salt_proxy):
  14. return salt_proxy.get_salt_call_cli(default_timeout=120)
  15. @pytest.fixture(scope="module")
  16. def package_name(grains):
  17. pkg = "figlet"
  18. if salt.utils.platform.is_windows():
  19. pkg = "putty"
  20. elif grains["os_family"] == "RedHat":
  21. pkg = "units"
  22. elif grains["os_family"] == "Arch":
  23. pkg = "xz"
  24. return pkg
  25. @slowTest
  26. def test_can_it_ping(salt_call_cli):
  27. """
  28. Ensure the proxy can ping
  29. """
  30. ret = salt_call_cli.run("test.ping")
  31. assert ret.exitcode == 0, ret
  32. assert ret.json is True
  33. @slowTest
  34. def test_list_pkgs(salt_call_cli, package_name):
  35. """
  36. Package test 1, really just tests that the virtual function capability
  37. is working OK.
  38. """
  39. ret = salt_call_cli.run("pkg.list_pkgs")
  40. assert ret.exitcode == 0, ret
  41. assert package_name in ret.json
  42. @slowTest
  43. @pytest.mark.skip_if_not_root
  44. @pytest.mark.destructive_test
  45. def test_upgrade(salt_call_cli):
  46. # Do we have any upgrades
  47. ret = salt_call_cli.run("pkg.list_upgrades")
  48. assert ret.exitcode == 0, ret
  49. if not ret.json:
  50. pytest.skip("No upgrades available to run test")
  51. ret = salt_call_cli.run("pkg.upgrade")
  52. assert ret.exitcode == 0, ret
  53. # Assert that something got upgraded
  54. assert ret.json
  55. @pytest.fixture
  56. def service_name(grains, sminion):
  57. _service_name = "cron"
  58. cmd_name = "crontab"
  59. os_family = grains["os_family"]
  60. os_release = grains["osrelease"]
  61. stopped = False
  62. running = True
  63. if os_family == "RedHat":
  64. _service_name = "crond"
  65. elif os_family == "Arch":
  66. _service_name = "sshd"
  67. cmd_name = "systemctl"
  68. elif os_family == "MacOS":
  69. _service_name = "org.ntp.ntpd"
  70. if int(os_release.split(".")[1]) >= 13:
  71. _service_name = "com.apple.AirPlayXPCHelper"
  72. stopped = ""
  73. running = "[0-9]"
  74. elif os_family == "Windows":
  75. _service_name = "Spooler"
  76. ret = sminion.functions.service.get_enabled()
  77. pre_srv_enabled = _service_name in ret
  78. post_srv_disable = False
  79. if not pre_srv_enabled:
  80. ret = sminion.functions.service.enable(name=_service_name)
  81. assert ret is True
  82. post_srv_disable = True
  83. if os_family != "Windows" and salt.utils.path.which(cmd_name) is None:
  84. pytest.skip("{} is not installed".format(cmd_name))
  85. yield _service_name
  86. if post_srv_disable:
  87. ret = sminion.functions.service.disable(name=_service_name)
  88. assert ret.exitcode == 0
  89. @slowTest
  90. @pytest.mark.skip_if_not_root
  91. def test_service_list(salt_call_cli, service_name):
  92. ret = salt_call_cli.run("service.list")
  93. assert ret.exitcode == 0, ret
  94. assert service_name in ret.json
  95. @slowTest
  96. @pytest.mark.skip_if_not_root
  97. def test_service_start(salt_call_cli, service_name):
  98. ret = salt_call_cli.run("service.start", service_name)
  99. assert ret.exitcode == 0, ret
  100. ret = salt_call_cli.run("service.status", service_name)
  101. assert ret.exitcode == 0, ret
  102. assert ret.json is True
  103. @slowTest
  104. @pytest.mark.skip_if_not_root
  105. def test_service_get_all(salt_call_cli, service_name):
  106. ret = salt_call_cli.run("service.get_all")
  107. assert ret.exitcode == 0, ret
  108. assert service_name in ret.json
  109. @slowTest
  110. def test_grains_items(salt_call_cli):
  111. ret = salt_call_cli.run("grains.items")
  112. assert ret.exitcode == 0, ret
  113. assert ret.json["kernel"] == "proxy"
  114. assert ret.json["kernelrelease"] == "proxy"