mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Fix some additional tests
- Fix problem with invalid characters in requisites.prereq_simple2 - Fix problem with true/false commands in Windows. Need to use exit - Fix some issues with hard-coded paths to /tmp
This commit is contained in:
parent
0be187cfe0
commit
53506a5e86
@ -7,7 +7,7 @@
|
||||
# | | |
|
||||
# B --------+ | |
|
||||
# | |
|
||||
# D-------------+ |
|
||||
# D-------------+ |
|
||||
# |
|
||||
# E-----------------+
|
||||
|
||||
|
@ -1,6 +1,13 @@
|
||||
{% if grains['os'] == 'Windows' %}
|
||||
{% set cmd_true = 'exit' %}
|
||||
{% set cmd_false = 'exit /B 1' %}
|
||||
{% else %}
|
||||
{% set cmd_true = 'true' %}
|
||||
{% set cmd_false = 'false' %}
|
||||
{% endif %}
|
||||
A:
|
||||
cmd.wait:
|
||||
- name: 'true'
|
||||
- name: {{ cmd_true }}
|
||||
- watch_any:
|
||||
- cmd: B
|
||||
- cmd: C
|
||||
@ -8,19 +15,19 @@ A:
|
||||
|
||||
B:
|
||||
cmd.run:
|
||||
- name: 'true'
|
||||
- name: {{ cmd_true }}
|
||||
|
||||
C:
|
||||
cmd.run:
|
||||
- name: 'false'
|
||||
- name: {{ cmd_false }}
|
||||
|
||||
D:
|
||||
cmd.run:
|
||||
- name: 'true'
|
||||
- name: {{ cmd_true }}
|
||||
|
||||
E:
|
||||
cmd.wait:
|
||||
- name: 'true'
|
||||
- name: {{ cmd_true }}
|
||||
- watch_any:
|
||||
- cmd: F
|
||||
- cmd: G
|
||||
@ -28,12 +35,12 @@ E:
|
||||
|
||||
F:
|
||||
cmd.run:
|
||||
- name: 'true'
|
||||
- name: {{ cmd_true }}
|
||||
|
||||
G:
|
||||
cmd.run:
|
||||
- name: 'false'
|
||||
- name: {{ cmd_false }}
|
||||
|
||||
H:
|
||||
cmd.run:
|
||||
- name: 'false'
|
||||
- name: {{ cmd_false }}
|
||||
|
@ -1,4 +1,4 @@
|
||||
test_file:
|
||||
file.managed:
|
||||
- name: /tmp/nonbase_env
|
||||
- name: {{ salt['runtests_helpers.get_salt_temp_dir_for_path']('nonbase_env') }}
|
||||
- source: salt://nonbase_env
|
||||
|
@ -764,52 +764,58 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
|
||||
Ensure that some of them are failing and that the order is right.
|
||||
'''
|
||||
if salt.utils.platform.is_windows():
|
||||
cmd_true = 'exit'
|
||||
cmd_false = 'exit /B 1'
|
||||
else:
|
||||
cmd_true = 'true'
|
||||
cmd_false = 'false'
|
||||
expected_result = {
|
||||
'cmd_|-A_|-true_|-wait': {
|
||||
'cmd_|-A_|-{0}_|-wait'.format(cmd_true): {
|
||||
'__run_num__': 4,
|
||||
'comment': 'Command "true" run',
|
||||
'comment': 'Command "{0}" run'.format(cmd_true),
|
||||
'result': True,
|
||||
'changes': True,
|
||||
},
|
||||
'cmd_|-B_|-true_|-run': {
|
||||
'cmd_|-B_|-{0}_|-run'.format(cmd_true): {
|
||||
'__run_num__': 0,
|
||||
'comment': 'Command "true" run',
|
||||
'comment': 'Command "{0}" run'.format(cmd_true),
|
||||
'result': True,
|
||||
'changes': True,
|
||||
},
|
||||
'cmd_|-C_|-false_|-run': {
|
||||
'cmd_|-C_|-{0}_|-run'.format(cmd_false): {
|
||||
'__run_num__': 1,
|
||||
'comment': 'Command "false" run',
|
||||
'comment': 'Command "{0}" run'.format(cmd_false),
|
||||
'result': False,
|
||||
'changes': True,
|
||||
},
|
||||
'cmd_|-D_|-true_|-run': {
|
||||
'cmd_|-D_|-{0}_|-run'.format(cmd_true): {
|
||||
'__run_num__': 2,
|
||||
'comment': 'Command "true" run',
|
||||
'comment': 'Command "{0}" run'.format(cmd_true),
|
||||
'result': True,
|
||||
'changes': True,
|
||||
},
|
||||
'cmd_|-E_|-true_|-wait': {
|
||||
'cmd_|-E_|-{0}_|-wait'.format(cmd_true): {
|
||||
'__run_num__': 9,
|
||||
'comment': 'Command "true" run',
|
||||
'comment': 'Command "{0}" run'.format(cmd_true),
|
||||
'result': True,
|
||||
'changes': True,
|
||||
},
|
||||
'cmd_|-F_|-true_|-run': {
|
||||
'cmd_|-F_|-{0}_|-run'.format(cmd_true): {
|
||||
'__run_num__': 5,
|
||||
'comment': 'Command "true" run',
|
||||
'comment': 'Command "{0}" run'.format(cmd_true),
|
||||
'result': True,
|
||||
'changes': True,
|
||||
},
|
||||
'cmd_|-G_|-false_|-run': {
|
||||
'cmd_|-G_|-{0}_|-run'.format(cmd_false): {
|
||||
'__run_num__': 6,
|
||||
'comment': 'Command "false" run',
|
||||
'comment': 'Command "{0}" run'.format(cmd_false),
|
||||
'result': False,
|
||||
'changes': True,
|
||||
},
|
||||
'cmd_|-H_|-false_|-run': {
|
||||
'cmd_|-H_|-{0}_|-run'.format(cmd_false): {
|
||||
'__run_num__': 7,
|
||||
'comment': 'Command "false" run',
|
||||
'comment': 'Command "{0}" run'.format(cmd_false),
|
||||
'result': False,
|
||||
'changes': True,
|
||||
},
|
||||
@ -1632,15 +1638,18 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
test state.sls with saltenv using a nonbase environment
|
||||
with a salt source
|
||||
'''
|
||||
file_name = os.path.join(TMP, 'nonbase_env')
|
||||
state_run = self.run_function(
|
||||
'state.sls',
|
||||
mods='non-base-env',
|
||||
saltenv='prod'
|
||||
)
|
||||
state_id = 'file_|-test_file_|-/tmp/nonbase_env_|-managed'
|
||||
self.assertEqual(state_run[state_id]['comment'], 'File /tmp/nonbase_env updated')
|
||||
self.assertTrue(state_run['file_|-test_file_|-/tmp/nonbase_env_|-managed']['result'])
|
||||
self.assertTrue(os.path.isfile('/tmp/nonbase_env'))
|
||||
state_id = 'file_|-test_file_|-{0}_|-managed'.format(file_name)
|
||||
self.assertEqual(state_run[state_id]['comment'],
|
||||
'File {0} updated'.format(file_name))
|
||||
self.assertTrue(
|
||||
state_run['file_|-test_file_|-{0}_|-managed'.format(file_name)]['result'])
|
||||
self.assertTrue(os.path.isfile(file_name))
|
||||
|
||||
def _add_runtime_pillar(self, pillar):
|
||||
'''
|
||||
@ -1680,25 +1689,32 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
test state.sls_id when test is set to
|
||||
true post the state already being run previously
|
||||
'''
|
||||
file_name = os.path.join(TMP, 'testfile')
|
||||
ret = self.run_function('state.sls', ['core'])
|
||||
for key, val in ret.items():
|
||||
self.assertEqual(val['comment'], 'File /tmp/salt-tests-tmpdir/testfile updated')
|
||||
self.assertEqual(val['comment'],
|
||||
'File {0} updated'.format(file_name))
|
||||
self.assertEqual(val['changes']['diff'], 'New file')
|
||||
|
||||
self._add_runtime_pillar(pillar={'test': True})
|
||||
ret = self.run_function('state.sls', ['core'])
|
||||
|
||||
for key, val in ret.items():
|
||||
self.assertEqual(val['comment'], 'The file /tmp/salt-tests-tmpdir/testfile is in the correct state')
|
||||
self.assertEqual(
|
||||
val['comment'],
|
||||
'The file {0} is in the correct state'.format(file_name))
|
||||
self.assertEqual(val['changes'], {})
|
||||
|
||||
def test_state_sls_id_test_true(self):
|
||||
'''
|
||||
test state.sls_id when test=True is passed as arg
|
||||
'''
|
||||
file_name = os.path.join(TMP, 'testfile')
|
||||
ret = self.run_function('state.sls', ['core'], test=True)
|
||||
for key, val in ret.items():
|
||||
self.assertEqual(val['comment'], 'The file /tmp/salt-tests-tmpdir/testfile is set to be changed')
|
||||
self.assertEqual(
|
||||
val['comment'],
|
||||
'The file {0} is set to be changed'.format(file_name))
|
||||
self.assertEqual(val['changes'], {})
|
||||
|
||||
def test_state_sls_id_test_true_post_run(self):
|
||||
@ -1706,15 +1722,19 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
test state.sls_id when test is set to true as an
|
||||
arg post the state already being run previously
|
||||
'''
|
||||
file_name = os.path.join(TMP, 'testfile')
|
||||
ret = self.run_function('state.sls', ['core'])
|
||||
for key, val in ret.items():
|
||||
self.assertEqual(val['comment'], 'File /tmp/salt-tests-tmpdir/testfile updated')
|
||||
self.assertEqual(val['comment'],
|
||||
'File {0} updated'.format(file_name))
|
||||
self.assertEqual(val['changes']['diff'], 'New file')
|
||||
|
||||
ret = self.run_function('state.sls', ['core'], test=True)
|
||||
|
||||
for key, val in ret.items():
|
||||
self.assertEqual(val['comment'], 'The file /tmp/salt-tests-tmpdir/testfile is in the correct state')
|
||||
self.assertEqual(
|
||||
val['comment'],
|
||||
'The file {0} is in the correct state'.format(file_name))
|
||||
self.assertEqual(val['changes'], {})
|
||||
|
||||
def test_state_sls_id_test_false_pillar_true(self):
|
||||
@ -1723,11 +1743,13 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
arg and minion_state_test is set to True. Should
|
||||
return test=False.
|
||||
'''
|
||||
file_name = os.path.join(TMP, 'testfile')
|
||||
self._add_runtime_pillar(pillar={'test': True})
|
||||
ret = self.run_function('state.sls', ['core'], test=False)
|
||||
|
||||
for key, val in ret.items():
|
||||
self.assertEqual(val['comment'], 'File /tmp/salt-tests-tmpdir/testfile updated')
|
||||
self.assertEqual(val['comment'],
|
||||
'File {0} updated'.format(file_name))
|
||||
self.assertEqual(val['changes']['diff'], 'New file')
|
||||
|
||||
def tearDown(self):
|
||||
|
Loading…
Reference in New Issue
Block a user