test_oozie_server.py 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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. from mock.mock import MagicMock, call, patch
  18. from stacks.utils.RMFTestCase import *
  19. from resource_management.core import shell
  20. from resource_management.core.exceptions import Fail
  21. class TestOozieServer(RMFTestCase):
  22. COMMON_SERVICES_PACKAGE_DIR = "OOZIE/4.0.0.2.0/package"
  23. STACK_VERSION = "2.0.6"
  24. UPGRADE_STACK_VERSION = "2.2"
  25. def test_configure_default(self):
  26. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  27. classname = "OozieServer",
  28. command = "configure",
  29. config_file="default.json",
  30. hdp_stack_version = self.STACK_VERSION,
  31. target = RMFTestCase.TARGET_COMMON_SERVICES
  32. )
  33. self.assert_configure_default()
  34. self.assertNoMoreResources()
  35. @patch("os.path.isfile")
  36. def test_start_default(self, isfile_mock):
  37. isfile_mock.return_value = True
  38. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  39. classname = "OozieServer",
  40. command = "start",
  41. config_file="default.json",
  42. hdp_stack_version = self.STACK_VERSION,
  43. target = RMFTestCase.TARGET_COMMON_SERVICES
  44. )
  45. self.assert_configure_default()
  46. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/ooziedb.sh create -sqlfile oozie.sql -run',
  47. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  48. ignore_failures = True,
  49. user = 'oozie',
  50. )
  51. self.assertResourceCalled('Execute', ' hadoop --config /etc/hadoop/conf dfs -put /usr/lib/oozie/share /user/oozie ; hadoop --config /etc/hadoop/conf dfs -chmod -R 755 /user/oozie/share',
  52. not_if = " hadoop --config /etc/hadoop/conf dfs -ls /user/oozie/share | awk 'BEGIN {count=0;} /share/ {count++} END {if (count > 0) {exit 0} else {exit 1}}'",
  53. user = 'oozie',
  54. path = ['/usr/bin:/usr/bin'],
  55. )
  56. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-start.sh',
  57. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  58. user = 'oozie',
  59. )
  60. self.assertNoMoreResources()
  61. def test_stop_default(self):
  62. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  63. classname = "OozieServer",
  64. command = "stop",
  65. config_file="default.json",
  66. hdp_stack_version = self.STACK_VERSION,
  67. target = RMFTestCase.TARGET_COMMON_SERVICES
  68. )
  69. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-stop.sh',
  70. only_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  71. user = 'oozie',
  72. )
  73. self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
  74. action = ['delete'],
  75. )
  76. self.assertNoMoreResources()
  77. def test_configure_secured(self):
  78. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  79. classname = "OozieServer",
  80. command = "configure",
  81. config_file="secured.json",
  82. hdp_stack_version = self.STACK_VERSION,
  83. target = RMFTestCase.TARGET_COMMON_SERVICES
  84. )
  85. self.assert_configure_secured()
  86. self.assertNoMoreResources()
  87. @patch("os.path.isfile")
  88. def test_start_secured(self, isfile_mock):
  89. isfile_mock.return_value = True
  90. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  91. classname = "OozieServer",
  92. command = "start",
  93. config_file="secured.json",
  94. hdp_stack_version = self.STACK_VERSION,
  95. target = RMFTestCase.TARGET_COMMON_SERVICES
  96. )
  97. self.assert_configure_secured()
  98. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/ooziedb.sh create -sqlfile oozie.sql -run',
  99. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  100. ignore_failures = True,
  101. user = 'oozie',
  102. )
  103. self.assertResourceCalled('Execute', '/usr/bin/kinit -kt /etc/security/keytabs/oozie.service.keytab oozie/c6402.ambari.apache.org@EXAMPLE.COM; hadoop --config /etc/hadoop/conf dfs -put /usr/lib/oozie/share /user/oozie ; hadoop --config /etc/hadoop/conf dfs -chmod -R 755 /user/oozie/share',
  104. not_if = "/usr/bin/kinit -kt /etc/security/keytabs/oozie.service.keytab oozie/c6402.ambari.apache.org@EXAMPLE.COM; hadoop --config /etc/hadoop/conf dfs -ls /user/oozie/share | awk 'BEGIN {count=0;} /share/ {count++} END {if (count > 0) {exit 0} else {exit 1}}'",
  105. user = 'oozie',
  106. path = ['/usr/bin:/usr/bin'],
  107. )
  108. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-start.sh',
  109. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  110. user = 'oozie',
  111. )
  112. self.assertNoMoreResources()
  113. def test_stop_secured(self):
  114. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  115. classname = "OozieServer",
  116. command = "stop",
  117. config_file="secured.json",
  118. hdp_stack_version = self.STACK_VERSION,
  119. target = RMFTestCase.TARGET_COMMON_SERVICES
  120. )
  121. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-stop.sh',
  122. only_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  123. user = 'oozie',
  124. )
  125. self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
  126. action = ['delete'],
  127. )
  128. self.assertNoMoreResources()
  129. def assert_configure_default(self):
  130. self.assertResourceCalled('HdfsDirectory', '/user/oozie',
  131. security_enabled = False,
  132. keytab = UnknownConfigurationMock(),
  133. conf_dir = '/etc/hadoop/conf',
  134. hdfs_user = 'hdfs',
  135. kinit_path_local = '/usr/bin/kinit',
  136. mode = 0775,
  137. owner = 'oozie',
  138. bin_dir = '/usr/bin',
  139. action = ['create'],
  140. )
  141. self.assertResourceCalled('Directory', '/etc/oozie/conf',
  142. owner = 'oozie',
  143. group = 'hadoop',
  144. recursive = True
  145. )
  146. self.assertResourceCalled('XmlConfig', 'oozie-site.xml',
  147. owner = 'oozie',
  148. group = 'hadoop',
  149. mode = 0664,
  150. conf_dir = '/etc/oozie/conf',
  151. configurations = self.getConfig()['configurations']['oozie-site'],
  152. configuration_attributes = self.getConfig()['configuration_attributes']['oozie-site']
  153. )
  154. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-env.sh',
  155. owner = 'oozie',
  156. content = InlineTemplate(self.getConfig()['configurations']['oozie-env']['content'])
  157. )
  158. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-log4j.properties',
  159. owner = 'oozie',
  160. group = 'hadoop',
  161. mode = 0644,
  162. content = 'log4jproperties\nline2'
  163. )
  164. self.assertResourceCalled('File', '/etc/oozie/conf/adminusers.txt',
  165. owner = 'oozie',
  166. group = 'hadoop',
  167. )
  168. self.assertResourceCalled('File', '/etc/oozie/conf/hadoop-config.xml',
  169. owner = 'oozie',
  170. group = 'hadoop',
  171. )
  172. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-default.xml',
  173. owner = 'oozie',
  174. group = 'hadoop',
  175. )
  176. self.assertResourceCalled('Directory', '/etc/oozie/conf/action-conf',
  177. owner = 'oozie',
  178. group = 'hadoop',
  179. )
  180. self.assertResourceCalled('File', '/etc/oozie/conf/action-conf/hive.xml',
  181. owner = 'oozie',
  182. group = 'hadoop',
  183. )
  184. self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
  185. action=["delete"],
  186. not_if="ls {pid_file} >/dev/null 2>&1 && !(ps `cat {pid_file}` >/dev/null 2>&1)"
  187. )
  188. self.assertResourceCalled('Directory', '/usr/lib/oozie//var/tmp/oozie',
  189. owner = 'oozie',
  190. group = 'hadoop',
  191. recursive = True,
  192. mode = 0755,
  193. cd_access='a'
  194. )
  195. self.assertResourceCalled('Directory', '/var/run/oozie',
  196. owner = 'oozie',
  197. group = 'hadoop',
  198. recursive = True,
  199. mode = 0755,
  200. cd_access='a'
  201. )
  202. self.assertResourceCalled('Directory', '/var/log/oozie',
  203. owner = 'oozie',
  204. group = 'hadoop',
  205. recursive = True,
  206. mode = 0755,
  207. cd_access='a'
  208. )
  209. self.assertResourceCalled('Directory', '/var/tmp/oozie',
  210. owner = 'oozie',
  211. group = 'hadoop',
  212. recursive = True,
  213. mode = 0755,
  214. cd_access='a'
  215. )
  216. self.assertResourceCalled('Directory', '/hadoop/oozie/data',
  217. owner = 'oozie',
  218. group = 'hadoop',
  219. recursive = True,
  220. mode = 0755,
  221. cd_access='a'
  222. )
  223. self.assertResourceCalled('Directory', '/var/lib/oozie',
  224. owner = 'oozie',
  225. group = 'hadoop',
  226. recursive = True,
  227. mode = 0755,
  228. cd_access='a'
  229. )
  230. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/webapps/',
  231. owner = 'oozie',
  232. group = 'hadoop',
  233. recursive = True,
  234. mode = 0755,
  235. cd_access='a'
  236. )
  237. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/conf',
  238. owner = 'oozie',
  239. group = 'hadoop',
  240. recursive = True,
  241. mode = 0755,
  242. cd_access='a'
  243. )
  244. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server',
  245. owner = 'oozie',
  246. group = 'hadoop',
  247. recursive = True,
  248. mode = 0755,
  249. cd_access='a'
  250. )
  251. self.assertResourceCalled('Directory', '/usr/lib/oozie/libext',
  252. recursive = True,
  253. )
  254. self.assertResourceCalled('Execute', ('tar', '-xvf', '/usr/lib/oozie/oozie-sharelib.tar.gz', '-C', '/usr/lib/oozie'),
  255. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  256. sudo = True,
  257. )
  258. self.assertResourceCalled('Execute', ('cp', '/usr/share/HDP-oozie/ext-2.2.zip', '/usr/lib/oozie/libext'),
  259. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  260. sudo = True,
  261. )
  262. self.assertResourceCalled('Execute', ('chown', u'oozie:hadoop', '/usr/lib/oozie/libext/ext-2.2.zip'),
  263. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  264. sudo = True,
  265. )
  266. self.assertResourceCalled('Execute', ('chown', '-RL', u'oozie:hadoop', '/var/lib/oozie/oozie-server/conf'),
  267. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  268. sudo = True,
  269. )
  270. self.assertResourceCalled('Execute', 'ambari-sudo.sh cp /usr/lib/falcon/oozie/ext/falcon-oozie-el-extension-*.jar /usr/lib/oozie/libext',
  271. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  272. )
  273. self.assertResourceCalled('Execute', 'ambari-sudo.sh chown oozie:hadoop /usr/lib/oozie/libext/falcon-oozie-el-extension-*.jar',
  274. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  275. )
  276. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war',
  277. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  278. user = 'oozie',
  279. )
  280. def assert_configure_secured(self):
  281. self.assertResourceCalled('HdfsDirectory', '/user/oozie',
  282. security_enabled = True,
  283. keytab = '/etc/security/keytabs/hdfs.headless.keytab',
  284. conf_dir = '/etc/hadoop/conf',
  285. hdfs_user = 'hdfs',
  286. kinit_path_local = '/usr/bin/kinit',
  287. mode = 0775,
  288. owner = 'oozie',
  289. bin_dir = '/usr/bin',
  290. action = ['create'],
  291. )
  292. self.assertResourceCalled('Directory', '/etc/oozie/conf',
  293. owner = 'oozie',
  294. group = 'hadoop',
  295. recursive = True
  296. )
  297. self.assertResourceCalled('XmlConfig', 'oozie-site.xml',
  298. owner = 'oozie',
  299. group = 'hadoop',
  300. mode = 0664,
  301. conf_dir = '/etc/oozie/conf',
  302. configurations = self.getConfig()['configurations']['oozie-site'],
  303. configuration_attributes = self.getConfig()['configuration_attributes']['oozie-site']
  304. )
  305. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-env.sh',
  306. owner = 'oozie',
  307. content = InlineTemplate(self.getConfig()['configurations']['oozie-env']['content'])
  308. )
  309. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-log4j.properties',
  310. owner = 'oozie',
  311. group = 'hadoop',
  312. mode = 0644,
  313. content = 'log4jproperties\nline2'
  314. )
  315. self.assertResourceCalled('File', '/etc/oozie/conf/adminusers.txt',
  316. owner = 'oozie',
  317. group = 'hadoop',
  318. )
  319. self.assertResourceCalled('File', '/etc/oozie/conf/hadoop-config.xml',
  320. owner = 'oozie',
  321. group = 'hadoop',
  322. )
  323. self.assertResourceCalled('File', '/etc/oozie/conf/oozie-default.xml',
  324. owner = 'oozie',
  325. group = 'hadoop',
  326. )
  327. self.assertResourceCalled('Directory', '/etc/oozie/conf/action-conf',
  328. owner = 'oozie',
  329. group = 'hadoop',
  330. )
  331. self.assertResourceCalled('File', '/etc/oozie/conf/action-conf/hive.xml',
  332. owner = 'oozie',
  333. group = 'hadoop',
  334. )
  335. self.assertResourceCalled('File', '/var/run/oozie/oozie.pid',
  336. action=["delete"],
  337. not_if="ls {pid_file} >/dev/null 2>&1 && !(ps `cat {pid_file}` >/dev/null 2>&1)"
  338. )
  339. self.assertResourceCalled('Directory', '/usr/lib/oozie//var/tmp/oozie',
  340. owner = 'oozie',
  341. group = 'hadoop',
  342. recursive = True,
  343. mode = 0755,
  344. cd_access='a'
  345. )
  346. self.assertResourceCalled('Directory', '/var/run/oozie',
  347. owner = 'oozie',
  348. group = 'hadoop',
  349. recursive = True,
  350. mode = 0755,
  351. cd_access='a'
  352. )
  353. self.assertResourceCalled('Directory', '/var/log/oozie',
  354. owner = 'oozie',
  355. group = 'hadoop',
  356. recursive = True,
  357. mode = 0755,
  358. cd_access='a'
  359. )
  360. self.assertResourceCalled('Directory', '/var/tmp/oozie',
  361. owner = 'oozie',
  362. group = 'hadoop',
  363. recursive = True,
  364. mode = 0755,
  365. cd_access='a'
  366. )
  367. self.assertResourceCalled('Directory', '/hadoop/oozie/data',
  368. owner = 'oozie',
  369. group = 'hadoop',
  370. recursive = True,
  371. mode = 0755,
  372. cd_access='a'
  373. )
  374. self.assertResourceCalled('Directory', '/var/lib/oozie',
  375. owner = 'oozie',
  376. group = 'hadoop',
  377. recursive = True,
  378. mode = 0755,
  379. cd_access='a'
  380. )
  381. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/webapps/',
  382. owner = 'oozie',
  383. group = 'hadoop',
  384. recursive = True,
  385. mode = 0755,
  386. cd_access='a'
  387. )
  388. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server/conf',
  389. owner = 'oozie',
  390. group = 'hadoop',
  391. recursive = True,
  392. mode = 0755,
  393. cd_access='a'
  394. )
  395. self.assertResourceCalled('Directory', '/var/lib/oozie/oozie-server',
  396. owner = 'oozie',
  397. group = 'hadoop',
  398. recursive = True,
  399. mode = 0755,
  400. cd_access='a'
  401. )
  402. self.assertResourceCalled('Directory', '/usr/lib/oozie/libext',
  403. recursive = True,
  404. )
  405. self.assertResourceCalled('Execute', ('tar', '-xvf', '/usr/lib/oozie/oozie-sharelib.tar.gz', '-C', '/usr/lib/oozie'),
  406. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  407. sudo = True,
  408. )
  409. self.assertResourceCalled('Execute', ('cp', '/usr/share/HDP-oozie/ext-2.2.zip', '/usr/lib/oozie/libext'),
  410. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  411. sudo = True,
  412. )
  413. self.assertResourceCalled('Execute', ('chown', u'oozie:hadoop', '/usr/lib/oozie/libext/ext-2.2.zip'),
  414. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  415. sudo = True,
  416. )
  417. self.assertResourceCalled('Execute', ('chown', '-RL', u'oozie:hadoop', '/var/lib/oozie/oozie-server/conf'),
  418. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  419. sudo = True,
  420. )
  421. self.assertResourceCalled('Execute', 'ambari-sudo.sh cp /usr/lib/falcon/oozie/ext/falcon-oozie-el-extension-*.jar /usr/lib/oozie/libext',
  422. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  423. )
  424. self.assertResourceCalled('Execute', 'ambari-sudo.sh chown oozie:hadoop /usr/lib/oozie/libext/falcon-oozie-el-extension-*.jar',
  425. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  426. )
  427. self.assertResourceCalled('Execute', 'cd /var/tmp/oozie && /usr/lib/oozie/bin/oozie-setup.sh prepare-war',
  428. not_if = 'ls /var/run/oozie/oozie.pid >/dev/null 2>&1 && ps -p `cat /var/run/oozie/oozie.pid` >/dev/null 2>&1',
  429. user = 'oozie',
  430. )
  431. def test_configure_default_hdp22(self):
  432. config_file = "stacks/2.0.6/configs/default.json"
  433. with open(config_file, "r") as f:
  434. default_json = json.load(f)
  435. default_json['hostLevelParams']['stack_version']= '2.2'
  436. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  437. classname = "OozieServer",
  438. command = "configure",
  439. config_file="default.json",
  440. hdp_stack_version = self.STACK_VERSION,
  441. target = RMFTestCase.TARGET_COMMON_SERVICES
  442. )
  443. self.assert_configure_default()
  444. self.assertResourceCalled('Directory', '/etc/oozie/conf/action-conf/hive',
  445. owner = 'oozie',
  446. group = 'hadoop',
  447. recursive = True
  448. )
  449. self.assertResourceCalled('XmlConfig', 'hive-site',
  450. owner = 'oozie',
  451. group = 'hadoop',
  452. mode = 0664,
  453. conf_dir = '/etc/oozie/conf/action-conf/hive',
  454. configurations = self.getConfig()['configurations']['hive-site'],
  455. configuration_attributes = self.getConfig()['configuration_attributes']['hive-site']
  456. )
  457. self.assertResourceCalled('XmlConfig', 'tez-site',
  458. owner = 'oozie',
  459. group = 'hadoop',
  460. mode = 0664,
  461. conf_dir = '/etc/oozie/conf/action-conf/hive',
  462. configurations = self.getConfig()['configurations']['tez-site'],
  463. configuration_attributes = self.getConfig()['configuration_attributes']['tez-site']
  464. )
  465. self.assertNoMoreResources()
  466. @patch("resource_management.libraries.functions.security_commons.build_expectations")
  467. @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem")
  468. @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties")
  469. @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor")
  470. @patch("resource_management.libraries.script.Script.put_structured_out")
  471. def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock):
  472. # Test that function works when is called with correct parameters
  473. security_params = {
  474. "oozie-site": {
  475. "oozie.authentication.type": "kerberos",
  476. "oozie.service.AuthorizationService.security.enabled": "true",
  477. "oozie.service.HadoopAccessorService.kerberos.enabled": "true",
  478. "local.realm": "EXAMPLE.COM",
  479. "oozie.authentication.kerberos.principal": "principal",
  480. "oozie.authentication.kerberos.keytab": "/path/to_keytab",
  481. "oozie.service.HadoopAccessorService.kerberos.principal": "principal",
  482. "oozie.service.HadoopAccessorService.keytab.file": "/path/to_keytab"}
  483. }
  484. result_issues = []
  485. props_value_check = {"oozie.authentication.type": "kerberos",
  486. "oozie.service.AuthorizationService.security.enabled": "true",
  487. "oozie.service.HadoopAccessorService.kerberos.enabled": "true"}
  488. props_empty_check = [ "local.realm",
  489. "oozie.authentication.kerberos.principal",
  490. "oozie.authentication.kerberos.keytab",
  491. "oozie.service.HadoopAccessorService.kerberos.principal",
  492. "oozie.service.HadoopAccessorService.keytab.file"]
  493. props_read_check = None
  494. get_params_mock.return_value = security_params
  495. validate_security_config_mock.return_value = result_issues
  496. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  497. classname = "OozieServer",
  498. command = "security_status",
  499. config_file="secured.json",
  500. hdp_stack_version = self.STACK_VERSION,
  501. target = RMFTestCase.TARGET_COMMON_SERVICES
  502. )
  503. import status_params
  504. get_params_mock.assert_called_with(status_params.conf_dir, {'oozie-site.xml': 'XML'})
  505. build_exp_mock.assert_called_with('oozie-site', props_value_check, props_empty_check, props_read_check)
  506. put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"})
  507. self.assertTrue(cached_kinit_executor_mock.call_count, 2)
  508. cached_kinit_executor_mock.assert_called_with(status_params.kinit_path_local,
  509. status_params.oozie_user,
  510. security_params['oozie-site']['oozie.service.HadoopAccessorService.keytab.file'],
  511. security_params['oozie-site']['oozie.service.HadoopAccessorService.kerberos.principal'],
  512. status_params.hostname,
  513. status_params.tmp_dir)
  514. # Testing that the exception throw by cached_executor is caught
  515. cached_kinit_executor_mock.reset_mock()
  516. cached_kinit_executor_mock.side_effect = Exception("Invalid command")
  517. try:
  518. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  519. classname = "OozieServer",
  520. command = "security_status",
  521. config_file="secured.json",
  522. hdp_stack_version = self.STACK_VERSION,
  523. target = RMFTestCase.TARGET_COMMON_SERVICES
  524. )
  525. except:
  526. self.assertTrue(True)
  527. # Testing with a security_params which doesn't contains oozie-site
  528. empty_security_params = {}
  529. cached_kinit_executor_mock.reset_mock()
  530. get_params_mock.reset_mock()
  531. put_structured_out_mock.reset_mock()
  532. get_params_mock.return_value = empty_security_params
  533. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  534. classname = "OozieServer",
  535. command = "security_status",
  536. config_file="secured.json",
  537. hdp_stack_version = self.STACK_VERSION,
  538. target = RMFTestCase.TARGET_COMMON_SERVICES
  539. )
  540. put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."})
  541. # Testing with not empty result_issues
  542. result_issues_with_params = {}
  543. result_issues_with_params['oozie-site']="Something bad happened"
  544. validate_security_config_mock.reset_mock()
  545. get_params_mock.reset_mock()
  546. validate_security_config_mock.return_value = result_issues_with_params
  547. get_params_mock.return_value = security_params
  548. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  549. classname = "OozieServer",
  550. command = "security_status",
  551. config_file="secured.json",
  552. hdp_stack_version = self.STACK_VERSION,
  553. target = RMFTestCase.TARGET_COMMON_SERVICES
  554. )
  555. put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"})
  556. # Testing with security_enable = false
  557. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  558. classname = "OozieServer",
  559. command = "security_status",
  560. config_file="default.json",
  561. hdp_stack_version = self.STACK_VERSION,
  562. target = RMFTestCase.TARGET_COMMON_SERVICES
  563. )
  564. put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"})
  565. @patch("tarfile.open")
  566. @patch("os.path.isdir")
  567. @patch("os.path.exists")
  568. @patch("os.path.isfile")
  569. @patch("os.remove")
  570. @patch("os.chmod")
  571. @patch("shutil.rmtree", new = MagicMock())
  572. @patch("glob.iglob")
  573. @patch("shutil.copy", new = MagicMock())
  574. @patch.object(shell, "call")
  575. def test_upgrade(self, call_mock, glob_mock, chmod_mock, remove_mock,
  576. isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
  577. isdir_mock.return_value = True
  578. exists_mock.side_effect = [False,False,True]
  579. isfile_mock.return_value = True
  580. glob_mock.return_value = ["/usr/hdp/2.2.1.0-2187/hadoop/lib/hadoop-lzo-0.6.0.2.2.1.0-2187.jar"]
  581. prepare_war_stdout = """INFO: Adding extension: libext/mysql-connector-java.jar
  582. New Oozie WAR file with added 'JARs' at /var/lib/oozie/oozie-server/webapps/oozie.war"""
  583. call_mock.return_value = (0, prepare_war_stdout)
  584. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  585. classname = "OozieServer", command = "pre_rolling_restart", config_file = "oozie-upgrade.json",
  586. hdp_stack_version = self.UPGRADE_STACK_VERSION,
  587. target = RMFTestCase.TARGET_COMMON_SERVICES )
  588. # 2 calls to tarfile.open (1 directories, read + write)
  589. self.assertTrue(tarfile_open_mock.called)
  590. self.assertEqual(tarfile_open_mock.call_count,2)
  591. self.assertTrue(chmod_mock.called)
  592. self.assertEqual(chmod_mock.call_count,1)
  593. chmod_mock.assert_called_once_with('/usr/hdp/current/oozie-server/libext-customer', 511)
  594. self.assertTrue(isfile_mock.called)
  595. self.assertEqual(isfile_mock.call_count,3)
  596. isfile_mock.assert_called_with('/usr/share/HDP-oozie/ext-2.2.zip')
  597. self.assertTrue(glob_mock.called)
  598. self.assertEqual(glob_mock.call_count,1)
  599. glob_mock.assert_called_with('/usr/hdp/2.2.1.0-2135/hadoop/lib/hadoop-lzo*.jar')
  600. self.assertResourceCalled('Execute', 'hdp-select set oozie-server 2.2.1.0-2135')
  601. self.assertResourceCalled('Execute', 'hdfs dfs -chown oozie:hadoop /user/oozie/share', user='oozie')
  602. self.assertResourceCalled('Execute', 'hdfs dfs -chmod -R 755 /user/oozie/share', user='oozie')
  603. self.assertResourceCalled('Execute', '/usr/hdp/current/oozie-server/bin/ooziedb.sh upgrade -run', user='oozie')
  604. self.assertResourceCalled('Execute', '/usr/hdp/current/oozie-server/bin/oozie-setup.sh sharelib create -fs hdfs://c6401.ambari.apache.org:8020', user='oozie')
  605. self.assertNoMoreResources()
  606. @patch("tarfile.open")
  607. @patch("os.path.isdir")
  608. @patch("os.path.exists")
  609. @patch("os.path.isfile")
  610. @patch("os.remove")
  611. @patch("os.chmod")
  612. @patch("shutil.rmtree", new = MagicMock())
  613. @patch("shutil.copy", new = MagicMock())
  614. @patch.object(shell, "call")
  615. def test_downgrade_no_compression_library_copy(self, call_mock, chmod_mock, remove_mock,
  616. isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
  617. isdir_mock.return_value = True
  618. exists_mock.side_effect = [False,False,True]
  619. isfile_mock.return_value = True
  620. prepare_war_stdout = """INFO: Adding extension: libext/mysql-connector-java.jar
  621. New Oozie WAR file with added 'JARs' at /var/lib/oozie/oozie-server/webapps/oozie.war"""
  622. call_mock.return_value = (0, prepare_war_stdout)
  623. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  624. classname = "OozieServer", command = "pre_rolling_restart", config_file = "oozie-downgrade.json",
  625. hdp_stack_version = self.UPGRADE_STACK_VERSION,
  626. target = RMFTestCase.TARGET_COMMON_SERVICES )
  627. # 2 calls to tarfile.open (1 directories, read + write)
  628. self.assertTrue(tarfile_open_mock.called)
  629. self.assertEqual(tarfile_open_mock.call_count,2)
  630. self.assertTrue(chmod_mock.called)
  631. self.assertEqual(chmod_mock.call_count,1)
  632. chmod_mock.assert_called_once_with('/usr/hdp/current/oozie-server/libext-customer', 511)
  633. self.assertTrue(isfile_mock.called)
  634. self.assertEqual(isfile_mock.call_count,2)
  635. isfile_mock.assert_called_with('/usr/share/HDP-oozie/ext-2.2.zip')
  636. self.assertResourceCalled('Execute', 'hdp-select set oozie-server 2.2.0.0-0000')
  637. self.assertResourceCalled('Execute', 'hdfs dfs -chown oozie:hadoop /user/oozie/share', user='oozie')
  638. self.assertResourceCalled('Execute', 'hdfs dfs -chmod -R 755 /user/oozie/share', user='oozie')
  639. self.assertResourceCalled('Execute', '/usr/hdp/current/oozie-server/bin/ooziedb.sh upgrade -run', user='oozie')
  640. self.assertResourceCalled('Execute', '/usr/hdp/current/oozie-server/bin/oozie-setup.sh sharelib create -fs hdfs://c6401.ambari.apache.org:8020', user='oozie')
  641. @patch("tarfile.open")
  642. @patch("os.path.isdir")
  643. @patch("os.path.exists")
  644. @patch("os.path.isfile")
  645. @patch("os.remove")
  646. @patch("os.chmod")
  647. @patch("shutil.rmtree", new = MagicMock())
  648. @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"]))
  649. @patch("shutil.copy")
  650. @patch.object(shell, "call")
  651. def test_upgrade_failed_prepare_war(self, call_mock, shutil_copy_mock, chmod_mock, remove_mock,
  652. isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
  653. isdir_mock.return_value = True
  654. exists_mock.side_effect = [False,False,True]
  655. isfile_mock.return_value = True
  656. call_mock.return_value = (0, 'Whoops, you messed up the WAR.')
  657. try:
  658. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
  659. classname = "OozieServer", command = "pre_rolling_restart", config_file = "oozie-upgrade.json",
  660. hdp_stack_version = self.UPGRADE_STACK_VERSION,
  661. target = RMFTestCase.TARGET_COMMON_SERVICES )
  662. self.fail("An invalid WAR preparation should have caused an error")
  663. except Fail,f:
  664. pass