mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #8898 from s0undt3ch/develop
Merge and cleanup salt-cloud's test suite.
This commit is contained in:
commit
529eecbd89
@ -1,111 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
integration
|
||||
~~~~~~~~~~~
|
||||
|
||||
Integration testing
|
||||
|
||||
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
||||
:copyright: © 2013 by the SaltStack Team, see AUTHORS for more details.
|
||||
:license: Apache 2.0, see LICENSE for more details.
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
# Import external libs
|
||||
import yaml
|
||||
|
||||
INTEGRATION_TEST_DIR = os.path.dirname(
|
||||
os.path.normpath(os.path.abspath(__file__))
|
||||
)
|
||||
CODE_DIR = os.path.dirname(os.path.dirname(INTEGRATION_TEST_DIR))
|
||||
SALTCLOUD_LIBS = os.path.dirname(CODE_DIR)
|
||||
SCRIPT_DIR = os.path.join(CODE_DIR, 'scripts')
|
||||
PYEXEC = 'python{0}.{1}'.format(sys.version_info[0], sys.version_info[1])
|
||||
|
||||
# Update sys.path
|
||||
for dir_ in [CODE_DIR, SALTCLOUD_LIBS]:
|
||||
if not dir_ in sys.path:
|
||||
sys.path.insert(0, dir_)
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting import TestCase
|
||||
from salttesting.case import ShellTestCase
|
||||
from salttesting.mixins import CheckShellBinaryNameAndVersionMixIn
|
||||
from salttesting.parser import run_testcase
|
||||
|
||||
# Import salt libs
|
||||
import salt.config
|
||||
|
||||
# Import salt cloud libs
|
||||
import saltcloud.config
|
||||
import saltcloud.version
|
||||
|
||||
|
||||
class ShellCaseCommonTestsMixIn(CheckShellBinaryNameAndVersionMixIn):
|
||||
|
||||
_call_binary_expected_version_ = saltcloud.version.__version__
|
||||
|
||||
|
||||
class ShellCase(ShellTestCase, CheckShellBinaryNameAndVersionMixIn):
|
||||
'''
|
||||
Execute a test for a shell command
|
||||
'''
|
||||
|
||||
_code_dir_ = CODE_DIR
|
||||
_script_dir_ = SCRIPT_DIR
|
||||
_python_executable_ = PYEXEC
|
||||
_temp_cloud_config_dir_ = None
|
||||
_temp_cloud_config_file_ = None
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
'''
|
||||
Setup temporary configuration
|
||||
'''
|
||||
cls._temp_cloud_config_dir_ = tempfile.mkdtemp()
|
||||
root_dir = os.path.join(cls._temp_cloud_config_dir_, 'root-dir')
|
||||
os.makedirs(root_dir)
|
||||
|
||||
# Let's create a temporary master configuration
|
||||
master_config_file = os.path.join(
|
||||
cls._temp_cloud_config_dir_, 'master'
|
||||
)
|
||||
master_config = salt.config.DEFAULT_MASTER_OPTS.copy()
|
||||
# Let's update it with some working settings
|
||||
master_config['root_dir'] = root_dir
|
||||
master_config['sock_dir'] = 'socks'
|
||||
master_config['pki_dir'] = 'pki/master'
|
||||
master_config['cache_dir'] = 'cache'
|
||||
master_config['conf_file'] = master_config_file
|
||||
master_config['log_file'] = 'logs/master'
|
||||
master_config['pidfile'] = 'run/salt-master.pid'
|
||||
master_config['key_logfile'] = 'logs/key'
|
||||
open(master_config_file, 'w').write(yaml.dump(master_config))
|
||||
|
||||
# Let's create a temporary cloud configuration
|
||||
cls._temp_cloud_config_file_ = cloud_config_file = os.path.join(
|
||||
cls._temp_cloud_config_dir_, 'cloud'
|
||||
)
|
||||
cloud_config = saltcloud.config.CLOUD_CONFIG_DEFAULTS.copy()
|
||||
# Let's update it with some working settings
|
||||
cloud_config['log_file'] = 'logs/cloud'
|
||||
cloud_config['conf_file'] = cloud_config
|
||||
cloud_config['master_config'] = master_config_file
|
||||
open(cloud_config_file, 'w').write(yaml.dump(cloud_config))
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
if os.path.isdir(cls._temp_cloud_config_dir_):
|
||||
shutil.rmtree(cls._temp_cloud_config_dir_)
|
||||
|
||||
def run_cloud(self, arg_str, catch_stderr=False, timeout=None):
|
||||
'''
|
||||
Execute salt-cloud
|
||||
'''
|
||||
arg_str = '-C {0} {1}'.format(self._temp_cloud_config_file_, arg_str)
|
||||
return self.run_script('salt-cloud', arg_str, catch_stderr, timeout)
|
@ -1,150 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
runtests.py
|
||||
~~~~~~~~~~~
|
||||
|
||||
salt-cloud tests
|
||||
|
||||
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
||||
:copyright: © 2013 by the SaltStack Team, see AUTHORS for more details.
|
||||
:license: Apache 2.0, see LICENSE for more details.
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
# Import salt testing libs
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
from salttesting.parser.cover import SaltCoverageTestingParser
|
||||
|
||||
TEST_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
SALTCLOUD_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
ensure_in_syspath(SALTCLOUD_ROOT)
|
||||
|
||||
XML_OUTPUT_DIR = os.environ.get(
|
||||
'XML_TEST_REPORTS', os.path.join(
|
||||
tempfile.gettempdir(), 'xml-test-reports'
|
||||
)
|
||||
)
|
||||
HTML_OUTPUT_DIR = os.environ.get(
|
||||
'HTML_OUTPUT_DIR', os.path.join(
|
||||
tempfile.gettempdir(), 'html-test-results'
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
if SALTCLOUD_ROOT:
|
||||
os.chdir(SALTCLOUD_ROOT)
|
||||
except OSError as err:
|
||||
print 'Failed to change directory to salt-cloud\'s source: {0}'.format(err)
|
||||
|
||||
|
||||
class SaltCloudTestingParser(SaltCoverageTestingParser):
|
||||
def setup_additional_options(self):
|
||||
self.test_selection_group.add_option(
|
||||
'-u',
|
||||
'--unit',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Run unit tests'
|
||||
)
|
||||
self.test_selection_group.add_option(
|
||||
'-s',
|
||||
'--shell',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Run shell tests'
|
||||
)
|
||||
|
||||
def validate_options(self):
|
||||
if self.options.coverage and any((
|
||||
self.options.name, self.options.unit, self.options.shell)):
|
||||
self.error(
|
||||
'No sense in generating the tests coverage report when not '
|
||||
'running the full test suite, it would only produce '
|
||||
'incorrect results.'
|
||||
)
|
||||
|
||||
# Set test suite defaults if no specific suite options are provided
|
||||
if not any((self.options.name, self.options.unit, self.options.shell)):
|
||||
self.options.unit = True
|
||||
self.options.shell = True
|
||||
|
||||
self.start_coverage(
|
||||
branch=True,
|
||||
source=[os.path.join(SALTCLOUD_ROOT, 'saltcloud')],
|
||||
)
|
||||
|
||||
def run_integration_suite(self, suite_folder, display_name):
|
||||
'''
|
||||
Run an integration test suite
|
||||
'''
|
||||
path = os.path.join(TEST_DIR, 'integration', suite_folder)
|
||||
return self.run_suite(path, display_name)
|
||||
|
||||
def run_integration_tests(self):
|
||||
'''
|
||||
Execute the integration tests suite
|
||||
'''
|
||||
status = []
|
||||
if not any([self.options.shell, self.options.name]):
|
||||
return status
|
||||
|
||||
if self.options.name:
|
||||
for name in self.options.name:
|
||||
results = self.run_suite('', name)
|
||||
status.append(results)
|
||||
if self.options.shell:
|
||||
status.append(
|
||||
self.run_suite(
|
||||
os.path.join(TEST_DIR, 'integration'), 'Shell', 'cli*.py'
|
||||
)
|
||||
)
|
||||
return status
|
||||
|
||||
def run_unit_tests(self):
|
||||
'''
|
||||
Execute the unit tests
|
||||
'''
|
||||
if not self.options.unit:
|
||||
return [True]
|
||||
|
||||
status = []
|
||||
if self.options.name:
|
||||
for name in self.options.name:
|
||||
results = self.run_suite(os.path.join(TEST_DIR, 'unit'), name)
|
||||
status.append(results)
|
||||
else:
|
||||
results = self.run_suite(
|
||||
os.path.join(TEST_DIR, 'unit'), 'Unit', '*_test.py'
|
||||
)
|
||||
status.append(results)
|
||||
return status
|
||||
|
||||
|
||||
def main():
|
||||
parser = SaltCloudTestingParser(
|
||||
TEST_DIR,
|
||||
xml_output_dir=XML_OUTPUT_DIR,
|
||||
html_output_dir=HTML_OUTPUT_DIR,
|
||||
tests_logfile=os.path.join(
|
||||
tempfile.gettempdir(), 'salt-cloud-runtests.log'
|
||||
)
|
||||
)
|
||||
parser.parse_args()
|
||||
|
||||
overall_status = []
|
||||
overall_status.extend(parser.run_unit_tests())
|
||||
overall_status.extend(parser.run_integration_tests())
|
||||
false_count = overall_status.count(False)
|
||||
|
||||
if false_count > 0:
|
||||
parser.finalize(1)
|
||||
parser.finalize(0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -800,6 +800,15 @@ class ShellCase(AdaptedConfigurationTestCaseMixIn, ShellTestCase):
|
||||
arg_str = '--config-dir {0} {1}'.format(self.get_config_dir(), arg_str)
|
||||
return self.run_script('salt-call', arg_str, with_retcode=with_retcode)
|
||||
|
||||
def run_cloud(self, arg_str, catch_stderr=False, timeout=None):
|
||||
'''
|
||||
Execute salt-cloud
|
||||
'''
|
||||
arg_str = '-C {0} {1}'.format(
|
||||
os.path.join(self.get_config_dir(), 'cloud'), arg_str
|
||||
)
|
||||
return self.run_script('salt-cloud', arg_str, catch_stderr, timeout)
|
||||
|
||||
|
||||
class ShellCaseCommonTestsMixIn(CheckShellBinaryNameAndVersionMixIn):
|
||||
|
||||
|
3
tests/integration/files/conf/cloud
Normal file
3
tests/integration/files/conf/cloud
Normal file
@ -0,0 +1,3 @@
|
||||
#
|
||||
master_config: master
|
||||
log_file: logs/cloud
|
Loading…
Reference in New Issue
Block a user