test_jboss7.py 25 KB

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