2013-06-28 13:03:01 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
integration.cli_test
|
|
|
|
~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
CLI related unit testing
|
|
|
|
|
|
|
|
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
|
|
|
'''
|
|
|
|
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import Python libs
|
2014-11-22 10:58:31 +00:00
|
|
|
from __future__ import absolute_import, print_function
|
2013-06-28 13:03:01 +00:00
|
|
|
|
|
|
|
# Import salt testing libs
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf
|
2013-06-28 13:03:01 +00:00
|
|
|
|
2013-06-25 14:33:10 +00:00
|
|
|
# Import salt libs
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ShellCase
|
|
|
|
from tests.support.mixins import ShellCaseCommonTestsMixin
|
2013-06-25 14:33:10 +00:00
|
|
|
|
2013-11-28 19:40:17 +00:00
|
|
|
# Import 3rd-party libs
|
2014-11-22 10:58:31 +00:00
|
|
|
# pylint: disable=import-error
|
|
|
|
from salt.ext.six.moves import range # pylint: disable=redefined-builtin
|
2013-11-28 19:40:17 +00:00
|
|
|
try:
|
2014-11-22 10:58:31 +00:00
|
|
|
import libcloud # pylint: disable=unused-import
|
2013-11-28 19:40:17 +00:00
|
|
|
HAS_LIBCLOUD = True
|
|
|
|
except ImportError:
|
|
|
|
HAS_LIBCLOUD = False
|
2014-11-22 10:58:31 +00:00
|
|
|
# pylint: enable=import-error
|
2013-06-25 14:33:10 +00:00
|
|
|
|
2013-11-28 19:40:17 +00:00
|
|
|
|
|
|
|
@skipIf(HAS_LIBCLOUD is False, 'salt-cloud requires >= libcloud 0.11.4')
|
2017-04-03 16:04:09 +00:00
|
|
|
class SaltCloudCliTest(ShellCase,
|
|
|
|
ShellCaseCommonTestsMixin):
|
2013-06-25 14:33:10 +00:00
|
|
|
|
|
|
|
_call_binary_ = 'salt-cloud'
|
|
|
|
|
2013-06-25 17:52:58 +00:00
|
|
|
def test_function_arguments(self):
|
|
|
|
self.assertIn(
|
|
|
|
'salt-cloud: error: --function expects two arguments: '
|
|
|
|
'<function-name> <provider>',
|
|
|
|
self.run_cloud('--function show_image -h', catch_stderr=True)[1]
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_list_providers_accepts_no_arguments(self):
|
|
|
|
self.assertIn(
|
|
|
|
'salt-cloud: error: \'--list-providers\' does not accept any '
|
|
|
|
'arguments',
|
|
|
|
self.run_cloud('--list-providers ec2', catch_stderr=True)[1]
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_mutually_exclusive_query_options(self):
|
|
|
|
test_options = [
|
|
|
|
'--query', '--full-query', '--select-query', '--list-providers'
|
|
|
|
]
|
|
|
|
while True:
|
|
|
|
for idx in range(1, len(test_options)):
|
|
|
|
self.assertIn(
|
|
|
|
'salt-cloud: error: The options {0}/{1} are mutually '
|
|
|
|
'exclusive. Please only choose one of them'.format(
|
|
|
|
test_options[0], test_options[idx]
|
|
|
|
),
|
|
|
|
self.run_cloud(
|
|
|
|
'{0} {1}'.format(test_options[0], test_options[idx]),
|
|
|
|
catch_stderr=True)[1]
|
|
|
|
)
|
|
|
|
# Remove the first option from the list
|
|
|
|
test_options.pop(0)
|
|
|
|
if len(test_options) <= 1:
|
|
|
|
# Only one left? Stop iterating
|
|
|
|
break
|
|
|
|
|
|
|
|
def test_mutually_exclusive_list_options(self):
|
|
|
|
test_options = ['--list-locations', '--list-images', '--list-sizes']
|
|
|
|
while True:
|
|
|
|
for idx in range(1, len(test_options)):
|
|
|
|
output = self.run_cloud(
|
|
|
|
'{0} ec2 {1} ec2'.format(
|
|
|
|
test_options[0], test_options[idx]
|
|
|
|
), catch_stderr=True
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
self.assertIn(
|
|
|
|
'salt-cloud: error: The options {0}/{1} are mutually '
|
|
|
|
'exclusive. Please only choose one of them'.format(
|
|
|
|
test_options[0], test_options[idx]
|
|
|
|
),
|
|
|
|
output[1]
|
|
|
|
)
|
|
|
|
except AssertionError:
|
2014-11-22 10:58:31 +00:00
|
|
|
print(output)
|
2013-06-25 17:52:58 +00:00
|
|
|
raise
|
|
|
|
# Remove the first option from the list
|
|
|
|
test_options.pop(0)
|
|
|
|
if len(test_options) <= 1:
|
|
|
|
# Only one left? Stop iterating
|
|
|
|
break
|