Migrate pydsl tests to integration test suite

This marks the beginning of a migration of the pydsl renderer tests
to the integration test suite and away from the unit test suite.

The unit test approach is becoming too difficult to maintain due to its complex approach to trying to internally manage a highstate run instead of calling into the salt state system to fully manage it.
This commit is contained in:
Mike Place 2015-11-24 15:46:14 -07:00
parent 68d6c454b8
commit 81bf332be4
6 changed files with 96 additions and 97 deletions

View file

@ -17,6 +17,9 @@ SYS_TMP_DIR = tempfile.gettempdir()
TMP = os.path.join(SYS_TMP_DIR, 'salt-tests-tmpdir')
def get_salt_temp_dir():
return TMP
def get_salt_temp_dir_for_path(*path):
return os.path.join(TMP, *path)

View file

@ -0,0 +1,11 @@
#!pydsl|stateconf -ps
include('pydsl.xxx')
yyy = include('pydsl.yyy')
# ensure states in xxx are run first, then those in yyy and then those in aaa last.
extend(state('pydsl.yyy::start').stateconf.require(stateconf='pydsl.xxx::goal'))
extend(state('.start').stateconf.require(stateconf='pydsl.yyy::goal'))
extend(state('pydsl.yyy::Y2').cmd.run('echo Y2 extended >> {0}'.format('/tmp/output')))
__pydsl__.set(ordered=True)
yyy.hello('red', 1)
yyy.hello('green', 2)
yyy.hello('blue', 3)

View file

@ -0,0 +1,23 @@
#!stateconf -os yaml . jinja
include:
- pydsl.yyy
extend:
pydsl.yyy::start:
stateconf.set:
- require:
- stateconf: .goal
pydsl.yyy::Y1:
cmd.run:
- name: 'echo Y1 extended >> /tmp/output'
.X1:
cmd.run:
- name: echo X1 >> /tmp/output
- cwd: /
.X2:
cmd.run:
- name: echo X2 >> /tmp/output
- cwd: /
.X3:
cmd.run:
- name: echo X3 >> /tmp/output
- cwd: /

View file

@ -0,0 +1,8 @@
#!pydsl|stateconf -ps
include('pydsl.xxx')
__pydsl__.set(ordered=True)
state('.Y1').cmd.run('echo Y1 >> {0}'.format('/tmp/output'), cwd='/')
state('.Y2').cmd.run('echo Y2 >> {0}'.format('/tmp/output'), cwd='/')
state('.Y3').cmd.run('echo Y3 >> {0}'.format('/tmp/output'), cwd='/')
def hello(color, number):
state(color).cmd.run('echo hello '+color+' '+str(number)+' >> {0}'.format('/tmp/output'), cwd='/')

View file

@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# Import Python libs
from __future__ import absolute_import
import os
import textwrap
# Import Salt Testing libs
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../')
# Import Salt libs
import integration
import salt.utils
class PyDSLRendererIncludeTestCase(integration.ModuleCase):
def test_rendering_includes(self):
'''
This test is currently hard-coded to /tmp to work-around a seeming
inability to load custom modules inside the pydsl renderers. This
is a FIXME.
'''
try:
self.run_function('state.sls', ['pydsl.aaa'])
expected = textwrap.dedent('''\
X1
X2
X3
Y1 extended
Y2 extended
Y3
hello red 1
hello green 2
hello blue 3
''')
with salt.utils.fopen('/tmp/output', 'r') as f:
self.assertEqual(sorted(f.read()), sorted(expected))
finally:
os.remove('/tmp/output')
if __name__ == '__main__':
from integration import run_tests
tests = [PyDSLRendererIncludeTestCase]
run_tests(*tests, needs_daemon=True)

View file

@ -445,102 +445,6 @@ class PyDSLRendererTestCase(CommonTestCaseBoilerplate):
shutil.rmtree(dirpath, ignore_errors=True)
class PyDSLRendererIncludeTestCase(CommonTestCaseBoilerplate):
def test_rendering_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, 'aaa.sls'), textwrap.dedent('''\
#!pydsl|stateconf -ps
include('xxx')
yyy = include('yyy')
# ensure states in xxx are run first, then those in yyy and then those in aaa last.
extend(state('yyy::start').stateconf.require(stateconf='xxx::goal'))
extend(state('.start').stateconf.require(stateconf='yyy::goal'))
extend(state('yyy::Y2').cmd.run('echo Y2 extended >> {0}'))
__pydsl__.set(ordered=True)
yyy.hello('red', 1)
yyy.hello('green', 2)
yyy.hello('blue', 3)
'''.format(output)))
write_to(os.path.join(dirpath, 'xxx.sls'), textwrap.dedent('''\
#!stateconf -os yaml . jinja
include:
- yyy
extend:
yyy::start:
stateconf.set:
- require:
- stateconf: .goal
yyy::Y1:
cmd.run:
- name: 'echo Y1 extended >> {0}'
.X1:
cmd.run:
- name: echo X1 >> {1}
- cwd: /
.X2:
cmd.run:
- name: echo X2 >> {2}
- cwd: /
.X3:
cmd.run:
- name: echo X3 >> {3}
- cwd: /
'''.format(output, output, output, output)))
write_to(os.path.join(dirpath, 'yyy.sls'), textwrap.dedent('''\
#!pydsl|stateconf -ps
include('xxx')
__pydsl__.set(ordered=True)
state('.Y1').cmd.run('echo Y1 >> {0}', cwd='/')
state('.Y2').cmd.run('echo Y2 >> {1}', cwd='/')
state('.Y3').cmd.run('echo Y3 >> {2}', cwd='/')
def hello(color, number):
state(color).cmd.run('echo hello '+color+' '+str(number)+' >> {3}', cwd='/')
'''.format(output, output, output, output)))
self.state_highstate({'base': ['aaa']}, dirpath)
expected = textwrap.dedent('''\
X1
X2
X3
Y1 extended
Y2 extended
Y3
hello red 1
hello green 2
hello blue 3
''')
with salt.utils.fopen(output, 'r') as f:
self.assertEqual(sorted(f.read()), sorted(expected))
finally:
shutil.rmtree(dirpath, ignore_errors=True)
def write_to(fpath, content):
with salt.utils.fopen(fpath, 'w') as f:
f.write(content)
@ -548,5 +452,5 @@ def write_to(fpath, content):
if __name__ == '__main__':
from integration import run_tests
tests = [PyDSLRendererTestCase, PyDSLRendererIncludeTestCase]
tests = [PyDSLRendererTestCase]
run_tests(*tests, needs_daemon=False)