2012-03-28 06:10:13 +00:00
|
|
|
'''
|
|
|
|
Set up the Salt integration test suite
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python libs
|
2013-09-05 02:34:12 +00:00
|
|
|
import re
|
2012-02-20 12:18:13 +00:00
|
|
|
import os
|
2012-04-21 23:27:59 +00:00
|
|
|
import sys
|
2013-06-29 19:57:23 +00:00
|
|
|
import time
|
2012-03-28 06:10:13 +00:00
|
|
|
import shutil
|
2013-04-25 19:59:34 +00:00
|
|
|
import pprint
|
|
|
|
import logging
|
2013-06-29 19:57:23 +00:00
|
|
|
import tempfile
|
2013-01-14 12:35:42 +00:00
|
|
|
import subprocess
|
2013-06-29 19:57:23 +00:00
|
|
|
import multiprocessing
|
2012-12-01 18:12:59 +00:00
|
|
|
from hashlib import md5
|
2012-11-17 17:37:53 +00:00
|
|
|
from datetime import datetime, timedelta
|
2012-06-23 09:47:53 +00:00
|
|
|
try:
|
|
|
|
import pwd
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2013-06-24 23:50:02 +00:00
|
|
|
|
|
|
|
INTEGRATION_TEST_DIR = os.path.dirname(
|
|
|
|
os.path.normpath(os.path.abspath(__file__))
|
|
|
|
)
|
|
|
|
CODE_DIR = os.path.dirname(os.path.dirname(INTEGRATION_TEST_DIR))
|
|
|
|
SALT_LIBS = os.path.dirname(CODE_DIR)
|
2013-06-29 19:57:23 +00:00
|
|
|
|
|
|
|
# Import Salt Testing libs
|
|
|
|
from salttesting import TestCase
|
|
|
|
from salttesting.case import ShellTestCase
|
|
|
|
from salttesting.mixins import CheckShellBinaryNameAndVersionMixIn
|
|
|
|
from salttesting.parser import PNUM, print_header, SaltTestcaseParser
|
|
|
|
from salttesting.helpers import ensure_in_syspath, RedirectStdStreams
|
2013-06-24 23:50:02 +00:00
|
|
|
|
|
|
|
# Update sys.path
|
2013-06-29 19:57:23 +00:00
|
|
|
ensure_in_syspath(CODE_DIR, SALT_LIBS)
|
2013-06-24 23:50:02 +00:00
|
|
|
|
2012-03-28 06:10:13 +00:00
|
|
|
# Import Salt libs
|
2012-02-20 12:18:13 +00:00
|
|
|
import salt
|
|
|
|
import salt.config
|
|
|
|
import salt.master
|
|
|
|
import salt.minion
|
2012-05-28 03:00:10 +00:00
|
|
|
import salt.runner
|
2013-02-08 00:35:50 +00:00
|
|
|
import salt.output
|
2013-08-16 01:01:26 +00:00
|
|
|
import salt.version
|
2012-12-01 18:12:59 +00:00
|
|
|
from salt.utils import fopen, get_colors
|
2012-03-09 07:47:34 +00:00
|
|
|
from salt.utils.verify import verify_env
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2013-08-30 17:24:15 +00:00
|
|
|
# Import 3rd-party libs
|
|
|
|
import yaml
|
|
|
|
|
2013-01-15 17:50:09 +00:00
|
|
|
# Gentoo Portage prefers ebuild tests are rooted in ${TMPDIR}
|
|
|
|
SYS_TMP_DIR = os.environ.get('TMPDIR', tempfile.gettempdir())
|
2012-11-06 12:14:02 +00:00
|
|
|
TMP = os.path.join(SYS_TMP_DIR, 'salt-tests-tmpdir')
|
2012-02-20 12:18:13 +00:00
|
|
|
FILES = os.path.join(INTEGRATION_TEST_DIR, 'files')
|
2013-06-29 19:57:23 +00:00
|
|
|
PYEXEC = 'python{0}.{1}'.format(sys.version_info[0], sys.version_info[1])
|
2012-07-26 16:14:00 +00:00
|
|
|
MOCKBIN = os.path.join(INTEGRATION_TEST_DIR, 'mockbin')
|
2013-06-29 19:57:23 +00:00
|
|
|
SCRIPT_DIR = os.path.join(CODE_DIR, 'scripts')
|
2012-12-12 18:38:39 +00:00
|
|
|
TMP_STATE_TREE = os.path.join(SYS_TMP_DIR, 'salt-temp-state-tree')
|
2013-08-30 17:24:15 +00:00
|
|
|
TMP_CONF_DIR = os.path.join(TMP, 'config')
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2013-04-25 19:59:34 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2013-10-03 15:09:57 +00:00
|
|
|
def run_tests(*test_cases, **kwargs):
|
2012-07-20 06:21:01 +00:00
|
|
|
'''
|
2013-10-03 15:09:57 +00:00
|
|
|
Run integration tests for the chosen test cases.
|
2012-07-20 06:21:01 +00:00
|
|
|
|
|
|
|
Function uses optparse to set up test environment
|
|
|
|
'''
|
2013-10-03 15:09:57 +00:00
|
|
|
|
|
|
|
needs_daemon = kwargs.pop('needs_daemon', True)
|
|
|
|
if kwargs:
|
|
|
|
raise RuntimeError(
|
|
|
|
'The \'run_tests\' function only accepts \'needs_daemon\' as a '
|
|
|
|
'keyword argument'
|
|
|
|
)
|
|
|
|
|
2013-06-25 10:45:28 +00:00
|
|
|
class TestcaseParser(SaltTestcaseParser):
|
2013-06-24 18:37:07 +00:00
|
|
|
def setup_additional_options(self):
|
|
|
|
self.add_option(
|
|
|
|
'--sysinfo',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Print some system information.'
|
|
|
|
)
|
|
|
|
self.output_options_group.add_option(
|
|
|
|
'--no-colors',
|
|
|
|
'--no-colours',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Disable colour printing.'
|
|
|
|
)
|
2012-07-20 06:21:01 +00:00
|
|
|
|
2013-06-25 10:45:28 +00:00
|
|
|
def run_testcase(self, testcase, needs_daemon=True):
|
2013-06-24 22:53:59 +00:00
|
|
|
if needs_daemon:
|
2013-06-25 10:45:28 +00:00
|
|
|
print('Setting up Salt daemons to execute tests')
|
2013-06-24 22:53:59 +00:00
|
|
|
with TestDaemon(self):
|
2013-06-25 10:45:28 +00:00
|
|
|
return SaltTestcaseParser.run_testcase(self, testcase)
|
|
|
|
return SaltTestcaseParser.run_testcase(self, testcase)
|
|
|
|
|
|
|
|
parser = TestcaseParser()
|
2013-06-24 18:37:07 +00:00
|
|
|
parser.parse_args()
|
2013-10-03 15:09:57 +00:00
|
|
|
for case in test_cases:
|
|
|
|
if parser.run_testcase(case, needs_daemon=needs_daemon) is False:
|
|
|
|
parser.finalize(1)
|
2013-06-24 18:37:07 +00:00
|
|
|
parser.finalize(0)
|
2012-07-20 06:21:01 +00:00
|
|
|
|
|
|
|
|
2012-02-20 12:18:13 +00:00
|
|
|
class TestDaemon(object):
|
|
|
|
'''
|
|
|
|
Set up the master and minion daemons, and run related cases
|
|
|
|
'''
|
2012-12-04 13:02:56 +00:00
|
|
|
MINIONS_CONNECT_TIMEOUT = MINIONS_SYNC_TIMEOUT = 120
|
2012-07-20 06:16:14 +00:00
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
def __init__(self, parser):
|
|
|
|
self.parser = parser
|
|
|
|
self.colors = get_colors(self.parser.options.no_colors is False)
|
2012-07-20 06:16:14 +00:00
|
|
|
|
2012-02-20 12:18:13 +00:00
|
|
|
def __enter__(self):
|
|
|
|
'''
|
|
|
|
Start a master and minion
|
|
|
|
'''
|
2013-08-30 17:24:15 +00:00
|
|
|
running_tests_user = pwd.getpwuid(os.getuid()).pw_name
|
2012-03-09 07:47:34 +00:00
|
|
|
self.master_opts = salt.config.master_config(
|
2012-06-30 20:10:34 +00:00
|
|
|
os.path.join(INTEGRATION_TEST_DIR, 'files', 'conf', 'master')
|
|
|
|
)
|
2013-08-30 17:24:15 +00:00
|
|
|
self.master_opts['user'] = running_tests_user
|
2013-07-17 15:22:18 +00:00
|
|
|
minion_config_path = os.path.join(
|
|
|
|
INTEGRATION_TEST_DIR, 'files', 'conf', 'minion'
|
|
|
|
)
|
2013-07-13 19:53:11 +00:00
|
|
|
self.minion_opts = salt.config.minion_config(minion_config_path)
|
2013-08-30 17:24:15 +00:00
|
|
|
self.minion_opts['user'] = running_tests_user
|
2013-07-17 15:22:18 +00:00
|
|
|
self.syndic_opts = salt.config.syndic_config(
|
|
|
|
os.path.join(INTEGRATION_TEST_DIR, 'files', 'conf', 'syndic'),
|
|
|
|
minion_config_path
|
|
|
|
)
|
2013-08-30 17:24:15 +00:00
|
|
|
self.syndic_opts['user'] = running_tests_user
|
2013-07-13 19:53:11 +00:00
|
|
|
|
2012-12-03 23:35:32 +00:00
|
|
|
#if sys.version_info < (2, 7):
|
|
|
|
# self.minion_opts['multiprocessing'] = False
|
2012-05-23 14:04:38 +00:00
|
|
|
self.sub_minion_opts = salt.config.minion_config(
|
2012-06-30 20:10:34 +00:00
|
|
|
os.path.join(INTEGRATION_TEST_DIR, 'files', 'conf', 'sub_minion')
|
|
|
|
)
|
2013-09-10 09:40:10 +00:00
|
|
|
self.sub_minion_opts['root_dir'] = os.path.join(TMP, 'subsalt')
|
2013-08-30 17:24:15 +00:00
|
|
|
self.sub_minion_opts['user'] = running_tests_user
|
2012-12-03 23:35:32 +00:00
|
|
|
#if sys.version_info < (2, 7):
|
|
|
|
# self.sub_minion_opts['multiprocessing'] = False
|
2012-03-29 04:14:31 +00:00
|
|
|
self.smaster_opts = salt.config.master_config(
|
2012-06-30 20:10:34 +00:00
|
|
|
os.path.join(
|
|
|
|
INTEGRATION_TEST_DIR, 'files', 'conf', 'syndic_master'
|
|
|
|
)
|
|
|
|
)
|
2013-08-30 17:24:15 +00:00
|
|
|
self.smaster_opts['user'] = running_tests_user
|
2013-07-13 19:53:11 +00:00
|
|
|
|
2012-03-29 22:19:19 +00:00
|
|
|
# Set up config options that require internal data
|
|
|
|
self.master_opts['pillar_roots'] = {
|
2012-06-30 20:10:34 +00:00
|
|
|
'base': [os.path.join(FILES, 'pillar', 'base')]
|
|
|
|
}
|
2012-03-29 22:51:56 +00:00
|
|
|
self.master_opts['file_roots'] = {
|
2012-12-12 18:38:39 +00:00
|
|
|
'base': [
|
|
|
|
os.path.join(FILES, 'file', 'base'),
|
|
|
|
# Let's support runtime created files that can be used like:
|
|
|
|
# salt://my-temp-file.txt
|
|
|
|
TMP_STATE_TREE
|
|
|
|
]
|
2012-06-30 20:10:34 +00:00
|
|
|
}
|
2013-10-11 17:53:00 +00:00
|
|
|
self.master_opts['ext_pillar'].append(
|
2012-06-30 20:10:34 +00:00
|
|
|
{'cmd_yaml': 'cat {0}'.format(
|
|
|
|
os.path.join(
|
|
|
|
FILES,
|
|
|
|
'ext.yaml'
|
|
|
|
)
|
|
|
|
)}
|
2013-10-11 17:53:00 +00:00
|
|
|
)
|
|
|
|
self.master_opts['extension_modules'] = os.path.join(INTEGRATION_TEST_DIR, 'files', 'extension_modules')
|
2012-03-28 06:10:13 +00:00
|
|
|
# clean up the old files
|
2012-04-04 05:14:26 +00:00
|
|
|
self._clean()
|
2012-10-05 06:10:53 +00:00
|
|
|
|
|
|
|
# Point the config values to the correct temporary paths
|
|
|
|
for name in ('hosts', 'aliases'):
|
2012-11-06 11:20:06 +00:00
|
|
|
optname = '{0}.file'.format(name)
|
|
|
|
optname_path = os.path.join(TMP, name)
|
|
|
|
self.master_opts[optname] = optname_path
|
|
|
|
self.minion_opts[optname] = optname_path
|
|
|
|
self.sub_minion_opts[optname] = optname_path
|
2012-10-05 06:10:53 +00:00
|
|
|
|
2012-07-09 04:50:12 +00:00
|
|
|
verify_env([os.path.join(self.master_opts['pki_dir'], 'minions'),
|
2012-02-20 12:18:13 +00:00
|
|
|
os.path.join(self.master_opts['pki_dir'], 'minions_pre'),
|
2012-07-09 04:50:12 +00:00
|
|
|
os.path.join(self.master_opts['pki_dir'],
|
|
|
|
'minions_rejected'),
|
2012-02-20 12:18:13 +00:00
|
|
|
os.path.join(self.master_opts['cachedir'], 'jobs'),
|
2012-03-29 04:14:31 +00:00
|
|
|
os.path.join(self.smaster_opts['pki_dir'], 'minions'),
|
|
|
|
os.path.join(self.smaster_opts['pki_dir'], 'minions_pre'),
|
2012-07-09 04:50:12 +00:00
|
|
|
os.path.join(self.smaster_opts['pki_dir'],
|
|
|
|
'minions_rejected'),
|
2012-03-29 04:14:31 +00:00
|
|
|
os.path.join(self.smaster_opts['cachedir'], 'jobs'),
|
2012-02-20 12:18:13 +00:00
|
|
|
os.path.dirname(self.master_opts['log_file']),
|
|
|
|
self.minion_opts['extension_modules'],
|
2012-05-23 14:04:38 +00:00
|
|
|
self.sub_minion_opts['extension_modules'],
|
|
|
|
self.sub_minion_opts['pki_dir'],
|
2012-02-20 12:18:13 +00:00
|
|
|
self.master_opts['sock_dir'],
|
2012-03-29 04:14:31 +00:00
|
|
|
self.smaster_opts['sock_dir'],
|
2012-07-08 04:11:36 +00:00
|
|
|
self.sub_minion_opts['sock_dir'],
|
|
|
|
self.minion_opts['sock_dir'],
|
2012-12-12 18:38:39 +00:00
|
|
|
TMP_STATE_TREE,
|
2012-10-05 01:45:35 +00:00
|
|
|
TMP
|
2012-06-03 05:17:52 +00:00
|
|
|
],
|
2013-08-30 17:24:15 +00:00
|
|
|
running_tests_user)
|
2012-10-02 12:04:22 +00:00
|
|
|
|
2012-07-26 16:14:00 +00:00
|
|
|
# Set up PATH to mockbin
|
|
|
|
self._enter_mockbin()
|
2012-02-20 12:18:13 +00:00
|
|
|
|
|
|
|
master = salt.master.Master(self.master_opts)
|
|
|
|
self.master_process = multiprocessing.Process(target=master.start)
|
|
|
|
self.master_process.start()
|
|
|
|
|
|
|
|
minion = salt.minion.Minion(self.minion_opts)
|
|
|
|
self.minion_process = multiprocessing.Process(target=minion.tune_in)
|
|
|
|
self.minion_process.start()
|
|
|
|
|
2012-05-23 14:04:38 +00:00
|
|
|
sub_minion = salt.minion.Minion(self.sub_minion_opts)
|
|
|
|
self.sub_minion_process = multiprocessing.Process(
|
2012-06-30 20:10:34 +00:00
|
|
|
target=sub_minion.tune_in
|
|
|
|
)
|
2012-05-23 14:04:38 +00:00
|
|
|
self.sub_minion_process.start()
|
|
|
|
|
2012-03-29 04:14:31 +00:00
|
|
|
smaster = salt.master.Master(self.smaster_opts)
|
|
|
|
self.smaster_process = multiprocessing.Process(target=smaster.start)
|
|
|
|
self.smaster_process.start()
|
|
|
|
|
|
|
|
syndic = salt.minion.Syndic(self.syndic_opts)
|
|
|
|
self.syndic_process = multiprocessing.Process(target=syndic.tune_in)
|
|
|
|
self.syndic_process.start()
|
|
|
|
|
2013-01-11 16:21:04 +00:00
|
|
|
if os.environ.get('DUMP_SALT_CONFIG', None) is not None:
|
|
|
|
from copy import deepcopy
|
|
|
|
try:
|
|
|
|
os.makedirs('/tmp/salttest/conf')
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
master_opts = deepcopy(self.master_opts)
|
|
|
|
minion_opts = deepcopy(self.minion_opts)
|
|
|
|
master_opts.pop('conf_file', None)
|
|
|
|
|
|
|
|
minion_opts.pop('conf_file', None)
|
|
|
|
minion_opts.pop('grains', None)
|
|
|
|
minion_opts.pop('pillar', None)
|
|
|
|
open('/tmp/salttest/conf/master', 'w').write(
|
|
|
|
yaml.dump(master_opts)
|
|
|
|
)
|
|
|
|
open('/tmp/salttest/conf/minion', 'w').write(
|
|
|
|
yaml.dump(minion_opts)
|
|
|
|
)
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
self.minion_targets = set(['minion', 'sub_minion'])
|
|
|
|
self.pre_setup_minions()
|
|
|
|
self.setup_minions()
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
if self.parser.options.sysinfo:
|
2012-11-06 18:11:26 +00:00
|
|
|
print_header('~~~~~~~ Versions Report ', inline=True)
|
2013-08-16 01:01:26 +00:00
|
|
|
print('\n'.join(salt.version.versions_report()))
|
2012-11-06 18:11:26 +00:00
|
|
|
|
|
|
|
print_header(
|
|
|
|
'~~~~~~~ Minion Grains Information ', inline=True,
|
|
|
|
)
|
2013-02-08 00:35:50 +00:00
|
|
|
|
2012-11-06 18:11:26 +00:00
|
|
|
print_header('', sep='=', inline=True)
|
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
try:
|
|
|
|
return self
|
|
|
|
finally:
|
|
|
|
self.post_setup_minions()
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2013-01-11 16:21:04 +00:00
|
|
|
@property
|
|
|
|
def client(self):
|
|
|
|
'''
|
|
|
|
Return a local client which will be used for example to ping and sync
|
|
|
|
the test minions.
|
|
|
|
|
|
|
|
This client is defined as a class attribute because it's creation needs
|
|
|
|
to be deferred to a latter stage. If created it on `__enter__` like it
|
|
|
|
previously was, it would not receive the master events.
|
|
|
|
'''
|
|
|
|
return salt.client.LocalClient(
|
|
|
|
mopts=self.master_opts
|
|
|
|
)
|
|
|
|
|
2012-02-20 12:18:13 +00:00
|
|
|
def __exit__(self, type, value, traceback):
|
|
|
|
'''
|
|
|
|
Kill the minion and master processes
|
|
|
|
'''
|
2013-07-13 19:53:11 +00:00
|
|
|
import integration
|
|
|
|
integration.SYNDIC = None
|
2012-05-23 14:04:38 +00:00
|
|
|
self.sub_minion_process.terminate()
|
2013-04-24 21:31:57 +00:00
|
|
|
self.sub_minion_process.join()
|
2012-02-20 12:18:13 +00:00
|
|
|
self.minion_process.terminate()
|
2013-04-24 21:31:57 +00:00
|
|
|
self.minion_process.join()
|
2012-02-20 12:18:13 +00:00
|
|
|
self.master_process.terminate()
|
2013-04-24 21:31:57 +00:00
|
|
|
self.master_process.join()
|
2012-03-29 04:14:31 +00:00
|
|
|
self.syndic_process.terminate()
|
2013-04-24 21:31:57 +00:00
|
|
|
self.syndic_process.join()
|
2012-03-29 04:14:31 +00:00
|
|
|
self.smaster_process.terminate()
|
2013-04-24 21:31:57 +00:00
|
|
|
self.smaster_process.join()
|
2012-07-26 16:14:00 +00:00
|
|
|
self._exit_mockbin()
|
2012-04-04 05:14:26 +00:00
|
|
|
self._clean()
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
def pre_setup_minions(self):
|
2013-01-10 07:25:02 +00:00
|
|
|
'''
|
2012-11-26 05:44:18 +00:00
|
|
|
Subclass this method for additional minion setups.
|
2013-01-10 07:25:02 +00:00
|
|
|
'''
|
2012-11-26 05:44:18 +00:00
|
|
|
|
|
|
|
def setup_minions(self):
|
|
|
|
# Wait for minions to connect back
|
|
|
|
wait_minion_connections = multiprocessing.Process(
|
|
|
|
target=self.wait_for_minion_connections,
|
|
|
|
args=(self.minion_targets, self.MINIONS_CONNECT_TIMEOUT)
|
|
|
|
)
|
|
|
|
wait_minion_connections.start()
|
|
|
|
wait_minion_connections.join()
|
|
|
|
wait_minion_connections.terminate()
|
|
|
|
if wait_minion_connections.exitcode > 0:
|
2012-12-04 13:36:33 +00:00
|
|
|
print(
|
2012-12-04 16:29:53 +00:00
|
|
|
'\n {RED_BOLD}*{ENDC} ERROR: Minions failed to connect'.format(
|
2012-12-04 13:36:33 +00:00
|
|
|
**self.colors
|
|
|
|
)
|
|
|
|
)
|
2012-11-26 05:44:18 +00:00
|
|
|
return False
|
|
|
|
|
2013-06-03 18:53:04 +00:00
|
|
|
del wait_minion_connections
|
2012-11-26 05:44:18 +00:00
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
sync_needed = self.parser.options.clean
|
|
|
|
if self.parser.options.clean is False:
|
2012-12-01 18:12:59 +00:00
|
|
|
def sumfile(fpath):
|
2012-12-04 13:36:33 +00:00
|
|
|
# Since we will be do'in this for small files, it should be ok
|
2012-12-01 18:12:59 +00:00
|
|
|
fobj = fopen(fpath)
|
|
|
|
m = md5()
|
|
|
|
while True:
|
|
|
|
d = fobj.read(8096)
|
|
|
|
if not d:
|
|
|
|
break
|
|
|
|
m.update(d)
|
|
|
|
return m.hexdigest()
|
|
|
|
# Since we're not cleaning up, let's see if modules are already up
|
|
|
|
# to date so we don't need to re-sync them
|
|
|
|
modules_dir = os.path.join(FILES, 'file', 'base', '_modules')
|
|
|
|
for fname in os.listdir(modules_dir):
|
|
|
|
if not fname.endswith('.py'):
|
|
|
|
continue
|
|
|
|
dfile = os.path.join(
|
|
|
|
'/tmp/salttest/cachedir/extmods/modules/', fname
|
|
|
|
)
|
|
|
|
|
|
|
|
if not os.path.exists(dfile):
|
|
|
|
sync_needed = True
|
|
|
|
break
|
|
|
|
|
|
|
|
sfile = os.path.join(modules_dir, fname)
|
|
|
|
if sumfile(sfile) != sumfile(dfile):
|
|
|
|
sync_needed = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if sync_needed:
|
|
|
|
# Wait for minions to "sync_all"
|
|
|
|
sync_minions = multiprocessing.Process(
|
2012-12-04 17:36:45 +00:00
|
|
|
target=self.sync_minion_modules,
|
2012-12-01 18:12:59 +00:00
|
|
|
args=(self.minion_targets, self.MINIONS_SYNC_TIMEOUT)
|
|
|
|
)
|
|
|
|
sync_minions.start()
|
|
|
|
sync_minions.join()
|
|
|
|
if sync_minions.exitcode > 0:
|
|
|
|
return False
|
|
|
|
sync_minions.terminate()
|
2013-06-03 18:53:04 +00:00
|
|
|
del sync_minions
|
2012-12-01 18:12:59 +00:00
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
def post_setup_minions(self):
|
2013-01-20 01:22:54 +00:00
|
|
|
'''
|
2012-11-26 05:44:18 +00:00
|
|
|
Subclass this method to execute code after the minions have been setup
|
2013-01-20 01:22:54 +00:00
|
|
|
'''
|
2012-11-26 05:44:18 +00:00
|
|
|
|
2012-07-26 16:14:00 +00:00
|
|
|
def _enter_mockbin(self):
|
|
|
|
path = os.environ.get('PATH', '')
|
|
|
|
path_items = path.split(os.pathsep)
|
|
|
|
if MOCKBIN not in path_items:
|
|
|
|
path_items.insert(0, MOCKBIN)
|
|
|
|
os.environ['PATH'] = os.pathsep.join(path_items)
|
|
|
|
|
|
|
|
def _exit_mockbin(self):
|
|
|
|
path = os.environ.get('PATH', '')
|
|
|
|
path_items = path.split(os.pathsep)
|
|
|
|
try:
|
|
|
|
path_items.remove(MOCKBIN)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
os.environ['PATH'] = os.pathsep.join(path_items)
|
|
|
|
|
2012-04-04 05:14:26 +00:00
|
|
|
def _clean(self):
|
|
|
|
'''
|
|
|
|
Clean out the tmp files
|
|
|
|
'''
|
2013-06-24 18:37:07 +00:00
|
|
|
if not self.parser.options.clean:
|
2012-07-20 06:16:14 +00:00
|
|
|
return
|
2012-05-31 10:43:03 +00:00
|
|
|
if os.path.isdir(self.sub_minion_opts['root_dir']):
|
|
|
|
shutil.rmtree(self.sub_minion_opts['root_dir'])
|
2012-04-04 05:14:26 +00:00
|
|
|
if os.path.isdir(self.master_opts['root_dir']):
|
|
|
|
shutil.rmtree(self.master_opts['root_dir'])
|
2012-05-31 10:43:03 +00:00
|
|
|
if os.path.isdir(self.smaster_opts['root_dir']):
|
|
|
|
shutil.rmtree(self.smaster_opts['root_dir'])
|
2012-10-04 23:52:00 +00:00
|
|
|
if os.path.isdir(TMP):
|
|
|
|
shutil.rmtree(TMP)
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2012-11-09 15:25:16 +00:00
|
|
|
def wait_for_jid(self, targets, jid, timeout=120):
|
2012-11-26 05:44:18 +00:00
|
|
|
time.sleep(1) # Allow some time for minions to accept jobs
|
2012-11-17 17:37:53 +00:00
|
|
|
now = datetime.now()
|
|
|
|
expire = now + timedelta(seconds=timeout)
|
2012-11-26 05:44:18 +00:00
|
|
|
job_finished = False
|
2012-11-17 17:37:53 +00:00
|
|
|
while now <= expire:
|
2012-11-09 15:25:16 +00:00
|
|
|
running = self.__client_job_running(targets, jid)
|
|
|
|
sys.stdout.write('\r' + ' ' * PNUM + '\r')
|
2012-11-26 05:44:18 +00:00
|
|
|
if not running and job_finished is False:
|
|
|
|
# Let's not have false positives and wait one more seconds
|
|
|
|
job_finished = True
|
|
|
|
elif not running and job_finished is True:
|
2012-11-09 15:25:16 +00:00
|
|
|
return True
|
2012-11-26 05:44:18 +00:00
|
|
|
elif running and job_finished is True:
|
|
|
|
job_finished = False
|
|
|
|
|
|
|
|
if job_finished is False:
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {YELLOW}[Quit in {0}]{ENDC} Waiting for {1}'.format(
|
|
|
|
'{0}'.format(expire - now).rsplit('.', 1)[0],
|
|
|
|
', '.join(running),
|
|
|
|
**self.colors
|
|
|
|
)
|
2012-11-09 15:25:16 +00:00
|
|
|
)
|
2012-11-26 05:44:18 +00:00
|
|
|
sys.stdout.flush()
|
2012-11-09 15:25:16 +00:00
|
|
|
time.sleep(1)
|
2012-11-17 17:37:53 +00:00
|
|
|
now = datetime.now()
|
2012-11-09 15:25:16 +00:00
|
|
|
else:
|
2012-11-26 05:44:18 +00:00
|
|
|
sys.stdout.write(
|
|
|
|
'\n {RED_BOLD}*{ENDC} ERROR: Failed to get information '
|
|
|
|
'back\n'.format(**self.colors)
|
|
|
|
)
|
2012-11-09 15:25:16 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
return False
|
|
|
|
|
|
|
|
def __client_job_running(self, targets, jid):
|
|
|
|
running = self.client.cmd(
|
2013-01-11 19:03:53 +00:00
|
|
|
list(targets), 'saltutil.running', expr_form='list'
|
2012-11-09 15:25:16 +00:00
|
|
|
)
|
|
|
|
return [
|
|
|
|
k for (k, v) in running.iteritems() if v and v[0]['jid'] == jid
|
|
|
|
]
|
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
def wait_for_minion_connections(self, targets, timeout):
|
|
|
|
sys.stdout.write(
|
|
|
|
' {LIGHT_BLUE}*{ENDC} Waiting at most {0} for minions({1}) to '
|
|
|
|
'connect back\n'.format(
|
|
|
|
(timeout > 60 and
|
|
|
|
timedelta(seconds=timeout) or
|
|
|
|
'{0} secs'.format(timeout)),
|
|
|
|
', '.join(targets),
|
|
|
|
**self.colors
|
|
|
|
)
|
2012-11-06 11:20:06 +00:00
|
|
|
)
|
2012-11-26 05:44:18 +00:00
|
|
|
sys.stdout.flush()
|
2012-11-06 11:20:06 +00:00
|
|
|
expected_connections = set(targets)
|
2012-11-26 05:44:18 +00:00
|
|
|
now = datetime.now()
|
|
|
|
expire = now + timedelta(seconds=timeout)
|
|
|
|
while now <= expire:
|
|
|
|
sys.stdout.write('\r' + ' ' * PNUM + '\r')
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {YELLOW}[Quit in {0}]{ENDC} Waiting for {1}'.format(
|
|
|
|
'{0}'.format(expire - now).rsplit('.', 1)[0],
|
|
|
|
', '.join(expected_connections),
|
|
|
|
**self.colors
|
|
|
|
)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
2012-11-26 04:32:25 +00:00
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
responses = self.client.cmd(
|
2013-01-11 16:21:04 +00:00
|
|
|
list(expected_connections), 'test.ping', expr_form='list',
|
2012-11-26 05:44:18 +00:00
|
|
|
)
|
|
|
|
for target in responses:
|
2012-11-06 11:20:06 +00:00
|
|
|
if target not in expected_connections:
|
|
|
|
# Someone(minion) else "listening"?
|
|
|
|
continue
|
|
|
|
expected_connections.remove(target)
|
2012-11-26 05:44:18 +00:00
|
|
|
sys.stdout.write('\r' + ' ' * PNUM + '\r')
|
|
|
|
sys.stdout.write(
|
|
|
|
' {LIGHT_GREEN}*{ENDC} {0} connected.\n'.format(
|
2012-11-26 04:32:25 +00:00
|
|
|
target, **self.colors
|
|
|
|
)
|
|
|
|
)
|
2012-11-26 05:44:18 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
|
2012-11-06 11:20:06 +00:00
|
|
|
if not expected_connections:
|
2012-11-26 05:44:18 +00:00
|
|
|
return
|
|
|
|
|
2012-11-06 11:20:06 +00:00
|
|
|
time.sleep(1)
|
2012-11-26 05:44:18 +00:00
|
|
|
now = datetime.now()
|
|
|
|
else:
|
|
|
|
print(
|
|
|
|
'\n {RED_BOLD}*{ENDC} WARNING: Minions failed to connect '
|
|
|
|
'back. Tests requiring them WILL fail'.format(**self.colors)
|
|
|
|
)
|
|
|
|
print_header('=', sep='=', inline=True)
|
|
|
|
raise SystemExit()
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2012-12-04 16:29:53 +00:00
|
|
|
def sync_minion_modules(self, targets, timeout=120):
|
2012-11-06 11:20:06 +00:00
|
|
|
# Let's sync all connected minions
|
2012-11-26 05:44:18 +00:00
|
|
|
print(
|
2012-12-04 16:29:53 +00:00
|
|
|
' {LIGHT_BLUE}*{ENDC} Syncing minion\'s modules '
|
|
|
|
'(saltutil.sync_modules)'.format(
|
2012-11-26 05:44:18 +00:00
|
|
|
', '.join(targets),
|
|
|
|
**self.colors
|
|
|
|
)
|
|
|
|
)
|
2012-11-06 11:20:06 +00:00
|
|
|
syncing = set(targets)
|
|
|
|
jid_info = self.client.run_job(
|
2013-01-11 19:03:53 +00:00
|
|
|
list(targets), 'saltutil.sync_modules',
|
2012-11-06 11:20:06 +00:00
|
|
|
expr_form='list',
|
|
|
|
timeout=9999999999999999,
|
|
|
|
)
|
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
if self.wait_for_jid(targets, jid_info['jid'], timeout) is False:
|
|
|
|
print(
|
2012-12-04 16:29:53 +00:00
|
|
|
' {RED_BOLD}*{ENDC} WARNING: Minions failed to sync modules. '
|
|
|
|
'Tests requiring these modules WILL fail'.format(**self.colors)
|
2012-11-26 05:44:18 +00:00
|
|
|
)
|
|
|
|
raise SystemExit()
|
2012-11-09 15:25:16 +00:00
|
|
|
|
2012-11-06 11:20:06 +00:00
|
|
|
while syncing:
|
2013-01-11 19:03:53 +00:00
|
|
|
rdata = self.client.get_full_returns(jid_info['jid'], syncing, 1)
|
2012-11-06 11:20:06 +00:00
|
|
|
if rdata:
|
2012-11-26 05:44:18 +00:00
|
|
|
for name, output in rdata.iteritems():
|
2013-01-11 19:03:53 +00:00
|
|
|
if not output['ret']:
|
|
|
|
# Already synced!?
|
|
|
|
syncing.remove(name)
|
|
|
|
continue
|
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
print(
|
2012-12-04 16:29:53 +00:00
|
|
|
' {LIGHT_GREEN}*{ENDC} Synced {0} modules: '
|
2013-01-11 19:03:53 +00:00
|
|
|
'{1}'.format(
|
|
|
|
name, ', '.join(output['ret']), **self.colors
|
|
|
|
)
|
2012-11-26 05:44:18 +00:00
|
|
|
)
|
2012-11-06 11:20:06 +00:00
|
|
|
# Synced!
|
|
|
|
try:
|
|
|
|
syncing.remove(name)
|
|
|
|
except KeyError:
|
2012-11-26 05:44:18 +00:00
|
|
|
print(
|
|
|
|
' {RED_BOLD}*{ENDC} {0} already synced??? '
|
|
|
|
'{1}'.format(name, output, **self.colors)
|
|
|
|
)
|
|
|
|
return True
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2012-05-28 03:00:10 +00:00
|
|
|
|
2013-08-30 17:24:15 +00:00
|
|
|
class AdaptedConfigurationTestCaseMixIn(object):
|
|
|
|
|
|
|
|
__slots__ = ()
|
|
|
|
|
|
|
|
def get_config_dir(self):
|
|
|
|
integration_config_dir = os.path.join(
|
|
|
|
INTEGRATION_TEST_DIR, 'files', 'conf'
|
|
|
|
)
|
|
|
|
if os.getuid() == 0:
|
|
|
|
# Running as root, the running user does not need to be updated
|
|
|
|
return integration_config_dir
|
|
|
|
|
|
|
|
for fname in os.listdir(integration_config_dir):
|
|
|
|
self.get_config_file_path(fname)
|
|
|
|
return TMP_CONF_DIR
|
|
|
|
|
|
|
|
def get_config_file_path(self, filename):
|
|
|
|
integration_config_file = os.path.join(
|
|
|
|
INTEGRATION_TEST_DIR, 'files', 'conf', filename
|
|
|
|
)
|
|
|
|
if os.getuid() == 0:
|
|
|
|
# Running as root, the running user does not need to be updated
|
|
|
|
return integration_config_file
|
|
|
|
|
|
|
|
if not os.path.isdir(TMP_CONF_DIR):
|
|
|
|
os.makedirs(TMP_CONF_DIR)
|
|
|
|
|
|
|
|
updated_config_path = os.path.join(TMP_CONF_DIR, filename)
|
|
|
|
if not os.path.isfile(updated_config_path):
|
|
|
|
self.__update_config(integration_config_file, updated_config_path)
|
|
|
|
return updated_config_path
|
|
|
|
|
|
|
|
def __update_config(self, source, dest):
|
|
|
|
if not os.path.isfile(dest):
|
|
|
|
running_tests_user = pwd.getpwuid(os.getuid()).pw_name
|
|
|
|
configuration = yaml.load(open(source).read())
|
|
|
|
configuration['user'] = running_tests_user
|
|
|
|
open(dest, 'w').write(yaml.dump(configuration))
|
|
|
|
|
|
|
|
|
|
|
|
class SaltClientTestCaseMixIn(AdaptedConfigurationTestCaseMixIn):
|
2012-11-07 13:40:39 +00:00
|
|
|
|
2012-12-04 11:51:37 +00:00
|
|
|
_salt_client_config_file_name_ = 'master'
|
|
|
|
__slots__ = ('client', '_salt_client_config_file_name_')
|
2012-11-07 13:40:39 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def client(self):
|
2012-12-04 11:51:37 +00:00
|
|
|
return salt.client.LocalClient(
|
2013-08-30 17:24:15 +00:00
|
|
|
self.get_config_file_path(self._salt_client_config_file_name_)
|
2012-12-04 11:51:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ModuleCase(TestCase, SaltClientTestCaseMixIn):
|
|
|
|
'''
|
|
|
|
Execute a module function
|
|
|
|
'''
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2012-10-17 18:06:17 +00:00
|
|
|
def minion_run(self, _function, *args, **kw):
|
|
|
|
'''
|
|
|
|
Run a single salt function on the 'minion' target and condition
|
|
|
|
the return down to match the behavior of the raw function call
|
|
|
|
'''
|
|
|
|
return self.run_function(_function, args, **kw)
|
|
|
|
|
2013-04-25 19:59:34 +00:00
|
|
|
def run_function(self, function, arg=(), minion_tgt='minion', timeout=25,
|
2013-01-14 14:07:58 +00:00
|
|
|
**kwargs):
|
2012-02-20 12:18:13 +00:00
|
|
|
'''
|
|
|
|
Run a single salt function and condition the return down to match the
|
|
|
|
behavior of the raw function call
|
|
|
|
'''
|
2013-09-05 22:06:41 +00:00
|
|
|
know_to_return_none = (
|
|
|
|
'file.chown', 'file.chgrp', 'ssh.recv_known_host'
|
|
|
|
)
|
2012-08-04 22:25:37 +00:00
|
|
|
orig = self.client.cmd(
|
2013-04-22 21:04:33 +00:00
|
|
|
minion_tgt, function, arg, timeout=timeout, kwarg=kwargs
|
2012-08-04 22:25:37 +00:00
|
|
|
)
|
2012-09-01 06:29:06 +00:00
|
|
|
|
2012-09-07 19:03:44 +00:00
|
|
|
if minion_tgt not in orig:
|
|
|
|
self.skipTest(
|
|
|
|
'WARNING(SHOULD NOT HAPPEN #1935): Failed to get a reply '
|
2012-10-05 06:10:53 +00:00
|
|
|
'from the minion \'{0}\'. Command output: {1}'.format(
|
|
|
|
minion_tgt, orig
|
|
|
|
)
|
2012-09-07 19:03:44 +00:00
|
|
|
)
|
|
|
|
elif orig[minion_tgt] is None and function not in know_to_return_none:
|
2012-09-01 04:20:53 +00:00
|
|
|
self.skipTest(
|
|
|
|
'WARNING(SHOULD NOT HAPPEN #1935): Failed to get \'{0}\' from '
|
2012-10-05 06:10:53 +00:00
|
|
|
'the minion \'{1}\'. Command output: {2}'.format(
|
|
|
|
function, minion_tgt, orig
|
|
|
|
)
|
2012-09-01 04:20:53 +00:00
|
|
|
)
|
2012-09-01 06:29:06 +00:00
|
|
|
return orig[minion_tgt]
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2012-05-13 02:40:28 +00:00
|
|
|
def run_state(self, function, **kwargs):
|
|
|
|
'''
|
|
|
|
Run the state.single command and return the state return structure
|
|
|
|
'''
|
2012-05-13 04:27:30 +00:00
|
|
|
return self.run_function('state.single', [function], **kwargs)
|
2012-05-13 02:40:28 +00:00
|
|
|
|
2012-06-30 20:54:23 +00:00
|
|
|
@property
|
2012-02-20 12:18:13 +00:00
|
|
|
def minion_opts(self):
|
|
|
|
'''
|
|
|
|
Return the options used for the minion
|
|
|
|
'''
|
|
|
|
return salt.config.minion_config(
|
2013-08-30 17:24:15 +00:00
|
|
|
self.get_config_file_path('minion')
|
2012-07-09 04:50:12 +00:00
|
|
|
)
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2012-06-30 20:54:23 +00:00
|
|
|
@property
|
2012-09-01 06:29:06 +00:00
|
|
|
def sub_minion_opts(self):
|
2012-02-20 12:18:13 +00:00
|
|
|
'''
|
|
|
|
Return the options used for the minion
|
|
|
|
'''
|
|
|
|
return salt.config.minion_config(
|
2013-08-30 17:24:15 +00:00
|
|
|
self.get_config_file_path('sub_minion')
|
2012-09-01 06:29:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def master_opts(self):
|
|
|
|
'''
|
|
|
|
Return the options used for the minion
|
|
|
|
'''
|
|
|
|
return salt.config.master_config(
|
2013-08-30 17:24:15 +00:00
|
|
|
self.get_config_file_path('master')
|
2012-07-09 04:50:12 +00:00
|
|
|
)
|
2012-03-29 04:25:59 +00:00
|
|
|
|
2012-05-29 16:40:20 +00:00
|
|
|
|
2012-12-04 11:51:37 +00:00
|
|
|
class SyndicCase(TestCase, SaltClientTestCaseMixIn):
|
2012-03-29 04:25:59 +00:00
|
|
|
'''
|
|
|
|
Execute a syndic based execution test
|
|
|
|
'''
|
2012-12-04 11:51:37 +00:00
|
|
|
_salt_client_config_file_name_ = 'syndic_master'
|
2012-03-29 04:25:59 +00:00
|
|
|
|
|
|
|
def run_function(self, function, arg=()):
|
|
|
|
'''
|
|
|
|
Run a single salt function and condition the return down to match the
|
|
|
|
behavior of the raw function call
|
|
|
|
'''
|
2013-04-25 19:59:34 +00:00
|
|
|
orig = self.client.cmd('minion', function, arg, timeout=25)
|
2012-09-07 19:24:35 +00:00
|
|
|
if 'minion' not in orig:
|
|
|
|
self.skipTest(
|
|
|
|
'WARNING(SHOULD NOT HAPPEN #1935): Failed to get a reply '
|
2012-10-05 06:10:53 +00:00
|
|
|
'from the minion. Command output: {0}'.format(orig)
|
2012-09-07 19:24:35 +00:00
|
|
|
)
|
2012-03-29 04:25:59 +00:00
|
|
|
return orig['minion']
|
2012-04-21 22:58:03 +00:00
|
|
|
|
2012-05-13 02:40:28 +00:00
|
|
|
|
2013-08-30 17:24:15 +00:00
|
|
|
class ShellCase(AdaptedConfigurationTestCaseMixIn, ShellTestCase):
|
2012-04-21 22:58:03 +00:00
|
|
|
'''
|
|
|
|
Execute a test for a shell command
|
|
|
|
'''
|
2012-11-18 23:49:37 +00:00
|
|
|
|
2013-06-25 13:13:14 +00:00
|
|
|
_code_dir_ = CODE_DIR
|
|
|
|
_script_dir_ = SCRIPT_DIR
|
|
|
|
_python_executable_ = PYEXEC
|
2012-04-21 23:27:59 +00:00
|
|
|
|
2013-09-13 16:51:25 +00:00
|
|
|
def run_salt(self, arg_str, with_retcode=False):
|
2012-04-21 23:52:29 +00:00
|
|
|
'''
|
2012-05-23 14:14:16 +00:00
|
|
|
Execute salt
|
2012-04-21 23:52:29 +00:00
|
|
|
'''
|
2013-08-30 17:24:15 +00:00
|
|
|
arg_str = '-c {0} {1}'.format(self.get_config_dir(), arg_str)
|
2013-09-13 16:51:25 +00:00
|
|
|
return self.run_script('salt', arg_str, with_retcode=with_retcode)
|
2012-04-21 23:52:29 +00:00
|
|
|
|
2013-09-13 16:51:25 +00:00
|
|
|
def run_run(self, arg_str, with_retcode=False):
|
2012-04-21 23:52:29 +00:00
|
|
|
'''
|
2012-05-23 14:14:16 +00:00
|
|
|
Execute salt-run
|
2012-04-21 23:52:29 +00:00
|
|
|
'''
|
2013-08-30 17:24:15 +00:00
|
|
|
arg_str = '-c {0} {1}'.format(self.get_config_dir(), arg_str)
|
2013-09-13 16:51:25 +00:00
|
|
|
return self.run_script('salt-run', arg_str, with_retcode=with_retcode)
|
2012-04-21 23:52:29 +00:00
|
|
|
|
2012-05-28 03:00:10 +00:00
|
|
|
def run_run_plus(self, fun, options='', *arg):
|
|
|
|
'''
|
|
|
|
Execute Salt run and the salt run function and return the data from
|
|
|
|
each in a dict
|
|
|
|
'''
|
|
|
|
ret = {}
|
|
|
|
ret['out'] = self.run_run(
|
2012-07-09 04:50:12 +00:00
|
|
|
'{0} {1} {2}'.format(options, fun, ' '.join(arg))
|
|
|
|
)
|
2012-05-28 03:00:10 +00:00
|
|
|
opts = salt.config.master_config(
|
2013-08-30 17:24:15 +00:00
|
|
|
self.get_config_file_path('master')
|
2012-08-04 22:25:37 +00:00
|
|
|
)
|
|
|
|
opts.update({'doc': False, 'fun': fun, 'arg': arg})
|
2012-11-23 12:19:09 +00:00
|
|
|
with RedirectStdStreams():
|
|
|
|
runner = salt.runner.Runner(opts)
|
|
|
|
ret['fun'] = runner.run()
|
2012-05-28 03:00:10 +00:00
|
|
|
return ret
|
|
|
|
|
2013-09-13 16:51:25 +00:00
|
|
|
def run_key(self, arg_str, catch_stderr=False, with_retcode=False):
|
2012-04-21 23:27:59 +00:00
|
|
|
'''
|
|
|
|
Execute salt-key
|
|
|
|
'''
|
2013-08-30 17:24:15 +00:00
|
|
|
arg_str = '-c {0} {1}'.format(self.get_config_dir(), arg_str)
|
2013-09-13 16:51:25 +00:00
|
|
|
return self.run_script(
|
|
|
|
'salt-key',
|
|
|
|
arg_str,
|
|
|
|
catch_stderr=catch_stderr,
|
|
|
|
with_retcode=with_retcode
|
|
|
|
)
|
2012-08-04 21:28:51 +00:00
|
|
|
|
2013-09-13 16:51:25 +00:00
|
|
|
def run_cp(self, arg_str, with_retcode=False):
|
2012-08-04 21:28:51 +00:00
|
|
|
'''
|
|
|
|
Execute salt-cp
|
|
|
|
'''
|
2013-08-30 17:24:15 +00:00
|
|
|
arg_str = '--config-dir {0} {1}'.format(self.get_config_dir(), arg_str)
|
2013-09-13 16:51:25 +00:00
|
|
|
return self.run_script('salt-cp', arg_str, with_retcode=with_retcode)
|
2012-08-13 06:10:42 +00:00
|
|
|
|
2013-09-13 16:12:11 +00:00
|
|
|
def run_call(self, arg_str, with_retcode=False):
|
2013-08-30 17:24:15 +00:00
|
|
|
arg_str = '--config-dir {0} {1}'.format(self.get_config_dir(), arg_str)
|
2013-09-13 16:12:11 +00:00
|
|
|
return self.run_script('salt-call', arg_str, with_retcode=with_retcode)
|
2012-08-04 18:58:32 +00:00
|
|
|
|
|
|
|
|
2013-06-25 13:41:26 +00:00
|
|
|
class ShellCaseCommonTestsMixIn(CheckShellBinaryNameAndVersionMixIn):
|
2012-08-04 18:58:32 +00:00
|
|
|
|
2013-06-25 13:41:26 +00:00
|
|
|
_call_binary_expected_version_ = salt.__version__
|
2012-11-20 16:09:57 +00:00
|
|
|
|
2013-01-14 12:35:42 +00:00
|
|
|
def test_salt_with_git_version(self):
|
|
|
|
if getattr(self, '_call_binary_', None) is None:
|
|
|
|
self.skipTest('\'_call_binary_\' not defined.')
|
|
|
|
from salt.utils import which
|
2013-09-19 17:50:51 +00:00
|
|
|
from salt.version import __version_info__, SaltStackVersion
|
2013-01-14 12:35:42 +00:00
|
|
|
git = which('git')
|
|
|
|
if not git:
|
|
|
|
self.skipTest('The git binary is not available')
|
|
|
|
|
|
|
|
# Let's get the output of git describe
|
|
|
|
process = subprocess.Popen(
|
2013-09-05 02:34:12 +00:00
|
|
|
[git, 'describe', '--tags', '--match', 'v[0-9]*'],
|
2013-01-14 12:35:42 +00:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
close_fds=True,
|
2013-01-15 14:16:39 +00:00
|
|
|
cwd=CODE_DIR
|
2013-01-14 12:35:42 +00:00
|
|
|
)
|
2013-01-15 14:16:39 +00:00
|
|
|
out, err = process.communicate()
|
2013-01-14 12:35:42 +00:00
|
|
|
if not out:
|
2013-01-15 14:16:39 +00:00
|
|
|
self.skipTest(
|
|
|
|
'Failed to get the output of \'git describe\'. '
|
|
|
|
'Error: {0!r}'.format(
|
|
|
|
err
|
|
|
|
)
|
|
|
|
)
|
2013-01-14 12:35:42 +00:00
|
|
|
|
2013-09-19 17:50:51 +00:00
|
|
|
parsed_version = SaltStackVersion.parse(out)
|
2013-09-05 02:34:12 +00:00
|
|
|
|
2013-09-19 17:50:51 +00:00
|
|
|
if parsed_version.info < __version_info__:
|
2013-01-15 19:42:24 +00:00
|
|
|
self.skipTest(
|
2013-09-05 02:34:12 +00:00
|
|
|
'We\'re likely about to release a new version. This test '
|
|
|
|
'would fail. Parsed({0!r}) < Expected({1!r})'.format(
|
2013-09-19 17:50:51 +00:00
|
|
|
parsed_version.info, __version_info__
|
2013-01-15 19:42:24 +00:00
|
|
|
)
|
|
|
|
)
|
2013-09-19 17:50:51 +00:00
|
|
|
elif parsed_version.info != __version_info__:
|
2013-01-14 12:35:42 +00:00
|
|
|
self.skipTest(
|
|
|
|
'In order to get the proper salt version with the '
|
|
|
|
'git hash you need to update salt\'s local git '
|
|
|
|
'tags. Something like: \'git fetch --tags\' or '
|
|
|
|
'\'git fetch --tags upstream\' if you followed '
|
|
|
|
'salt\'s contribute documentation. The version '
|
|
|
|
'string WILL NOT include the git hash.'
|
|
|
|
)
|
|
|
|
out = '\n'.join(self.run_script(self._call_binary_, '--version'))
|
2013-09-19 17:50:51 +00:00
|
|
|
self.assertIn(parsed_version.string, out)
|
2013-01-14 12:35:42 +00:00
|
|
|
|
2012-11-20 16:09:57 +00:00
|
|
|
|
|
|
|
class SaltReturnAssertsMixIn(object):
|
|
|
|
|
2012-11-25 22:29:08 +00:00
|
|
|
def assertReturnSaltType(self, ret):
|
2012-11-20 16:09:57 +00:00
|
|
|
try:
|
2012-11-21 12:16:17 +00:00
|
|
|
self.assertTrue(isinstance(ret, dict))
|
2012-11-20 16:09:57 +00:00
|
|
|
except AssertionError:
|
|
|
|
raise AssertionError(
|
2012-11-21 12:16:17 +00:00
|
|
|
'{0} is not dict. Salt returned: {1}'.format(
|
2012-11-25 22:29:08 +00:00
|
|
|
type(ret).__name__, ret
|
2012-11-20 16:09:57 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2012-11-25 22:29:08 +00:00
|
|
|
def assertReturnNonEmptySaltType(self, ret):
|
|
|
|
self.assertReturnSaltType(ret)
|
2012-11-21 12:16:17 +00:00
|
|
|
try:
|
|
|
|
self.assertNotEqual(ret, {})
|
|
|
|
except AssertionError:
|
|
|
|
raise AssertionError(
|
|
|
|
'{} is equal to {}. Salt returned an empty dictionary.'
|
|
|
|
)
|
|
|
|
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
def __return_valid_keys(self, keys):
|
2012-12-12 17:11:44 +00:00
|
|
|
if isinstance(keys, tuple):
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
# If it's a tuple, turn it into a list
|
2012-12-07 12:46:02 +00:00
|
|
|
keys = list(keys)
|
2012-12-12 17:11:44 +00:00
|
|
|
elif isinstance(keys, basestring):
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
# If it's a basestring , make it a one item list
|
2012-12-07 12:46:02 +00:00
|
|
|
keys = [keys]
|
2012-12-12 17:11:44 +00:00
|
|
|
elif not isinstance(keys, list):
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
# If we've reached here, it's a bad type passed to keys
|
2012-12-07 12:46:02 +00:00
|
|
|
raise RuntimeError('The passed keys need to be a list')
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
return keys
|
2012-12-07 12:46:02 +00:00
|
|
|
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
def __getWithinSaltReturn(self, ret, keys):
|
2012-12-12 17:11:44 +00:00
|
|
|
self.assertReturnNonEmptySaltType(ret)
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
keys = self.__return_valid_keys(keys)
|
|
|
|
okeys = keys[:]
|
2012-12-07 12:46:02 +00:00
|
|
|
for part in ret.itervalues():
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
try:
|
|
|
|
ret_item = part[okeys.pop(0)]
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
raise AssertionError(
|
|
|
|
'Could not get ret{0} from salt\'s return: {1}'.format(
|
|
|
|
''.join(['[{0!r}]'.format(k) for k in keys]), part
|
|
|
|
)
|
|
|
|
)
|
2012-12-07 12:46:02 +00:00
|
|
|
while okeys:
|
|
|
|
try:
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
ret_item = ret_item[okeys.pop(0)]
|
2012-12-07 12:46:02 +00:00
|
|
|
except (KeyError, TypeError):
|
|
|
|
raise AssertionError(
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
'Could not get ret{0} from salt\'s return: {1}'.format(
|
|
|
|
''.join(['[{0!r}]'.format(k) for k in keys]), part
|
2012-12-07 12:46:02 +00:00
|
|
|
)
|
|
|
|
)
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
return ret_item
|
|
|
|
|
2012-12-12 17:11:44 +00:00
|
|
|
def assertSaltTrueReturn(self, ret):
|
|
|
|
try:
|
|
|
|
self.assertTrue(self.__getWithinSaltReturn(ret, 'result'))
|
|
|
|
except AssertionError:
|
2013-04-25 19:59:34 +00:00
|
|
|
log.info('Salt Full Return:\n{0}'.format(pprint.pformat(ret)))
|
2013-01-14 14:07:58 +00:00
|
|
|
try:
|
|
|
|
raise AssertionError(
|
|
|
|
'{result} is not True. Salt Comment:\n{comment}'.format(
|
|
|
|
**(ret.values()[0])
|
|
|
|
)
|
|
|
|
)
|
2013-04-25 19:59:34 +00:00
|
|
|
except (AttributeError, IndexError):
|
2013-01-14 14:07:58 +00:00
|
|
|
raise AssertionError(
|
2013-04-25 19:59:34 +00:00
|
|
|
'Failed to get result. Salt Returned:\n{0}'.format(
|
|
|
|
pprint.pformat(ret)
|
|
|
|
)
|
2012-12-12 17:11:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def assertSaltFalseReturn(self, ret):
|
|
|
|
try:
|
|
|
|
self.assertFalse(self.__getWithinSaltReturn(ret, 'result'))
|
|
|
|
except AssertionError:
|
2013-04-25 19:59:34 +00:00
|
|
|
log.info('Salt Full Return:\n{0}'.format(pprint.pformat(ret)))
|
2013-01-14 14:07:58 +00:00
|
|
|
try:
|
|
|
|
raise AssertionError(
|
|
|
|
'{result} is not False. Salt Comment:\n{comment}'.format(
|
|
|
|
**(ret.values()[0])
|
|
|
|
)
|
|
|
|
)
|
2013-04-25 19:59:34 +00:00
|
|
|
except (AttributeError, IndexError):
|
2013-01-14 14:07:58 +00:00
|
|
|
raise AssertionError(
|
|
|
|
'Failed to get result. Salt Returned: {0}'.format(ret)
|
2012-12-12 17:11:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def assertSaltNoneReturn(self, ret):
|
|
|
|
try:
|
|
|
|
self.assertIsNone(self.__getWithinSaltReturn(ret, 'result'))
|
|
|
|
except AssertionError:
|
2013-04-25 19:59:34 +00:00
|
|
|
log.info('Salt Full Return:\n{0}'.format(pprint.pformat(ret)))
|
2013-01-14 14:07:58 +00:00
|
|
|
try:
|
|
|
|
raise AssertionError(
|
|
|
|
'{result} is not None. Salt Comment:\n{comment}'.format(
|
|
|
|
**(ret.values()[0])
|
|
|
|
)
|
|
|
|
)
|
2013-04-25 19:59:34 +00:00
|
|
|
except (AttributeError, IndexError):
|
2013-01-14 14:07:58 +00:00
|
|
|
raise AssertionError(
|
|
|
|
'Failed to get result. Salt Returned: {0}'.format(ret)
|
2012-12-12 17:11:44 +00:00
|
|
|
)
|
|
|
|
|
2013-08-18 04:46:33 +00:00
|
|
|
def assertInSaltComment(self, in_comment, ret):
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
return self.assertIn(
|
|
|
|
in_comment, self.__getWithinSaltReturn(ret, 'comment')
|
|
|
|
)
|
|
|
|
|
2013-08-18 04:49:18 +00:00
|
|
|
def assertNotInSaltComment(self, not_in_comment, ret):
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
return self.assertNotIn(
|
|
|
|
not_in_comment, self.__getWithinSaltReturn(ret, 'comment')
|
|
|
|
)
|
|
|
|
|
|
|
|
def assertSaltCommentRegexpMatches(self, ret, pattern):
|
|
|
|
return self.assertInSaltReturnRegexpMatches(ret, pattern, 'comment')
|
|
|
|
|
2013-07-27 14:58:28 +00:00
|
|
|
def assertInSalStatetWarning(self, in_comment, ret):
|
|
|
|
return self.assertIn(
|
|
|
|
in_comment, self.__getWithinSaltReturn(ret, 'warnings')
|
|
|
|
)
|
|
|
|
|
|
|
|
def assertNotInSaltStateWarning(self, not_in_comment, ret):
|
|
|
|
return self.assertNotIn(
|
|
|
|
not_in_comment, self.__getWithinSaltReturn(ret, 'warnings')
|
|
|
|
)
|
|
|
|
|
2013-08-18 05:01:38 +00:00
|
|
|
def assertInSaltReturn(self, item_to_check, ret, keys):
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
return self.assertIn(
|
|
|
|
item_to_check, self.__getWithinSaltReturn(ret, keys)
|
|
|
|
)
|
|
|
|
|
2013-08-18 04:58:42 +00:00
|
|
|
def assertNotInSaltReturn(self, item_to_check, ret, keys):
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
return self.assertNotIn(
|
|
|
|
item_to_check, self.__getWithinSaltReturn(ret, keys)
|
|
|
|
)
|
|
|
|
|
|
|
|
def assertInSaltReturnRegexpMatches(self, ret, pattern, keys=()):
|
|
|
|
return self.assertRegexpMatches(
|
|
|
|
self.__getWithinSaltReturn(ret, keys), pattern
|
|
|
|
)
|
2012-12-07 12:46:02 +00:00
|
|
|
|
|
|
|
def assertSaltStateChangesEqual(self, ret, comparison, keys=()):
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
keys = ['changes'] + self.__return_valid_keys(keys)
|
|
|
|
return self.assertEqual(
|
|
|
|
self.__getWithinSaltReturn(ret, keys), comparison
|
|
|
|
)
|
2012-12-07 12:46:02 +00:00
|
|
|
|
|
|
|
def assertSaltStateChangesNotEqual(self, ret, comparison, keys=()):
|
Abstract `SaltReturnAssertsMixIn` to allow more tests using it.
* Created a method which gets a deep keyed value in a salt state return. For example, allow getting, `ret['changes']['new']`.
* Created a method which tries to make sure the correct type of the passed keys for the above added method.
* Also added were the methods, `assertInSaltReturn`, `assertNotInSaltReturn`, `assertInSaltReturnRegexpMatches`, which simplified the existing `assertInSaltComment`, `assertNotInSaltComment`, `assertSaltCommentRegexpMatches`, `assertSaltStateChangesEqual` and `assertSaltStateChangesNotEqual`, also allowing to do similar tests in every key(deep or not) of a salt state return dictionary.
2012-12-12 13:29:43 +00:00
|
|
|
keys = ['changes'] + self.__return_valid_keys(keys)
|
|
|
|
return self.assertNotEqual(
|
|
|
|
self.__getWithinSaltReturn(ret, keys), comparison
|
|
|
|
)
|