test_cloud.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # -*- coding: utf-8 -*-
  2. """
  3. integration.cli_test
  4. ~~~~~~~~~~~~~~~~~~~~
  5. CLI related unit testing
  6. :codeauthor: Pedro Algarvio (pedro@algarvio.me)
  7. """
  8. from __future__ import absolute_import, print_function
  9. # pylint: disable=import-error
  10. from salt.ext.six.moves import range # pylint: disable=redefined-builtin
  11. from tests.support.case import ShellCase
  12. from tests.support.helpers import slowTest
  13. from tests.support.mixins import ShellCaseCommonTestsMixin
  14. from tests.support.unit import skipIf
  15. try:
  16. import libcloud # pylint: disable=unused-import
  17. HAS_LIBCLOUD = True
  18. except ImportError:
  19. HAS_LIBCLOUD = False
  20. # pylint: enable=import-error
  21. @skipIf(HAS_LIBCLOUD is False, "salt-cloud requires >= libcloud 0.11.4")
  22. class SaltCloudCliTest(ShellCase, ShellCaseCommonTestsMixin):
  23. _call_binary_ = "salt-cloud"
  24. @slowTest
  25. def test_function_arguments(self):
  26. self.assertIn(
  27. "error: --function expects two arguments: " "<function-name> <provider>",
  28. "\n".join(self.run_cloud("--function show_image -h", catch_stderr=True)[1]),
  29. )
  30. @slowTest
  31. def test_list_providers_accepts_no_arguments(self):
  32. self.assertIn(
  33. "error: '--list-providers' does not accept any " "arguments",
  34. "\n".join(self.run_cloud("--list-providers ec2", catch_stderr=True)[1]),
  35. )
  36. @slowTest
  37. def test_mutually_exclusive_query_options(self):
  38. test_options = ["--query", "--full-query", "--select-query", "--list-providers"]
  39. while True:
  40. for idx in range(1, len(test_options)):
  41. self.assertIn(
  42. "error: The options {0}/{1} are mutually "
  43. "exclusive. Please only choose one of them".format(
  44. test_options[0], test_options[idx]
  45. ),
  46. "\n".join(
  47. self.run_cloud(
  48. "{0} {1}".format(test_options[0], test_options[idx]),
  49. catch_stderr=True,
  50. )[1]
  51. ),
  52. )
  53. # Remove the first option from the list
  54. test_options.pop(0)
  55. if len(test_options) <= 1:
  56. # Only one left? Stop iterating
  57. break
  58. @slowTest
  59. def test_mutually_exclusive_list_options(self):
  60. test_options = ["--list-locations", "--list-images", "--list-sizes"]
  61. while True:
  62. for idx in range(1, len(test_options)):
  63. output = self.run_cloud(
  64. "{0} ec2 {1} ec2".format(test_options[0], test_options[idx]),
  65. catch_stderr=True,
  66. )
  67. try:
  68. self.assertIn(
  69. "error: The options {0}/{1} are mutually "
  70. "exclusive. Please only choose one of them".format(
  71. test_options[0], test_options[idx]
  72. ),
  73. "\n".join(output[1]),
  74. )
  75. except AssertionError:
  76. print(output)
  77. raise
  78. # Remove the first option from the list
  79. test_options.pop(0)
  80. if len(test_options) <= 1:
  81. # Only one left? Stop iterating
  82. break