def state_highstate(matches, dirpath): OPTS['file_roots'] = dict(base=[dirpath]) HIGHSTATE = HighState(OPTS) HIGHSTATE.push_active() try: high, errors = HIGHSTATE.render_highstate({'base': ['aaa']}) if errors: import pprint pprint.pprint('\n'.join(errors)) pprint.pprint(high) out = HIGHSTATE.state.call_high(high) # pprint.pprint(out) finally: HIGHSTATE.pop_active()
def state_highstate(state, dirpath): OPTS['file_roots'] = dict(base=[dirpath]) HIGHSTATE = HighState(OPTS) HIGHSTATE.push_active() try: high, errors = HIGHSTATE.render_highstate(state) if errors: import pprint pprint.pprint('\n'.join(errors)) pprint.pprint(high) out = HIGHSTATE.state.call_high(high) # pprint.pprint(out) finally: HIGHSTATE.pop_active()
def state_highstate(matches, dirpath): OPTS["file_roots"] = dict(base=[dirpath]) HIGHSTATE = HighState(OPTS) HIGHSTATE.push_active() try: high, errors = HIGHSTATE.render_highstate({"base": ["aaa"]}) if errors: import pprint pprint.pprint("\n".join(errors)) pprint.pprint(high) out = HIGHSTATE.state.call_high(high) # pprint.pprint(out) finally: HIGHSTATE.pop_active()
def state_highstate(self, state, dirpath): opts = copy.copy(self.config) opts['file_roots'] = dict(base=[dirpath]) HIGHSTATE = HighState(opts) HIGHSTATE.push_active() try: high, errors = HIGHSTATE.render_highstate(state) if errors: import pprint pprint.pprint('\n'.join(errors)) pprint.pprint(high) out = HIGHSTATE.state.call_high(high) # pprint.pprint(out) finally: HIGHSTATE.pop_active()
def state_highstate(self, state, dirpath): opts = copy.copy(self.config) opts["file_roots"] = dict(base=[dirpath]) HIGHSTATE = HighState(opts) HIGHSTATE.push_active() try: high, errors = HIGHSTATE.render_highstate(state) if errors: import pprint pprint.pprint("\n".join(errors)) pprint.pprint(high) out = HIGHSTATE.state.call_high(high) # pprint.pprint(out) finally: HIGHSTATE.pop_active()
def test_pipe_through_stateconf(self): if sys.version_info < (2, 7) and not HAS_ORDERED_DICT: self.skipTest('OrderedDict is not available') dirpath = tempfile.mkdtemp() output = os.path.join(dirpath, 'output') try: xxx = os.path.join(dirpath, 'xxx.sls') with open(xxx, 'w') as xxx: xxx.write('''#!stateconf -os yaml . jinja .X: cmd.run: - name: echo X >> {0} - cwd: / .Y: cmd.run: - name: echo Y >> {1} - cwd: / .Z: cmd.run: - name: echo Z >> {2} - cwd: / '''.format(output, output, output)) yyy = os.path.join(dirpath, 'yyy.sls') with open(yyy, 'w') as yyy: yyy.write('''#!pydsl|stateconf -ps state('.D').cmd.run('echo D >> {0}', cwd='/') state('.E').cmd.run('echo E >> {1}', cwd='/') state('.F').cmd.run('echo F >> {2}', cwd='/') '''.format(output, output, output)) aaa = os.path.join(dirpath, 'aaa.sls') with open(aaa, 'w') as aaa: aaa.write('''#!pydsl|stateconf -ps include('xxx', 'yyy') # make all states in yyy run BEFORE states in this sls. extend(state('.start').stateconf.require(stateconf='xxx::goal')) # make all states in xxx run AFTER this sls. extend(state('.goal').stateconf.require_in(stateconf='yyy::start')) __pydsl__.set(ordered=True) state('.A').cmd.run('echo A >> {0}', cwd='/') state('.B').cmd.run('echo B >> {1}', cwd='/') state('.C').cmd.run('echo C >> {2}', cwd='/') '''.format(output, output, output)) OPTS['file_roots'] = dict(base=[dirpath]) HIGHSTATE = HighState(OPTS) HIGHSTATE.state.load_modules() sys.modules['salt.loaded.int.render.pydsl'].__salt__ = HIGHSTATE.state.functions high, errors = HIGHSTATE.render_highstate({'base': ['aaa']}) # import pprint # pprint.pprint(errors) # pprint.pprint(high) out = HIGHSTATE.state.call_high(high) # pprint.pprint(out) with open(output, 'r') as f: self.assertEqual(''.join(f.read().split()), "XYZABCDEF") finally: shutil.rmtree(dirpath, ignore_errors=True)