1
0

test_shell.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # -*- coding: utf-8 -*-
  2. """
  3. Test salt-call --proxyid commands
  4. tests.integration.proxy.test_shell
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. """
  7. from __future__ import absolute_import, print_function, unicode_literals
  8. import json
  9. import logging
  10. import sys
  11. import salt.ext.six as six
  12. import salt.utils.json as json
  13. from tests.support.case import ShellCase
  14. from tests.support.helpers import slowTest
  15. from tests.support.runtests import RUNTIME_VARS
  16. log = logging.getLogger(__name__)
  17. class ProxyCallerSimpleTestCase(ShellCase):
  18. """
  19. Test salt-call --proxyid <proxyid> commands
  20. """
  21. RUN_TIMEOUT = 300
  22. @staticmethod
  23. def _load_return(ret):
  24. try:
  25. return json.loads("\n".join(ret))
  26. except ValueError:
  27. log.warning("Failed to JSON decode: '%s'", ret)
  28. six.reraise(*sys.exc_info())
  29. @slowTest
  30. def test_can_it_ping(self):
  31. """
  32. Ensure the proxy can ping
  33. """
  34. ret = self._load_return(
  35. self.run_call(
  36. "--proxyid proxytest --out=json test.ping",
  37. config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
  38. )
  39. )
  40. self.assertEqual(ret["local"], True)
  41. @slowTest
  42. def test_list_pkgs(self):
  43. """
  44. Package test 1, really just tests that the virtual function capability
  45. is working OK.
  46. """
  47. ret = self._load_return(
  48. self.run_call(
  49. "--proxyid proxytest --out=json pkg.list_pkgs",
  50. config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
  51. )
  52. )
  53. self.assertIn("coreutils", ret["local"])
  54. self.assertIn("apache", ret["local"])
  55. self.assertIn("redbull", ret["local"])
  56. @slowTest
  57. def test_upgrade(self):
  58. ret = self._load_return(
  59. self.run_call(
  60. "--proxyid proxytest --out=json pkg.upgrade",
  61. config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
  62. )
  63. )
  64. self.assertEqual(ret["local"]["coreutils"]["new"], "2.0")
  65. self.assertEqual(ret["local"]["redbull"]["new"], "1000.99")
  66. @slowTest
  67. def test_service_list(self):
  68. ret = self._load_return(
  69. self.run_call(
  70. "--proxyid proxytest --out=json service.list",
  71. config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
  72. )
  73. )
  74. self.assertIn("ntp", ret["local"])
  75. @slowTest
  76. def test_service_start(self):
  77. ret = self._load_return(
  78. self.run_call(
  79. "--proxyid proxytest --out=json service.start samba",
  80. config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
  81. )
  82. )
  83. ret = self._load_return(
  84. self.run_call(
  85. "--proxyid proxytest --out=json service.status samba",
  86. config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
  87. )
  88. )
  89. self.assertTrue(ret)
  90. @slowTest
  91. def test_service_get_all(self):
  92. ret = self._load_return(
  93. self.run_call(
  94. "--proxyid proxytest --out=json service.get_all",
  95. config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
  96. )
  97. )
  98. self.assertIn("samba", ret["local"])
  99. @slowTest
  100. def test_grains_items(self):
  101. ret = self._load_return(
  102. self.run_call(
  103. "--proxyid proxytest --out=json grains.items",
  104. config_dir=RUNTIME_VARS.TMP_PROXY_CONF_DIR,
  105. )
  106. )
  107. self.assertEqual(ret["local"]["kernel"], "proxy")
  108. self.assertEqual(ret["local"]["kernelrelease"], "proxy")