test_jboss7.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. # -*- coding: utf-8 -*-
  2. # pylint: disable=unused-argument
  3. # Import Python libs
  4. from __future__ import absolute_import, print_function, unicode_literals
  5. import pytest
  6. # Import Salt libs
  7. import salt.states.jboss7 as jboss7
  8. from salt.exceptions import CommandExecutionError
  9. from salt.ext import six
  10. # Import Salt testing libs
  11. from tests.support.mixins import LoaderModuleMockMixin
  12. from tests.support.mock import MagicMock, patch
  13. from tests.support.unit import TestCase
  14. class JBoss7StateTestCase(TestCase, LoaderModuleMockMixin):
  15. def setup_loader_modules(self):
  16. return {
  17. jboss7: {
  18. "__salt__": {
  19. "jboss7.read_datasource": MagicMock(),
  20. "jboss7.create_datasource": MagicMock(),
  21. "jboss7.update_datasource": MagicMock(),
  22. "jboss7.remove_datasource": MagicMock(),
  23. "jboss7.read_simple_binding": MagicMock(),
  24. "jboss7.create_simple_binding": MagicMock(),
  25. "jboss7.update_simple_binding": MagicMock(),
  26. "jboss7.undeploy": MagicMock(),
  27. "jboss7.deploy": MagicMock,
  28. "file.get_managed": MagicMock,
  29. "file.manage_file": MagicMock,
  30. "jboss7.list_deployments": MagicMock,
  31. },
  32. "__env__": "base",
  33. }
  34. }
  35. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  36. def test_should_not_redeploy_unchanged(self):
  37. # given
  38. parameters = {
  39. "target_file": "some_artifact",
  40. "undeploy_force": False,
  41. "undeploy": "some_artifact",
  42. "source": "some_artifact_on_master",
  43. }
  44. jboss_conf = {"cli_path": "somewhere", "controller": "some_controller"}
  45. def list_deployments(jboss_config):
  46. return ["some_artifact"]
  47. def file_get_managed(
  48. name,
  49. template,
  50. source,
  51. source_hash,
  52. source_hash_name,
  53. user,
  54. group,
  55. mode,
  56. attrs,
  57. saltenv,
  58. context,
  59. defaults,
  60. skip_verify,
  61. kwargs,
  62. ):
  63. return "sfn", "hash", ""
  64. def file_manage_file(
  65. name,
  66. sfn,
  67. ret,
  68. source,
  69. source_sum,
  70. user,
  71. group,
  72. mode,
  73. attrs,
  74. saltenv,
  75. backup,
  76. makedirs,
  77. template,
  78. show_diff,
  79. contents,
  80. dir_mode,
  81. ):
  82. return {"result": True, "changes": False}
  83. jboss7_undeploy_mock = MagicMock()
  84. jboss7_deploy_mock = MagicMock()
  85. file_get_managed = MagicMock(side_effect=file_get_managed)
  86. file_manage_file = MagicMock(side_effect=file_manage_file)
  87. list_deployments_mock = MagicMock(side_effect=list_deployments)
  88. with patch.dict(
  89. jboss7.__salt__,
  90. {
  91. "jboss7.undeploy": jboss7_undeploy_mock,
  92. "jboss7.deploy": jboss7_deploy_mock,
  93. "file.get_managed": file_get_managed,
  94. "file.manage_file": file_manage_file,
  95. "jboss7.list_deployments": list_deployments_mock,
  96. },
  97. ):
  98. # when
  99. result = jboss7.deployed(
  100. name="unchanged", jboss_config=jboss_conf, salt_source=parameters
  101. )
  102. # then
  103. self.assertFalse(jboss7_undeploy_mock.called)
  104. self.assertFalse(jboss7_deploy_mock.called)
  105. def test_should_redeploy_changed(self):
  106. # given
  107. parameters = {
  108. "target_file": "some_artifact",
  109. "undeploy_force": False,
  110. "undeploy": "some_artifact",
  111. "source": "some_artifact_on_master",
  112. }
  113. jboss_conf = {"cli_path": "somewhere", "controller": "some_controller"}
  114. def list_deployments(jboss_config):
  115. return ["some_artifact"]
  116. def file_get_managed(
  117. name,
  118. template,
  119. source,
  120. source_hash,
  121. source_hash_name,
  122. user,
  123. group,
  124. mode,
  125. attrs,
  126. saltenv,
  127. context,
  128. defaults,
  129. skip_verify,
  130. kwargs,
  131. ):
  132. return "sfn", "hash", ""
  133. def file_manage_file(
  134. name,
  135. sfn,
  136. ret,
  137. source,
  138. source_sum,
  139. user,
  140. group,
  141. mode,
  142. attrs,
  143. saltenv,
  144. backup,
  145. makedirs,
  146. template,
  147. show_diff,
  148. contents,
  149. dir_mode,
  150. ):
  151. return {"result": True, "changes": True}
  152. jboss7_undeploy_mock = MagicMock()
  153. jboss7_deploy_mock = MagicMock()
  154. file_get_managed = MagicMock(side_effect=file_get_managed)
  155. file_manage_file = MagicMock(side_effect=file_manage_file)
  156. list_deployments_mock = MagicMock(side_effect=list_deployments)
  157. with patch.dict(
  158. jboss7.__salt__,
  159. {
  160. "jboss7.undeploy": jboss7_undeploy_mock,
  161. "jboss7.deploy": jboss7_deploy_mock,
  162. "file.get_managed": file_get_managed,
  163. "file.manage_file": file_manage_file,
  164. "jboss7.list_deployments": list_deployments_mock,
  165. },
  166. ):
  167. # when
  168. result = jboss7.deployed(
  169. name="unchanged", jboss_config=jboss_conf, salt_source=parameters
  170. )
  171. # then
  172. self.assertTrue(jboss7_undeploy_mock.called)
  173. self.assertTrue(jboss7_deploy_mock.called)
  174. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  175. def test_should_deploy_different_artifact(self):
  176. # given
  177. parameters = {
  178. "target_file": "some_artifact",
  179. "undeploy_force": False,
  180. "undeploy": "some_artifact",
  181. "source": "some_artifact_on_master",
  182. }
  183. jboss_conf = {"cli_path": "somewhere", "controller": "some_controller"}
  184. def list_deployments(jboss_config):
  185. return ["some_other_artifact"]
  186. def file_get_managed(
  187. name,
  188. template,
  189. source,
  190. source_hash,
  191. source_hash_name,
  192. user,
  193. group,
  194. mode,
  195. attrs,
  196. saltenv,
  197. context,
  198. defaults,
  199. skip_verify,
  200. kwargs,
  201. ):
  202. return "sfn", "hash", ""
  203. def file_manage_file(
  204. name,
  205. sfn,
  206. ret,
  207. source,
  208. source_sum,
  209. user,
  210. group,
  211. mode,
  212. attrs,
  213. saltenv,
  214. backup,
  215. makedirs,
  216. template,
  217. show_diff,
  218. contents,
  219. dir_mode,
  220. ):
  221. return {"result": True, "changes": False}
  222. jboss7_undeploy_mock = MagicMock()
  223. jboss7_deploy_mock = MagicMock()
  224. file_get_managed = MagicMock(side_effect=file_get_managed)
  225. file_manage_file = MagicMock(side_effect=file_manage_file)
  226. list_deployments_mock = MagicMock(side_effect=list_deployments)
  227. with patch.dict(
  228. jboss7.__salt__,
  229. {
  230. "jboss7.undeploy": jboss7_undeploy_mock,
  231. "jboss7.deploy": jboss7_deploy_mock,
  232. "file.get_managed": file_get_managed,
  233. "file.manage_file": file_manage_file,
  234. "jboss7.list_deployments": list_deployments_mock,
  235. },
  236. ):
  237. # when
  238. result = jboss7.deployed(
  239. name="unchanged", jboss_config=jboss_conf, salt_source=parameters
  240. )
  241. # then
  242. self.assertFalse(jboss7_undeploy_mock.called)
  243. self.assertTrue(jboss7_deploy_mock.called)
  244. def test_should_redploy_undeploy_force(self):
  245. # given
  246. parameters = {
  247. "target_file": "some_artifact",
  248. "undeploy_force": True,
  249. "undeploy": "some_artifact",
  250. "source": "some_artifact_on_master",
  251. }
  252. jboss_conf = {"cli_path": "somewhere", "controller": "some_controller"}
  253. def list_deployments(jboss_config):
  254. return ["some_artifact"]
  255. def file_get_managed(
  256. name,
  257. template,
  258. source,
  259. source_hash,
  260. source_hash_name,
  261. user,
  262. group,
  263. mode,
  264. attrs,
  265. saltenv,
  266. context,
  267. defaults,
  268. skip_verify,
  269. kwargs,
  270. ):
  271. return "sfn", "hash", ""
  272. def file_manage_file(
  273. name,
  274. sfn,
  275. ret,
  276. source,
  277. source_sum,
  278. user,
  279. group,
  280. mode,
  281. attrs,
  282. saltenv,
  283. backup,
  284. makedirs,
  285. template,
  286. show_diff,
  287. contents,
  288. dir_mode,
  289. ):
  290. return {"result": True, "changes": False}
  291. jboss7_undeploy_mock = MagicMock()
  292. jboss7_deploy_mock = MagicMock()
  293. file_get_managed = MagicMock(side_effect=file_get_managed)
  294. file_manage_file = MagicMock(side_effect=file_manage_file)
  295. list_deployments_mock = MagicMock(side_effect=list_deployments)
  296. with patch.dict(
  297. jboss7.__salt__,
  298. {
  299. "jboss7.undeploy": jboss7_undeploy_mock,
  300. "jboss7.deploy": jboss7_deploy_mock,
  301. "file.get_managed": file_get_managed,
  302. "file.manage_file": file_manage_file,
  303. "jboss7.list_deployments": list_deployments_mock,
  304. },
  305. ):
  306. # when
  307. result = jboss7.deployed(
  308. name="unchanged", jboss_config=jboss_conf, salt_source=parameters
  309. )
  310. # then
  311. self.assertTrue(jboss7_undeploy_mock.called)
  312. self.assertTrue(jboss7_deploy_mock.called)
  313. def test_should_create_new_datasource_if_not_exists(self):
  314. # given
  315. datasource_properties = {"connection-url": "jdbc:/old-connection-url"}
  316. ds_status = {"created": False}
  317. def read_func(jboss_config, name, profile):
  318. if ds_status["created"]:
  319. return {"success": True, "result": datasource_properties}
  320. else:
  321. return {"success": False, "err_code": "JBAS014807"}
  322. def create_func(jboss_config, name, datasource_properties, profile):
  323. ds_status["created"] = True
  324. return {"success": True}
  325. read_mock = MagicMock(side_effect=read_func)
  326. create_mock = MagicMock(side_effect=create_func)
  327. update_mock = MagicMock()
  328. with patch.dict(
  329. jboss7.__salt__,
  330. {
  331. "jboss7.read_datasource": read_mock,
  332. "jboss7.create_datasource": create_mock,
  333. "jboss7.update_datasource": update_mock,
  334. },
  335. ):
  336. # when
  337. result = jboss7.datasource_exists(
  338. name="appDS",
  339. jboss_config={},
  340. datasource_properties=datasource_properties,
  341. profile=None,
  342. )
  343. # then
  344. create_mock.assert_called_with(
  345. name="appDS",
  346. jboss_config={},
  347. datasource_properties=datasource_properties,
  348. profile=None,
  349. )
  350. self.assertFalse(update_mock.called)
  351. self.assertEqual(result["comment"], "Datasource created.")
  352. def test_should_update_the_datasource_if_exists(self):
  353. ds_status = {"updated": False}
  354. def read_func(jboss_config, name, profile):
  355. if ds_status["updated"]:
  356. return {
  357. "success": True,
  358. "result": {"connection-url": "jdbc:/new-connection-url"},
  359. }
  360. else:
  361. return {
  362. "success": True,
  363. "result": {"connection-url": "jdbc:/old-connection-url"},
  364. }
  365. def update_func(jboss_config, name, new_properties, profile):
  366. ds_status["updated"] = True
  367. return {"success": True}
  368. read_mock = MagicMock(side_effect=read_func)
  369. create_mock = MagicMock()
  370. update_mock = MagicMock(side_effect=update_func)
  371. with patch.dict(
  372. jboss7.__salt__,
  373. {
  374. "jboss7.read_datasource": read_mock,
  375. "jboss7.create_datasource": create_mock,
  376. "jboss7.update_datasource": update_mock,
  377. },
  378. ):
  379. result = jboss7.datasource_exists(
  380. name="appDS",
  381. jboss_config={},
  382. datasource_properties={"connection-url": "jdbc:/new-connection-url"},
  383. profile=None,
  384. )
  385. update_mock.assert_called_with(
  386. name="appDS",
  387. jboss_config={},
  388. new_properties={"connection-url": "jdbc:/new-connection-url"},
  389. profile=None,
  390. )
  391. self.assertTrue(read_mock.called)
  392. self.assertEqual(result["comment"], "Datasource updated.")
  393. def test_should_recreate_the_datasource_if_specified(self):
  394. read_mock = MagicMock(
  395. return_value={
  396. "success": True,
  397. "result": {"connection-url": "jdbc:/same-connection-url"},
  398. }
  399. )
  400. create_mock = MagicMock(return_value={"success": True})
  401. remove_mock = MagicMock(return_value={"success": True})
  402. update_mock = MagicMock()
  403. with patch.dict(
  404. jboss7.__salt__,
  405. {
  406. "jboss7.read_datasource": read_mock,
  407. "jboss7.create_datasource": create_mock,
  408. "jboss7.remove_datasource": remove_mock,
  409. "jboss7.update_datasource": update_mock,
  410. },
  411. ):
  412. result = jboss7.datasource_exists(
  413. name="appDS",
  414. jboss_config={},
  415. datasource_properties={"connection-url": "jdbc:/same-connection-url"},
  416. recreate=True,
  417. )
  418. remove_mock.assert_called_with(name="appDS", jboss_config={}, profile=None)
  419. create_mock.assert_called_with(
  420. name="appDS",
  421. jboss_config={},
  422. datasource_properties={"connection-url": "jdbc:/same-connection-url"},
  423. profile=None,
  424. )
  425. self.assertEqual(result["changes"]["removed"], "appDS")
  426. self.assertEqual(result["changes"]["created"], "appDS")
  427. def test_should_inform_if_the_datasource_has_not_changed(self):
  428. read_mock = MagicMock(
  429. return_value={
  430. "success": True,
  431. "result": {"connection-url": "jdbc:/same-connection-url"},
  432. }
  433. )
  434. create_mock = MagicMock()
  435. remove_mock = MagicMock()
  436. update_mock = MagicMock(return_value={"success": True})
  437. with patch.dict(
  438. jboss7.__salt__,
  439. {
  440. "jboss7.read_datasource": read_mock,
  441. "jboss7.create_datasource": create_mock,
  442. "jboss7.remove_datasource": remove_mock,
  443. "jboss7.update_datasource": update_mock,
  444. },
  445. ):
  446. result = jboss7.datasource_exists(
  447. name="appDS",
  448. jboss_config={},
  449. datasource_properties={"connection-url": "jdbc:/old-connection-url"},
  450. )
  451. update_mock.assert_called_with(
  452. name="appDS",
  453. jboss_config={},
  454. new_properties={"connection-url": "jdbc:/old-connection-url"},
  455. profile=None,
  456. )
  457. self.assertFalse(create_mock.called)
  458. self.assertEqual(result["comment"], "Datasource not changed.")
  459. def test_should_create_binding_if_not_exists(self):
  460. # given
  461. binding_status = {"created": False}
  462. def read_func(jboss_config, binding_name, profile):
  463. if binding_status["created"]:
  464. return {"success": True, "result": {"value": "DEV"}}
  465. else:
  466. return {"success": False, "err_code": "JBAS014807"}
  467. def create_func(jboss_config, binding_name, value, profile):
  468. binding_status["created"] = True
  469. return {"success": True}
  470. read_mock = MagicMock(side_effect=read_func)
  471. create_mock = MagicMock(side_effect=create_func)
  472. update_mock = MagicMock()
  473. with patch.dict(
  474. jboss7.__salt__,
  475. {
  476. "jboss7.read_simple_binding": read_mock,
  477. "jboss7.create_simple_binding": create_mock,
  478. "jboss7.update_simple_binding": update_mock,
  479. },
  480. ):
  481. # when
  482. result = jboss7.bindings_exist(
  483. name="bindings", jboss_config={}, bindings={"env": "DEV"}, profile=None
  484. )
  485. # then
  486. create_mock.assert_called_with(
  487. jboss_config={}, binding_name="env", value="DEV", profile=None
  488. )
  489. self.assertEqual(update_mock.call_count, 0)
  490. self.assertEqual(result["changes"], {"added": "env:DEV\n"})
  491. self.assertEqual(result["comment"], "Bindings changed.")
  492. def test_should_update_bindings_if_exists_and_different(self):
  493. # given
  494. binding_status = {"updated": False}
  495. def read_func(jboss_config, binding_name, profile):
  496. if binding_status["updated"]:
  497. return {"success": True, "result": {"value": "DEV2"}}
  498. else:
  499. return {"success": True, "result": {"value": "DEV"}}
  500. def update_func(jboss_config, binding_name, value, profile):
  501. binding_status["updated"] = True
  502. return {"success": True}
  503. read_mock = MagicMock(side_effect=read_func)
  504. create_mock = MagicMock()
  505. update_mock = MagicMock(side_effect=update_func)
  506. with patch.dict(
  507. jboss7.__salt__,
  508. {
  509. "jboss7.read_simple_binding": read_mock,
  510. "jboss7.create_simple_binding": create_mock,
  511. "jboss7.update_simple_binding": update_mock,
  512. },
  513. ):
  514. # when
  515. result = jboss7.bindings_exist(
  516. name="bindings", jboss_config={}, bindings={"env": "DEV2"}, profile=None
  517. )
  518. # then
  519. update_mock.assert_called_with(
  520. jboss_config={}, binding_name="env", value="DEV2", profile=None
  521. )
  522. self.assertEqual(create_mock.call_count, 0)
  523. self.assertEqual(result["changes"], {"changed": "env:DEV->DEV2\n"})
  524. self.assertEqual(result["comment"], "Bindings changed.")
  525. def test_should_not_update_bindings_if_same(self):
  526. # given
  527. read_mock = MagicMock(
  528. return_value={"success": True, "result": {"value": "DEV2"}}
  529. )
  530. create_mock = MagicMock()
  531. update_mock = MagicMock()
  532. with patch.dict(
  533. jboss7.__salt__,
  534. {
  535. "jboss7.read_simple_binding": read_mock,
  536. "jboss7.create_simple_binding": create_mock,
  537. "jboss7.update_simple_binding": update_mock,
  538. },
  539. ):
  540. # when
  541. result = jboss7.bindings_exist(
  542. name="bindings", jboss_config={}, bindings={"env": "DEV2"}
  543. )
  544. # then
  545. self.assertEqual(create_mock.call_count, 0)
  546. self.assertEqual(update_mock.call_count, 0)
  547. self.assertEqual(result["changes"], {})
  548. self.assertEqual(result["comment"], "Bindings not changed.")
  549. def test_should_raise_exception_if_cannot_create_binding(self):
  550. def read_func(jboss_config, binding_name, profile):
  551. return {"success": False, "err_code": "JBAS014807"}
  552. def create_func(jboss_config, binding_name, value, profile):
  553. return {"success": False, "failure-description": "Incorrect binding name."}
  554. read_mock = MagicMock(side_effect=read_func)
  555. create_mock = MagicMock(side_effect=create_func)
  556. update_mock = MagicMock()
  557. with patch.dict(
  558. jboss7.__salt__,
  559. {
  560. "jboss7.read_simple_binding": read_mock,
  561. "jboss7.create_simple_binding": create_mock,
  562. "jboss7.update_simple_binding": update_mock,
  563. },
  564. ):
  565. # when
  566. try:
  567. jboss7.bindings_exist(
  568. name="bindings",
  569. jboss_config={},
  570. bindings={"env": "DEV2"},
  571. profile=None,
  572. )
  573. self.fail("An exception should be thrown")
  574. except CommandExecutionError as e:
  575. self.assertEqual(six.text_type(e), "Incorrect binding name.")
  576. def test_should_raise_exception_if_cannot_update_binding(self):
  577. def read_func(jboss_config, binding_name, profile):
  578. return {"success": True, "result": {"value": "DEV"}}
  579. def update_func(jboss_config, binding_name, value, profile):
  580. return {"success": False, "failure-description": "Incorrect binding name."}
  581. read_mock = MagicMock(side_effect=read_func)
  582. create_mock = MagicMock()
  583. update_mock = MagicMock(side_effect=update_func)
  584. with patch.dict(
  585. jboss7.__salt__,
  586. {
  587. "jboss7.read_simple_binding": read_mock,
  588. "jboss7.create_simple_binding": create_mock,
  589. "jboss7.update_simple_binding": update_mock,
  590. },
  591. ):
  592. # when
  593. try:
  594. jboss7.bindings_exist(
  595. name="bindings",
  596. jboss_config={},
  597. bindings={"env": "!@#!///some weird value"},
  598. profile=None,
  599. )
  600. self.fail("An exception should be thrown")
  601. except CommandExecutionError as e:
  602. self.assertEqual(six.text_type(e), "Incorrect binding name.")
  603. def test_datasource_exist_create_datasource_good_code(self):
  604. jboss_config = {
  605. "cli_path": "/home/ch44d/Desktop/wildfly-18.0.0.Final/bin/jboss-cli.sh",
  606. "controller": "127.0.0.1: 9990",
  607. "cli_user": "user",
  608. "cli_password": "user",
  609. }
  610. datasource_properties = {
  611. "driver - name": "h2",
  612. "connection - url": "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test_s2",
  613. "jndi - name": "java:/home/ch44d/Desktop/sqljdbc_7.4/enu/mssql-jdbc-7.4.1.jre8.jar",
  614. "user - name": "user",
  615. "password": "user",
  616. "use - java - context": True,
  617. }
  618. read_datasource = MagicMock(
  619. return_value={"success": False, "err_code": "WFLYCTL0216"}
  620. )
  621. error_msg = "Error: -1"
  622. create_datasource = MagicMock(
  623. return_value={"success": False, "stdout": error_msg}
  624. )
  625. with patch.dict(
  626. jboss7.__salt__,
  627. {
  628. "jboss7.read_datasource": read_datasource,
  629. "jboss7.create_datasource": create_datasource,
  630. },
  631. ):
  632. ret = jboss7.datasource_exists("SQL", jboss_config, datasource_properties)
  633. self.assertTrue("result" in ret)
  634. self.assertFalse(ret["result"])
  635. self.assertTrue("comment" in ret)
  636. self.assertTrue(error_msg in ret["comment"])
  637. read_datasource.assert_called_once()
  638. create_datasource.assert_called_once()
  639. def test_datasource_exist_create_datasource_bad_code(self):
  640. jboss_config = {
  641. "cli_path": "/home/ch44d/Desktop/wildfly-18.0.0.Final/bin/jboss-cli.sh",
  642. "controller": "127.0.0.1: 9990",
  643. "cli_user": "user",
  644. "cli_password": "user",
  645. }
  646. datasource_properties = {
  647. "driver - name": "h2",
  648. "connection - url": "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test_s2",
  649. "jndi - name": "java:/home/ch44d/Desktop/sqljdbc_7.4/enu/mssql-jdbc-7.4.1.jre8.jar",
  650. "user - name": "user",
  651. "password": "user",
  652. "use - java - context": True,
  653. }
  654. read_datasource = MagicMock(
  655. return_value={
  656. "success": False,
  657. "err_code": "WFLYCTL0217",
  658. "failure-description": "Something happened",
  659. }
  660. )
  661. with patch.dict(jboss7.__salt__, {"jboss7.read_datasource": read_datasource}):
  662. self.assertRaises(
  663. CommandExecutionError,
  664. jboss7.datasource_exists,
  665. "SQL",
  666. jboss_config,
  667. datasource_properties,
  668. )
  669. read_datasource.assert_called_once()