Merge pull request #18638 from s0undt3ch/2014.7

Some 2014.7 test fixes
This commit is contained in:
Pedro Algarvio 2014-12-03 00:54:43 +00:00
commit 60b9d47be5
3 changed files with 101 additions and 52 deletions

View File

@ -1,5 +1,10 @@
# -*- coding: utf-8 -*-
# Import python libs
import os
import os.path
import tempfile
# Import Salt Testing libs
from salttesting import TestCase
from salttesting.helpers import ensure_in_syspath
@ -8,22 +13,33 @@ ensure_in_syspath('../')
ensure_in_syspath('../../')
# Import Salt libs
import integration
import salt.config
from salt.state import HighState
OPTS = salt.config.minion_config(None)
OPTS['id'] = 'match'
OPTS['file_client'] = 'local'
OPTS['file_roots'] = dict(base=['/tmp'])
OPTS['test'] = False
OPTS['grains'] = salt.loader.grains(OPTS)
OPTS['cachedir'] = 'cachedir'
class HighStateTestCase(TestCase):
def setUp(self):
self.highstate = HighState(OPTS)
self.root_dir = tempfile.mkdtemp(dir=integration.TMP)
self.state_tree_dir = os.path.join(self.root_dir, 'state_tree')
self.cache_dir = os.path.join(self.root_dir, 'cachedir')
if not os.path.isdir(self.root_dir):
os.makedirs(self.root_dir)
if not os.path.isdir(self.state_tree_dir):
os.makedirs(self.state_tree_dir)
if not os.path.isdir(self.cache_dir):
os.makedirs(self.cache_dir)
self.config = salt.config.minion_config(None)
self.config['root_dir'] = self.root_dir
self.config['state_events'] = False
self.config['id'] = 'match'
self.config['file_client'] = 'local'
self.config['file_roots'] = dict(base=[self.state_tree_dir])
self.config['cachedir'] = self.cache_dir
self.config['test'] = False
self.highstate = HighState(self.config)
self.highstate.push_active()
def tearDown(self):

View File

@ -10,9 +10,10 @@ from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../')
import integration
import salt.config
import salt.state
import salt.utils
from salt.config import minion_config
from salt.template import compile_template
from salt.utils.odict import OrderedDict
from salt.utils.pyobjects import (StateFactory, State, Registry,
@ -192,24 +193,32 @@ class RendererMixin(object):
def setUp(self, *args, **kwargs):
super(RendererMixin, self).setUp(*args, **kwargs)
self.root_dir = tempfile.mkdtemp('pyobjects_test_root')
self.root_dir = tempfile.mkdtemp('pyobjects_test_root', dir=integration.TMP)
self.state_tree_dir = os.path.join(self.root_dir, 'state_tree')
self.cache_dir = os.path.join(self.root_dir, 'cachedir')
if not os.path.isdir(self.root_dir):
os.makedirs(self.root_dir)
self.config = minion_config(None)
self.config.update({
'file_client': 'local',
'file_roots': {
'base': [self.root_dir]
},
'cachedir': 'cachedir'
})
if not os.path.isdir(self.state_tree_dir):
os.makedirs(self.state_tree_dir)
if not os.path.isdir(self.cache_dir):
os.makedirs(self.cache_dir)
self.config = salt.config.minion_config(None)
self.config['root_dir'] = self.root_dir
self.config['state_events'] = False
self.config['id'] = 'match'
self.config['file_client'] = 'local'
self.config['file_roots'] = dict(base=[self.state_tree_dir])
self.config['cachedir'] = self.cache_dir
self.config['test'] = False
def tearDown(self, *args, **kwargs):
shutil.rmtree(self.root_dir)
super(RendererMixin, self).tearDown(*args, **kwargs)
def write_template_file(self, filename, content):
full_path = os.path.join(self.root_dir, filename)
full_path = os.path.join(self.state_tree_dir, filename)
with salt.utils.fopen(full_path, 'w') as f:
f.write(content)
return full_path
@ -243,7 +252,6 @@ class RendererTests(RendererMixin, TestCase):
]
}),
]))
self.assertEqual(Registry.states, OrderedDict())
def test_invalid_function(self):

View File

@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
# Import Python libs
import os
import os.path
import tempfile
from cStringIO import StringIO
@ -13,32 +16,54 @@ ensure_in_syspath('../')
# Import Salt libs
import salt.loader
import salt.config
import integration
REQUISITES = ['require', 'require_in', 'use', 'use_in', 'watch', 'watch_in']
OPTS = salt.config.minion_config(None)
OPTS['file_client'] = 'local'
OPTS['file_roots'] = dict(base=['/'])
FUNCS = {}
FUNCS['config.get'] = lambda a, b: False
RENDERERS = salt.loader.render(OPTS, FUNCS)
def render_sls(content, sls='', saltenv='base', argline='-G yaml . jinja', **kws):
return RENDERERS['stateconf'](
StringIO(content), saltenv=saltenv, sls=sls,
argline=argline,
renderers=salt.loader.render(OPTS, {}),
**kws
)
class StateConfigRendererTestCase(TestCase):
def setUp(self):
self.root_dir = tempfile.mkdtemp(dir=integration.TMP)
self.state_tree_dir = os.path.join(self.root_dir, 'state_tree')
self.cache_dir = os.path.join(self.root_dir, 'cachedir')
if not os.path.isdir(self.root_dir):
os.makedirs(self.root_dir)
if not os.path.isdir(self.state_tree_dir):
os.makedirs(self.state_tree_dir)
if not os.path.isdir(self.cache_dir):
os.makedirs(self.cache_dir)
self.config = salt.config.minion_config(None)
self.config['root_dir'] = self.root_dir
self.config['state_events'] = False
self.config['id'] = 'match'
self.config['file_client'] = 'local'
self.config['file_roots'] = dict(base=[self.state_tree_dir])
self.config['cachedir'] = self.cache_dir
self.config['test'] = False
self._renderers = salt.loader.render(
self.config,
{'config.get': lambda a, b: False}
)
def _render_sls(self,
content,
sls='',
saltenv='base',
argline='-G yaml . jinja',
**kws):
return self._renderers['stateconf'](
StringIO(content), saltenv=saltenv, sls=sls,
argline=argline,
renderers=salt.loader.render(self.config, {}),
**kws
)
def test_state_config(self):
result = render_sls('''
result = self._render_sls('''
.sls_params:
stateconf.set:
- name1: value1
@ -63,7 +88,7 @@ test:
'echo name1=value1 name2=value2 value')
def test_sls_dir(self):
result = render_sls('''
result = self._render_sls('''
test:
cmd.run:
- name: echo sls_dir={{sls_dir}}
@ -73,7 +98,7 @@ test:
'echo sls_dir=path/to')
def test_states_declared_with_shorthand_no_args(self):
result = render_sls('''
result = self._render_sls('''
test:
cmd.run:
- name: echo testing
@ -91,7 +116,7 @@ test2:
self.assertEqual(result['test']['cmd.run'][0]['name'], 'echo testing')
def test_adding_state_name_arg_for_dot_state_id(self):
result = render_sls('''
result = self._render_sls('''
.test:
pkg.installed:
- cwd: /
@ -107,7 +132,7 @@ test2:
)
def test_state_prefix(self):
result = render_sls('''
result = self._render_sls('''
.test:
cmd.run:
- name: echo renamed
@ -125,7 +150,7 @@ state_id:
def test_dot_state_id_in_requisites(self):
for req in REQUISITES:
result = render_sls('''
result = self._render_sls('''
.test:
cmd.run:
- name: echo renamed
@ -148,7 +173,7 @@ state_id:
def test_relative_include_with_requisites(self):
for req in REQUISITES:
result = render_sls('''
result = self._render_sls('''
include:
- some.helper
- .utils
@ -167,7 +192,7 @@ state_id:
)
def test_relative_include_and_extend(self):
result = render_sls('''
result = self._render_sls('''
include:
- some.helper
- .utils
@ -180,7 +205,7 @@ extend:
self.assertTrue('test.utils::some_state' in result['extend'])
def test_start_state_generation(self):
result = render_sls('''
result = self._render_sls('''
A:
cmd.run:
- name: echo hello
@ -197,7 +222,7 @@ B:
)
def test_goal_state_generation(self):
result = render_sls('''
result = self._render_sls('''
{% for sid in "ABCDE": %}
{{sid}}:
cmd.run:
@ -214,7 +239,7 @@ B:
)
def test_implicit_require_with_goal_state(self):
result = render_sls('''
result = self._render_sls('''
{% for sid in "ABCDE": %}
{{sid}}:
cmd.run:
@ -269,7 +294,7 @@ G:
)
def test_slsdir(self):
result = render_sls('''
result = self._render_sls('''
formula/woot.sls:
cmd.run:
- name: echo {{ slspath }}