2012-05-05 14:09:23 +00:00
|
|
|
# Import python libs
|
2012-08-25 23:38:39 +00:00
|
|
|
import os
|
2012-09-28 15:04:38 +00:00
|
|
|
import shutil
|
2012-11-18 18:57:10 +00:00
|
|
|
|
2013-06-27 11:45:28 +00:00
|
|
|
# Import Salt Testing libs
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
|
|
|
ensure_in_syspath('../../')
|
|
|
|
|
2012-11-18 18:57:10 +00:00
|
|
|
# Import salt libs
|
2013-06-27 11:45:28 +00:00
|
|
|
import integration
|
2012-11-18 19:06:17 +00:00
|
|
|
import salt.utils
|
2012-05-05 14:09:23 +00:00
|
|
|
|
2012-03-29 23:18:32 +00:00
|
|
|
|
2012-12-07 18:44:06 +00:00
|
|
|
class StateModuleTest(integration.ModuleCase,
|
|
|
|
integration.SaltReturnAssertsMixIn):
|
2012-03-29 23:18:32 +00:00
|
|
|
'''
|
|
|
|
Validate the test module
|
|
|
|
'''
|
2012-09-01 06:49:34 +00:00
|
|
|
|
|
|
|
maxDiff = None
|
|
|
|
|
2012-03-29 23:18:32 +00:00
|
|
|
def test_show_highstate(self):
|
|
|
|
'''
|
|
|
|
state.show_highstate
|
|
|
|
'''
|
|
|
|
high = self.run_function('state.show_highstate')
|
2013-11-01 19:36:09 +00:00
|
|
|
destpath = os.path.join(integration.SYS_TMP_DIR, 'testfile')
|
2012-03-29 23:18:32 +00:00
|
|
|
self.assertTrue(isinstance(high, dict))
|
2013-11-01 19:36:09 +00:00
|
|
|
self.assertTrue(destpath in high)
|
|
|
|
self.assertEqual(high[destpath]['__env__'], 'base')
|
2012-03-29 23:18:32 +00:00
|
|
|
|
|
|
|
def test_show_lowstate(self):
|
|
|
|
'''
|
|
|
|
state.show_lowstate
|
|
|
|
'''
|
|
|
|
low = self.run_function('state.show_lowstate')
|
|
|
|
self.assertTrue(isinstance(low, list))
|
|
|
|
self.assertTrue(isinstance(low[0], dict))
|
|
|
|
|
2012-05-14 03:31:46 +00:00
|
|
|
def test_catch_recurse(self):
|
|
|
|
'''
|
|
|
|
state.show_sls used to catch a recursive ref
|
|
|
|
'''
|
|
|
|
err = self.run_function('state.sls', mods='recurse_fail')
|
2012-05-14 05:16:45 +00:00
|
|
|
self.assertIn('recursive', err[0])
|
2012-05-14 03:31:46 +00:00
|
|
|
|
2012-06-16 04:41:36 +00:00
|
|
|
def test_no_recurse(self):
|
|
|
|
'''
|
2012-06-19 16:29:14 +00:00
|
|
|
verify that a sls structure is NOT a recursive ref
|
2012-06-16 04:41:36 +00:00
|
|
|
'''
|
|
|
|
sls = self.run_function('state.show_sls', mods='recurse_ok')
|
|
|
|
self.assertIn('snmpd', sls)
|
|
|
|
|
2012-06-19 16:29:14 +00:00
|
|
|
def test_no_recurse_two(self):
|
|
|
|
'''
|
|
|
|
verify that a sls structure is NOT a recursive ref
|
|
|
|
'''
|
|
|
|
sls = self.run_function('state.show_sls', mods='recurse_ok_two')
|
|
|
|
self.assertIn('/etc/nagios/nrpe.cfg', sls)
|
|
|
|
|
2012-09-01 06:49:34 +00:00
|
|
|
def test_issue_1896_file_append_source(self):
|
|
|
|
'''
|
|
|
|
Verify that we can append a file's contents
|
|
|
|
'''
|
2012-11-06 11:20:06 +00:00
|
|
|
testfile = os.path.join(integration.TMP, 'test.append')
|
|
|
|
if os.path.isfile(testfile):
|
|
|
|
os.unlink(testfile)
|
|
|
|
|
|
|
|
ret = self.run_function('state.sls', mods='testappend')
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-06 11:20:06 +00:00
|
|
|
|
|
|
|
ret = self.run_function('state.sls', mods='testappend.step-1')
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-06 11:20:06 +00:00
|
|
|
|
|
|
|
ret = self.run_function('state.sls', mods='testappend.step-2')
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-04 11:35:23 +00:00
|
|
|
|
2012-09-28 23:40:30 +00:00
|
|
|
self.assertMultiLineEqual('''\
|
2012-09-01 06:49:34 +00:00
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
2012-09-03 15:40:52 +00:00
|
|
|
|
2012-09-01 06:49:34 +00:00
|
|
|
# enable bash completion in interactive shells
|
|
|
|
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
|
|
|
|
. /etc/bash_completion
|
|
|
|
fi
|
2012-11-18 18:57:10 +00:00
|
|
|
''', salt.utils.fopen(testfile, 'r').read())
|
2012-09-01 06:49:34 +00:00
|
|
|
|
|
|
|
# Re-append switching order
|
2012-11-06 11:20:06 +00:00
|
|
|
ret = self.run_function('state.sls', mods='testappend.step-2')
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-06 11:20:06 +00:00
|
|
|
|
|
|
|
ret = self.run_function('state.sls', mods='testappend.step-1')
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2012-09-28 23:40:30 +00:00
|
|
|
self.assertMultiLineEqual('''\
|
2012-09-01 06:49:34 +00:00
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
2012-09-03 15:40:52 +00:00
|
|
|
|
2012-09-01 06:49:34 +00:00
|
|
|
# enable bash completion in interactive shells
|
|
|
|
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
|
|
|
|
. /etc/bash_completion
|
|
|
|
fi
|
2012-11-18 18:57:10 +00:00
|
|
|
''', salt.utils.fopen(testfile, 'r').read())
|
2012-09-01 06:49:34 +00:00
|
|
|
|
2012-08-25 13:44:07 +00:00
|
|
|
def test_issue_1876_syntax_error(self):
|
|
|
|
'''
|
|
|
|
verify that we catch the following syntax error::
|
|
|
|
|
|
|
|
/tmp/salttest/issue-1876:
|
|
|
|
|
|
|
|
file:
|
|
|
|
- managed
|
|
|
|
- source: salt://testfile
|
|
|
|
|
|
|
|
file.append:
|
|
|
|
- text: foo
|
|
|
|
|
|
|
|
'''
|
2012-11-06 11:20:06 +00:00
|
|
|
testfile = os.path.join(integration.TMP, 'issue-1876')
|
2012-08-25 13:44:07 +00:00
|
|
|
sls = self.run_function('state.sls', mods='issue-1876')
|
|
|
|
self.assertIn(
|
2012-11-06 11:20:06 +00:00
|
|
|
'Name "{0}" in sls "issue-1876" contains multiple state decs of '
|
|
|
|
'the same type'.format(testfile),
|
|
|
|
sls
|
2012-08-25 13:44:07 +00:00
|
|
|
)
|
|
|
|
|
2012-08-25 23:38:39 +00:00
|
|
|
def test_issue_1879_too_simple_contains_check(self):
|
2012-09-28 23:40:30 +00:00
|
|
|
contents = '''\
|
2012-08-25 23:38:39 +00:00
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
|
|
|
# enable bash completion in interactive shells
|
|
|
|
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
|
|
|
|
. /etc/bash_completion
|
2012-08-28 09:03:11 +00:00
|
|
|
fi
|
2012-09-28 23:40:30 +00:00
|
|
|
'''
|
2012-11-06 11:20:06 +00:00
|
|
|
testfile = os.path.join(integration.TMP, 'issue-1879')
|
2012-11-04 11:46:00 +00:00
|
|
|
# Delete if exiting
|
2012-11-06 11:20:06 +00:00
|
|
|
if os.path.isfile(testfile):
|
|
|
|
os.unlink(testfile)
|
2012-11-04 11:46:00 +00:00
|
|
|
|
2012-08-28 09:03:11 +00:00
|
|
|
# Create the file
|
2013-01-14 14:07:58 +00:00
|
|
|
ret = self.run_function('state.sls', mods='issue-1879', timeout=120)
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2012-08-28 09:03:11 +00:00
|
|
|
# The first append
|
2013-01-14 14:07:58 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'state.sls', mods='issue-1879.step-1', timeout=120
|
|
|
|
)
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-06 11:20:06 +00:00
|
|
|
|
|
|
|
# The second append
|
2013-01-14 14:07:58 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'state.sls', mods='issue-1879.step-2', timeout=120
|
|
|
|
)
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2012-08-28 09:03:11 +00:00
|
|
|
# Does it match?
|
|
|
|
try:
|
|
|
|
self.assertMultiLineEqual(
|
2012-11-06 11:20:06 +00:00
|
|
|
contents,
|
2012-11-18 18:57:10 +00:00
|
|
|
salt.utils.fopen(testfile, 'r').read()
|
2012-08-28 09:03:11 +00:00
|
|
|
)
|
|
|
|
# Make sure we don't re-append existing text
|
2013-01-14 14:07:58 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'state.sls', mods='issue-1879.step-1', timeout=120
|
|
|
|
)
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
|
2013-01-14 14:07:58 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'state.sls', mods='issue-1879.step-2', timeout=120
|
|
|
|
)
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-08-28 09:03:11 +00:00
|
|
|
self.assertMultiLineEqual(
|
2012-11-06 11:20:06 +00:00
|
|
|
contents,
|
2012-11-18 18:57:10 +00:00
|
|
|
salt.utils.fopen(testfile, 'r').read()
|
2012-08-28 09:03:11 +00:00
|
|
|
)
|
|
|
|
except Exception:
|
2012-11-06 11:20:06 +00:00
|
|
|
if os.path.exists(testfile):
|
|
|
|
shutil.copy(testfile, testfile + '.bak')
|
2012-08-28 09:03:11 +00:00
|
|
|
raise
|
|
|
|
finally:
|
2012-11-06 11:20:06 +00:00
|
|
|
if os.path.exists(testfile):
|
|
|
|
os.unlink(testfile)
|
2012-08-25 23:38:39 +00:00
|
|
|
|
2012-09-28 00:17:37 +00:00
|
|
|
def test_include(self):
|
2012-11-06 12:44:53 +00:00
|
|
|
fnames = (
|
|
|
|
os.path.join(integration.SYS_TMP_DIR, 'include-test'),
|
|
|
|
os.path.join(integration.SYS_TMP_DIR, 'to-include-test')
|
|
|
|
)
|
|
|
|
exclude_test_file = os.path.join(
|
|
|
|
integration.SYS_TMP_DIR, 'exclude-test'
|
|
|
|
)
|
2012-09-28 00:17:37 +00:00
|
|
|
try:
|
|
|
|
ret = self.run_function('state.sls', mods='include-test')
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
|
2012-09-28 00:17:37 +00:00
|
|
|
for fname in fnames:
|
|
|
|
self.assertTrue(os.path.isfile(fname))
|
2012-11-06 12:44:53 +00:00
|
|
|
self.assertFalse(os.path.isfile(exclude_test_file))
|
2012-09-28 00:17:37 +00:00
|
|
|
finally:
|
2012-11-06 12:44:53 +00:00
|
|
|
for fname in list(fnames) + [exclude_test_file]:
|
2012-09-28 00:17:37 +00:00
|
|
|
if os.path.isfile(fname):
|
|
|
|
os.remove(fname)
|
|
|
|
|
|
|
|
def test_exclude(self):
|
2012-11-06 12:44:53 +00:00
|
|
|
fnames = (
|
|
|
|
os.path.join(integration.SYS_TMP_DIR, 'include-test'),
|
|
|
|
os.path.join(integration.SYS_TMP_DIR, 'exclude-test')
|
|
|
|
)
|
|
|
|
to_include_test_file = os.path.join(
|
|
|
|
integration.SYS_TMP_DIR, 'to-include-test'
|
|
|
|
)
|
2012-09-28 00:17:37 +00:00
|
|
|
try:
|
|
|
|
ret = self.run_function('state.sls', mods='exclude-test')
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
|
2012-09-28 00:17:37 +00:00
|
|
|
for fname in fnames:
|
|
|
|
self.assertTrue(os.path.isfile(fname))
|
2012-11-06 12:44:53 +00:00
|
|
|
self.assertFalse(os.path.isfile(to_include_test_file))
|
2012-09-28 00:17:37 +00:00
|
|
|
finally:
|
2012-11-06 12:44:53 +00:00
|
|
|
for fname in list(fnames) + [to_include_test_file]:
|
2012-09-28 00:17:37 +00:00
|
|
|
if os.path.isfile(fname):
|
|
|
|
os.remove(fname)
|
2013-06-24 19:06:49 +00:00
|
|
|
|
2012-09-28 15:04:38 +00:00
|
|
|
def test_issue_2068_template_str(self):
|
2013-01-26 04:16:11 +00:00
|
|
|
ret = self.run_function('cmd.has_exec', ['virtualenv'])
|
|
|
|
if not ret:
|
|
|
|
self.skipTest('virtualenv not installed')
|
2012-11-06 12:44:53 +00:00
|
|
|
venv_dir = os.path.join(
|
|
|
|
integration.SYS_TMP_DIR, 'issue-2068-template-str'
|
|
|
|
)
|
2012-09-28 00:17:37 +00:00
|
|
|
|
2012-09-28 15:04:38 +00:00
|
|
|
try:
|
|
|
|
ret = self.run_function(
|
2013-01-14 14:07:58 +00:00
|
|
|
'state.sls', mods='issue-2068-template-str-no-dot',
|
|
|
|
timeout=120
|
2012-09-28 15:04:38 +00:00
|
|
|
)
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-09-28 15:04:38 +00:00
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
|
|
|
|
|
|
|
# Let's load the template from the filesystem. If running this state
|
|
|
|
# with state.sls works, so should using state.template_str
|
|
|
|
template_path = os.path.join(
|
|
|
|
os.path.dirname(os.path.dirname(__file__)),
|
|
|
|
'files', 'file', 'base', 'issue-2068-template-str-no-dot.sls'
|
|
|
|
)
|
|
|
|
|
2012-11-18 18:57:10 +00:00
|
|
|
template = salt.utils.fopen(template_path, 'r').read()
|
2012-09-28 15:04:38 +00:00
|
|
|
try:
|
2013-01-14 14:07:58 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'state.template_str', [template], timeout=120
|
|
|
|
)
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-09-28 15:04:38 +00:00
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
os.path.isfile(os.path.join(venv_dir, 'bin', 'pep8'))
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
|
|
|
|
2012-09-28 16:34:55 +00:00
|
|
|
# Now using state.template
|
|
|
|
try:
|
2013-01-14 14:07:58 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'state.template', [template_path], timeout=120
|
|
|
|
)
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-09-28 16:34:55 +00:00
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
|
|
|
|
2012-09-28 15:04:38 +00:00
|
|
|
# Now the problematic #2068 including dot's
|
|
|
|
try:
|
|
|
|
ret = self.run_function(
|
2013-01-14 14:07:58 +00:00
|
|
|
'state.sls', mods='issue-2068-template-str', timeout=120
|
2012-09-28 15:04:38 +00:00
|
|
|
)
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-09-28 15:04:38 +00:00
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
|
|
|
|
|
|
|
# Let's load the template from the filesystem. If running this state
|
|
|
|
# with state.sls works, so should using state.template_str
|
|
|
|
template_path = os.path.join(
|
|
|
|
os.path.dirname(os.path.dirname(__file__)),
|
|
|
|
'files', 'file', 'base', 'issue-2068-template-str.sls'
|
|
|
|
)
|
|
|
|
|
2012-11-18 18:57:10 +00:00
|
|
|
template = salt.utils.fopen(template_path, 'r').read()
|
2012-09-28 15:04:38 +00:00
|
|
|
try:
|
2013-01-14 14:07:58 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'state.template_str', [template], timeout=120
|
|
|
|
)
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-09-28 15:04:38 +00:00
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
os.path.isfile(os.path.join(venv_dir, 'bin', 'pep8'))
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
2012-08-25 23:38:39 +00:00
|
|
|
|
2012-09-28 16:34:55 +00:00
|
|
|
# Now using state.template
|
|
|
|
try:
|
2013-01-14 14:07:58 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'state.template', [template_path], timeout=120
|
|
|
|
)
|
2012-12-07 18:44:06 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-09-28 16:34:55 +00:00
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
|
|
|
|
2012-09-28 16:56:13 +00:00
|
|
|
def test_template_invalid_items(self):
|
|
|
|
TEMPLATE = '''\
|
|
|
|
{0}:
|
|
|
|
- issue-2068-template-str
|
|
|
|
|
|
|
|
/tmp/test-template-invalid-items:
|
|
|
|
file:
|
|
|
|
- managed
|
|
|
|
- source: salt://testfile
|
|
|
|
'''
|
|
|
|
for item in ('include', 'exclude', 'extends'):
|
|
|
|
ret = self.run_function(
|
|
|
|
'state.template_str', [TEMPLATE.format(item)]
|
|
|
|
)
|
|
|
|
self.assertTrue(isinstance(ret, list))
|
|
|
|
self.assertNotEqual(ret, [])
|
|
|
|
self.assertEqual(
|
|
|
|
['The \'{0}\' declaration found on \'<template-str>\' is '
|
|
|
|
'invalid when rendering single templates'.format(item)],
|
|
|
|
ret
|
|
|
|
)
|
|
|
|
|
2013-05-18 22:47:14 +00:00
|
|
|
def test_pydsl(self):
|
|
|
|
'''
|
|
|
|
Test the basics of the pydsl
|
|
|
|
'''
|
|
|
|
ret = self.run_function('state.sls', mods='pydsl-1')
|
2013-05-18 22:58:08 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2013-05-18 22:47:14 +00:00
|
|
|
|
2013-10-31 16:42:59 +00:00
|
|
|
def test_issues_7905_and_8174_sls_syntax_error(self):
|
|
|
|
'''
|
|
|
|
Call sls file with yaml syntax error.
|
|
|
|
|
|
|
|
Ensure theses errors are detected and presented to the user without
|
|
|
|
stack traces.
|
|
|
|
'''
|
|
|
|
ret = self.run_function('state.sls', mods='syntax.badlist')
|
|
|
|
self.assertEqual(ret, [
|
|
|
|
'The state "A" in sls syntax.badlist is not formed as a list'
|
|
|
|
])
|
|
|
|
ret = self.run_function('state.sls', mods='syntax.badlist2')
|
|
|
|
self.assertEqual(ret, [
|
|
|
|
'The state "C" in sls syntax.badlist2 is not formed as a list'
|
|
|
|
])
|
|
|
|
|
2013-11-24 17:28:22 +00:00
|
|
|
def test_requisites_mixed_require_prereq_use(self):
|
|
|
|
'''
|
|
|
|
Call sls file containing several requisites.
|
|
|
|
'''
|
|
|
|
expected_simple_result={
|
|
|
|
'cmd_|-A_|-echo A_|-run': {
|
|
|
|
'__run_num__': 2,
|
|
|
|
'comment': 'Command "echo A" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-B_|-echo B_|-run': {
|
|
|
|
'__run_num__': 1,
|
|
|
|
'comment': 'Command "echo B" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-C_|-echo C_|-run': {
|
|
|
|
'__run_num__': 0,
|
|
|
|
'comment': 'Command "echo C" run',
|
|
|
|
'result': True}
|
|
|
|
}
|
|
|
|
expected_result={
|
|
|
|
'cmd_|-A_|-echo A fifth_|-run': {
|
|
|
|
'__run_num__': 4,
|
|
|
|
'comment': 'Command "echo A fifth" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-B_|-echo B third_|-run': {
|
|
|
|
'__run_num__': 2,
|
|
|
|
'comment': 'Command "echo B third" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-C_|-echo C second_|-run': {
|
|
|
|
'__run_num__': 1,
|
|
|
|
'comment': 'Command "echo C second" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-D_|-echo D first_|-run': {
|
|
|
|
'__run_num__': 0,
|
|
|
|
'comment': 'Command "echo D first" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-E_|-echo E fourth_|-run': {
|
|
|
|
'__run_num__': 3,
|
|
|
|
'comment': 'Command "echo E fourth" run',
|
|
|
|
'result': True}
|
|
|
|
}
|
2013-11-25 10:06:37 +00:00
|
|
|
expected_req_use_result={
|
|
|
|
'cmd_|-A_|-echo A_|-run': {
|
|
|
|
'__run_num__': 1,
|
|
|
|
'comment': 'Command "echo A" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-B_|-echo B_|-run': {
|
|
|
|
'__run_num__': 4,
|
|
|
|
'comment': 'Command "echo B" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-C_|-echo C_|-run': {
|
|
|
|
'__run_num__': 0,
|
|
|
|
'comment': 'Command "echo C" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-D_|-echo D_|-run': {
|
|
|
|
'__run_num__': 5,
|
|
|
|
'comment': 'Command "echo D" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-E_|-echo E_|-run': {
|
|
|
|
'__run_num__': 2,
|
|
|
|
'comment': 'Command "echo E" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-F_|-echo F_|-run': {
|
|
|
|
'__run_num__': 3,
|
|
|
|
'comment': 'Command "echo F" run',
|
|
|
|
'result': True}
|
|
|
|
}
|
2013-11-24 17:28:22 +00:00
|
|
|
result={}
|
|
|
|
ret = self.run_function('state.sls', mods='requisites.mixed_simple')
|
|
|
|
for item,descr in ret.iteritems():
|
|
|
|
result[item] = {
|
|
|
|
'__run_num__': descr['__run_num__'],
|
|
|
|
'comment':descr['comment'],
|
|
|
|
'result':descr['result']
|
|
|
|
}
|
|
|
|
self.assertEqual(expected_simple_result, result)
|
|
|
|
|
|
|
|
# test Traceback recursion prereq+require #8785
|
|
|
|
# TODO: this is actually failing badly
|
|
|
|
#ret = self.run_function('state.sls', mods='requisites.prereq_require_recursion_error2')
|
|
|
|
#self.assertEqual(
|
|
|
|
# ret,
|
|
|
|
# ['A recursive requisite was found, SLS "requisites.prereq_require_recursion_error2" ID "B" ID "A"']
|
|
|
|
#)
|
|
|
|
|
|
|
|
# test Infinite recursion prereq+require #8785 v2
|
|
|
|
# TODO: this is actually failing badly
|
|
|
|
#ret = self.run_function('state.sls', mods='requisites.prereq_require_recursion_error3')
|
|
|
|
#self.assertEqual(
|
|
|
|
# ret,
|
|
|
|
# ['A recursive requisite was found, SLS "requisites.prereq_require_recursion_error2" ID "B" ID "A"']
|
|
|
|
#)
|
|
|
|
|
|
|
|
# test Infinite recursion prereq+require #8785 v3
|
|
|
|
# TODO: this is actually failing badly, and expected result is maybe not a recursion
|
|
|
|
#ret = self.run_function('state.sls', mods='requisites.prereq_require_recursion_error4')
|
|
|
|
#self.assertEqual(
|
|
|
|
# ret,
|
|
|
|
# ['A recursive requisite was found, SLS "requisites.prereq_require_recursion_error2" ID "B" ID "A"']
|
|
|
|
#)
|
|
|
|
|
|
|
|
# undetected infinite loopS prevents this test from running...
|
|
|
|
# TODO: this is actually failing badly
|
|
|
|
#result={}
|
|
|
|
#ret = self.run_function('state.sls', mods='requisites.mixed_complex1')
|
|
|
|
#for item,descr in ret.iteritems():
|
|
|
|
# result[item] = {
|
|
|
|
# '__run_num__': descr['__run_num__'],
|
|
|
|
# 'comment':descr['comment'],
|
|
|
|
# 'result':descr['result']
|
|
|
|
# }
|
|
|
|
#self.assertEqual(expected_result, result)
|
|
|
|
|
2013-11-25 10:06:37 +00:00
|
|
|
# issue #8796: use does not inherit require
|
|
|
|
# TODO: this test contains actually requires duplication to work
|
|
|
|
# that shoudl be removed when use will be able to inherit require instructions
|
|
|
|
result={}
|
|
|
|
ret = self.run_function('state.sls', mods='requisites.require_and_use')
|
|
|
|
for item,descr in ret.iteritems():
|
|
|
|
result[item] = {
|
|
|
|
'__run_num__': descr['__run_num__'],
|
|
|
|
'comment':descr['comment'],
|
|
|
|
'result':descr['result']
|
|
|
|
}
|
|
|
|
self.assertEqual(expected_req_use_result, result)
|
|
|
|
|
2013-11-23 15:37:57 +00:00
|
|
|
def test_requisites_require_ordering_and_errors(self):
|
|
|
|
'''
|
|
|
|
Call sls file containing several require_in and require.
|
|
|
|
|
|
|
|
Ensure that some of them are failing and that the order is right.
|
|
|
|
'''
|
|
|
|
expected_result={
|
|
|
|
'cmd_|-A_|-echo A fifth_|-run': {
|
|
|
|
'__run_num__': 4,
|
|
|
|
'comment': 'Command "echo A fifth" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-B_|-echo B second_|-run': {
|
|
|
|
'__run_num__': 1,
|
|
|
|
'comment': 'Command "echo B second" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-C_|-echo C third_|-run': {
|
|
|
|
'__run_num__': 2,
|
|
|
|
'comment': 'Command "echo C third" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-D_|-echo D first_|-run': {
|
|
|
|
'__run_num__': 0,
|
|
|
|
'comment': 'Command "echo D first" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-E_|-echo E fourth_|-run': {
|
|
|
|
'__run_num__': 3,
|
|
|
|
'comment': 'Command "echo E fourth" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-F_|-echo F_|-run': {
|
|
|
|
'__run_num__': 5,
|
|
|
|
'comment': 'The following requisites were not found:\n'
|
|
|
|
+ ' require:\n'
|
|
|
|
+ ' foobar: A\n',
|
|
|
|
'result': False},
|
|
|
|
'cmd_|-G_|-echo G_|-run': {
|
|
|
|
'__run_num__': 6,
|
|
|
|
'comment': 'The following requisites were not found:\n'
|
|
|
|
+ ' require:\n'
|
|
|
|
+ ' cmd: Z\n',
|
|
|
|
'result': False}
|
|
|
|
}
|
|
|
|
result={}
|
|
|
|
ret = self.run_function('state.sls', mods='requisites.require')
|
|
|
|
for item,descr in ret.iteritems():
|
|
|
|
result[item] = {
|
|
|
|
'__run_num__': descr['__run_num__'],
|
|
|
|
'comment':descr['comment'],
|
|
|
|
'result':descr['result']
|
|
|
|
}
|
|
|
|
self.assertEqual(expected_result, result)
|
|
|
|
ret = self.run_function('state.sls', mods='requisites.require_error1')
|
|
|
|
self.assertEqual(ret, [
|
|
|
|
'Cannot extend ID W in "base:requisites.require_error1".'
|
|
|
|
+ ' It is not part of the high state.'
|
|
|
|
])
|
2013-11-23 17:20:15 +00:00
|
|
|
|
2013-11-23 15:37:57 +00:00
|
|
|
# commented until a fix is made for issue #8772
|
2013-11-23 17:20:15 +00:00
|
|
|
# TODO: this test actually fails
|
2013-11-23 15:37:57 +00:00
|
|
|
#ret = self.run_function('state.sls', mods='requisites.require_error2')
|
|
|
|
#self.assertEqual(ret, [
|
|
|
|
# 'Cannot extend state foobar for ID A in "base:requisites.require_error2".'
|
|
|
|
# + ' It is not part of the high state.'
|
|
|
|
#])
|
|
|
|
|
2013-11-23 17:20:15 +00:00
|
|
|
ret = self.run_function('state.sls', mods='requisites.require_recursion_error1')
|
|
|
|
self.assertEqual(
|
|
|
|
ret,
|
|
|
|
['A recursive requisite was found, SLS "requisites.require_recursion_error1" ID "B" ID "A"']
|
|
|
|
)
|
|
|
|
|
2013-11-23 17:56:07 +00:00
|
|
|
def test_requisites_full_sls(self):
|
|
|
|
'''
|
|
|
|
Teste the sls special command in requisites
|
|
|
|
'''
|
|
|
|
expected_result={
|
|
|
|
'cmd_|-A_|-echo A_|-run': {
|
|
|
|
'__run_num__': 2,
|
|
|
|
'comment': 'Command "echo A" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-B_|-echo B_|-run': {
|
|
|
|
'__run_num__': 0,
|
|
|
|
'comment': 'Command "echo B" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-C_|-echo C_|-run': {
|
|
|
|
'__run_num__': 1,
|
|
|
|
'comment': 'Command "echo C" run',
|
|
|
|
'result': True},
|
|
|
|
}
|
|
|
|
result={}
|
|
|
|
ret = self.run_function('state.sls', mods='requisites.fullsls_require')
|
|
|
|
for item,descr in ret.iteritems():
|
|
|
|
result[item] = {
|
|
|
|
'__run_num__': descr['__run_num__'],
|
|
|
|
'comment':descr['comment'],
|
|
|
|
'result':descr['result']
|
|
|
|
}
|
|
|
|
self.assertEqual(expected_result, result)
|
|
|
|
|
|
|
|
# TODO: not done
|
|
|
|
#ret = self.run_function('state.sls', mods='requisites.fullsls_require_in')
|
|
|
|
#self.assertEqual(['sls command can only be used with require requisite'], ret)
|
|
|
|
|
|
|
|
# issue #8233: traceback on prereq sls
|
|
|
|
# TODO: not done
|
|
|
|
#ret = self.run_function('state.sls', mods='requisites.fullsls_prereq')
|
|
|
|
#self.assertEqual(['sls command can only be used with require requisite'], ret)
|
|
|
|
|
2013-11-23 15:39:19 +00:00
|
|
|
def test_requisites_prereq_simple_ordering_and_errors(self):
|
|
|
|
'''
|
|
|
|
Call sls file containing several prereq_in and prereq.
|
|
|
|
|
|
|
|
Ensure that some of them are failing and that the order is right.
|
|
|
|
'''
|
|
|
|
expected_result_simple={
|
|
|
|
'cmd_|-A_|-echo A third_|-run': {
|
|
|
|
'__run_num__': 2,
|
|
|
|
'comment': 'Command "echo A third" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-B_|-echo B first_|-run': {
|
|
|
|
'__run_num__': 0,
|
|
|
|
'comment': 'Command "echo B first" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-C_|-echo C second_|-run': {
|
|
|
|
'__run_num__': 1,
|
|
|
|
'comment': 'Command "echo C second" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-I_|-echo I_|-run': {
|
|
|
|
'__run_num__': 3,
|
|
|
|
'comment': 'The following requisites were not found:\n'
|
|
|
|
+ ' prereq:\n'
|
|
|
|
+ ' cmd: Z\n',
|
|
|
|
'result': False},
|
|
|
|
'cmd_|-J_|-echo J_|-run': {
|
|
|
|
'__run_num__': 4,
|
|
|
|
'comment': 'The following requisites were not found:\n'
|
|
|
|
+ ' prereq:\n'
|
|
|
|
+ ' foobar: A\n',
|
|
|
|
'result': False}
|
|
|
|
}
|
2013-11-24 17:30:15 +00:00
|
|
|
expected_result_simple2={
|
|
|
|
'cmd_|-A_|-echo A_|-run': {
|
|
|
|
'__run_num__': 1,
|
|
|
|
'comment': 'Command "echo A" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-B_|-echo B_|-run': {
|
|
|
|
'__run_num__': 2,
|
|
|
|
'comment': 'Command "echo B" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-C_|-echo C_|-run': {
|
|
|
|
'__run_num__': 0,
|
|
|
|
'comment': 'Command "echo C" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-D_|-echo D_|-run': {
|
|
|
|
'__run_num__': 3,
|
|
|
|
'comment': 'Command "echo D" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-E_|-echo E_|-run': {
|
|
|
|
'__run_num__': 4,
|
|
|
|
'comment': 'Command "echo E" run',
|
|
|
|
'result': True}
|
|
|
|
}
|
2013-11-23 15:59:10 +00:00
|
|
|
expected_result_complex={
|
|
|
|
'cmd_|-A_|-echo A fourth_|-run': {
|
|
|
|
'__run_num__': 3,
|
|
|
|
'comment': 'Command "echo A fourth" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-B_|-echo B first_|-run': {
|
|
|
|
'__run_num__': 0,
|
|
|
|
'comment': 'Command "echo B first" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-C_|-echo C second_|-run': {
|
|
|
|
'__run_num__': 1,
|
|
|
|
'comment': 'Command "echo C second" run',
|
|
|
|
'result': True},
|
|
|
|
'cmd_|-D_|-echo D third_|-run': {
|
|
|
|
'__run_num__': 2,
|
|
|
|
'comment': 'Command "echo D third" run',
|
|
|
|
'result': True},
|
|
|
|
}
|
2013-11-23 15:39:19 +00:00
|
|
|
result={}
|
|
|
|
ret = self.run_function('state.sls', mods='requisites.prereq_simple')
|
|
|
|
for item,descr in ret.iteritems():
|
|
|
|
result[item] = {
|
|
|
|
'__run_num__': descr['__run_num__'],
|
|
|
|
'comment':descr['comment'],
|
|
|
|
'result':descr['result']
|
|
|
|
}
|
|
|
|
self.assertEqual(expected_result_simple, result)
|
|
|
|
|
2013-11-24 17:30:15 +00:00
|
|
|
result={}
|
|
|
|
ret = self.run_function('state.sls', mods='requisites.prereq_simple2')
|
|
|
|
for item,descr in ret.iteritems():
|
|
|
|
result[item] = {
|
|
|
|
'__run_num__': descr['__run_num__'],
|
|
|
|
'comment':descr['comment'],
|
|
|
|
'result':descr['result']
|
|
|
|
}
|
|
|
|
self.assertEqual(expected_result_simple2, result)
|
|
|
|
|
2013-11-23 15:39:19 +00:00
|
|
|
ret = self.run_function('state.sls', mods='requisites.prereq_compile_error1')
|
|
|
|
self.assertEqual(
|
|
|
|
ret['cmd_|-B_|-echo B_|-run']['comment'],
|
|
|
|
'The following requisites were not found:\n'
|
|
|
|
+ ' prereq:\n'
|
|
|
|
+ ' foobar: A\n'
|
|
|
|
)
|
|
|
|
|
|
|
|
ret = self.run_function('state.sls', mods='requisites.prereq_compile_error2')
|
|
|
|
self.assertEqual(
|
|
|
|
ret['cmd_|-B_|-echo B_|-run']['comment'],
|
|
|
|
'The following requisites were not found:\n'
|
|
|
|
+ ' prereq:\n'
|
|
|
|
+ ' foobar: C\n'
|
|
|
|
)
|
|
|
|
|
2013-11-23 15:59:10 +00:00
|
|
|
# issue #8211, chaining complex prereq & prereq_in
|
|
|
|
# TODO: Actually this test fails
|
|
|
|
#result={}
|
|
|
|
#ret = self.run_function('state.sls', mods='requisites.prereq_complex')
|
|
|
|
#for item,descr in ret.iteritems():
|
|
|
|
# result[item] = {
|
|
|
|
# '__run_num__': descr['__run_num__'],
|
|
|
|
# 'comment':descr['comment'],
|
|
|
|
# 'result':descr['result']
|
|
|
|
# }
|
|
|
|
#self.assertEqual(expected_result_complex, result)
|
|
|
|
|
2013-11-23 17:20:15 +00:00
|
|
|
# issue #8210 : prereq recursion undetected
|
|
|
|
# TODO: this test fails
|
|
|
|
#ret = self.run_function('state.sls', mods='requisites.prereq_recursion_error')
|
|
|
|
#self.assertEqual(
|
|
|
|
# ret,
|
|
|
|
# ['A recursive requisite was found, SLS "requisites.prereq_recursion_error" ID "B" ID "A"']
|
|
|
|
#)
|
|
|
|
|
2013-11-23 16:26:37 +00:00
|
|
|
def test_requisites_use(self):
|
|
|
|
'''
|
|
|
|
Call sls file containing several use_in and use.
|
|
|
|
|
|
|
|
'''
|
|
|
|
# TODO issue #8235 & #8774 some examples are still commented in the test file
|
|
|
|
ret = self.run_function('state.sls', mods='requisites.use')
|
|
|
|
for item,descr in ret.iteritems():
|
|
|
|
self.assertEqual(descr['comment'], 'onlyif execution failed')
|
|
|
|
|
2013-11-01 19:36:09 +00:00
|
|
|
def test_get_file_from_env_in_top_match(self):
|
|
|
|
tgt = os.path.join(integration.SYS_TMP_DIR, 'prod-cheese-file')
|
|
|
|
try:
|
|
|
|
ret = self.run_function(
|
|
|
|
'state.highstate', minion_tgt='sub_minion'
|
|
|
|
)
|
|
|
|
self.assertSaltTrueReturn(ret)
|
2013-11-02 18:31:14 +00:00
|
|
|
self.assertTrue(os.path.isfile(tgt))
|
2013-11-01 19:36:09 +00:00
|
|
|
with salt.utils.fopen(tgt, 'r') as cheese:
|
|
|
|
data = cheese.read()
|
|
|
|
self.assertIn('Gromit', data)
|
|
|
|
self.assertIn('Comte', data)
|
|
|
|
finally:
|
|
|
|
os.unlink(tgt)
|
|
|
|
|
2012-07-20 06:21:01 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(StateModuleTest)
|