test_cloud.py 3.4 KB

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