Merge pull request #29170 from cachedout/refactor_pydsl_test

Migrate pydsl tests to integration test suite
This commit is contained in:
Mike Place 2015-11-25 12:56:48 -07:00
commit 1937a47dec
8 changed files with 113 additions and 99 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 @@
# -*- coding: utf-8 -*-

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

@ -121,6 +121,14 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
action='store_true',
help='Run salt/runners/*.py tests'
)
self.test_selection_group.add_option(
'-R',
'--renderers',
dest='renderers',
default=False,
action='store_true',
help='Run salt/renderers/*.py tests'
)
self.test_selection_group.add_option(
'-l',
'--loader',
@ -203,6 +211,7 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
self.options.unit,
self.options.state,
self.options.runners,
self.options.renderers,
self.options.loader,
self.options.name,
self.options.outputter,
@ -223,13 +232,15 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
self.options.shell, self.options.unit, self.options.state,
self.options.runners, self.options.loader, self.options.name,
self.options.outputter, self.options.cloud_provider_tests,
self.options.fileserver, self.options.wheel, self.options.api)):
self.options.fileserver, self.options.wheel, self.options.api,
self.options.renderers)):
self.options.module = True
self.options.cli = True
self.options.client = True
self.options.shell = True
self.options.unit = True
self.options.runners = True
self.options.renderers = True
self.options.state = True
self.options.loader = True
self.options.outputter = True
@ -348,6 +359,7 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
if (self.options.unit or named_unit_test) and not \
(self.options.runners or
self.options.renderers or
self.options.state or
self.options.module or
self.options.cli or
@ -379,7 +391,7 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
if not any([self.options.cli, self.options.client, self.options.module,
self.options.runners, self.options.shell, self.options.state,
self.options.loader, self.options.outputter, self.options.name,
self.options.cloud_provider_tests, self.options.api,
self.options.cloud_provider_tests, self.options.api, self.options.renderers,
self.options.fileserver, self.options.wheel]):
return status
@ -414,6 +426,8 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
status.append(self.run_integration_suite('cloud/providers', 'Cloud Provider'))
if self.options.api:
status.append(self.run_integration_suite('netapi', 'NetAPI'))
if self.options.renderers:
status.append(self.run_integration_suite('renderers', 'Renderers'))
return status
def run_unit_tests(self):

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)