test_falcon_server.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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, patch
  19. import shutil
  20. from stacks.utils.RMFTestCase import *
  21. import tarfile
  22. import tempfile
  23. @patch("platform.linux_distribution", new = MagicMock(return_value="Linux"))
  24. @patch.object(tempfile, "gettempdir", new=MagicMock(return_value="/tmp"))
  25. class TestFalconServer(RMFTestCase):
  26. COMMON_SERVICES_PACKAGE_DIR = "FALCON/0.5.0.2.1/package"
  27. STACK_VERSION = "2.1"
  28. UPGRADE_STACK_VERSION = "2.2"
  29. def test_start_default(self):
  30. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py",
  31. classname="FalconServer",
  32. command="start",
  33. config_file="default.json",
  34. hdp_stack_version = self.STACK_VERSION,
  35. target = RMFTestCase.TARGET_COMMON_SERVICES)
  36. self.assert_configure_default()
  37. self.assertResourceCalled('Execute', '/usr/lib/falcon/bin/falcon-start -port 15000',
  38. path = ['/usr/bin'],
  39. user = 'falcon',
  40. environment = {'HADOOP_HOME': '/usr/lib/hadoop'})
  41. self.assertNoMoreResources()
  42. def test_stop_default(self):
  43. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py",
  44. classname="FalconServer",
  45. command="stop",
  46. config_file="default.json",
  47. hdp_stack_version = self.STACK_VERSION,
  48. target = RMFTestCase.TARGET_COMMON_SERVICES)
  49. self.assertResourceCalled('Execute', '/usr/lib/falcon/bin/falcon-stop',
  50. path = ['/usr/bin'],
  51. user = 'falcon',
  52. environment = {'HADOOP_HOME': '/usr/lib/hadoop'})
  53. self.assertResourceCalled('File', '/var/run/falcon/falcon.pid',
  54. action = ['delete'])
  55. self.assertNoMoreResources()
  56. def test_configure_default(self):
  57. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py",
  58. classname="FalconServer",
  59. command="configure",
  60. config_file="default.json",
  61. hdp_stack_version = self.STACK_VERSION,
  62. target = RMFTestCase.TARGET_COMMON_SERVICES
  63. )
  64. self.assert_configure_default()
  65. self.assertNoMoreResources()
  66. def assert_configure_default(self):
  67. self.assertResourceCalled('Directory', '/var/run/falcon',
  68. owner = 'falcon',
  69. recursive = True
  70. )
  71. self.assertResourceCalled('Directory', '/var/log/falcon',
  72. owner = 'falcon',
  73. recursive = True
  74. )
  75. self.assertResourceCalled('Directory', '/var/lib/falcon/webapp',
  76. owner = 'falcon',
  77. recursive = True
  78. )
  79. self.assertResourceCalled('Directory', '/usr/lib/falcon',
  80. owner = 'falcon',
  81. recursive = True
  82. )
  83. self.assertResourceCalled('Directory', '/etc/falcon',
  84. mode = 0755,
  85. recursive = True
  86. )
  87. self.assertResourceCalled('Directory', '/etc/falcon/conf',
  88. owner = 'falcon',
  89. recursive = True
  90. )
  91. self.assertResourceCalled('File', '/etc/falcon/conf/falcon-env.sh',
  92. content = InlineTemplate(self.getConfig()['configurations']['falcon-env']['content']),
  93. owner = 'falcon',
  94. group = 'hadoop'
  95. )
  96. self.assertResourceCalled('File', '/etc/falcon/conf/client.properties',
  97. content = Template('client.properties.j2'),
  98. mode = 0644,
  99. owner = 'falcon'
  100. )
  101. self.assertResourceCalled('PropertiesFile', '/etc/falcon/conf/runtime.properties',
  102. mode = 0644,
  103. properties = self.getConfig()['configurations']['falcon-runtime.properties'],
  104. owner = 'falcon'
  105. )
  106. self.assertResourceCalled('PropertiesFile', '/etc/falcon/conf/startup.properties',
  107. mode = 0644,
  108. properties = self.getConfig()['configurations']['falcon-startup.properties'],
  109. owner = 'falcon'
  110. )
  111. self.assertResourceCalled('Directory', '/hadoop/falcon/store',
  112. owner = 'falcon',
  113. recursive = True
  114. )
  115. self.assertResourceCalled('HdfsResource', '/apps/falcon',
  116. security_enabled = False,
  117. hadoop_bin_dir = '/usr/bin',
  118. keytab = UnknownConfigurationMock(),
  119. kinit_path_local = '/usr/bin/kinit',
  120. user = 'hdfs',
  121. dfs_type = '',
  122. owner = 'falcon',
  123. hadoop_conf_dir = '/etc/hadoop/conf',
  124. type = 'directory',
  125. action = ['create_on_execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020',
  126. mode = 0777,
  127. )
  128. self.assertResourceCalled('Directory', '/hadoop/falcon/store',
  129. owner = 'falcon',
  130. recursive = True,
  131. )
  132. self.assertResourceCalled('HdfsResource', '/apps/data-mirroring',
  133. security_enabled = False,
  134. hadoop_bin_dir = '/usr/bin',
  135. keytab = UnknownConfigurationMock(),
  136. kinit_path_local = '/usr/bin/kinit',
  137. user = 'hdfs',
  138. dfs_type = '',
  139. owner = 'falcon',
  140. group='users',
  141. hadoop_conf_dir = '/etc/hadoop/conf',
  142. type = 'directory',
  143. recursive_chown = True,
  144. recursive_chmod = True,
  145. action = ['create_on_execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020',
  146. mode = 0770,
  147. source='/usr/hdp/current/falcon-server/data-mirroring'
  148. )
  149. self.assertResourceCalled('HdfsResource', None,
  150. security_enabled = False,
  151. hadoop_bin_dir = '/usr/bin',
  152. keytab = UnknownConfigurationMock(),
  153. kinit_path_local = '/usr/bin/kinit',
  154. user = 'hdfs',
  155. dfs_type = '',
  156. action = ['execute'], hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020',
  157. hadoop_conf_dir = '/etc/hadoop/conf',
  158. )
  159. self.assertResourceCalled('Directory', '/hadoop/falcon',
  160. owner = 'falcon',
  161. recursive = True,
  162. cd_access='a'
  163. )
  164. self.assertResourceCalled('Directory', '/hadoop/falcon/embeddedmq',
  165. owner = 'falcon',
  166. recursive = True
  167. )
  168. self.assertResourceCalled('Directory', '/hadoop/falcon/embeddedmq/data',
  169. owner = 'falcon',
  170. recursive = True
  171. )
  172. @patch("os.path.isdir")
  173. @patch("os.path.exists")
  174. @patch("os.path.isfile")
  175. def test_upgrade(self, isfile_mock, exists_mock, isdir_mock):
  176. isdir_mock.return_value = True
  177. exists_mock.side_effect = [False,False,True, True]
  178. isfile_mock.return_value = True
  179. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py",
  180. classname = "FalconServer", command = "restart", config_file = "falcon-upgrade.json",
  181. hdp_stack_version = self.UPGRADE_STACK_VERSION,
  182. target = RMFTestCase.TARGET_COMMON_SERVICES )
  183. self.assertResourceCalled('Execute',
  184. '/usr/hdp/current/falcon-server/bin/falcon-stop',
  185. path = ['/usr/hdp/current/hadoop-client/bin'], user='falcon',
  186. environment = {'HADOOP_HOME': '/usr/hdp/current/hadoop-client'})
  187. self.assertResourceCalled('File', '/var/run/falcon/falcon.pid',
  188. action = ['delete'])
  189. self.assertResourceCalled('Execute', ('tar',
  190. '-zcvhf',
  191. '/tmp/falcon-upgrade-backup/falcon-conf-backup.tar',
  192. '/usr/hdp/current/falcon-server/conf'),
  193. sudo = True,
  194. )
  195. self.assertResourceCalled('Execute', ('tar',
  196. '-zcvhf',
  197. '/tmp/falcon-upgrade-backup/falcon-local-backup.tar',
  198. u'/hadoop/falcon'),
  199. sudo = True,
  200. )
  201. self.assertResourceCalled('Execute', ('ambari-python-wrap', '/usr/bin/hdp-select', 'set', 'falcon-server', u'2.2.1.0-2135'),
  202. sudo = True,
  203. )
  204. self.assertResourceCalled('Execute', ('tar',
  205. '-xvf',
  206. '/tmp/falcon-upgrade-backup/falcon-conf-backup.tar',
  207. '-C',
  208. '/usr/hdp/current/falcon-server/conf/'),
  209. sudo = True,
  210. )
  211. self.assertResourceCalled('Execute', ('tar',
  212. '-xvf',
  213. '/tmp/falcon-upgrade-backup/falcon-local-backup.tar',
  214. '-C',
  215. u'/hadoop/falcon/'),
  216. sudo = True,
  217. )
  218. self.assertResourceCalled('Directory', '/tmp/falcon-upgrade-backup',
  219. action = ['delete'],
  220. )
  221. self.assertResourceCalled('Directory', '/var/run/falcon',
  222. owner = 'falcon',
  223. recursive = True,
  224. )
  225. self.assertResourceCalled('Directory', '/var/log/falcon',
  226. owner = 'falcon',
  227. recursive = True,
  228. )
  229. self.assertResourceCalled('Directory', '/usr/hdp/current/falcon-server/webapp',
  230. owner = 'falcon',
  231. recursive = True,
  232. )
  233. self.assertResourceCalled('Directory', '/usr/hdp/current/falcon-server',
  234. owner = 'falcon',
  235. recursive = True,
  236. )
  237. self.assertResourceCalled('Directory', '/etc/falcon',
  238. recursive = True,
  239. mode = 0755,
  240. )
  241. self.assertResourceCalled('Directory', '/usr/hdp/current/falcon-server/conf',
  242. owner = 'falcon',
  243. recursive = True,
  244. )
  245. self.assertResourceCalled('File', '/usr/hdp/current/falcon-server/conf/falcon-env.sh',
  246. owner = 'falcon',
  247. content = InlineTemplate(self.getConfig()['configurations']['falcon-env']['content']),
  248. group = 'hadoop'
  249. )
  250. self.assertResourceCalled('File', '/usr/hdp/current/falcon-server/conf/client.properties',
  251. owner = 'falcon',
  252. content = Template('client.properties.j2'),
  253. mode = 0644,
  254. )
  255. self.assertResourceCalled('PropertiesFile', '/usr/hdp/current/falcon-server/conf/runtime.properties',
  256. owner = 'falcon',
  257. mode = 0644,
  258. properties = {u'*.domain': u'${falcon.app.type}',
  259. u'*.log.cleanup.frequency.days.retention': u'days(7)',
  260. u'*.log.cleanup.frequency.hours.retention': u'minutes(1)',
  261. u'*.log.cleanup.frequency.minutes.retention': u'hours(6)',
  262. u'*.log.cleanup.frequency.months.retention': u'months(3)'},
  263. )
  264. self.assertResourceCalled('PropertiesFile', '/usr/hdp/current/falcon-server/conf/startup.properties',
  265. owner = 'falcon',
  266. mode = 0644,
  267. properties = self.getConfig()['configurations']['falcon-startup.properties'],
  268. )
  269. self.assertResourceCalled('Directory', '/hadoop/falcon/data/lineage/graphdb',
  270. owner = 'falcon',
  271. recursive = True,
  272. group = 'hadoop',
  273. mode = 0775,
  274. cd_access = 'a',
  275. )
  276. self.assertResourceCalled('Directory', '/hadoop/falcon/data/lineage',
  277. owner = 'falcon',
  278. recursive = True,
  279. group = 'hadoop',
  280. mode = 0775,
  281. cd_access = 'a',
  282. )
  283. self.assertResourceCalled('Directory', '/hadoop/falcon/store',
  284. owner = 'falcon',
  285. recursive = True,
  286. )
  287. self.assertResourceCalled('HdfsResource', '/apps/falcon',
  288. security_enabled = False,
  289. hadoop_bin_dir = '/usr/hdp/current/hadoop-client/bin',
  290. keytab = UnknownConfigurationMock(),
  291. default_fs = 'hdfs://c6401.ambari.apache.org:8020',
  292. hdfs_site = self.getConfig()['configurations']['hdfs-site'],
  293. kinit_path_local = '/usr/bin/kinit',
  294. principal_name = UnknownConfigurationMock(),
  295. user = 'hdfs',
  296. dfs_type = '',
  297. owner = 'falcon',
  298. hadoop_conf_dir = '/usr/hdp/current/hadoop-client/conf',
  299. type = 'directory',
  300. action = ['create_on_execute'],
  301. mode = 0777,
  302. )
  303. self.assertResourceCalled('Directory', '/hadoop/falcon/store',
  304. owner = 'falcon',
  305. recursive = True,
  306. )
  307. self.assertResourceCalled('HdfsResource', '/apps/data-mirroring',
  308. security_enabled = False,
  309. hadoop_bin_dir = '/usr/hdp/current/hadoop-client/bin',
  310. keytab = UnknownConfigurationMock(),
  311. source = '/usr/hdp/current/falcon-server/data-mirroring',
  312. default_fs = 'hdfs://c6401.ambari.apache.org:8020',
  313. user = 'hdfs',
  314. dfs_type = '',
  315. hdfs_site = self.getConfig()['configurations']['hdfs-site'],
  316. kinit_path_local = '/usr/bin/kinit',
  317. principal_name = UnknownConfigurationMock(),
  318. recursive_chmod = True,
  319. recursive_chown = True,
  320. owner = 'falcon',
  321. group = 'users',
  322. hadoop_conf_dir = '/usr/hdp/current/hadoop-client/conf',
  323. type = 'directory',
  324. action = ['create_on_execute'],
  325. mode = 0770,
  326. )
  327. self.assertResourceCalled('HdfsResource', None,
  328. security_enabled = False,
  329. hadoop_bin_dir = '/usr/hdp/current/hadoop-client/bin',
  330. keytab = UnknownConfigurationMock(),
  331. default_fs = 'hdfs://c6401.ambari.apache.org:8020',
  332. hdfs_site = self.getConfig()['configurations']['hdfs-site'],
  333. kinit_path_local = '/usr/bin/kinit',
  334. principal_name = UnknownConfigurationMock(),
  335. user = 'hdfs',
  336. dfs_type = '',
  337. action = ['execute'],
  338. hadoop_conf_dir = '/usr/hdp/current/hadoop-client/conf',
  339. )
  340. self.assertResourceCalled('Directory', '/hadoop/falcon',
  341. owner = 'falcon',
  342. recursive = True,
  343. cd_access = 'a',
  344. )
  345. self.assertResourceCalled('Directory', '/hadoop/falcon/embeddedmq',
  346. owner = 'falcon',
  347. recursive = True,
  348. )
  349. self.assertResourceCalled('Directory', '/hadoop/falcon/embeddedmq/data',
  350. owner = 'falcon',
  351. recursive = True,
  352. )
  353. self.assertResourceCalled('Execute', '/usr/hdp/current/falcon-server/bin/falcon-start -port 15000',
  354. environment = {'HADOOP_HOME': '/usr/hdp/current/hadoop-client'},
  355. path = ['/usr/hdp/current/hadoop-client/bin'],
  356. user = 'falcon',
  357. )
  358. self.assertNoMoreResources()
  359. @patch("resource_management.libraries.functions.security_commons.build_expectations")
  360. @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem")
  361. @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties")
  362. @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor")
  363. @patch("resource_management.libraries.script.Script.put_structured_out")
  364. def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock):
  365. # Test that function works when is called with correct parameters
  366. security_params = {
  367. 'startup': {
  368. '*.falcon.service.authentication.kerberos.keytab': 'path/to/falcon/service/keytab',
  369. '*.falcon.service.authentication.kerberos.principal': 'falcon_service_keytab',
  370. '*.falcon.http.authentication.kerberos.keytab': 'path/to/falcon/http/keytab',
  371. '*.falcon.http.authentication.kerberos.principal': 'falcon_http_principal'
  372. }
  373. }
  374. result_issues = []
  375. props_value_check = {"*.falcon.authentication.type": "kerberos",
  376. "*.falcon.http.authentication.type": "kerberos"}
  377. props_empty_check = ["*.falcon.service.authentication.kerberos.principal",
  378. "*.falcon.service.authentication.kerberos.keytab",
  379. "*.falcon.http.authentication.kerberos.principal",
  380. "*.falcon.http.authentication.kerberos.keytab"]
  381. props_read_check = ["*.falcon.service.authentication.kerberos.keytab",
  382. "*.falcon.http.authentication.kerberos.keytab"]
  383. get_params_mock.return_value = security_params
  384. validate_security_config_mock.return_value = result_issues
  385. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py",
  386. classname="FalconServer",
  387. command="security_status",
  388. config_file="secured.json",
  389. hdp_stack_version = self.STACK_VERSION,
  390. target = RMFTestCase.TARGET_COMMON_SERVICES
  391. )
  392. get_params_mock.assert_called_with('/etc/falcon/conf', {'startup.properties': 'PROPERTIES'})
  393. build_exp_mock.assert_called_with('startup', props_value_check, props_empty_check, props_read_check)
  394. put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"})
  395. self.assertTrue(cached_kinit_executor_mock.call_count, 2)
  396. cached_kinit_executor_mock.assert_called_with('/usr/bin/kinit',
  397. self.config_dict['configurations']['falcon-env']['falcon_user'],
  398. security_params['startup']['*.falcon.http.authentication.kerberos.keytab'],
  399. security_params['startup']['*.falcon.http.authentication.kerberos.principal'],
  400. self.config_dict['hostname'],
  401. '/tmp')
  402. # Testing that the exception throw by cached_executor is caught
  403. cached_kinit_executor_mock.reset_mock()
  404. cached_kinit_executor_mock.side_effect = Exception("Invalid command")
  405. try:
  406. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py",
  407. classname="FalconServer",
  408. command="security_status",
  409. config_file="secured.json",
  410. hdp_stack_version = self.STACK_VERSION,
  411. target = RMFTestCase.TARGET_COMMON_SERVICES
  412. )
  413. except:
  414. self.assertTrue(True)
  415. # Testing with a security_params which doesn't contains startup
  416. empty_security_params = {}
  417. cached_kinit_executor_mock.reset_mock()
  418. get_params_mock.reset_mock()
  419. put_structured_out_mock.reset_mock()
  420. get_params_mock.return_value = empty_security_params
  421. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py",
  422. classname="FalconServer",
  423. command="security_status",
  424. config_file="secured.json",
  425. hdp_stack_version = self.STACK_VERSION,
  426. target = RMFTestCase.TARGET_COMMON_SERVICES
  427. )
  428. put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."})
  429. # Testing with not empty result_issues
  430. result_issues_with_params = {
  431. 'startup': "Something bad happened"
  432. }
  433. validate_security_config_mock.reset_mock()
  434. get_params_mock.reset_mock()
  435. validate_security_config_mock.return_value = result_issues_with_params
  436. get_params_mock.return_value = security_params
  437. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py",
  438. classname="FalconServer",
  439. command="security_status",
  440. config_file="secured.json",
  441. hdp_stack_version = self.STACK_VERSION,
  442. target = RMFTestCase.TARGET_COMMON_SERVICES
  443. )
  444. put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"})
  445. # Testing with security_enable = false
  446. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py",
  447. classname="FalconServer",
  448. command="security_status",
  449. config_file="default.json",
  450. hdp_stack_version = self.STACK_VERSION,
  451. target = RMFTestCase.TARGET_COMMON_SERVICES
  452. )
  453. put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"})
  454. @patch('os.path.isfile', new=MagicMock(return_value=True))
  455. def test_pre_rolling_restart(self):
  456. config_file = self.get_src_folder()+"/test/python/stacks/2.2/configs/falcon-upgrade.json"
  457. with open(config_file, "r") as f:
  458. json_content = json.load(f)
  459. version = '2.2.1.0-3242'
  460. json_content['commandParams']['version'] = version
  461. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py",
  462. classname = "FalconServer",
  463. command = "pre_rolling_restart",
  464. config_dict = json_content,
  465. hdp_stack_version = self.STACK_VERSION,
  466. target = RMFTestCase.TARGET_COMMON_SERVICES)
  467. self.assertResourceCalled('Execute',
  468. ('ambari-python-wrap', '/usr/bin/hdp-select', 'set', 'falcon-server', version), sudo=True,)
  469. self.printResources()
  470. @patch('os.path.isfile', new=MagicMock(return_value=True))
  471. @patch.object(tarfile, 'open')
  472. @patch.object(shutil, 'rmtree')
  473. @patch("resource_management.core.shell.call")
  474. def test_pre_rolling_restart_23(self, tarfile_open_mock, rmtree_mock, call_mock):
  475. config_file = self.get_src_folder()+"/test/python/stacks/2.2/configs/falcon-upgrade.json"
  476. with open(config_file, "r") as f:
  477. json_content = json.load(f)
  478. version = '2.3.0.0-1234'
  479. json_content['commandParams']['version'] = version
  480. mocks_dict = {}
  481. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py",
  482. classname = "FalconServer",
  483. command = "pre_rolling_restart",
  484. config_dict = json_content,
  485. hdp_stack_version = self.STACK_VERSION,
  486. target = RMFTestCase.TARGET_COMMON_SERVICES,
  487. call_mocks = [(0, None), (0, None)],
  488. mocks_dict = mocks_dict)
  489. self.assertResourceCalled('Execute',
  490. ('ambari-python-wrap', '/usr/bin/hdp-select', 'set', 'falcon-server', version), sudo=True,)
  491. self.assertResourceCalled('Execute', ('tar',
  492. '-xvf',
  493. '/tmp/falcon-upgrade-backup/falcon-conf-backup.tar',
  494. '-C',
  495. '/usr/hdp/current/falcon-server/conf/'),
  496. sudo = True,
  497. )
  498. self.assertResourceCalled('Execute', ('tar',
  499. '-xvf',
  500. '/tmp/falcon-upgrade-backup/falcon-local-backup.tar',
  501. '-C',
  502. u'/hadoop/falcon/'),
  503. sudo = True,
  504. )
  505. self.assertResourceCalled('Directory', '/tmp/falcon-upgrade-backup',
  506. action = ['delete'],
  507. )
  508. self.assertNoMoreResources()
  509. self.assertEquals(1, mocks_dict['call'].call_count)
  510. self.assertEquals(1, mocks_dict['checked_call'].call_count)
  511. self.assertEquals(
  512. ('conf-select', 'set-conf-dir', '--package', 'falcon', '--stack-version', '2.3.0.0-1234', '--conf-version', '0'),
  513. mocks_dict['checked_call'].call_args_list[0][0][0])
  514. self.assertEquals(
  515. ('conf-select', 'create-conf-dir', '--package', 'falcon', '--stack-version', '2.3.0.0-1234', '--conf-version', '0'),
  516. mocks_dict['call'].call_args_list[0][0][0])