def process_sls_data(data, context=None, extract=False): sls_dir = ospath.dirname(sls.replace('.', ospath.sep)) ctx = dict(sls_dir=sls_dir if sls_dir else '.') if context: ctx.update(context) tmplout = render_template( StringIO(data), env, sls, context=ctx, argline=rt_argline.strip(), **kws ) high = render_data(tmplout, env, sls, argline=rd_argline.strip()) # make a copy so that the original, un-preprocessed highstate data # structure can be used later for error checking if anything goes # wrong during the preprocessing. data = copy.deepcopy(high) try: rewrite_single_shorthand_state_decl(data) rewrite_sls_includes_excludes(data, sls) if not extract and implicit_require: sid = has_names_decls(data) if sid: raise SaltRenderError( '\'names\' declaration(found in state id: {0}) is ' 'not supported with implicitly ordered states! You ' 'should generate the states in a template for-loop ' 'instead.'.format(sid) ) add_implicit_requires(data) if not extract and not no_goal_state: add_goal_state(data) rename_state_ids(data, sls) if extract: extract_state_confs(data) except Exception, err: if isinstance(err, SaltRenderError): raise log.exception( 'Error found while pre-processing the salt file, ' '{0}.\n'.format(sls) ) from salt.state import State state = State(__opts__) errors = state.verify_high(high) if errors: raise SaltRenderError('\n'.join(errors)) raise SaltRenderError('sls preprocessing/rendering failed!')
def process_sls_data(data, context=None, extract=False): sls_dir = ospath.dirname(sls.replace('.', ospath.sep)) ctx = dict(sls_dir=sls_dir if sls_dir else '.') if context: ctx.update(context) tmplout = render_template(StringIO(data), env, sls, context=ctx, argline=rt_argline.strip(), **kws) high = render_data(tmplout, env, sls, argline=rd_argline.strip()) # make a copy so that the original, un-preprocessed highstate data # structure can be used later for error checking if anything goes # wrong during the preprocessing. data = copy.deepcopy(high) try: rewrite_single_shorthand_state_decl(data) rewrite_sls_includes_excludes(data, sls) if not extract and implicit_require: sid = has_names_decls(data) if sid: raise SaltRenderError( '\'names\' declaration(found in state id: {0}) is ' 'not supported with implicitly ordered states! You ' 'should generate the states in a template for-loop ' 'instead.'.format(sid)) add_implicit_requires(data) if not extract and not no_goal_state: add_goal_state(data) rename_state_ids(data, sls) if extract: extract_state_confs(data) except Exception, err: if isinstance(err, SaltRenderError): raise log.exception('Error found while pre-processing the salt file, ' '{0}.\n'.format(sls)) from salt.state import State state = State(__opts__) errors = state.verify_high(high) if errors: raise SaltRenderError('\n'.join(errors)) raise SaltRenderError('sls preprocessing/rendering failed!')
def process_high_data(high, extract): # make a copy so that the original, un-preprocessed highstate data # structure can be used later for error checking if anything goes # wrong during the preprocessing. data = copy.deepcopy(high) try: rewrite_single_shorthand_state_decl(data) rewrite_sls_includes_excludes(data, sls, saltenv) if not extract and implicit_require: sid = has_names_decls(data) if sid: raise SaltRenderError( '\'names\' declaration(found in state id: {0}) is ' 'not supported with implicitly ordered states! You ' 'should generate the states in a template for-loop ' 'instead.'.format(sid) ) add_implicit_requires(data) if gen_start_state: add_start_state(data, sls) if not extract and not no_goal_state: add_goal_state(data) rename_state_ids(data, sls) # We must extract no matter what so extending a stateconf sls file # works! extract_state_confs(data) except SaltRenderError: raise except Exception as err: log.exception( 'Error found while pre-processing the salt file ' '{0}:\n{1}'.format(sls, err) ) from salt.state import State state = State(__opts__) errors = state.verify_high(high) if errors: raise SaltRenderError('\n'.join(errors)) raise SaltRenderError('sls preprocessing/rendering failed!') return data
def process_high_data(high, extract): # make a copy so that the original, un-preprocessed highstate data # structure can be used later for error checking if anything goes # wrong during the preprocessing. data = copy.deepcopy(high) try: rewrite_single_shorthand_state_decl(data) rewrite_sls_includes_excludes(data, sls, saltenv) if not extract and implicit_require: sid = has_names_decls(data) if sid: raise SaltRenderError( "'names' declaration(found in state id: {0}) is " "not supported with implicitly ordered states! You " "should generate the states in a template for-loop " "instead.".format(sid) ) add_implicit_requires(data) if gen_start_state: add_start_state(data, sls) if not extract and not no_goal_state: add_goal_state(data) rename_state_ids(data, sls) # We must extract no matter what so extending a stateconf sls file # works! extract_state_confs(data) except SaltRenderError: raise except Exception as err: # pylint: disable=broad-except log.exception( "Error found while pre-processing the salt file %s:\n%s", sls, err ) from salt.state import State state = State(__opts__) errors = state.verify_high(high) if errors: raise SaltRenderError("\n".join(errors)) raise SaltRenderError("sls preprocessing/rendering failed!") return data
def process_high_data(high, extract): # make a copy so that the original, un-preprocessed highstate data # structure can be used later for error checking if anything goes # wrong during the preprocessing. data = copy.deepcopy(high) try: rewrite_single_shorthand_state_decl(data) rewrite_sls_includes_excludes(data, sls, env) if not extract and implicit_require: sid = has_names_decls(data) if sid: raise SaltRenderError( '\'names\' declaration(found in state id: {0}) is ' 'not supported with implicitly ordered states! You ' 'should generate the states in a template for-loop ' 'instead.'.format(sid)) add_implicit_requires(data) if gen_start_state: add_start_state(data, sls) if not extract and not no_goal_state: add_goal_state(data) rename_state_ids(data, sls) if extract: extract_state_confs(data) except Exception, err: raise if isinstance(err, SaltRenderError): raise log.exception('Error found while pre-processing the salt file, ' '{0}.\n'.format(sls)) from salt.state import State state = State(__opts__) errors = state.verify_high(high) if errors: raise SaltRenderError('\n'.join(errors)) raise SaltRenderError('sls preprocessing/rendering failed!')
import salt.loader import salt.config from salt.state import State REQUISITES = ['require', 'require_in', 'use', 'use_in', 'watch', 'watch_in'] OPTS = salt.config.master_config('whatever, just load the defaults!') # we should have used minion_config(), but that would try to resolve # the master hostname, and retry for 30 seconds! Lucily for our purpose, # master conf or minion conf, it doesn't matter. OPTS['id'] = 'whatever' OPTS['file_client'] = 'local' OPTS['file_roots'] = dict(base=['/']) OPTS['test'] = False OPTS['grains'] = salt.loader.grains(OPTS) STATE = State(OPTS) def render_sls(content, sls='', env='base', **kws): return STATE.rend['pydsl'](StringIO(content), env=env, sls=sls, **kws) class PyDSLRendererTestCase(TestCase): def setUp(self): STATE.load_modules() sys.modules['salt.loaded.int.render.pydsl'].__salt__ = STATE.functions self.PyDslError = sys.modules[ 'salt.loaded.int.module.pydsl'].PyDslError def test_state_declarations(self): result = render_sls('''