test_zeppelin_070.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. from ambari_commons import OSCheck
  17. '''
  18. import glob
  19. import unittest
  20. from mock.mock import MagicMock, patch
  21. from resource_management.core import sudo
  22. from stacks.utils.RMFTestCase import *
  23. import interpreter_json_generated
  24. @patch.object(glob, "glob", new=MagicMock(return_value=["/tmp"]))
  25. @patch.object(sudo, "read_file",
  26. new=MagicMock(return_value=interpreter_json_generated.template))
  27. class TestZeppelin070(RMFTestCase):
  28. COMMON_SERVICES_PACKAGE_DIR = "ZEPPELIN/0.7.0/package"
  29. STACK_VERSION = "2.6"
  30. def assert_configure_default(self):
  31. self.assertResourceCalled('Directory', '/var/log/zeppelin',
  32. owner='zeppelin',
  33. group='zeppelin',
  34. create_parents=True,
  35. mode=0755,
  36. cd_access='a',
  37. )
  38. self.assertResourceCalled('Directory', '/var/run/zeppelin',
  39. owner='zeppelin',
  40. create_parents=True,
  41. group='zeppelin',
  42. mode=0755,
  43. cd_access='a',
  44. )
  45. self.assertResourceCalled('Directory', '/usr/hdp/current/zeppelin-server',
  46. owner='zeppelin',
  47. group='zeppelin',
  48. create_parents=True,
  49. mode=0755,
  50. cd_access='a',
  51. )
  52. self.assertResourceCalled('Execute', (
  53. 'chown', '-R', u'zeppelin:zeppelin', '/var/run/zeppelin'), sudo=True)
  54. self.assertResourceCalled('XmlConfig', 'zeppelin-site.xml',
  55. owner='zeppelin',
  56. group='zeppelin',
  57. conf_dir='/etc/zeppelin/conf',
  58. configurations=self.getConfig()['configurations'][
  59. 'zeppelin-config'],
  60. )
  61. self.assertResourceCalled('File', '/etc/zeppelin/conf/zeppelin-env.sh',
  62. owner='zeppelin',
  63. content=InlineTemplate(
  64. self.getConfig()['configurations'][
  65. 'zeppelin-env']['zeppelin_env_content']),
  66. group='zeppelin',
  67. )
  68. self.assertResourceCalled('File', '/etc/zeppelin/conf/shiro.ini',
  69. owner='zeppelin',
  70. content=InlineTemplate(
  71. self.getConfig()['configurations'][
  72. 'zeppelin-shiro-ini']['shiro_ini_content']),
  73. group='zeppelin',
  74. )
  75. self.assertResourceCalled('File', '/etc/zeppelin/conf/log4j.properties',
  76. owner=u'zeppelin',
  77. content=u'log4j.rootLogger = INFO, dailyfile',
  78. group=u'zeppelin',
  79. )
  80. self.assertResourceCalled('Directory',
  81. '/etc/zeppelin/conf/external-dependency-conf',
  82. owner='zeppelin',
  83. group='zeppelin',
  84. create_parents=True,
  85. mode=0755,
  86. cd_access='a',
  87. )
  88. def assert_configure_secured(self):
  89. self.assertResourceCalled('Directory', '/var/log/zeppelin',
  90. owner='zeppelin',
  91. group='zeppelin',
  92. create_parents=True,
  93. mode=0755,
  94. cd_access='a',
  95. )
  96. self.assertResourceCalled('Directory', '/var/run/zeppelin',
  97. owner='zeppelin',
  98. create_parents=True,
  99. group='zeppelin',
  100. mode=0755,
  101. cd_access='a',
  102. )
  103. self.assertResourceCalled('Directory', '/usr/hdp/current/zeppelin-server',
  104. owner='zeppelin',
  105. group='zeppelin',
  106. create_parents=True,
  107. mode=0755,
  108. cd_access='a',
  109. )
  110. self.assertResourceCalled('Execute', (
  111. 'chown', '-R', u'zeppelin:zeppelin', '/var/run/zeppelin'), sudo=True)
  112. self.assertResourceCalled('XmlConfig', 'zeppelin-site.xml',
  113. owner='zeppelin',
  114. group='zeppelin',
  115. conf_dir='/etc/zeppelin/conf',
  116. configurations=self.getConfig()['configurations'][
  117. 'zeppelin-config'],
  118. )
  119. self.assertResourceCalled('File', '/etc/zeppelin/conf/zeppelin-env.sh',
  120. owner='zeppelin',
  121. content=InlineTemplate(
  122. self.getConfig()['configurations'][
  123. 'zeppelin-env']['zeppelin_env_content']),
  124. group='zeppelin',
  125. )
  126. self.assertResourceCalled('File', '/etc/zeppelin/conf/shiro.ini',
  127. owner='zeppelin',
  128. content=InlineTemplate(
  129. self.getConfig()['configurations'][
  130. 'zeppelin-shiro-ini']['shiro_ini_content']),
  131. group='zeppelin',
  132. )
  133. self.assertResourceCalled('File', '/etc/zeppelin/conf/log4j.properties',
  134. owner=u'zeppelin',
  135. content=u'log4j.rootLogger = INFO, dailyfile',
  136. group=u'zeppelin',
  137. )
  138. self.assertResourceCalled('Directory',
  139. '/etc/zeppelin/conf/external-dependency-conf',
  140. owner='zeppelin',
  141. group='zeppelin',
  142. create_parents=True,
  143. mode=0755,
  144. cd_access='a',
  145. )
  146. def test_configure_default(self):
  147. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/master.py",
  148. classname="Master",
  149. command="configure",
  150. config_file="default.json",
  151. stack_version=self.STACK_VERSION,
  152. target=RMFTestCase.TARGET_COMMON_SERVICES
  153. )
  154. self.assert_configure_default()
  155. self.assertNoMoreResources()
  156. def test_stop_default(self):
  157. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/master.py",
  158. classname="Master",
  159. command="stop",
  160. config_file="default.json",
  161. stack_version=self.STACK_VERSION,
  162. target=RMFTestCase.TARGET_COMMON_SERVICES
  163. )
  164. self.assertResourceCalled('Directory', '/var/log/zeppelin',
  165. owner='zeppelin',
  166. group='zeppelin',
  167. create_parents=True,
  168. mode=0755,
  169. cd_access='a',
  170. )
  171. self.assertResourceCalled('Execute', (
  172. 'chown', '-R', u'zeppelin:zeppelin', '/var/run/zeppelin'),
  173. sudo=True,
  174. )
  175. self.assertResourceCalled('Execute',
  176. '/usr/hdp/current/zeppelin-server/bin/zeppelin-daemon.sh stop >> /var/log/zeppelin/zeppelin-setup.log',
  177. user='zeppelin',
  178. )
  179. self.assertNoMoreResources()
  180. def test_start_default(self):
  181. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/master.py",
  182. classname="Master",
  183. command="start",
  184. config_file="default.json",
  185. stack_version=self.STACK_VERSION,
  186. target=RMFTestCase.TARGET_COMMON_SERVICES
  187. )
  188. self.assert_configure_default()
  189. self.assertResourceCalled('Execute', (
  190. 'chown', '-R', u'zeppelin:zeppelin', '/etc/zeppelin'),
  191. sudo=True,
  192. )
  193. @patch('os.path.exists', return_value=True)
  194. @unittest.skip("Disabled for stabilization, check AMBARI-25561")
  195. def test_start_secured(self, os_path_exists_mock):
  196. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/master.py",
  197. classname="Master",
  198. command="start",
  199. config_file="default.json",
  200. stack_version=self.STACK_VERSION,
  201. target=RMFTestCase.TARGET_COMMON_SERVICES
  202. )
  203. self.assert_configure_secured()
  204. self.assertResourceCalled('Execute', (
  205. 'chown', '-R', u'zeppelin:zeppelin', '/etc/zeppelin'),
  206. sudo=True,
  207. )
  208. self.assertResourceCalled('Execute', ('chown', '-R', 'zeppelin:zeppelin',
  209. '/usr/hdp/current/zeppelin-server/notebook'),
  210. sudo=True,
  211. )
  212. self.assertResourceCalled('HdfsResource', '/user/zeppelin/notebook',
  213. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  214. default_fs=u'hdfs://c6401.ambari.apache.org:8020',
  215. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  216. hdfs_site={u'a': u'b'},
  217. keytab=UnknownConfigurationMock(),
  218. kinit_path_local='/usr/bin/kinit',
  219. user='hdfs',
  220. owner='zeppelin',
  221. principal_name=UnknownConfigurationMock(),
  222. recursive_chown=True,
  223. security_enabled=False,
  224. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  225. type='directory',
  226. action=['create_on_execute'],
  227. recursive_chmod=True,
  228. dfs_type='',
  229. )
  230. self.assertResourceCalled('HdfsResource', '/user/zeppelin/notebook',
  231. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  232. default_fs=u'hdfs://c6401.ambari.apache.org:8020',
  233. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  234. hdfs_site={u'a': u'b'},
  235. keytab=UnknownConfigurationMock(),
  236. kinit_path_local='/usr/bin/kinit',
  237. user='hdfs',
  238. owner='zeppelin',
  239. principal_name=UnknownConfigurationMock(),
  240. recursive_chown=True,
  241. security_enabled=False,
  242. source='/usr/hdp/current/zeppelin-server/notebook',
  243. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  244. type='directory',
  245. action=['create_on_execute'],
  246. recursive_chmod=True,
  247. dfs_type='',
  248. )
  249. self.assertResourceCalled('HdfsResource', '/user/zeppelin',
  250. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  251. default_fs=u'hdfs://c6401.ambari.apache.org:8020',
  252. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  253. hdfs_site={u'a': u'b'},
  254. keytab=UnknownConfigurationMock(),
  255. kinit_path_local='/usr/bin/kinit',
  256. user='hdfs',
  257. owner='zeppelin',
  258. principal_name=UnknownConfigurationMock(),
  259. recursive_chown=True,
  260. security_enabled=False,
  261. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  262. type='directory',
  263. action=['create_on_execute'],
  264. recursive_chmod=True,
  265. dfs_type='',
  266. )
  267. self.assertResourceCalled('HdfsResource', '/user/zeppelin/test',
  268. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  269. default_fs=u'hdfs://c6401.ambari.apache.org:8020',
  270. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  271. hdfs_site={u'a': u'b'},
  272. kinit_path_local='/usr/bin/kinit',
  273. user='hdfs',
  274. owner='zeppelin',
  275. recursive_chown=True,
  276. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  277. type='directory',
  278. action=['create_on_execute'],
  279. recursive_chmod=True,
  280. keytab=UnknownConfigurationMock(),
  281. principal_name=UnknownConfigurationMock(),
  282. security_enabled=False,
  283. dfs_type='',
  284. )
  285. self.assertResourceCalled('HdfsResource', '/apps/zeppelin',
  286. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  287. default_fs=u'hdfs://c6401.ambari.apache.org:8020',
  288. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  289. hdfs_site={u'a': u'b'},
  290. kinit_path_local='/usr/bin/kinit',
  291. user='hdfs',
  292. owner='zeppelin',
  293. recursive_chown=True,
  294. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  295. type='directory',
  296. action=['create_on_execute'],
  297. recursive_chmod=True,
  298. keytab=UnknownConfigurationMock(),
  299. principal_name=UnknownConfigurationMock(),
  300. security_enabled=False,
  301. dfs_type='',
  302. )
  303. self.assertResourceCalled('HdfsResource', '/apps/zeppelin/tmp',
  304. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  305. source='/tmp',
  306. default_fs=u'hdfs://c6401.ambari.apache.org:8020',
  307. replace_existing_files=True,
  308. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  309. hdfs_site={u'a': u'b'},
  310. kinit_path_local='/usr/bin/kinit',
  311. user='hdfs',
  312. owner='zeppelin',
  313. group='zeppelin',
  314. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  315. type='file',
  316. action=['create_on_execute'],
  317. mode=0444,
  318. keytab=UnknownConfigurationMock(),
  319. principal_name=UnknownConfigurationMock(),
  320. security_enabled=False,
  321. dfs_type='',
  322. )
  323. self.assertResourceCalled('HdfsResource', None,
  324. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  325. default_fs=u'hdfs://c6401.ambari.apache.org:8020',
  326. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  327. hdfs_site={u'a': u'b'},
  328. kinit_path_local='/usr/bin/kinit',
  329. user='hdfs',
  330. action=['execute'],
  331. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  332. keytab=UnknownConfigurationMock(),
  333. principal_name=UnknownConfigurationMock(),
  334. security_enabled=False,
  335. dfs_type='',
  336. )
  337. self.assertResourceCalled('HdfsResource',
  338. 'hdfs:///user/zeppelin/conf',
  339. security_enabled=False,
  340. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  341. keytab=UnknownConfigurationMock(),
  342. default_fs='hdfs://c6401.ambari.apache.org:8020',
  343. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  344. hdfs_site={u'a': u'b'},
  345. kinit_path_local='/usr/bin/kinit',
  346. principal_name=UnknownConfigurationMock(),
  347. recursive_chown=True,
  348. recursive_chmod=True,
  349. user='hdfs',
  350. owner='zeppelin',
  351. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  352. type='directory',
  353. action=['create_on_execute'],
  354. dfs_type='',
  355. )
  356. self.assertResourceCalled('File', '/etc/zeppelin/conf/interpreter.json',
  357. content=interpreter_json_generated.template_after_base,
  358. owner='zeppelin',
  359. group='zeppelin',
  360. mode=0644
  361. )
  362. self.assertResourceCalled('HdfsResource',
  363. 'hdfs:///user/zeppelin/conf/interpreter.json',
  364. security_enabled=False,
  365. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  366. keytab=UnknownConfigurationMock(),
  367. default_fs='hdfs://c6401.ambari.apache.org:8020',
  368. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  369. hdfs_site={u'a': u'b'},
  370. kinit_path_local='/usr/bin/kinit',
  371. principal_name=UnknownConfigurationMock(),
  372. user='hdfs',
  373. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  374. type='file',
  375. action=['delete_on_execute'],
  376. dfs_type='',
  377. )
  378. self.assertResourceCalled('HdfsResource',
  379. 'hdfs:///user/zeppelin/conf/interpreter.json',
  380. security_enabled=False,
  381. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  382. keytab=UnknownConfigurationMock(),
  383. source='/etc/zeppelin/conf/interpreter.json',
  384. default_fs='hdfs://c6401.ambari.apache.org:8020',
  385. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  386. hdfs_site={u'a': u'b'},
  387. kinit_path_local='/usr/bin/kinit',
  388. principal_name=UnknownConfigurationMock(),
  389. recursive_chown=True,
  390. recursive_chmod=True,
  391. user='hdfs',
  392. owner='zeppelin',
  393. replace_existing_files=True,
  394. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  395. type='file',
  396. action=['create_on_execute'],
  397. dfs_type='',
  398. )
  399. self.assertResourceCalled('File', '/etc/zeppelin/conf/interpreter.json',
  400. content=interpreter_json_generated.template_after_without_spark_and_livy,
  401. owner='zeppelin',
  402. group='zeppelin',
  403. mode=0644
  404. )
  405. self.assertResourceCalled('HdfsResource',
  406. 'hdfs:///user/zeppelin/conf/interpreter.json',
  407. security_enabled=False,
  408. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  409. keytab=UnknownConfigurationMock(),
  410. default_fs='hdfs://c6401.ambari.apache.org:8020',
  411. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  412. hdfs_site={u'a': u'b'},
  413. kinit_path_local='/usr/bin/kinit',
  414. principal_name=UnknownConfigurationMock(),
  415. user='hdfs',
  416. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  417. type='file',
  418. action=['delete_on_execute'],
  419. dfs_type='',
  420. )
  421. self.assertResourceCalled('HdfsResource',
  422. 'hdfs:///user/zeppelin/conf/interpreter.json',
  423. security_enabled=False,
  424. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  425. keytab=UnknownConfigurationMock(),
  426. source='/etc/zeppelin/conf/interpreter.json',
  427. default_fs='hdfs://c6401.ambari.apache.org:8020',
  428. replace_existing_files=True,
  429. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  430. hdfs_site={u'a': u'b'},
  431. kinit_path_local='/usr/bin/kinit',
  432. principal_name=UnknownConfigurationMock(),
  433. recursive_chmod=True,
  434. recursive_chown=True,
  435. user='hdfs',
  436. owner='zeppelin',
  437. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  438. type='file',
  439. action=['create_on_execute'],
  440. dfs_type='',
  441. )
  442. self.assertResourceCalled('File', '/etc/zeppelin/conf/interpreter.json',
  443. content=interpreter_json_generated.template_after_kerberos,
  444. owner='zeppelin',
  445. group='zeppelin',
  446. mode=0644
  447. )
  448. self.assertResourceCalled('HdfsResource',
  449. 'hdfs:///user/zeppelin/conf/interpreter.json',
  450. security_enabled=False,
  451. hadoop_bin_dir='/usr/hdp/2.5.0.0-1235/hadoop/bin',
  452. keytab=UnknownConfigurationMock(),
  453. default_fs='hdfs://c6401.ambari.apache.org:8020',
  454. hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  455. hdfs_site={u'a': u'b'},
  456. kinit_path_local='/usr/bin/kinit',
  457. principal_name=UnknownConfigurationMock(),
  458. user='hdfs',
  459. hadoop_conf_dir='/usr/hdp/2.5.0.0-1235/hadoop/conf',
  460. type='file',
  461. action=['delete_on_execute'],
  462. dfs_type='',
  463. )
  464. self.assertResourceCalled('HdfsResource', 'hdfs:///user/zeppelin/conf/interpreter.json',
  465. security_enabled = False,
  466. hadoop_bin_dir = '/usr/hdp/2.5.0.0-1235/hadoop/bin',
  467. keytab = UnknownConfigurationMock(),
  468. source = '/etc/zeppelin/conf/interpreter.json',
  469. default_fs = 'hdfs://c6401.ambari.apache.org:8020',
  470. hdfs_resource_ignore_file = '/var/lib/ambari-agent/data/.hdfs_resource_ignore',
  471. hdfs_site = {u'a': u'b'},
  472. kinit_path_local = '/usr/bin/kinit',
  473. principal_name = UnknownConfigurationMock(),
  474. replace_existing_files = True,
  475. recursive_chown=True,
  476. recursive_chmod=True,
  477. user = 'hdfs',
  478. owner = 'zeppelin',
  479. hadoop_conf_dir = '/usr/hdp/2.5.0.0-1235/hadoop/conf',
  480. type = 'file',
  481. action = ['create_on_execute'],
  482. dfs_type='',
  483. )
  484. self.assertResourceCalled('Execute',
  485. '/usr/hdp/current/zeppelin-server/bin/zeppelin-daemon.sh restart >> /var/log/zeppelin/zeppelin-setup.log',
  486. user='zeppelin'
  487. )
  488. self.assertNoMoreResources()