test_state.py 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. """
  2. :codeauthor: Nicole Thomas <nicole@saltstack.com>
  3. """
  4. import os
  5. import shutil
  6. import tempfile
  7. import salt.exceptions
  8. import salt.state
  9. import salt.utils.files
  10. import salt.utils.platform
  11. from salt.exceptions import CommandExecutionError
  12. from salt.utils.decorators import state as statedecorators
  13. from salt.utils.odict import OrderedDict
  14. from tests.support.helpers import slowTest, with_tempfile
  15. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  16. from tests.support.mock import MagicMock, patch
  17. from tests.support.runtests import RUNTIME_VARS
  18. from tests.support.unit import TestCase, skipIf
  19. try:
  20. import pytest
  21. except ImportError as err:
  22. pytest = None
  23. class StateCompilerTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
  24. """
  25. TestCase for the state compiler.
  26. """
  27. def test_format_log_non_ascii_character(self):
  28. """
  29. Tests running a non-ascii character through the state.format_log
  30. function. See Issue #33605.
  31. """
  32. # There is no return to test against as the format_log
  33. # function doesn't return anything. However, we do want
  34. # to make sure that the function doesn't stacktrace when
  35. # called.
  36. ret = {
  37. "changes": {"Français": {"old": "something old", "new": "something new"}},
  38. "result": True,
  39. }
  40. salt.state.format_log(ret)
  41. @slowTest
  42. def test_render_error_on_invalid_requisite(self):
  43. """
  44. Test that the state compiler correctly deliver a rendering
  45. exception when a requisite cannot be resolved
  46. """
  47. with patch("salt.state.State._gather_pillar") as state_patch:
  48. high_data = {
  49. "git": OrderedDict(
  50. [
  51. (
  52. "pkg",
  53. [
  54. OrderedDict(
  55. [
  56. (
  57. "require",
  58. [
  59. OrderedDict(
  60. [
  61. (
  62. "file",
  63. OrderedDict(
  64. [("test1", "test")]
  65. ),
  66. )
  67. ]
  68. )
  69. ],
  70. )
  71. ]
  72. ),
  73. "installed",
  74. {"order": 10000},
  75. ],
  76. ),
  77. ("__sls__", "issue_35226"),
  78. ("__env__", "base"),
  79. ]
  80. )
  81. }
  82. minion_opts = self.get_temp_config("minion")
  83. minion_opts["pillar"] = {"git": OrderedDict([("test1", "test")])}
  84. state_obj = salt.state.State(minion_opts)
  85. with self.assertRaises(salt.exceptions.SaltRenderError):
  86. state_obj.call_high(high_data)
  87. def test_verify_onlyif_parse(self):
  88. low_data = {
  89. "onlyif": [{"fun": "test.arg", "args": ["arg1", "arg2"]}],
  90. "name": "mysql-server-5.7",
  91. "state": "debconf",
  92. "__id__": "set root password",
  93. "fun": "set",
  94. "__env__": "base",
  95. "__sls__": "debconf",
  96. "data": {
  97. "mysql-server/root_password": {"type": "password", "value": "temp123"}
  98. },
  99. "order": 10000,
  100. }
  101. expected_result = {"comment": "onlyif condition is true", "result": False}
  102. with patch("salt.state.State._gather_pillar") as state_patch:
  103. minion_opts = self.get_temp_config("minion")
  104. state_obj = salt.state.State(minion_opts)
  105. return_result = state_obj._run_check_onlyif(low_data, "")
  106. self.assertEqual(expected_result, return_result)
  107. def test_verify_onlyif_parse_deep_return(self):
  108. low_data = {
  109. "state": "test",
  110. "name": "foo",
  111. "__sls__": "consol",
  112. "__env__": "base",
  113. "__id__": "test",
  114. "onlyif": [
  115. {
  116. "fun": "test.arg",
  117. "get_return": "kwargs:deep:return",
  118. "deep": {"return": "true"},
  119. }
  120. ],
  121. "order": 10000,
  122. "fun": "nop",
  123. }
  124. expected_result = {"comment": "onlyif condition is true", "result": False}
  125. with patch("salt.state.State._gather_pillar") as state_patch:
  126. minion_opts = self.get_temp_config("minion")
  127. state_obj = salt.state.State(minion_opts)
  128. return_result = state_obj._run_check_onlyif(low_data, "")
  129. self.assertEqual(expected_result, return_result)
  130. def test_verify_onlyif_cmd_error(self):
  131. """
  132. Simulates a failure in cmd.retcode from onlyif
  133. This could occur is runas is specified with a user that does not exist
  134. """
  135. low_data = {
  136. "onlyif": "somecommand",
  137. "runas": "doesntexist",
  138. "name": "echo something",
  139. "state": "cmd",
  140. "__id__": "this is just a test",
  141. "fun": "run",
  142. "__env__": "base",
  143. "__sls__": "sometest",
  144. "order": 10000,
  145. }
  146. expected_result = {
  147. "comment": "onlyif condition is false",
  148. "result": True,
  149. "skip_watch": True,
  150. }
  151. with patch("salt.state.State._gather_pillar") as state_patch:
  152. minion_opts = self.get_temp_config("minion")
  153. state_obj = salt.state.State(minion_opts)
  154. mock = MagicMock(side_effect=CommandExecutionError("Boom!"))
  155. with patch.dict(state_obj.functions, {"cmd.retcode": mock}):
  156. # The mock handles the exception, but the runas dict is being passed as it would actually be
  157. return_result = state_obj._run_check_onlyif(
  158. low_data, {"runas": "doesntexist"}
  159. )
  160. self.assertEqual(expected_result, return_result)
  161. def test_verify_unless_cmd_error(self):
  162. """
  163. Simulates a failure in cmd.retcode from unless
  164. This could occur is runas is specified with a user that does not exist
  165. """
  166. low_data = {
  167. "unless": "somecommand",
  168. "runas": "doesntexist",
  169. "name": "echo something",
  170. "state": "cmd",
  171. "__id__": "this is just a test",
  172. "fun": "run",
  173. "__env__": "base",
  174. "__sls__": "sometest",
  175. "order": 10000,
  176. }
  177. expected_result = {
  178. "comment": "unless condition is true",
  179. "result": True,
  180. "skip_watch": True,
  181. }
  182. with patch("salt.state.State._gather_pillar") as state_patch:
  183. minion_opts = self.get_temp_config("minion")
  184. state_obj = salt.state.State(minion_opts)
  185. mock = MagicMock(side_effect=CommandExecutionError("Boom!"))
  186. with patch.dict(state_obj.functions, {"cmd.retcode": mock}):
  187. # The mock handles the exception, but the runas dict is being passed as it would actually be
  188. return_result = state_obj._run_check_unless(
  189. low_data, {"runas": "doesntexist"}
  190. )
  191. self.assertEqual(expected_result, return_result)
  192. def test_verify_unless_parse(self):
  193. low_data = {
  194. "unless": [{"fun": "test.arg", "args": ["arg1", "arg2"]}],
  195. "name": "mysql-server-5.7",
  196. "state": "debconf",
  197. "__id__": "set root password",
  198. "fun": "set",
  199. "__env__": "base",
  200. "__sls__": "debconf",
  201. "data": {
  202. "mysql-server/root_password": {"type": "password", "value": "temp123"}
  203. },
  204. "order": 10000,
  205. }
  206. expected_result = {
  207. "comment": "unless condition is true",
  208. "result": True,
  209. "skip_watch": True,
  210. }
  211. with patch("salt.state.State._gather_pillar") as state_patch:
  212. minion_opts = self.get_temp_config("minion")
  213. state_obj = salt.state.State(minion_opts)
  214. return_result = state_obj._run_check_unless(low_data, "")
  215. self.assertEqual(expected_result, return_result)
  216. def test_verify_unless_parse_deep_return(self):
  217. low_data = {
  218. "state": "test",
  219. "name": "foo",
  220. "__sls__": "consol",
  221. "__env__": "base",
  222. "__id__": "test",
  223. "unless": [
  224. {
  225. "fun": "test.arg",
  226. "get_return": "kwargs:deep:return",
  227. "deep": {"return": False},
  228. }
  229. ],
  230. "order": 10000,
  231. "fun": "nop",
  232. }
  233. expected_result = {"comment": "unless condition is false", "result": False}
  234. with patch("salt.state.State._gather_pillar") as state_patch:
  235. minion_opts = self.get_temp_config("minion")
  236. state_obj = salt.state.State(minion_opts)
  237. return_result = state_obj._run_check_unless(low_data, "")
  238. self.assertEqual(expected_result, return_result)
  239. def test_verify_creates(self):
  240. low_data = {
  241. "state": "cmd",
  242. "name": 'echo "something"',
  243. "__sls__": "tests.creates",
  244. "__env__": "base",
  245. "__id__": "do_a_thing",
  246. "creates": "/tmp/thing",
  247. "order": 10000,
  248. "fun": "run",
  249. }
  250. with patch("salt.state.State._gather_pillar") as state_patch:
  251. minion_opts = self.get_temp_config("minion")
  252. state_obj = salt.state.State(minion_opts)
  253. with patch("os.path.exists") as path_mock:
  254. path_mock.return_value = True
  255. expected_result = {
  256. "comment": "/tmp/thing exists",
  257. "result": True,
  258. "skip_watch": True,
  259. }
  260. return_result = state_obj._run_check_creates(low_data)
  261. self.assertEqual(expected_result, return_result)
  262. path_mock.return_value = False
  263. expected_result = {
  264. "comment": "Creates files not found",
  265. "result": False,
  266. }
  267. return_result = state_obj._run_check_creates(low_data)
  268. self.assertEqual(expected_result, return_result)
  269. def test_verify_creates_list(self):
  270. low_data = {
  271. "state": "cmd",
  272. "name": 'echo "something"',
  273. "__sls__": "tests.creates",
  274. "__env__": "base",
  275. "__id__": "do_a_thing",
  276. "creates": ["/tmp/thing", "/tmp/thing2"],
  277. "order": 10000,
  278. "fun": "run",
  279. }
  280. with patch("salt.state.State._gather_pillar") as state_patch:
  281. minion_opts = self.get_temp_config("minion")
  282. state_obj = salt.state.State(minion_opts)
  283. with patch("os.path.exists") as path_mock:
  284. path_mock.return_value = True
  285. expected_result = {
  286. "comment": "All files in creates exist",
  287. "result": True,
  288. "skip_watch": True,
  289. }
  290. return_result = state_obj._run_check_creates(low_data)
  291. self.assertEqual(expected_result, return_result)
  292. path_mock.return_value = False
  293. expected_result = {
  294. "comment": "Creates files not found",
  295. "result": False,
  296. }
  297. return_result = state_obj._run_check_creates(low_data)
  298. self.assertEqual(expected_result, return_result)
  299. def _expand_win_path(self, path):
  300. """
  301. Expand C:/users/admini~1/appdata/local/temp/salt-tests-tmpdir/...
  302. into C:/users/adminitrator/appdata/local/temp/salt-tests-tmpdir/...
  303. to prevent file.search from expanding the "~" with os.path.expanduser
  304. """
  305. if salt.utils.platform.is_windows():
  306. import win32file
  307. return win32file.GetLongPathName(path).replace("\\", "/")
  308. else:
  309. return path
  310. @with_tempfile()
  311. def test_verify_onlyif_parse_slots(self, name):
  312. with salt.utils.files.fopen(name, "w") as fp:
  313. fp.write("file-contents")
  314. low_data = {
  315. "onlyif": [
  316. {
  317. "fun": "file.search",
  318. "args": [
  319. "__slot__:salt:test.echo({})".format(
  320. self._expand_win_path(name)
  321. ),
  322. ],
  323. "pattern": "__slot__:salt:test.echo(file-contents)",
  324. }
  325. ],
  326. "name": "mysql-server-5.7",
  327. "state": "debconf",
  328. "__id__": "set root password",
  329. "fun": "set",
  330. "__env__": "base",
  331. "__sls__": "debconf",
  332. "data": {
  333. "mysql-server/root_password": {"type": "password", "value": "temp123"}
  334. },
  335. "order": 10000,
  336. }
  337. expected_result = {"comment": "onlyif condition is true", "result": False}
  338. with patch("salt.state.State._gather_pillar") as state_patch:
  339. minion_opts = self.get_temp_config("minion")
  340. state_obj = salt.state.State(minion_opts)
  341. return_result = state_obj._run_check_onlyif(low_data, "")
  342. self.assertEqual(expected_result, return_result)
  343. def test_verify_onlyif_list_cmd(self):
  344. low_data = {
  345. "state": "cmd",
  346. "name": 'echo "something"',
  347. "__sls__": "tests.cmd",
  348. "__env__": "base",
  349. "__id__": "check onlyif",
  350. "onlyif": ["/bin/true", "/bin/false"],
  351. "order": 10001,
  352. "fun": "run",
  353. }
  354. expected_result = {
  355. "comment": "onlyif condition is false",
  356. "result": True,
  357. "skip_watch": True,
  358. }
  359. with patch("salt.state.State._gather_pillar") as state_patch:
  360. minion_opts = self.get_temp_config("minion")
  361. state_obj = salt.state.State(minion_opts)
  362. return_result = state_obj._run_check_onlyif(low_data, {})
  363. self.assertEqual(expected_result, return_result)
  364. def test_verify_onlyif_cmd_args(self):
  365. """
  366. Verify cmd.run state arguments are properly passed to cmd.retcode in onlyif
  367. """
  368. low_data = {
  369. "onlyif": "somecommand",
  370. "cwd": "acwd",
  371. "root": "aroot",
  372. "env": [{"akey": "avalue"}],
  373. "prepend_path": "apath",
  374. "umask": "0700",
  375. "success_retcodes": 1,
  376. "timeout": 5,
  377. "runas": "doesntexist",
  378. "name": "echo something",
  379. "shell": "/bin/dash",
  380. "state": "cmd",
  381. "__id__": "this is just a test",
  382. "fun": "run",
  383. "__env__": "base",
  384. "__sls__": "sometest",
  385. "order": 10000,
  386. }
  387. with patch("salt.state.State._gather_pillar") as state_patch:
  388. minion_opts = self.get_temp_config("minion")
  389. state_obj = salt.state.State(minion_opts)
  390. mock = MagicMock()
  391. with patch.dict(state_obj.functions, {"cmd.retcode": mock}):
  392. # The mock handles the exception, but the runas dict is being passed as it would actually be
  393. return_result = state_obj._run_check(low_data)
  394. mock.assert_called_once_with(
  395. "somecommand",
  396. ignore_retcode=True,
  397. python_shell=True,
  398. cwd="acwd",
  399. root="aroot",
  400. runas="doesntexist",
  401. env=[{"akey": "avalue"}],
  402. prepend_path="apath",
  403. umask="0700",
  404. timeout=5,
  405. success_retcodes=1,
  406. shell="/bin/dash",
  407. )
  408. @with_tempfile()
  409. def test_verify_unless_parse_slots(self, name):
  410. with salt.utils.files.fopen(name, "w") as fp:
  411. fp.write("file-contents")
  412. low_data = {
  413. "unless": [
  414. {
  415. "fun": "file.search",
  416. "args": [
  417. "__slot__:salt:test.echo({})".format(
  418. self._expand_win_path(name)
  419. ),
  420. ],
  421. "pattern": "__slot__:salt:test.echo(file-contents)",
  422. }
  423. ],
  424. "name": "mysql-server-5.7",
  425. "state": "debconf",
  426. "__id__": "set root password",
  427. "fun": "set",
  428. "__env__": "base",
  429. "__sls__": "debconf",
  430. "data": {
  431. "mysql-server/root_password": {"type": "password", "value": "temp123"}
  432. },
  433. "order": 10000,
  434. }
  435. expected_result = {
  436. "comment": "unless condition is true",
  437. "result": True,
  438. "skip_watch": True,
  439. }
  440. with patch("salt.state.State._gather_pillar") as state_patch:
  441. minion_opts = self.get_temp_config("minion")
  442. state_obj = salt.state.State(minion_opts)
  443. return_result = state_obj._run_check_unless(low_data, "")
  444. self.assertEqual(expected_result, return_result)
  445. def test_verify_retry_parsing(self):
  446. low_data = {
  447. "state": "file",
  448. "name": "/tmp/saltstack.README.rst",
  449. "__sls__": "demo.download",
  450. "__env__": "base",
  451. "__id__": "download sample data",
  452. "retry": {"attempts": 5, "interval": 5},
  453. "unless": ["test -f /tmp/saltstack.README.rst"],
  454. "source": [
  455. "https://raw.githubusercontent.com/saltstack/salt/develop/README.rst"
  456. ],
  457. "source_hash": "f2bc8c0aa2ae4f5bb5c2051686016b48",
  458. "order": 10000,
  459. "fun": "managed",
  460. }
  461. expected_result = {
  462. "__id__": "download sample data",
  463. "__run_num__": 0,
  464. "__sls__": "demo.download",
  465. "changes": {},
  466. "comment": "['unless condition is true'] The state would be retried every 5 "
  467. "seconds (with a splay of up to 0 seconds) a maximum of 5 times or "
  468. "until a result of True is returned",
  469. "name": "/tmp/saltstack.README.rst",
  470. "result": True,
  471. "skip_watch": True,
  472. }
  473. with patch("salt.state.State._gather_pillar") as state_patch:
  474. minion_opts = self.get_temp_config("minion")
  475. minion_opts["test"] = True
  476. minion_opts["file_client"] = "local"
  477. state_obj = salt.state.State(minion_opts)
  478. mock = {
  479. "result": True,
  480. "comment": ["unless condition is true"],
  481. "skip_watch": True,
  482. }
  483. with patch.object(state_obj, "_run_check", return_value=mock):
  484. self.assertDictContainsSubset(expected_result, state_obj.call(low_data))
  485. def test_render_requisite_require_disabled(self):
  486. """
  487. Test that the state compiler correctly deliver a rendering
  488. exception when a requisite cannot be resolved
  489. """
  490. with patch("salt.state.State._gather_pillar") as state_patch:
  491. high_data = {
  492. "step_one": OrderedDict(
  493. [
  494. (
  495. "test",
  496. [
  497. OrderedDict(
  498. [("require", [OrderedDict([("test", "step_two")])])]
  499. ),
  500. "succeed_with_changes",
  501. {"order": 10000},
  502. ],
  503. ),
  504. ("__sls__", "test.disable_require"),
  505. ("__env__", "base"),
  506. ]
  507. ),
  508. "step_two": {
  509. "test": ["succeed_with_changes", {"order": 10001}],
  510. "__env__": "base",
  511. "__sls__": "test.disable_require",
  512. },
  513. }
  514. minion_opts = self.get_temp_config("minion")
  515. minion_opts["disabled_requisites"] = ["require"]
  516. state_obj = salt.state.State(minion_opts)
  517. ret = state_obj.call_high(high_data)
  518. run_num = ret["test_|-step_one_|-step_one_|-succeed_with_changes"][
  519. "__run_num__"
  520. ]
  521. self.assertEqual(run_num, 0)
  522. def test_render_requisite_require_in_disabled(self):
  523. """
  524. Test that the state compiler correctly deliver a rendering
  525. exception when a requisite cannot be resolved
  526. """
  527. with patch("salt.state.State._gather_pillar") as state_patch:
  528. high_data = {
  529. "step_one": {
  530. "test": ["succeed_with_changes", {"order": 10000}],
  531. "__env__": "base",
  532. "__sls__": "test.disable_require_in",
  533. },
  534. "step_two": OrderedDict(
  535. [
  536. (
  537. "test",
  538. [
  539. OrderedDict(
  540. [
  541. (
  542. "require_in",
  543. [OrderedDict([("test", "step_one")])],
  544. )
  545. ]
  546. ),
  547. "succeed_with_changes",
  548. {"order": 10001},
  549. ],
  550. ),
  551. ("__sls__", "test.disable_require_in"),
  552. ("__env__", "base"),
  553. ]
  554. ),
  555. }
  556. minion_opts = self.get_temp_config("minion")
  557. minion_opts["disabled_requisites"] = ["require_in"]
  558. state_obj = salt.state.State(minion_opts)
  559. ret = state_obj.call_high(high_data)
  560. run_num = ret["test_|-step_one_|-step_one_|-succeed_with_changes"][
  561. "__run_num__"
  562. ]
  563. self.assertEqual(run_num, 0)
  564. def test_call_chunk_sub_state_run(self):
  565. """
  566. Test running a batch of states with an external runner
  567. that returns sub_state_run
  568. """
  569. low_data = {
  570. "state": "external",
  571. "name": "external_state_name",
  572. "__id__": "do_a_thing",
  573. "__sls__": "external",
  574. "order": 10000,
  575. "fun": "state",
  576. }
  577. mock_call_return = {
  578. "__run_num__": 0,
  579. "sub_state_run": [
  580. {
  581. "changes": {},
  582. "result": True,
  583. "comment": "",
  584. "low": {
  585. "name": "external_state_name",
  586. "__id__": "external_state_id",
  587. "state": "external_state",
  588. "fun": "external_function",
  589. },
  590. }
  591. ],
  592. }
  593. expected_sub_state_tag = "external_state_|-external_state_id_|-external_state_name_|-external_function"
  594. with patch("salt.state.State._gather_pillar") as state_patch:
  595. with patch("salt.state.State.call", return_value=mock_call_return):
  596. minion_opts = self.get_temp_config("minion")
  597. minion_opts["disabled_requisites"] = ["require"]
  598. state_obj = salt.state.State(minion_opts)
  599. ret = state_obj.call_chunk(low_data, {}, {})
  600. sub_state = ret.get(expected_sub_state_tag)
  601. assert sub_state
  602. self.assertEqual(sub_state["__run_num__"], 1)
  603. self.assertEqual(sub_state["name"], "external_state_name")
  604. self.assertEqual(sub_state["__state_ran__"], True)
  605. self.assertEqual(sub_state["__sls__"], "external")
  606. class HighStateTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
  607. def setUp(self):
  608. root_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  609. self.state_tree_dir = os.path.join(root_dir, "state_tree")
  610. cache_dir = os.path.join(root_dir, "cachedir")
  611. for dpath in (root_dir, self.state_tree_dir, cache_dir):
  612. if not os.path.isdir(dpath):
  613. os.makedirs(dpath)
  614. overrides = {}
  615. overrides["root_dir"] = root_dir
  616. overrides["state_events"] = False
  617. overrides["id"] = "match"
  618. overrides["file_client"] = "local"
  619. overrides["file_roots"] = dict(base=[self.state_tree_dir])
  620. overrides["cachedir"] = cache_dir
  621. overrides["test"] = False
  622. self.config = self.get_temp_config("minion", **overrides)
  623. self.addCleanup(delattr, self, "config")
  624. self.highstate = salt.state.HighState(self.config)
  625. self.addCleanup(delattr, self, "highstate")
  626. self.highstate.push_active()
  627. def tearDown(self):
  628. self.highstate.pop_active()
  629. def test_top_matches_with_list(self):
  630. top = {"env": {"match": ["state1", "state2"], "nomatch": ["state3"]}}
  631. matches = self.highstate.top_matches(top)
  632. self.assertEqual(matches, {"env": ["state1", "state2"]})
  633. def test_top_matches_with_string(self):
  634. top = {"env": {"match": "state1", "nomatch": "state2"}}
  635. matches = self.highstate.top_matches(top)
  636. self.assertEqual(matches, {"env": ["state1"]})
  637. def test_matches_whitelist(self):
  638. matches = {"env": ["state1", "state2", "state3"]}
  639. matches = self.highstate.matches_whitelist(matches, ["state2"])
  640. self.assertEqual(matches, {"env": ["state2"]})
  641. def test_matches_whitelist_with_string(self):
  642. matches = {"env": ["state1", "state2", "state3"]}
  643. matches = self.highstate.matches_whitelist(matches, "state2,state3")
  644. self.assertEqual(matches, {"env": ["state2", "state3"]})
  645. def test_show_state_usage(self):
  646. # monkey patch sub methods
  647. self.highstate.avail = {"base": ["state.a", "state.b", "state.c"]}
  648. def verify_tops(*args, **kwargs):
  649. return []
  650. def get_top(*args, **kwargs):
  651. return None
  652. def top_matches(*args, **kwargs):
  653. return {"base": ["state.a", "state.b"]}
  654. self.highstate.verify_tops = verify_tops
  655. self.highstate.get_top = get_top
  656. self.highstate.top_matches = top_matches
  657. # get compile_state_usage() result
  658. state_usage_dict = self.highstate.compile_state_usage()
  659. self.assertEqual(state_usage_dict["base"]["count_unused"], 1)
  660. self.assertEqual(state_usage_dict["base"]["count_used"], 2)
  661. self.assertEqual(state_usage_dict["base"]["count_all"], 3)
  662. self.assertEqual(state_usage_dict["base"]["used"], ["state.a", "state.b"])
  663. self.assertEqual(state_usage_dict["base"]["unused"], ["state.c"])
  664. def test_find_sls_ids_with_exclude(self):
  665. """
  666. See https://github.com/saltstack/salt/issues/47182
  667. """
  668. sls_dir = "issue-47182"
  669. shutil.copytree(
  670. os.path.join(RUNTIME_VARS.BASE_FILES, sls_dir),
  671. os.path.join(self.state_tree_dir, sls_dir),
  672. )
  673. shutil.move(
  674. os.path.join(self.state_tree_dir, sls_dir, "top.sls"), self.state_tree_dir
  675. )
  676. # Manually compile the high data. We don't have to worry about all of
  677. # the normal error checking we do here since we know that all the SLS
  678. # files exist and there is no whitelist/blacklist being used.
  679. top = self.highstate.get_top() # pylint: disable=assignment-from-none
  680. matches = self.highstate.top_matches(top)
  681. high, _ = self.highstate.render_highstate(matches)
  682. ret = salt.state.find_sls_ids("issue-47182.stateA.newer", high)
  683. self.assertEqual(ret, [("somestuff", "cmd")])
  684. class MultiEnvHighStateTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
  685. def setUp(self):
  686. root_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  687. self.base_state_tree_dir = os.path.join(root_dir, "base")
  688. self.other_state_tree_dir = os.path.join(root_dir, "other")
  689. cache_dir = os.path.join(root_dir, "cachedir")
  690. for dpath in (
  691. root_dir,
  692. self.base_state_tree_dir,
  693. self.other_state_tree_dir,
  694. cache_dir,
  695. ):
  696. if not os.path.isdir(dpath):
  697. os.makedirs(dpath)
  698. shutil.copy(
  699. os.path.join(RUNTIME_VARS.BASE_FILES, "top.sls"), self.base_state_tree_dir
  700. )
  701. shutil.copy(
  702. os.path.join(RUNTIME_VARS.BASE_FILES, "core.sls"), self.base_state_tree_dir
  703. )
  704. shutil.copy(
  705. os.path.join(RUNTIME_VARS.BASE_FILES, "test.sls"), self.other_state_tree_dir
  706. )
  707. overrides = {}
  708. overrides["root_dir"] = root_dir
  709. overrides["state_events"] = False
  710. overrides["id"] = "match"
  711. overrides["file_client"] = "local"
  712. overrides["file_roots"] = dict(
  713. base=[self.base_state_tree_dir], other=[self.other_state_tree_dir]
  714. )
  715. overrides["cachedir"] = cache_dir
  716. overrides["test"] = False
  717. self.config = self.get_temp_config("minion", **overrides)
  718. self.addCleanup(delattr, self, "config")
  719. self.highstate = salt.state.HighState(self.config)
  720. self.addCleanup(delattr, self, "highstate")
  721. self.highstate.push_active()
  722. def tearDown(self):
  723. self.highstate.pop_active()
  724. def test_lazy_avail_states_base(self):
  725. # list_states not called yet
  726. self.assertEqual(self.highstate.avail._filled, False)
  727. self.assertEqual(self.highstate.avail._avail, {"base": None})
  728. # After getting 'base' env available states
  729. self.highstate.avail["base"] # pylint: disable=pointless-statement
  730. self.assertEqual(self.highstate.avail._filled, False)
  731. self.assertEqual(self.highstate.avail._avail, {"base": ["core", "top"]})
  732. def test_lazy_avail_states_other(self):
  733. # list_states not called yet
  734. self.assertEqual(self.highstate.avail._filled, False)
  735. self.assertEqual(self.highstate.avail._avail, {"base": None})
  736. # After getting 'other' env available states
  737. self.highstate.avail["other"] # pylint: disable=pointless-statement
  738. self.assertEqual(self.highstate.avail._filled, True)
  739. self.assertEqual(self.highstate.avail._avail, {"base": None, "other": ["test"]})
  740. def test_lazy_avail_states_multi(self):
  741. # list_states not called yet
  742. self.assertEqual(self.highstate.avail._filled, False)
  743. self.assertEqual(self.highstate.avail._avail, {"base": None})
  744. # After getting 'base' env available states
  745. self.highstate.avail["base"] # pylint: disable=pointless-statement
  746. self.assertEqual(self.highstate.avail._filled, False)
  747. self.assertEqual(self.highstate.avail._avail, {"base": ["core", "top"]})
  748. # After getting 'other' env available states
  749. self.highstate.avail["other"] # pylint: disable=pointless-statement
  750. self.assertEqual(self.highstate.avail._filled, True)
  751. self.assertEqual(
  752. self.highstate.avail._avail, {"base": ["core", "top"], "other": ["test"]}
  753. )
  754. @skipIf(pytest is None, "PyTest is missing")
  755. class StateReturnsTestCase(TestCase):
  756. """
  757. TestCase for code handling state returns.
  758. """
  759. def test_state_output_check_changes_is_dict(self):
  760. """
  761. Test that changes key contains a dictionary.
  762. :return:
  763. """
  764. data = {"changes": []}
  765. out = statedecorators.OutputUnifier("content_check")(lambda: data)()
  766. assert "'Changes' should be a dictionary" in out["comment"]
  767. assert not out["result"]
  768. def test_state_output_check_return_is_dict(self):
  769. """
  770. Test for the entire return is a dictionary
  771. :return:
  772. """
  773. data = ["whatever"]
  774. out = statedecorators.OutputUnifier("content_check")(lambda: data)()
  775. assert (
  776. "Malformed state return. Data must be a dictionary type" in out["comment"]
  777. )
  778. assert not out["result"]
  779. def test_state_output_check_return_has_nrc(self):
  780. """
  781. Test for name/result/comment keys are inside the return.
  782. :return:
  783. """
  784. data = {"arbitrary": "data", "changes": {}}
  785. out = statedecorators.OutputUnifier("content_check")(lambda: data)()
  786. assert (
  787. " The following keys were not present in the state return: name, result, comment"
  788. in out["comment"]
  789. )
  790. assert not out["result"]
  791. def test_state_output_unifier_comment_is_not_list(self):
  792. """
  793. Test for output is unified so the comment is converted to a multi-line string
  794. :return:
  795. """
  796. data = {
  797. "comment": ["data", "in", "the", "list"],
  798. "changes": {},
  799. "name": None,
  800. "result": "fantastic!",
  801. }
  802. expected = {
  803. "comment": "data\nin\nthe\nlist",
  804. "changes": {},
  805. "name": None,
  806. "result": True,
  807. }
  808. assert statedecorators.OutputUnifier("unify")(lambda: data)() == expected
  809. data = {
  810. "comment": ["data", "in", "the", "list"],
  811. "changes": {},
  812. "name": None,
  813. "result": None,
  814. }
  815. expected = "data\nin\nthe\nlist"
  816. assert (
  817. statedecorators.OutputUnifier("unify")(lambda: data)()["comment"]
  818. == expected
  819. )
  820. def test_state_output_unifier_result_converted_to_true(self):
  821. """
  822. Test for output is unified so the result is converted to True
  823. :return:
  824. """
  825. data = {
  826. "comment": ["data", "in", "the", "list"],
  827. "changes": {},
  828. "name": None,
  829. "result": "Fantastic",
  830. }
  831. assert statedecorators.OutputUnifier("unify")(lambda: data)()["result"] is True
  832. def test_state_output_unifier_result_converted_to_false(self):
  833. """
  834. Test for output is unified so the result is converted to False
  835. :return:
  836. """
  837. data = {
  838. "comment": ["data", "in", "the", "list"],
  839. "changes": {},
  840. "name": None,
  841. "result": "",
  842. }
  843. assert statedecorators.OutputUnifier("unify")(lambda: data)()["result"] is False
  844. @skipIf(pytest is None, "PyTest is missing")
  845. class SubStateReturnsTestCase(TestCase):
  846. """
  847. TestCase for code handling state returns.
  848. """
  849. def test_sub_state_output_check_changes_is_dict(self):
  850. """
  851. Test that changes key contains a dictionary.
  852. :return:
  853. """
  854. data = {"changes": {}, "sub_state_run": [{"changes": []}]}
  855. out = statedecorators.OutputUnifier("content_check")(lambda: data)()
  856. assert "'Changes' should be a dictionary" in out["sub_state_run"][0]["comment"]
  857. assert not out["sub_state_run"][0]["result"]
  858. def test_sub_state_output_check_return_is_dict(self):
  859. """
  860. Test for the entire return is a dictionary
  861. :return:
  862. """
  863. data = {"sub_state_run": [["whatever"]]}
  864. out = statedecorators.OutputUnifier("content_check")(lambda: data)()
  865. assert (
  866. "Malformed state return. Data must be a dictionary type"
  867. in out["sub_state_run"][0]["comment"]
  868. )
  869. assert not out["sub_state_run"][0]["result"]
  870. def test_sub_state_output_check_return_has_nrc(self):
  871. """
  872. Test for name/result/comment keys are inside the return.
  873. :return:
  874. """
  875. data = {"sub_state_run": [{"arbitrary": "data", "changes": {}}]}
  876. out = statedecorators.OutputUnifier("content_check")(lambda: data)()
  877. assert (
  878. " The following keys were not present in the state return: name, result, comment"
  879. in out["sub_state_run"][0]["comment"]
  880. )
  881. assert not out["sub_state_run"][0]["result"]
  882. def test_sub_state_output_unifier_comment_is_not_list(self):
  883. """
  884. Test for output is unified so the comment is converted to a multi-line string
  885. :return:
  886. """
  887. data = {
  888. "sub_state_run": [
  889. {
  890. "comment": ["data", "in", "the", "list"],
  891. "changes": {},
  892. "name": None,
  893. "result": "fantastic!",
  894. }
  895. ]
  896. }
  897. expected = {
  898. "sub_state_run": [
  899. {
  900. "comment": "data\nin\nthe\nlist",
  901. "changes": {},
  902. "name": None,
  903. "result": True,
  904. }
  905. ]
  906. }
  907. assert statedecorators.OutputUnifier("unify")(lambda: data)() == expected
  908. data = {
  909. "sub_state_run": [
  910. {
  911. "comment": ["data", "in", "the", "list"],
  912. "changes": {},
  913. "name": None,
  914. "result": None,
  915. }
  916. ]
  917. }
  918. expected = "data\nin\nthe\nlist"
  919. assert (
  920. statedecorators.OutputUnifier("unify")(lambda: data)()["sub_state_run"][0][
  921. "comment"
  922. ]
  923. == expected
  924. )
  925. def test_sub_state_output_unifier_result_converted_to_true(self):
  926. """
  927. Test for output is unified so the result is converted to True
  928. :return:
  929. """
  930. data = {
  931. "sub_state_run": [
  932. {
  933. "comment": ["data", "in", "the", "list"],
  934. "changes": {},
  935. "name": None,
  936. "result": "Fantastic",
  937. }
  938. ]
  939. }
  940. assert (
  941. statedecorators.OutputUnifier("unify")(lambda: data)()["sub_state_run"][0][
  942. "result"
  943. ]
  944. is True
  945. )
  946. def test_sub_state_output_unifier_result_converted_to_false(self):
  947. """
  948. Test for output is unified so the result is converted to False
  949. :return:
  950. """
  951. data = {
  952. "sub_state_run": [
  953. {
  954. "comment": ["data", "in", "the", "list"],
  955. "changes": {},
  956. "name": None,
  957. "result": "",
  958. }
  959. ]
  960. }
  961. assert (
  962. statedecorators.OutputUnifier("unify")(lambda: data)()["sub_state_run"][0][
  963. "result"
  964. ]
  965. is False
  966. )
  967. class StateFormatSlotsTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
  968. """
  969. TestCase for code handling slots
  970. """
  971. def setUp(self):
  972. with patch("salt.state.State._gather_pillar"):
  973. minion_opts = self.get_temp_config("minion")
  974. self.state_obj = salt.state.State(minion_opts)
  975. def test_format_slots_no_slots(self):
  976. """
  977. Test the format slots keeps data without slots untouched.
  978. """
  979. cdata = {"args": ["arg"], "kwargs": {"key": "val"}}
  980. self.state_obj.format_slots(cdata)
  981. self.assertEqual(cdata, {"args": ["arg"], "kwargs": {"key": "val"}})
  982. @slowTest
  983. def test_format_slots_arg(self):
  984. """
  985. Test the format slots is calling a slot specified in args with corresponding arguments.
  986. """
  987. cdata = {
  988. "args": ["__slot__:salt:mod.fun(fun_arg, fun_key=fun_val)"],
  989. "kwargs": {"key": "val"},
  990. }
  991. mock = MagicMock(return_value="fun_return")
  992. with patch.dict(self.state_obj.functions, {"mod.fun": mock}):
  993. self.state_obj.format_slots(cdata)
  994. mock.assert_called_once_with("fun_arg", fun_key="fun_val")
  995. self.assertEqual(cdata, {"args": ["fun_return"], "kwargs": {"key": "val"}})
  996. @slowTest
  997. def test_format_slots_dict_arg(self):
  998. """
  999. Test the format slots is calling a slot specified in dict arg.
  1000. """
  1001. cdata = {
  1002. "args": [{"subarg": "__slot__:salt:mod.fun(fun_arg, fun_key=fun_val)"}],
  1003. "kwargs": {"key": "val"},
  1004. }
  1005. mock = MagicMock(return_value="fun_return")
  1006. with patch.dict(self.state_obj.functions, {"mod.fun": mock}):
  1007. self.state_obj.format_slots(cdata)
  1008. mock.assert_called_once_with("fun_arg", fun_key="fun_val")
  1009. self.assertEqual(
  1010. cdata, {"args": [{"subarg": "fun_return"}], "kwargs": {"key": "val"}}
  1011. )
  1012. @slowTest
  1013. def test_format_slots_listdict_arg(self):
  1014. """
  1015. Test the format slots is calling a slot specified in list containing a dict.
  1016. """
  1017. cdata = {
  1018. "args": [[{"subarg": "__slot__:salt:mod.fun(fun_arg, fun_key=fun_val)"}]],
  1019. "kwargs": {"key": "val"},
  1020. }
  1021. mock = MagicMock(return_value="fun_return")
  1022. with patch.dict(self.state_obj.functions, {"mod.fun": mock}):
  1023. self.state_obj.format_slots(cdata)
  1024. mock.assert_called_once_with("fun_arg", fun_key="fun_val")
  1025. self.assertEqual(
  1026. cdata, {"args": [[{"subarg": "fun_return"}]], "kwargs": {"key": "val"}}
  1027. )
  1028. @slowTest
  1029. def test_format_slots_liststr_arg(self):
  1030. """
  1031. Test the format slots is calling a slot specified in list containing a dict.
  1032. """
  1033. cdata = {
  1034. "args": [["__slot__:salt:mod.fun(fun_arg, fun_key=fun_val)"]],
  1035. "kwargs": {"key": "val"},
  1036. }
  1037. mock = MagicMock(return_value="fun_return")
  1038. with patch.dict(self.state_obj.functions, {"mod.fun": mock}):
  1039. self.state_obj.format_slots(cdata)
  1040. mock.assert_called_once_with("fun_arg", fun_key="fun_val")
  1041. self.assertEqual(cdata, {"args": [["fun_return"]], "kwargs": {"key": "val"}})
  1042. @slowTest
  1043. def test_format_slots_kwarg(self):
  1044. """
  1045. Test the format slots is calling a slot specified in kwargs with corresponding arguments.
  1046. """
  1047. cdata = {
  1048. "args": ["arg"],
  1049. "kwargs": {"key": "__slot__:salt:mod.fun(fun_arg, fun_key=fun_val)"},
  1050. }
  1051. mock = MagicMock(return_value="fun_return")
  1052. with patch.dict(self.state_obj.functions, {"mod.fun": mock}):
  1053. self.state_obj.format_slots(cdata)
  1054. mock.assert_called_once_with("fun_arg", fun_key="fun_val")
  1055. self.assertEqual(cdata, {"args": ["arg"], "kwargs": {"key": "fun_return"}})
  1056. @slowTest
  1057. def test_format_slots_multi(self):
  1058. """
  1059. Test the format slots is calling all slots with corresponding arguments when multiple slots
  1060. specified.
  1061. """
  1062. cdata = {
  1063. "args": [
  1064. "__slot__:salt:test_mod.fun_a(a_arg, a_key=a_kwarg)",
  1065. "__slot__:salt:test_mod.fun_b(b_arg, b_key=b_kwarg)",
  1066. ],
  1067. "kwargs": {
  1068. "kw_key_1": "__slot__:salt:test_mod.fun_c(c_arg, c_key=c_kwarg)",
  1069. "kw_key_2": "__slot__:salt:test_mod.fun_d(d_arg, d_key=d_kwarg)",
  1070. },
  1071. }
  1072. mock_a = MagicMock(return_value="fun_a_return")
  1073. mock_b = MagicMock(return_value="fun_b_return")
  1074. mock_c = MagicMock(return_value="fun_c_return")
  1075. mock_d = MagicMock(return_value="fun_d_return")
  1076. with patch.dict(
  1077. self.state_obj.functions,
  1078. {
  1079. "test_mod.fun_a": mock_a,
  1080. "test_mod.fun_b": mock_b,
  1081. "test_mod.fun_c": mock_c,
  1082. "test_mod.fun_d": mock_d,
  1083. },
  1084. ):
  1085. self.state_obj.format_slots(cdata)
  1086. mock_a.assert_called_once_with("a_arg", a_key="a_kwarg")
  1087. mock_b.assert_called_once_with("b_arg", b_key="b_kwarg")
  1088. mock_c.assert_called_once_with("c_arg", c_key="c_kwarg")
  1089. mock_d.assert_called_once_with("d_arg", d_key="d_kwarg")
  1090. self.assertEqual(
  1091. cdata,
  1092. {
  1093. "args": ["fun_a_return", "fun_b_return"],
  1094. "kwargs": {"kw_key_1": "fun_c_return", "kw_key_2": "fun_d_return"},
  1095. },
  1096. )
  1097. @slowTest
  1098. def test_format_slots_malformed(self):
  1099. """
  1100. Test the format slots keeps malformed slots untouched.
  1101. """
  1102. sls_data = {
  1103. "args": [
  1104. "__slot__:NOT_SUPPORTED:not.called()",
  1105. "__slot__:salt:not.called(",
  1106. "__slot__:salt:",
  1107. "__slot__:salt",
  1108. "__slot__:",
  1109. "__slot__",
  1110. ],
  1111. "kwargs": {
  1112. "key3": "__slot__:NOT_SUPPORTED:not.called()",
  1113. "key4": "__slot__:salt:not.called(",
  1114. "key5": "__slot__:salt:",
  1115. "key6": "__slot__:salt",
  1116. "key7": "__slot__:",
  1117. "key8": "__slot__",
  1118. },
  1119. }
  1120. cdata = sls_data.copy()
  1121. mock = MagicMock(return_value="return")
  1122. with patch.dict(self.state_obj.functions, {"not.called": mock}):
  1123. self.state_obj.format_slots(cdata)
  1124. mock.assert_not_called()
  1125. self.assertEqual(cdata, sls_data)
  1126. @slowTest
  1127. def test_slot_traverse_dict(self):
  1128. """
  1129. Test the slot parsing of dict response.
  1130. """
  1131. cdata = {
  1132. "args": ["arg"],
  1133. "kwargs": {"key": "__slot__:salt:mod.fun(fun_arg, fun_key=fun_val).key1"},
  1134. }
  1135. return_data = {"key1": "value1"}
  1136. mock = MagicMock(return_value=return_data)
  1137. with patch.dict(self.state_obj.functions, {"mod.fun": mock}):
  1138. self.state_obj.format_slots(cdata)
  1139. mock.assert_called_once_with("fun_arg", fun_key="fun_val")
  1140. self.assertEqual(cdata, {"args": ["arg"], "kwargs": {"key": "value1"}})
  1141. @slowTest
  1142. def test_slot_append(self):
  1143. """
  1144. Test the slot parsing of dict response.
  1145. """
  1146. cdata = {
  1147. "args": ["arg"],
  1148. "kwargs": {
  1149. "key": "__slot__:salt:mod.fun(fun_arg, fun_key=fun_val).key1 ~ thing~",
  1150. },
  1151. }
  1152. return_data = {"key1": "value1"}
  1153. mock = MagicMock(return_value=return_data)
  1154. with patch.dict(self.state_obj.functions, {"mod.fun": mock}):
  1155. self.state_obj.format_slots(cdata)
  1156. mock.assert_called_once_with("fun_arg", fun_key="fun_val")
  1157. self.assertEqual(cdata, {"args": ["arg"], "kwargs": {"key": "value1thing~"}})
  1158. # Skip on windows like integration.modules.test_state.StateModuleTest.test_parallel_state_with_long_tag
  1159. @skipIf(
  1160. salt.utils.platform.is_windows(),
  1161. "Skipped until parallel states can be fixed on Windows",
  1162. )
  1163. def test_format_slots_parallel(self):
  1164. """
  1165. Test if slots work with "parallel: true".
  1166. """
  1167. high_data = {
  1168. "always-changes-and-succeeds": {
  1169. "test": [
  1170. {"changes": True},
  1171. {"comment": "__slot__:salt:test.echo(fun_return)"},
  1172. {"parallel": True},
  1173. "configurable_test_state",
  1174. {"order": 10000},
  1175. ],
  1176. "__env__": "base",
  1177. "__sls__": "parallel_slots",
  1178. }
  1179. }
  1180. self.state_obj.jid = "123"
  1181. res = self.state_obj.call_high(high_data)
  1182. self.state_obj.jid = None
  1183. [(_, data)] = res.items()
  1184. self.assertEqual(data["comment"], "fun_return")