mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #20018 from cachedout/pydsl_separate
Split a test out into its own class to keep it from colliding
This commit is contained in:
commit
a8544afa1c
@ -35,6 +35,11 @@ OPTS['grains'] = salt.loader.grains(OPTS)
|
||||
|
||||
|
||||
class PyDSLRendererTestCase(TestCase):
|
||||
'''
|
||||
WARNING: If tests in here are flaky, they may need
|
||||
to be moved to their own class. Sharing HighState, especially
|
||||
through setUp/tearDown can create dangerous race conditions!
|
||||
'''
|
||||
|
||||
def setUp(self):
|
||||
self.HIGHSTATE = HighState(OPTS)
|
||||
@ -298,6 +303,110 @@ class PyDSLRendererTestCase(TestCase):
|
||||
finally:
|
||||
shutil.rmtree(dirpath, ignore_errors=True)
|
||||
|
||||
def test_compile_time_state_execution(self):
|
||||
if not sys.stdin.isatty():
|
||||
self.skipTest('Not attached to a TTY')
|
||||
dirpath = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
|
||||
if not os.path.isdir(dirpath):
|
||||
self.skipTest(
|
||||
'The temporary directory {0!r} was not created'.format(
|
||||
dirpath
|
||||
)
|
||||
)
|
||||
try:
|
||||
write_to(os.path.join(dirpath, 'aaa.sls'), textwrap.dedent('''\
|
||||
#!pydsl
|
||||
|
||||
__pydsl__.set(ordered=True)
|
||||
A = state('A')
|
||||
A.cmd.run('echo hehe > {0}/zzz.txt', cwd='/')
|
||||
A.file.managed('{1}/yyy.txt', source='salt://zzz.txt')
|
||||
A()
|
||||
A()
|
||||
|
||||
state().cmd.run('echo hoho >> {2}/yyy.txt', cwd='/')
|
||||
|
||||
A.file.managed('{3}/xxx.txt', source='salt://zzz.txt')
|
||||
A()
|
||||
'''.format(dirpath, dirpath, dirpath, dirpath)))
|
||||
state_highstate({'base': ['aaa']}, dirpath)
|
||||
with salt.utils.fopen(os.path.join(dirpath, 'yyy.txt'), 'r') as f:
|
||||
|
||||
self.assertEqual(f.read(), 'hehe\nhoho\n')
|
||||
with salt.utils.fopen(os.path.join(dirpath, 'xxx.txt'), 'r') as f:
|
||||
self.assertEqual(f.read(), 'hehe\n')
|
||||
finally:
|
||||
shutil.rmtree(dirpath, ignore_errors=True)
|
||||
|
||||
def test_nested_high_state_execution(self):
|
||||
dirpath = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
|
||||
if not os.path.isdir(dirpath):
|
||||
self.skipTest(
|
||||
'The temporary directory {0!r} was not created'.format(
|
||||
dirpath
|
||||
)
|
||||
)
|
||||
output = os.path.join(dirpath, 'output')
|
||||
try:
|
||||
write_to(os.path.join(dirpath, 'aaa.sls'), textwrap.dedent('''\
|
||||
#!pydsl
|
||||
__salt__['state.sls']('bbb')
|
||||
state().cmd.run('echo bbbbbb', cwd='/')
|
||||
'''))
|
||||
write_to(os.path.join(dirpath, 'bbb.sls'), textwrap.dedent(
|
||||
'''
|
||||
# {{ salt['state.sls']('ccc') }}
|
||||
test:
|
||||
cmd.run:
|
||||
- name: echo bbbbbbb
|
||||
- cwd: /
|
||||
'''))
|
||||
write_to(os.path.join(dirpath, 'ccc.sls'), textwrap.dedent(
|
||||
'''
|
||||
#!pydsl
|
||||
state().cmd.run('echo ccccc', cwd='/')
|
||||
'''))
|
||||
state_highstate({'base': ['aaa']}, dirpath)
|
||||
finally:
|
||||
shutil.rmtree(dirpath, ignore_errors=True)
|
||||
|
||||
def test_repeat_includes(self):
|
||||
dirpath = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
|
||||
if not os.path.isdir(dirpath):
|
||||
self.skipTest(
|
||||
'The temporary directory {0!r} was not created'.format(
|
||||
dirpath
|
||||
)
|
||||
)
|
||||
output = os.path.join(dirpath, 'output')
|
||||
try:
|
||||
write_to(os.path.join(dirpath, 'b.sls'), textwrap.dedent('''\
|
||||
#!pydsl
|
||||
include('c')
|
||||
include('d')
|
||||
'''))
|
||||
write_to(os.path.join(dirpath, 'c.sls'), textwrap.dedent('''\
|
||||
#!pydsl
|
||||
modtest = include('e')
|
||||
modtest.success
|
||||
'''))
|
||||
write_to(os.path.join(dirpath, 'd.sls'), textwrap.dedent('''\
|
||||
#!pydsl
|
||||
modtest = include('e')
|
||||
modtest.success
|
||||
'''))
|
||||
write_to(os.path.join(dirpath, 'e.sls'), textwrap.dedent('''\
|
||||
#!pydsl
|
||||
success = True
|
||||
'''))
|
||||
state_highstate({'base': ['b']}, dirpath)
|
||||
state_highstate({'base': ['c', 'd']}, dirpath)
|
||||
finally:
|
||||
shutil.rmtree(dirpath, ignore_errors=True)
|
||||
|
||||
|
||||
class PyDSLRendererIncludeTestCase(TestCase):
|
||||
|
||||
def test_rendering_includes(self):
|
||||
dirpath = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
|
||||
if not os.path.isdir(dirpath):
|
||||
@ -391,107 +500,6 @@ class PyDSLRendererTestCase(TestCase):
|
||||
finally:
|
||||
shutil.rmtree(dirpath, ignore_errors=True)
|
||||
|
||||
def test_compile_time_state_execution(self):
|
||||
if not sys.stdin.isatty():
|
||||
self.skipTest('Not attached to a TTY')
|
||||
dirpath = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
|
||||
if not os.path.isdir(dirpath):
|
||||
self.skipTest(
|
||||
'The temporary directory {0!r} was not created'.format(
|
||||
dirpath
|
||||
)
|
||||
)
|
||||
try:
|
||||
write_to(os.path.join(dirpath, 'aaa.sls'), textwrap.dedent('''\
|
||||
#!pydsl
|
||||
|
||||
__pydsl__.set(ordered=True)
|
||||
A = state('A')
|
||||
A.cmd.run('echo hehe > {0}/zzz.txt', cwd='/')
|
||||
A.file.managed('{1}/yyy.txt', source='salt://zzz.txt')
|
||||
A()
|
||||
A()
|
||||
|
||||
state().cmd.run('echo hoho >> {2}/yyy.txt', cwd='/')
|
||||
|
||||
A.file.managed('{3}/xxx.txt', source='salt://zzz.txt')
|
||||
A()
|
||||
'''.format(dirpath, dirpath, dirpath, dirpath)))
|
||||
state_highstate({'base': ['aaa']}, dirpath)
|
||||
with salt.utils.fopen(os.path.join(dirpath, 'yyy.txt'), 'r') as f:
|
||||
|
||||
self.assertEqual(f.read(), 'hehe\nhoho\n')
|
||||
with salt.utils.fopen(os.path.join(dirpath, 'xxx.txt'), 'r') as f:
|
||||
self.assertEqual(f.read(), 'hehe\n')
|
||||
finally:
|
||||
shutil.rmtree(dirpath, ignore_errors=True)
|
||||
|
||||
def test_nested_high_state_execution(self):
|
||||
dirpath = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
|
||||
if not os.path.isdir(dirpath):
|
||||
self.skipTest(
|
||||
'The temporary directory {0!r} was not created'.format(
|
||||
dirpath
|
||||
)
|
||||
)
|
||||
output = os.path.join(dirpath, 'output')
|
||||
try:
|
||||
write_to(os.path.join(dirpath, 'aaa.sls'), textwrap.dedent('''\
|
||||
#!pydsl
|
||||
__salt__['state.sls']('bbb')
|
||||
state().cmd.run('echo bbbbbb', cwd='/')
|
||||
'''))
|
||||
write_to(os.path.join(dirpath, 'bbb.sls'), textwrap.dedent(
|
||||
'''
|
||||
# {{ salt['state.sls']('ccc')
|
||||
test:
|
||||
cmd.run:
|
||||
- name: echo bbbbbbb
|
||||
- cwd: /
|
||||
'''))
|
||||
write_to(os.path.join(dirpath, 'ccc.sls'), textwrap.dedent(
|
||||
'''
|
||||
#!pydsl
|
||||
state().cmd.run('echo ccccc', cwd='/')
|
||||
'''))
|
||||
state_highstate({'base': ['aaa']}, dirpath)
|
||||
finally:
|
||||
shutil.rmtree(dirpath, ignore_errors=True)
|
||||
|
||||
def test_repeat_includes(self):
|
||||
dirpath = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR)
|
||||
if not os.path.isdir(dirpath):
|
||||
self.skipTest(
|
||||
'The temporary directory {0!r} was not created'.format(
|
||||
dirpath
|
||||
)
|
||||
)
|
||||
output = os.path.join(dirpath, 'output')
|
||||
try:
|
||||
write_to(os.path.join(dirpath, 'b.sls'), textwrap.dedent('''\
|
||||
#!pydsl
|
||||
include('c')
|
||||
include('d')
|
||||
'''))
|
||||
write_to(os.path.join(dirpath, 'c.sls'), textwrap.dedent('''\
|
||||
#!pydsl
|
||||
modtest = include('e')
|
||||
modtest.success
|
||||
'''))
|
||||
write_to(os.path.join(dirpath, 'd.sls'), textwrap.dedent('''\
|
||||
#!pydsl
|
||||
modtest = include('e')
|
||||
modtest.success
|
||||
'''))
|
||||
write_to(os.path.join(dirpath, 'e.sls'), textwrap.dedent('''\
|
||||
#!pydsl
|
||||
success = True
|
||||
'''))
|
||||
state_highstate({'base': ['b']}, dirpath)
|
||||
state_highstate({'base': ['c', 'd']}, dirpath)
|
||||
finally:
|
||||
shutil.rmtree(dirpath, ignore_errors=True)
|
||||
|
||||
|
||||
def write_to(fpath, content):
|
||||
with salt.utils.fopen(fpath, 'w') as f:
|
||||
|
Loading…
Reference in New Issue
Block a user