test_oozie_server.py 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. #!/usr/bin/env python
  2. '''
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. '''
  17. import json
  18. from mock.mock import MagicMock, call, patch
  19. from stacks.utils.RMFTestCase import *
  20. from resource_management.core import shell
  21. from resource_management.core.exceptions import Fail
  22. from resource_management.libraries import functions
  23. from resource_management.libraries.providers.hdfs_resource import WebHDFSUtil
  24. import hashlib
  25. md5_mock = MagicMock()
  26. md5_mock.hexdigest.return_value = "abc123hash"
  27. @patch("platform.linux_distribution", new = MagicMock(return_value="Linux"))
  28. @patch.object(hashlib, "md5", new=MagicMock(return_value=md5_mock))
  29. @patch.object(WebHDFSUtil, "run_command", new=MagicMock(return_value={}))
  30. class TestOozieServer(RMFTestCase):
  31. COMMON_SERVICES_PACKAGE_DIR = "OOZIE/4.0.0.2.0/package"
  32. STACK_VERSION = "2.0.6"
  33. UPGRADE_STACK_VERSION = "2.2"
  34. def setUp(self):
  35. self.maxDiff = None
  36. def test_configure_default(self):
  37. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  38. classname = "OozieServer",
  39. command = "configure",
  40. config_file="default.json",
  41. hdp_stack_version = self.STACK_VERSION,
  42. target = RMFTestCase.TARGET_COMMON_SERVICES
  43. )
  44. self.assert_configure_default()
  45. self.assertNoMoreResources()
  46. def test_configure_default_mysql(self):
  47. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  48. classname = "OozieServer",
  49. command = "configure",
  50. config_file="default_oozie_mysql.json",
  51. hdp_stack_version = self.STACK_VERSION,
  52. target = RMFTestCase.TARGET_COMMON_SERVICES
  53. )
  54. self.assertResourceCalled('HdfsResource', '/user/oozie',
  55. security_enabled = False,
  56. hadoop_bin_dir = '/usr/bin',
  57. keytab = UnknownConfigurationMock(),
  58. kinit_path_local = '/usr/bin/kinit',
  59. user = 'hdfs',
  60. owner = 'oozie',
  61. hadoop_conf_dir = '/etc/hadoop/conf',
  62. type = 'directory',
  63. action = ['create_on_execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020',
  64. mode = 0775,
  65. )
  66. self.assertResourceCalled('HdfsResource', None,
  67. security_enabled = False,
  68. hadoop_bin_dir = '/usr/bin',
  69. keytab = UnknownConfigurationMock(),
  70. kinit_path_local = '/usr/bin/kinit',
  71. user = 'hdfs',
  72. action = ['execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020',
  73. hadoop_conf_dir = '/etc/hadoop/conf',
  74. )
  75. self.assertResourceCalled('Directory', '/etc/oozie/conf',
  76. owner = 'oozie',
  77. group = 'hadoop',
  78. recursive = True,
  79. )
  80. self.assertResourceCalled('XmlConfig', 'oozie-site.xml',
  81. group = 'hadoop',
  82. conf_dir = '/etc/oozie/conf',
  83. mode = 0664,
  84. configuration_attributes = {u'final': {u'oozie.service.CallableQueueService.queue.size': u'true',
  85. u'oozie.service.PurgeService.purge.interval': u'true'}},
  86. owner = 'oozie',
  87. configurations = self.getConfig()['configurations']['oozie-site'],
  88. )
  89. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-env.sh',
  90. content = InlineTemplate(self.getConfig()['configurations']['oozie-env']['content']),
  91. owner = 'oozie',
  92. )
  93. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-log4j.properties',
  94. content = 'log4jproperties\nline2',
  95. owner = 'oozie',
  96. group = 'hadoop',
  97. mode = 0644,
  98. )
  99. self.assertResourceCalled('File', '/etc/oozie/conf/adminusers.txt',
  100. owner = 'oozie',
  101. group = 'hadoop',
  102. )
  103. self.assertResourceCalled('File', '/usr/lib/ambari-agent/DBConnectionVerification.jar',
  104. content = DownloadSource('http://c6401.ambari.apache.org:8080/resources/DBConnectionVerification.jar'),
  105. )
  106. self.assertResourceCalled('File', '/etc/oozie/conf/hadoop-config.xml',
  107. owner = 'oozie',
  108. group = 'hadoop',
  109. )
  110. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-default.xml',
  111. owner = 'oozie',
  112. group = 'hadoop',
  113. )
  114. self.assertResourceCalled('Directory', '/etc/oozie/conf/action-conf',
  115. owner = 'oozie',
  116. group = 'hadoop',
  117. )
  118. self.assertResourceCalled('File', '/etc/oozie/conf/action-conf/hive.xml',
  119. owner = 'oozie',
  120. group = 'hadoop',
  121. )
  122. self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
  123. action = ['delete'],
  124. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  125. )
  126. self.assertResourceCalled('Directory', '/usr/lib/oozie//var/tmp/oozie',
  127. owner = 'oozie',
  128. cd_access = 'a',
  129. group = 'hadoop',
  130. recursive = True,
  131. mode = 0755,
  132. )
  133. self.assertResourceCalled('Directory', '/var/run/oozie',
  134. owner = 'oozie',
  135. cd_access = 'a',
  136. group = 'hadoop',
  137. recursive = True,
  138. mode = 0755,
  139. )
  140. self.assertResourceCalled('Directory', '/var/log/oozie',
  141. owner = 'oozie',
  142. cd_access = 'a',
  143. group = 'hadoop',
  144. recursive = True,
  145. mode = 0755,
  146. )
  147. self.assertResourceCalled('Directory', '/var/tmp/oozie',
  148. owner = 'oozie',
  149. cd_access = 'a',
  150. group = 'hadoop',
  151. recursive = True,
  152. mode = 0755,
  153. )
  154. self.assertResourceCalled('Directory', '/hadoop/oozie/data',
  155. owner = 'oozie',
  156. cd_access = 'a',
  157. group = 'hadoop',
  158. recursive = True,
  159. mode = 0755,
  160. )
  161. self.assertResourceCalled('Directory', '/var/lib/oozie',
  162. owner = 'oozie',
  163. cd_access = 'a',
  164. group = 'hadoop',
  165. recursive = True,
  166. mode = 0755,
  167. )
  168. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/webapps/',
  169. owner = 'oozie',
  170. cd_access = 'a',
  171. group = 'hadoop',
  172. recursive = True,
  173. mode = 0755,
  174. )
  175. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/conf',
  176. owner = 'oozie',
  177. cd_access = 'a',
  178. group = 'hadoop',
  179. recursive = True,
  180. mode = 0755,
  181. )
  182. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server',
  183. owner = 'oozie',
  184. recursive = True,
  185. group = 'hadoop',
  186. mode = 0755,
  187. cd_access = 'a',
  188. )
  189. self.assertResourceCalled('Directory', '/usr/lib/oozie/libext',
  190. recursive = True,
  191. )
  192. self.assertResourceCalled('Execute', ('tar', '-xvf', '/usr/lib/oozie/oozie-sharelib.tar.gz', '-C', '/usr/lib/oozie'),
  193. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1' || test -f /usr/lib/oozie/.hashcode && test -d /usr/lib/oozie/share && [[ `cat /usr/lib/oozie/.hashcode` == 'abc123hash' ]]",
  194. sudo = True,
  195. )
  196. self.assertResourceCalled('Execute', ('cp', '/usr/share/HDP-oozie/ext-2.2.zip', '/usr/lib/oozie/libext'),
  197. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  198. sudo = True,
  199. )
  200. self.assertResourceCalled('Execute', ('chown', u'oozie:hadoop', '/usr/lib/oozie/libext/ext-2.2.zip'),
  201. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  202. sudo = True,
  203. )
  204. self.assertResourceCalled('Execute', ('chown', '-RL', u'oozie:hadoop', '/var/lib/oozie/oozie-server/conf'),
  205. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  206. sudo = True,
  207. )
  208. self.assertResourceCalled('File', '/tmp/mysql-connector-java.jar',
  209. content = DownloadSource('http://c6401.ambari.apache.org:8080/resources//mysql-jdbc-driver.jar'),
  210. )
  211. self.assertResourceCalled('Execute', ('cp',
  212. '--remove-destination',
  213. '/tmp/mysql-connector-java.jar',
  214. '/usr/lib/oozie/libext/mysql-connector-java.jar'),
  215. path = ['/bin', '/usr/bin/'],
  216. sudo = True,
  217. )
  218. self.assertResourceCalled('File', '/usr/lib/oozie/libext/mysql-connector-java.jar',
  219. owner = 'oozie',
  220. group = 'hadoop',
  221. )
  222. self.assertResourceCalled('Execute', 'ambari-sudo.sh cp /usr/lib/falcon/oozie/ext/falcon-oozie-el-extension-*.jar /usr/lib/oozie/libext',
  223. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  224. )
  225. self.assertResourceCalled('Execute', 'ambari-sudo.sh chown oozie:hadoop /usr/lib/oozie/libext/falcon-oozie-el-extension-*.jar',
  226. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  227. )
  228. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war ',
  229. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1' || test -f /usr/lib/oozie/.hashcode && test -d /usr/lib/oozie/share && [[ `cat /usr/lib/oozie/.hashcode` == 'abc123hash' ]] && test -f /usr/lib/oozie/.prepare_war_cmd && [[ `cat /usr/lib/oozie/.prepare_war_cmd` == 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war ' ]]",
  230. user = 'oozie',
  231. )
  232. self.assertResourceCalled('File', '/usr/lib/oozie/.hashcode',
  233. content = 'abc123hash',
  234. mode = 0644,
  235. )
  236. self.assertResourceCalled('File', '/usr/lib/oozie/.prepare_war_cmd',
  237. content = 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war ',
  238. mode = 0644,
  239. )
  240. self.assertResourceCalled('Execute', ('chown', '-R', u'oozie:hadoop', '/var/lib/oozie/oozie-server'),
  241. sudo = True,
  242. )
  243. @patch("os.path.isfile")
  244. def test_start_default(self, isfile_mock):
  245. isfile_mock.return_value = True
  246. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  247. classname = "OozieServer",
  248. command = "start",
  249. config_file="default.json",
  250. hdp_stack_version = self.STACK_VERSION,
  251. target = RMFTestCase.TARGET_COMMON_SERVICES
  252. )
  253. self.assert_configure_default()
  254. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/ooziedb.sh create -sqlfile oozie.sql -run',
  255. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  256. ignore_failures = True,
  257. user = 'oozie',
  258. )
  259. self.assertResourceCalled('Execute', 'hadoop --config /etc/hadoop/conf dfs -put /usr/lib/oozie/share /user/oozie',
  260. path = ['/usr/bin:/usr/bin'],
  261. user = 'oozie',
  262. )
  263. self.assertResourceCalled('HdfsResource', '/user/oozie/share',
  264. security_enabled = False,
  265. hadoop_bin_dir = '/usr/bin',
  266. keytab = UnknownConfigurationMock(),
  267. default_fs = 'hdfs://c6401.ambari.apache.org:8020',
  268. user = 'hdfs',
  269. hdfs_site = self.getConfig()['configurations']['hdfs-site'],
  270. kinit_path_local = '/usr/bin/kinit',
  271. principal_name = UnknownConfigurationMock(),
  272. recursive_chmod = True,
  273. action = ['create_on_execute'],
  274. hadoop_conf_dir = '/etc/hadoop/conf',
  275. type = 'directory',
  276. mode = 0755,
  277. )
  278. self.assertResourceCalled('HdfsResource', None,
  279. security_enabled = False,
  280. hadoop_bin_dir = '/usr/bin',
  281. keytab = UnknownConfigurationMock(),
  282. default_fs = 'hdfs://c6401.ambari.apache.org:8020',
  283. hdfs_site = self.getConfig()['configurations']['hdfs-site'],
  284. kinit_path_local = '/usr/bin/kinit',
  285. principal_name = UnknownConfigurationMock(),
  286. user = 'hdfs',
  287. action = ['execute'],
  288. hadoop_conf_dir = '/etc/hadoop/conf',
  289. )
  290. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-start.sh',
  291. environment = {'OOZIE_CONFIG': '/etc/oozie/conf'},
  292. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  293. user = 'oozie',
  294. )
  295. self.assertNoMoreResources()
  296. def test_stop_default(self):
  297. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  298. classname = "OozieServer",
  299. command = "stop",
  300. config_file="default.json",
  301. hdp_stack_version = self.STACK_VERSION,
  302. target = RMFTestCase.TARGET_COMMON_SERVICES
  303. )
  304. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-stop.sh',
  305. environment = {'OOZIE_CONFIG': '/etc/oozie/conf'},
  306. only_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  307. user = 'oozie',
  308. )
  309. self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
  310. action = ['delete'],
  311. )
  312. self.assertNoMoreResources()
  313. def test_configure_secured(self):
  314. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  315. classname = "OozieServer",
  316. command = "configure",
  317. config_file="secured.json",
  318. hdp_stack_version = self.STACK_VERSION,
  319. target = RMFTestCase.TARGET_COMMON_SERVICES
  320. )
  321. self.assert_configure_secured()
  322. self.assertNoMoreResources()
  323. @patch("os.path.isfile")
  324. def test_start_secured(self, isfile_mock):
  325. isfile_mock.return_value = True
  326. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  327. classname = "OozieServer",
  328. command = "start",
  329. config_file="secured.json",
  330. hdp_stack_version = self.STACK_VERSION,
  331. target = RMFTestCase.TARGET_COMMON_SERVICES
  332. )
  333. self.assert_configure_secured()
  334. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/ooziedb.sh create -sqlfile oozie.sql -run',
  335. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  336. ignore_failures = True,
  337. user = 'oozie',
  338. )
  339. self.assertResourceCalled('Execute', '/usr/bin/kinit -kt /etc/security/keytabs/oozie.service.keytab oozie/c6402.ambari.apache.org@EXAMPLE.COM;',
  340. user = 'oozie',
  341. )
  342. self.assertResourceCalled('Execute', 'hadoop --config /etc/hadoop/conf dfs -put /usr/lib/oozie/share /user/oozie',
  343. path = ['/usr/bin:/usr/bin'],
  344. user = 'oozie',
  345. )
  346. self.assertResourceCalled('HdfsResource', '/user/oozie/share',
  347. security_enabled = True,
  348. hadoop_bin_dir = '/usr/bin',
  349. keytab = '/etc/security/keytabs/hdfs.headless.keytab',
  350. default_fs = 'hdfs://c6401.ambari.apache.org:8020',
  351. user = 'hdfs',
  352. hdfs_site = self.getConfig()['configurations']['hdfs-site'],
  353. kinit_path_local = '/usr/bin/kinit',
  354. principal_name = 'hdfs',
  355. recursive_chmod = True,
  356. action = ['create_on_execute'],
  357. hadoop_conf_dir = '/etc/hadoop/conf',
  358. type = 'directory',
  359. mode = 0755,
  360. )
  361. self.assertResourceCalled('HdfsResource', None,
  362. security_enabled = True,
  363. hadoop_bin_dir = '/usr/bin',
  364. keytab = '/etc/security/keytabs/hdfs.headless.keytab',
  365. default_fs = 'hdfs://c6401.ambari.apache.org:8020',
  366. hdfs_site = self.getConfig()['configurations']['hdfs-site'],
  367. kinit_path_local = '/usr/bin/kinit',
  368. principal_name = 'hdfs',
  369. user = 'hdfs',
  370. action = ['execute'],
  371. hadoop_conf_dir = '/etc/hadoop/conf',
  372. )
  373. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-start.sh',
  374. environment = {'OOZIE_CONFIG': '/etc/oozie/conf'},
  375. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  376. user = 'oozie',
  377. )
  378. self.assertNoMoreResources()
  379. def test_stop_secured(self):
  380. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  381. classname = "OozieServer",
  382. command = "stop",
  383. config_file="secured.json",
  384. hdp_stack_version = self.STACK_VERSION,
  385. target = RMFTestCase.TARGET_COMMON_SERVICES
  386. )
  387. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-stop.sh',
  388. environment = {'OOZIE_CONFIG': '/etc/oozie/conf'},
  389. only_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  390. user = 'oozie',
  391. )
  392. self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
  393. action = ['delete'],
  394. )
  395. self.assertNoMoreResources()
  396. def assert_configure_default(self):
  397. self.assertResourceCalled('HdfsResource', '/user/oozie',
  398. security_enabled = False,
  399. hadoop_conf_dir = '/etc/hadoop/conf',
  400. keytab = UnknownConfigurationMock(),
  401. kinit_path_local = '/usr/bin/kinit',
  402. user = 'hdfs',
  403. owner = 'oozie',
  404. hadoop_bin_dir = '/usr/bin',
  405. type = 'directory',
  406. action = ['create_on_execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020',
  407. mode = 0775,
  408. )
  409. self.assertResourceCalled('HdfsResource', None,
  410. security_enabled = False,
  411. hadoop_bin_dir = '/usr/bin',
  412. keytab = UnknownConfigurationMock(),
  413. kinit_path_local = '/usr/bin/kinit',
  414. user = 'hdfs',
  415. action = ['execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020',
  416. hadoop_conf_dir = '/etc/hadoop/conf',
  417. )
  418. self.assertResourceCalled('Directory', '/etc/oozie/conf',
  419. owner = 'oozie',
  420. group = 'hadoop',
  421. recursive = True
  422. )
  423. self.assertResourceCalled('XmlConfig', 'oozie-site.xml',
  424. owner = 'oozie',
  425. group = 'hadoop',
  426. mode = 0664,
  427. conf_dir = '/etc/oozie/conf',
  428. configurations = self.getConfig()['configurations']['oozie-site'],
  429. configuration_attributes = self.getConfig()['configuration_attributes']['oozie-site']
  430. )
  431. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-env.sh',
  432. owner = 'oozie',
  433. content = InlineTemplate(self.getConfig()['configurations']['oozie-env']['content'])
  434. )
  435. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-log4j.properties',
  436. owner = 'oozie',
  437. group = 'hadoop',
  438. mode = 0644,
  439. content = 'log4jproperties\nline2'
  440. )
  441. self.assertResourceCalled('File', '/etc/oozie/conf/adminusers.txt',
  442. owner = 'oozie',
  443. group = 'hadoop',
  444. )
  445. self.assertResourceCalled('File', '/etc/oozie/conf/hadoop-config.xml',
  446. owner = 'oozie',
  447. group = 'hadoop',
  448. )
  449. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-default.xml',
  450. owner = 'oozie',
  451. group = 'hadoop',
  452. )
  453. self.assertResourceCalled('Directory', '/etc/oozie/conf/action-conf',
  454. owner = 'oozie',
  455. group = 'hadoop',
  456. )
  457. self.assertResourceCalled('File', '/etc/oozie/conf/action-conf/hive.xml',
  458. owner = 'oozie',
  459. group = 'hadoop',
  460. )
  461. self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
  462. action = ['delete'],
  463. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  464. )
  465. self.assertResourceCalled('Directory', '/usr/lib/oozie//var/tmp/oozie',
  466. owner = 'oozie',
  467. group = 'hadoop',
  468. recursive = True,
  469. mode = 0755,
  470. cd_access='a'
  471. )
  472. self.assertResourceCalled('Directory', '/var/run/oozie',
  473. owner = 'oozie',
  474. group = 'hadoop',
  475. recursive = True,
  476. mode = 0755,
  477. cd_access='a'
  478. )
  479. self.assertResourceCalled('Directory', '/var/log/oozie',
  480. owner = 'oozie',
  481. group = 'hadoop',
  482. recursive = True,
  483. mode = 0755,
  484. cd_access='a'
  485. )
  486. self.assertResourceCalled('Directory', '/var/tmp/oozie',
  487. owner = 'oozie',
  488. group = 'hadoop',
  489. recursive = True,
  490. mode = 0755,
  491. cd_access='a'
  492. )
  493. self.assertResourceCalled('Directory', '/hadoop/oozie/data',
  494. owner = 'oozie',
  495. group = 'hadoop',
  496. recursive = True,
  497. mode = 0755,
  498. cd_access='a'
  499. )
  500. self.assertResourceCalled('Directory', '/var/lib/oozie',
  501. owner = 'oozie',
  502. group = 'hadoop',
  503. recursive = True,
  504. mode = 0755,
  505. cd_access='a'
  506. )
  507. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/webapps/',
  508. owner = 'oozie',
  509. group = 'hadoop',
  510. recursive = True,
  511. mode = 0755,
  512. cd_access='a'
  513. )
  514. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/conf',
  515. owner = 'oozie',
  516. group = 'hadoop',
  517. recursive = True,
  518. mode = 0755,
  519. cd_access='a'
  520. )
  521. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server',
  522. owner = 'oozie',
  523. group = 'hadoop',
  524. recursive = True,
  525. mode = 0755,
  526. cd_access='a'
  527. )
  528. self.assertResourceCalled('Directory', '/usr/lib/oozie/libext',
  529. recursive = True,
  530. )
  531. self.assertResourceCalled('Execute', ('tar', '-xvf', '/usr/lib/oozie/oozie-sharelib.tar.gz', '-C', '/usr/lib/oozie'),
  532. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1' || test -f /usr/lib/oozie/.hashcode && test -d /usr/lib/oozie/share && [[ `cat /usr/lib/oozie/.hashcode` == 'abc123hash' ]]",
  533. sudo = True,
  534. )
  535. self.assertResourceCalled('Execute', ('cp', '/usr/share/HDP-oozie/ext-2.2.zip', '/usr/lib/oozie/libext'),
  536. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  537. sudo = True,
  538. )
  539. self.assertResourceCalled('Execute', ('chown', u'oozie:hadoop', '/usr/lib/oozie/libext/ext-2.2.zip'),
  540. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  541. sudo = True,
  542. )
  543. self.assertResourceCalled('Execute', ('chown', '-RL', u'oozie:hadoop', '/var/lib/oozie/oozie-server/conf'),
  544. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  545. sudo = True,
  546. )
  547. self.assertResourceCalled('Execute', 'ambari-sudo.sh cp /usr/lib/falcon/oozie/ext/falcon-oozie-el-extension-*.jar /usr/lib/oozie/libext',
  548. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  549. )
  550. self.assertResourceCalled('Execute', 'ambari-sudo.sh chown oozie:hadoop /usr/lib/oozie/libext/falcon-oozie-el-extension-*.jar',
  551. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  552. )
  553. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war ',
  554. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1' || test -f /usr/lib/oozie/.hashcode && test -d /usr/lib/oozie/share && [[ `cat /usr/lib/oozie/.hashcode` == 'abc123hash' ]] && test -f /usr/lib/oozie/.prepare_war_cmd && [[ `cat /usr/lib/oozie/.prepare_war_cmd` == 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war ' ]]",
  555. user = 'oozie',
  556. )
  557. self.assertResourceCalled('File', '/usr/lib/oozie/.hashcode',
  558. content = 'abc123hash',
  559. mode = 0644,
  560. )
  561. self.assertResourceCalled('File', '/usr/lib/oozie/.prepare_war_cmd',
  562. content = 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war ',
  563. mode = 0644,
  564. )
  565. self.assertResourceCalled('Execute', ('chown', '-R', u'oozie:hadoop', '/var/lib/oozie/oozie-server'),
  566. sudo = True,
  567. )
  568. def assert_configure_secured(self):
  569. self.assertResourceCalled('HdfsResource', '/user/oozie',
  570. security_enabled = True,
  571. hadoop_conf_dir = '/etc/hadoop/conf',
  572. keytab = '/etc/security/keytabs/hdfs.headless.keytab',
  573. kinit_path_local = '/usr/bin/kinit',
  574. user = 'hdfs',
  575. owner = 'oozie',
  576. hadoop_bin_dir = '/usr/bin',
  577. type = 'directory',
  578. action = ['create_on_execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name='hdfs', default_fs='hdfs://c6401.ambari.apache.org:8020',
  579. mode = 0775,
  580. )
  581. self.assertResourceCalled('HdfsResource', None,
  582. security_enabled = True,
  583. hadoop_bin_dir = '/usr/bin',
  584. keytab = '/etc/security/keytabs/hdfs.headless.keytab',
  585. kinit_path_local = '/usr/bin/kinit',
  586. user = 'hdfs',
  587. action = ['execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name='hdfs', default_fs='hdfs://c6401.ambari.apache.org:8020',
  588. hadoop_conf_dir = '/etc/hadoop/conf',
  589. )
  590. self.assertResourceCalled('Directory', '/etc/oozie/conf',
  591. owner = 'oozie',
  592. group = 'hadoop',
  593. recursive = True
  594. )
  595. self.assertResourceCalled('XmlConfig', 'oozie-site.xml',
  596. owner = 'oozie',
  597. group = 'hadoop',
  598. mode = 0664,
  599. conf_dir = '/etc/oozie/conf',
  600. configurations = self.getConfig()['configurations']['oozie-site'],
  601. configuration_attributes = self.getConfig()['configuration_attributes']['oozie-site']
  602. )
  603. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-env.sh',
  604. owner = 'oozie',
  605. content = InlineTemplate(self.getConfig()['configurations']['oozie-env']['content'])
  606. )
  607. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-log4j.properties',
  608. owner = 'oozie',
  609. group = 'hadoop',
  610. mode = 0644,
  611. content = 'log4jproperties\nline2'
  612. )
  613. self.assertResourceCalled('File', '/etc/oozie/conf/adminusers.txt',
  614. owner = 'oozie',
  615. group = 'hadoop',
  616. )
  617. self.assertResourceCalled('File', '/etc/oozie/conf/hadoop-config.xml',
  618. owner = 'oozie',
  619. group = 'hadoop',
  620. )
  621. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-default.xml',
  622. owner = 'oozie',
  623. group = 'hadoop',
  624. )
  625. self.assertResourceCalled('Directory', '/etc/oozie/conf/action-conf',
  626. owner = 'oozie',
  627. group = 'hadoop',
  628. )
  629. self.assertResourceCalled('File', '/etc/oozie/conf/action-conf/hive.xml',
  630. owner = 'oozie',
  631. group = 'hadoop',
  632. )
  633. self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
  634. action = ['delete'],
  635. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  636. )
  637. self.assertResourceCalled('Directory', '/usr/lib/oozie//var/tmp/oozie',
  638. owner = 'oozie',
  639. group = 'hadoop',
  640. recursive = True,
  641. mode = 0755,
  642. cd_access='a'
  643. )
  644. self.assertResourceCalled('Directory', '/var/run/oozie',
  645. owner = 'oozie',
  646. group = 'hadoop',
  647. recursive = True,
  648. mode = 0755,
  649. cd_access='a'
  650. )
  651. self.assertResourceCalled('Directory', '/var/log/oozie',
  652. owner = 'oozie',
  653. group = 'hadoop',
  654. recursive = True,
  655. mode = 0755,
  656. cd_access='a'
  657. )
  658. self.assertResourceCalled('Directory', '/var/tmp/oozie',
  659. owner = 'oozie',
  660. group = 'hadoop',
  661. recursive = True,
  662. mode = 0755,
  663. cd_access='a'
  664. )
  665. self.assertResourceCalled('Directory', '/hadoop/oozie/data',
  666. owner = 'oozie',
  667. group = 'hadoop',
  668. recursive = True,
  669. mode = 0755,
  670. cd_access='a'
  671. )
  672. self.assertResourceCalled('Directory', '/var/lib/oozie',
  673. owner = 'oozie',
  674. group = 'hadoop',
  675. recursive = True,
  676. mode = 0755,
  677. cd_access='a'
  678. )
  679. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/webapps/',
  680. owner = 'oozie',
  681. group = 'hadoop',
  682. recursive = True,
  683. mode = 0755,
  684. cd_access='a'
  685. )
  686. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/conf',
  687. owner = 'oozie',
  688. group = 'hadoop',
  689. recursive = True,
  690. mode = 0755,
  691. cd_access='a'
  692. )
  693. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server',
  694. owner = 'oozie',
  695. group = 'hadoop',
  696. recursive = True,
  697. mode = 0755,
  698. cd_access='a'
  699. )
  700. self.assertResourceCalled('Directory', '/usr/lib/oozie/libext',
  701. recursive = True,
  702. )
  703. self.assertResourceCalled('Execute', ('tar', '-xvf', '/usr/lib/oozie/oozie-sharelib.tar.gz', '-C', '/usr/lib/oozie'),
  704. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1' || test -f /usr/lib/oozie/.hashcode && test -d /usr/lib/oozie/share && [[ `cat /usr/lib/oozie/.hashcode` == 'abc123hash' ]]",
  705. sudo = True,
  706. )
  707. self.assertResourceCalled('Execute', ('cp', '/usr/share/HDP-oozie/ext-2.2.zip', '/usr/lib/oozie/libext'),
  708. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  709. sudo = True,
  710. )
  711. self.assertResourceCalled('Execute', ('chown', u'oozie:hadoop', '/usr/lib/oozie/libext/ext-2.2.zip'),
  712. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  713. sudo = True,
  714. )
  715. self.assertResourceCalled('Execute', ('chown', '-RL', u'oozie:hadoop', '/var/lib/oozie/oozie-server/conf'),
  716. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  717. sudo = True,
  718. )
  719. self.assertResourceCalled('Execute', 'ambari-sudo.sh cp /usr/lib/falcon/oozie/ext/falcon-oozie-el-extension-*.jar /usr/lib/oozie/libext',
  720. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  721. )
  722. self.assertResourceCalled('Execute', 'ambari-sudo.sh chown oozie:hadoop /usr/lib/oozie/libext/falcon-oozie-el-extension-*.jar',
  723. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1'",
  724. )
  725. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war -secure',
  726. not_if = "ambari-sudo.sh su oozie -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1' || test -f /usr/lib/oozie/.hashcode && test -d /usr/lib/oozie/share && [[ `cat /usr/lib/oozie/.hashcode` == 'abc123hash' ]] && test -f /usr/lib/oozie/.prepare_war_cmd && [[ `cat /usr/lib/oozie/.prepare_war_cmd` == 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war -secure' ]]",
  727. user = 'oozie',
  728. )
  729. self.assertResourceCalled('File', '/usr/lib/oozie/.hashcode',
  730. content = 'abc123hash',
  731. mode = 0644,
  732. )
  733. self.assertResourceCalled('File', '/usr/lib/oozie/.prepare_war_cmd',
  734. content = 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war -secure',
  735. mode = 0644,
  736. )
  737. self.assertResourceCalled('Execute', ('chown', '-R', u'oozie:hadoop', '/var/lib/oozie/oozie-server'),
  738. sudo = True,
  739. )
  740. def test_configure_default_hdp22(self):
  741. config_file = "stacks/2.0.6/configs/default.json"
  742. with open(config_file, "r") as f:
  743. default_json = json.load(f)
  744. default_json['hostLevelParams']['stack_version']= '2.2'
  745. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  746. classname = "OozieServer",
  747. command = "configure",
  748. config_file="default.json",
  749. hdp_stack_version = self.STACK_VERSION,
  750. target = RMFTestCase.TARGET_COMMON_SERVICES
  751. )
  752. self.assert_configure_default()
  753. self.assertResourceCalled('Directory', '/etc/oozie/conf/action-conf/hive',
  754. owner = 'oozie',
  755. group = 'hadoop',
  756. recursive = True
  757. )
  758. self.assertResourceCalled('XmlConfig', 'hive-site',
  759. owner = 'oozie',
  760. group = 'hadoop',
  761. mode = 0664,
  762. conf_dir = '/etc/oozie/conf/action-conf/hive',
  763. configurations = self.getConfig()['configurations']['hive-site'],
  764. configuration_attributes = self.getConfig()['configuration_attributes']['hive-site']
  765. )
  766. self.assertResourceCalled('XmlConfig', 'tez-site',
  767. owner = 'oozie',
  768. group = 'hadoop',
  769. mode = 0664,
  770. conf_dir = '/etc/oozie/conf/action-conf/hive',
  771. configurations = self.getConfig()['configurations']['tez-site'],
  772. configuration_attributes = self.getConfig()['configuration_attributes']['tez-site']
  773. )
  774. self.assertNoMoreResources()
  775. @patch("resource_management.libraries.functions.security_commons.build_expectations")
  776. @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem")
  777. @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties")
  778. @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor")
  779. @patch("resource_management.libraries.script.Script.put_structured_out")
  780. def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock):
  781. # Test that function works when is called with correct parameters
  782. security_params = {
  783. "oozie-site": {
  784. "oozie.authentication.type": "kerberos",
  785. "oozie.service.AuthorizationService.security.enabled": "true",
  786. "oozie.service.HadoopAccessorService.kerberos.enabled": "true",
  787. "local.realm": "EXAMPLE.COM",
  788. "oozie.authentication.kerberos.principal": "principal",
  789. "oozie.authentication.kerberos.keytab": "/path/to_keytab",
  790. "oozie.service.HadoopAccessorService.kerberos.principal": "principal",
  791. "oozie.service.HadoopAccessorService.keytab.file": "/path/to_keytab"}
  792. }
  793. result_issues = []
  794. props_value_check = {"oozie.authentication.type": "kerberos",
  795. "oozie.service.AuthorizationService.security.enabled": "true",
  796. "oozie.service.HadoopAccessorService.kerberos.enabled": "true"}
  797. props_empty_check = [ "local.realm",
  798. "oozie.authentication.kerberos.principal",
  799. "oozie.authentication.kerberos.keytab",
  800. "oozie.service.HadoopAccessorService.kerberos.principal",
  801. "oozie.service.HadoopAccessorService.keytab.file"]
  802. props_read_check = None
  803. get_params_mock.return_value = security_params
  804. validate_security_config_mock.return_value = result_issues
  805. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  806. classname = "OozieServer",
  807. command = "security_status",
  808. config_file="secured.json",
  809. hdp_stack_version = self.STACK_VERSION,
  810. target = RMFTestCase.TARGET_COMMON_SERVICES
  811. )
  812. get_params_mock.assert_called_with("/etc/oozie/conf", {'oozie-site.xml': 'XML'})
  813. build_exp_mock.assert_called_with('oozie-site', props_value_check, props_empty_check, props_read_check)
  814. put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"})
  815. self.assertTrue(cached_kinit_executor_mock.call_count, 2)
  816. cached_kinit_executor_mock.assert_called_with('/usr/bin/kinit',
  817. self.config_dict['configurations']['oozie-env']['oozie_user'],
  818. security_params['oozie-site']['oozie.service.HadoopAccessorService.keytab.file'],
  819. security_params['oozie-site']['oozie.service.HadoopAccessorService.kerberos.principal'],
  820. self.config_dict['hostname'],
  821. '/tmp')
  822. # Testing that the exception throw by cached_executor is caught
  823. cached_kinit_executor_mock.reset_mock()
  824. cached_kinit_executor_mock.side_effect = Exception("Invalid command")
  825. try:
  826. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  827. classname = "OozieServer",
  828. command = "security_status",
  829. config_file="secured.json",
  830. hdp_stack_version = self.STACK_VERSION,
  831. target = RMFTestCase.TARGET_COMMON_SERVICES
  832. )
  833. except:
  834. self.assertTrue(True)
  835. # Testing with a security_params which doesn't contains oozie-site
  836. empty_security_params = {}
  837. cached_kinit_executor_mock.reset_mock()
  838. get_params_mock.reset_mock()
  839. put_structured_out_mock.reset_mock()
  840. get_params_mock.return_value = empty_security_params
  841. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  842. classname = "OozieServer",
  843. command = "security_status",
  844. config_file="secured.json",
  845. hdp_stack_version = self.STACK_VERSION,
  846. target = RMFTestCase.TARGET_COMMON_SERVICES
  847. )
  848. put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."})
  849. # Testing with not empty result_issues
  850. result_issues_with_params = {
  851. 'oozie-site': "Something bad happened"
  852. }
  853. validate_security_config_mock.reset_mock()
  854. get_params_mock.reset_mock()
  855. validate_security_config_mock.return_value = result_issues_with_params
  856. get_params_mock.return_value = security_params
  857. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  858. classname = "OozieServer",
  859. command = "security_status",
  860. config_file="secured.json",
  861. hdp_stack_version = self.STACK_VERSION,
  862. target = RMFTestCase.TARGET_COMMON_SERVICES
  863. )
  864. put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"})
  865. # Testing with security_enable = false
  866. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  867. classname = "OozieServer",
  868. command = "security_status",
  869. config_file="default.json",
  870. hdp_stack_version = self.STACK_VERSION,
  871. target = RMFTestCase.TARGET_COMMON_SERVICES
  872. )
  873. put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"})
  874. @patch("tarfile.open")
  875. @patch("os.path.isdir")
  876. @patch("os.path.exists")
  877. @patch("os.path.isfile")
  878. @patch("os.remove")
  879. @patch("os.chmod")
  880. @patch("shutil.rmtree", new = MagicMock())
  881. @patch("glob.iglob")
  882. @patch("shutil.copy2", new = MagicMock())
  883. def test_upgrade(self, glob_mock, chmod_mock, remove_mock,
  884. isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
  885. def exists_mock_side_effect(path):
  886. if path == '/tmp/oozie-upgrade-backup/oozie-conf-backup.tar':
  887. return True
  888. return False
  889. exists_mock.side_effect = exists_mock_side_effect
  890. isdir_mock.return_value = True
  891. isfile_mock.return_value = True
  892. glob_mock.return_value = ["/usr/hdp/2.2.1.0-2187/hadoop/lib/hadoop-lzo-0.6.0.2.2.1.0-2187.jar"]
  893. prepare_war_stdout = """INFO: Adding extension: libext/mysql-connector-java.jar
  894. New Oozie WAR file with added 'JARs' at /var/lib/oozie/oozie-server/webapps/oozie.war"""
  895. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  896. classname = "OozieServer", command = "pre_rolling_restart", config_file = "oozie-upgrade.json",
  897. hdp_stack_version = self.UPGRADE_STACK_VERSION,
  898. target = RMFTestCase.TARGET_COMMON_SERVICES,
  899. call_mocks = [(0, prepare_war_stdout)]
  900. )
  901. # 2 calls to tarfile.open (1 directories, read + write)
  902. self.assertTrue(tarfile_open_mock.called)
  903. self.assertEqual(tarfile_open_mock.call_count,2)
  904. # check the call args for creation of the tarfile
  905. call_args = tarfile_open_mock.call_args_list[0]
  906. call_argument_tarfile = call_args[0][0]
  907. call_kwargs = call_args[1]
  908. self.assertTrue("oozie-upgrade-backup/oozie-conf-backup.tar" in call_argument_tarfile)
  909. self.assertEquals(True, call_kwargs["dereference"])
  910. self.assertTrue(chmod_mock.called)
  911. self.assertEqual(chmod_mock.call_count,1)
  912. chmod_mock.assert_called_once_with('/usr/hdp/current/oozie-server/libext-customer', 511)
  913. self.assertTrue(isfile_mock.called)
  914. self.assertEqual(isfile_mock.call_count,3)
  915. isfile_mock.assert_called_with('/usr/share/HDP-oozie/ext-2.2.zip')
  916. self.assertTrue(glob_mock.called)
  917. self.assertEqual(glob_mock.call_count,1)
  918. glob_mock.assert_called_with('/usr/hdp/2.2.1.0-2135/hadoop/lib/hadoop-lzo*.jar')
  919. self.assertResourceCalled('Execute', ('hdp-select', 'set', 'oozie-server', '2.2.1.0-2135'), sudo=True,)
  920. self.assertNoMoreResources()
  921. @patch("tarfile.open")
  922. @patch("os.path.isdir")
  923. @patch("os.path.exists")
  924. @patch("os.path.isfile")
  925. @patch("os.remove")
  926. @patch("os.chmod")
  927. @patch("shutil.rmtree", new = MagicMock())
  928. @patch("glob.iglob")
  929. @patch("shutil.copy2", new = MagicMock())
  930. def test_upgrade_23(self, glob_mock, chmod_mock, remove_mock,
  931. isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
  932. def exists_mock_side_effect(path):
  933. if path == '/tmp/oozie-upgrade-backup/oozie-conf-backup.tar':
  934. return True
  935. return False
  936. isdir_mock.return_value = True
  937. exists_mock.side_effect = exists_mock_side_effect
  938. isfile_mock.return_value = True
  939. glob_mock.return_value = ["/usr/hdp/2.2.1.0-2187/hadoop/lib/hadoop-lzo-0.6.0.2.2.1.0-2187.jar"]
  940. prepare_war_stdout = """INFO: Adding extension: libext/mysql-connector-java.jar
  941. New Oozie WAR file with added 'JARs' at /var/lib/oozie/oozie-server/webapps/oozie.war"""
  942. config_file = self.get_src_folder()+"/test/python/stacks/2.2/configs/oozie-upgrade.json"
  943. with open(config_file, "r") as f:
  944. json_content = json.load(f)
  945. version = '2.3.0.0-1234'
  946. json_content['commandParams']['version'] = version
  947. mocks_dict = {}
  948. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  949. classname = "OozieServer", command = "pre_rolling_restart", config_dict = json_content,
  950. hdp_stack_version = self.UPGRADE_STACK_VERSION,
  951. target = RMFTestCase.TARGET_COMMON_SERVICES,
  952. call_mocks = [(0, None), (0, prepare_war_stdout)],
  953. mocks_dict = mocks_dict
  954. )
  955. # 2 calls to tarfile.open (1 directories, read + write)
  956. self.assertTrue(tarfile_open_mock.called)
  957. self.assertEqual(tarfile_open_mock.call_count,2)
  958. self.assertTrue(chmod_mock.called)
  959. self.assertEqual(chmod_mock.call_count,1)
  960. chmod_mock.assert_called_once_with('/usr/hdp/current/oozie-server/libext-customer', 511)
  961. self.assertTrue(isfile_mock.called)
  962. self.assertEqual(isfile_mock.call_count,3)
  963. isfile_mock.assert_called_with('/usr/share/HDP-oozie/ext-2.2.zip')
  964. self.assertTrue(glob_mock.called)
  965. self.assertEqual(glob_mock.call_count,1)
  966. glob_mock.assert_called_with('/usr/hdp/2.3.0.0-1234/hadoop/lib/hadoop-lzo*.jar')
  967. self.assertResourceCalled('Execute', ('hdp-select', 'set', 'oozie-server', '2.3.0.0-1234'), sudo=True)
  968. self.assertNoMoreResources()
  969. self.assertEquals(2, mocks_dict['call'].call_count)
  970. self.assertEquals(1, mocks_dict['checked_call'].call_count)
  971. self.assertEquals(
  972. ('conf-select', 'set-conf-dir', '--package', 'oozie', '--stack-version', '2.3.0.0-1234', '--conf-version', '0'),
  973. mocks_dict['checked_call'].call_args_list[0][0][0])
  974. self.assertEquals(
  975. ('conf-select', 'create-conf-dir', '--package', 'oozie', '--stack-version', '2.3.0.0-1234', '--conf-version', '0'),
  976. mocks_dict['call'].call_args_list[0][0][0])
  977. @patch("tarfile.open")
  978. @patch("os.path.isdir")
  979. @patch("os.path.exists")
  980. @patch("os.path.isfile")
  981. @patch("os.remove")
  982. @patch("os.chmod")
  983. @patch("shutil.rmtree", new = MagicMock())
  984. @patch("shutil.copy2", new = MagicMock())
  985. def test_downgrade_no_compression_library_copy(self, chmod_mock, remove_mock,
  986. isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
  987. isdir_mock.return_value = True
  988. exists_mock.return_value = False
  989. isfile_mock.return_value = True
  990. prepare_war_stdout = """INFO: Adding extension: libext/mysql-connector-java.jar
  991. New Oozie WAR file with added 'JARs' at /var/lib/oozie/oozie-server/webapps/oozie.war"""
  992. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  993. classname = "OozieServer", command = "pre_rolling_restart", config_file = "oozie-downgrade.json",
  994. hdp_stack_version = self.UPGRADE_STACK_VERSION,
  995. target = RMFTestCase.TARGET_COMMON_SERVICES,
  996. call_mocks = [(0, prepare_war_stdout)])
  997. # 2 calls to tarfile.open (1 directories, read + write)
  998. self.assertTrue(tarfile_open_mock.called)
  999. self.assertEqual(tarfile_open_mock.call_count,2)
  1000. self.assertTrue(chmod_mock.called)
  1001. self.assertEqual(chmod_mock.call_count,1)
  1002. chmod_mock.assert_called_once_with('/usr/hdp/current/oozie-server/libext-customer', 511)
  1003. self.assertTrue(isfile_mock.called)
  1004. self.assertEqual(isfile_mock.call_count,2)
  1005. isfile_mock.assert_called_with('/usr/share/HDP-oozie/ext-2.2.zip')
  1006. self.assertResourceCalled('Execute', ('hdp-select', 'set', 'oozie-server', '2.2.0.0-0000'), sudo=True)
  1007. self.assertNoMoreResources()
  1008. @patch("tarfile.open")
  1009. @patch("os.path.isdir")
  1010. @patch("os.path.exists")
  1011. @patch("os.path.isfile")
  1012. @patch("os.remove")
  1013. @patch("os.chmod")
  1014. @patch("shutil.rmtree", new = MagicMock())
  1015. @patch("glob.iglob", new = MagicMock(return_value=["/usr/hdp/2.2.1.0-2187/hadoop/lib/hadoop-lzo-0.6.0.2.2.1.0-2187.jar"]))
  1016. @patch("shutil.copy2")
  1017. def test_upgrade_failed_prepare_war(self, shutil_copy_mock, chmod_mock, remove_mock,
  1018. isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
  1019. isdir_mock.return_value = True
  1020. exists_mock.return_value = False
  1021. isfile_mock.return_value = True
  1022. try:
  1023. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  1024. classname = "OozieServer", command = "pre_rolling_restart", config_file = "oozie-upgrade.json",
  1025. hdp_stack_version = self.UPGRADE_STACK_VERSION,
  1026. target = RMFTestCase.TARGET_COMMON_SERVICES )
  1027. self.fail("An invalid WAR preparation should have caused an error")
  1028. except Fail,f:
  1029. pass
  1030. def test_upgrade_database_sharelib(self):
  1031. """
  1032. Tests that the upgrade script runs the proper commands before the
  1033. actual upgrade begins.
  1034. :return:
  1035. """
  1036. config_file = self.get_src_folder()+"/test/python/stacks/2.2/configs/oozie-upgrade.json"
  1037. with open(config_file, "r") as f:
  1038. json_content = json.load(f)
  1039. version = '2.3.0.0-1234'
  1040. json_content['commandParams']['version'] = version
  1041. json_content['hostLevelParams']['stack_name'] = "HDP"
  1042. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server_upgrade.py",
  1043. classname = "OozieUpgrade", command = "upgrade_oozie_database_and_sharelib",
  1044. config_dict = json_content,
  1045. hdp_stack_version = self.UPGRADE_STACK_VERSION,
  1046. target = RMFTestCase.TARGET_COMMON_SERVICES )
  1047. self.assertResourceCalled('Execute', '/usr/hdp/2.3.0.0-1234/oozie/bin/ooziedb.sh upgrade -run',
  1048. user = 'oozie', logoutput = True )
  1049. self.assertResourceCalled('HdfsResource', '/user/oozie/share',
  1050. security_enabled = False,
  1051. hadoop_bin_dir = '/usr/hdp/2.3.0.0-1234/hadoop/bin',
  1052. keytab = UnknownConfigurationMock(),
  1053. default_fs = 'hdfs://c6401.ambari.apache.org:8020',
  1054. user = 'hdfs',
  1055. hdfs_site = UnknownConfigurationMock(),
  1056. kinit_path_local = '/usr/bin/kinit',
  1057. principal_name = UnknownConfigurationMock(),
  1058. recursive_chmod = True,
  1059. owner = 'oozie',
  1060. group = 'hadoop',
  1061. hadoop_conf_dir = '/usr/hdp/current/hadoop-client/conf',
  1062. type = 'directory',
  1063. action = ['create_on_execute'],
  1064. mode = 0755 )
  1065. self.assertResourceCalled('HdfsResource', None,
  1066. security_enabled = False,
  1067. hadoop_bin_dir = '/usr/hdp/2.3.0.0-1234/hadoop/bin',
  1068. keytab = UnknownConfigurationMock(),
  1069. default_fs = 'hdfs://c6401.ambari.apache.org:8020',
  1070. hdfs_site = UnknownConfigurationMock(),
  1071. kinit_path_local = '/usr/bin/kinit',
  1072. principal_name = UnknownConfigurationMock(),
  1073. user = 'hdfs',
  1074. action = ['execute'],
  1075. hadoop_conf_dir = '/usr/hdp/current/hadoop-client/conf' )
  1076. self.assertResourceCalled('Execute', '/usr/hdp/2.3.0.0-1234/oozie/bin/oozie-setup.sh sharelib create -fs hdfs://c6401.ambari.apache.org:8020',
  1077. user='oozie', logoutput = True)
  1078. def test_upgrade_database_sharelib_existing_mysql(self):
  1079. """
  1080. Tests that the upgrade script runs the proper commands before the
  1081. actual upgrade begins when Oozie is using and external database. This
  1082. should ensure that the JDBC JAR is copied.
  1083. :return:
  1084. """
  1085. config_file = self.get_src_folder()+"/test/python/stacks/2.2/configs/oozie-upgrade.json"
  1086. with open(config_file, "r") as f:
  1087. json_content = json.load(f)
  1088. version = '2.3.0.0-1234'
  1089. json_content['commandParams']['version'] = version
  1090. json_content['hostLevelParams']['stack_name'] = "HDP"
  1091. # use mysql external database
  1092. json_content['configurations']['oozie-site']['oozie.service.JPAService.jdbc.driver'] = "com.mysql.jdbc.Driver"
  1093. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server_upgrade.py",
  1094. classname = "OozieUpgrade", command = "upgrade_oozie_database_and_sharelib",
  1095. config_dict = json_content,
  1096. hdp_stack_version = self.UPGRADE_STACK_VERSION,
  1097. target = RMFTestCase.TARGET_COMMON_SERVICES )
  1098. self.assertResourceCalled('File', '/tmp/mysql-connector-java.jar',
  1099. content = DownloadSource('http://c6401.ambari.apache.org:8080/resources//mysql-jdbc-driver.jar') )
  1100. self.assertResourceCalled('Execute', ('cp', '--remove-destination', '/tmp/mysql-connector-java.jar',
  1101. '/usr/hdp/2.3.0.0-1234/oozie/libext/mysql-connector-java.jar'),
  1102. path = ['/bin', '/usr/bin/'], sudo = True)
  1103. self.assertResourceCalled('File', '/usr/hdp/2.3.0.0-1234/oozie/libext/mysql-connector-java.jar',
  1104. owner = 'oozie', group = 'hadoop' )
  1105. self.assertResourceCalled('Execute', '/usr/hdp/2.3.0.0-1234/oozie/bin/ooziedb.sh upgrade -run',
  1106. user = 'oozie', logoutput = True )
  1107. self.assertResourceCalled('HdfsResource', '/user/oozie/share',
  1108. security_enabled = False,
  1109. hadoop_bin_dir = '/usr/hdp/2.3.0.0-1234/hadoop/bin',
  1110. keytab = UnknownConfigurationMock(),
  1111. default_fs = 'hdfs://c6401.ambari.apache.org:8020',
  1112. user = 'hdfs',
  1113. hdfs_site = UnknownConfigurationMock(),
  1114. kinit_path_local = '/usr/bin/kinit',
  1115. principal_name = UnknownConfigurationMock(),
  1116. recursive_chmod = True,
  1117. owner = 'oozie',
  1118. group = 'hadoop',
  1119. hadoop_conf_dir = '/usr/hdp/current/hadoop-client/conf',
  1120. type = 'directory',
  1121. action = ['create_on_execute'],
  1122. mode = 0755 )
  1123. self.assertResourceCalled('HdfsResource', None,
  1124. security_enabled = False,
  1125. hadoop_bin_dir = '/usr/hdp/2.3.0.0-1234/hadoop/bin',
  1126. keytab = UnknownConfigurationMock(),
  1127. default_fs = 'hdfs://c6401.ambari.apache.org:8020',
  1128. hdfs_site = UnknownConfigurationMock(),
  1129. kinit_path_local = '/usr/bin/kinit',
  1130. principal_name = UnknownConfigurationMock(),
  1131. user = 'hdfs',
  1132. action = ['execute'],
  1133. hadoop_conf_dir = '/usr/hdp/current/hadoop-client/conf' )
  1134. self.assertResourceCalled('Execute', '/usr/hdp/2.3.0.0-1234/oozie/bin/oozie-setup.sh sharelib create -fs hdfs://c6401.ambari.apache.org:8020',
  1135. user='oozie', logoutput = True)