TestInstallPackages.py 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  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. import os
  19. import subprocess
  20. import select
  21. import install_packages
  22. from mock.mock import patch
  23. from mock.mock import MagicMock
  24. from stacks.utils.RMFTestCase import *
  25. from mock.mock import patch, MagicMock
  26. from resource_management.core.base import Resource
  27. from resource_management.core.exceptions import Fail
  28. OLD_VERSION_STUB = '2.1.0.0-400'
  29. VERSION_STUB_WITHOUT_BUILD_NUMBER = '2.2.0.1'
  30. VERSION_STUB = '2.2.0.1-885'
  31. from only_for_platform import get_platform, not_for_platform, only_for_platform, os_distro_value, PLATFORM_WINDOWS
  32. if get_platform() != PLATFORM_WINDOWS:
  33. import pty
  34. subproc_mock = MagicMock()
  35. subproc_mock.return_value = MagicMock()
  36. subproc_stdout = MagicMock()
  37. subproc_mock.return_value.stdout = subproc_stdout
  38. @not_for_platform(PLATFORM_WINDOWS)
  39. @patch.object(os, "read", new=MagicMock(return_value=None))
  40. @patch.object(select, "select", new=MagicMock(return_value=([subproc_stdout], None, None)))
  41. @patch("pty.openpty", new = MagicMock(return_value=(1,5)))
  42. @patch.object(os, "close", new=MagicMock())
  43. @patch.object(subprocess, "Popen", new=subproc_mock)
  44. class TestInstallPackages(RMFTestCase):
  45. def setUp(self):
  46. self.maxDiff = None
  47. @staticmethod
  48. def _add_packages(arg):
  49. arg.append(["pkg1", "1.0", "repo"])
  50. arg.append(["pkg2", "2.0", "repo2"])
  51. @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
  52. @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
  53. @patch("resource_management.libraries.script.Script.put_structured_out")
  54. @patch("resource_management.libraries.functions.hdp_select.get_hdp_versions")
  55. @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
  56. @patch("resource_management.libraries.functions.repo_version_history.write_actual_version_to_history_file")
  57. def test_normal_flow_rhel(self,
  58. write_actual_version_to_history_file_mock,
  59. read_actual_version_from_history_file_mock,
  60. hdp_versions_mock,
  61. put_structured_out_mock, allInstalledPackages_mock, list_ambari_managed_repos_mock):
  62. read_actual_version_from_history_file_mock.return_value = VERSION_STUB
  63. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  64. list_ambari_managed_repos_mock.return_value=[]
  65. self.executeScript("scripts/install_packages.py",
  66. classname="InstallPackages",
  67. command="actionexecute",
  68. config_file="install_packages_config.json",
  69. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  70. os_type=('Redhat', '6.4', 'Final'),
  71. )
  72. self.assertTrue(put_structured_out_mock.called)
  73. self.assertEquals(put_structured_out_mock.call_args[0][0],
  74. {'package_installation_result': 'SUCCESS',
  75. 'installed_repository_version': VERSION_STUB,
  76. 'stack_id': 'HDP-2.2',
  77. 'actual_version': VERSION_STUB,
  78. 'ambari_repositories': []})
  79. self.assertResourceCalled('Repository', 'HDP-UTILS-2.2.0.1-885',
  80. base_url=u'http://repo1/HDP/centos5/2.x/updates/2.2.0.0',
  81. action=['create'],
  82. components=[u'HDP-UTILS', 'main'],
  83. repo_template='[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0',
  84. repo_file_name=u'HDP-2.2.0.1-885',
  85. mirror_list=None,
  86. append_to_file=False,
  87. )
  88. self.assertResourceCalled('Repository', 'HDP-2.2.0.1-885',
  89. base_url=u'http://repo1/HDP/centos5/2.x/updates/2.2.0.0',
  90. action=['create'],
  91. components=[u'HDP', 'main'],
  92. repo_template='[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0',
  93. repo_file_name=u'HDP-2.2.0.1-885',
  94. mirror_list=None,
  95. append_to_file=True,
  96. )
  97. self.assertResourceCalled('Package', 'hadoop_2_2_*', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  98. self.assertResourceCalled('Package', 'snappy', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  99. self.assertResourceCalled('Package', 'snappy-devel', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  100. self.assertResourceCalled('Package', 'lzo', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  101. self.assertResourceCalled('Package', 'hadooplzo_2_2_*', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  102. self.assertResourceCalled('Package', 'hadoop_2_2_*-libhdfs', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  103. self.assertResourceCalled('Package', 'ambari-log4j', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  104. self.assertNoMoreResources()
  105. @patch("ambari_commons.os_check.OSCheck.is_suse_family")
  106. @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
  107. @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
  108. @patch("resource_management.libraries.script.Script.put_structured_out")
  109. @patch("resource_management.libraries.functions.hdp_select.get_hdp_versions")
  110. @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
  111. @patch("resource_management.libraries.functions.repo_version_history.write_actual_version_to_history_file")
  112. def test_normal_flow_sles(self, write_actual_version_to_history_file_mock,
  113. read_actual_version_from_history_file_mock,
  114. hdp_versions_mock, put_structured_out_mock, allInstalledPackages_mock, list_ambari_managed_repos_mock, is_suse_family_mock):
  115. is_suse_family_mock = True
  116. read_actual_version_from_history_file_mock.return_value = VERSION_STUB
  117. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  118. list_ambari_managed_repos_mock.return_value=[]
  119. self.executeScript("scripts/install_packages.py",
  120. classname="InstallPackages",
  121. command="actionexecute",
  122. config_file="install_packages_config.json",
  123. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  124. os_type=('Suse', '11', 'SP1'),
  125. )
  126. self.assertTrue(put_structured_out_mock.called)
  127. self.assertEquals(put_structured_out_mock.call_args[0][0],
  128. {'package_installation_result': 'SUCCESS',
  129. 'installed_repository_version': VERSION_STUB,
  130. 'stack_id': 'HDP-2.2',
  131. 'actual_version': VERSION_STUB,
  132. 'ambari_repositories': []})
  133. self.assertResourceCalled('Repository', 'HDP-UTILS-2.2.0.1-885',
  134. base_url=u'http://repo1/HDP/centos5/2.x/updates/2.2.0.0',
  135. action=['create'],
  136. components=[u'HDP-UTILS', 'main'],
  137. repo_template='[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0',
  138. repo_file_name=u'HDP-2.2.0.1-885',
  139. mirror_list=None,
  140. append_to_file=False,
  141. )
  142. self.assertResourceCalled('Repository', 'HDP-2.2.0.1-885',
  143. base_url=u'http://repo1/HDP/centos5/2.x/updates/2.2.0.0',
  144. action=['create'],
  145. components=[u'HDP', 'main'],
  146. repo_template=u'[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0',
  147. repo_file_name=u'HDP-2.2.0.1-885',
  148. mirror_list=None,
  149. append_to_file=True,
  150. )
  151. self.assertResourceCalled('Package', 'hadoop_2_2_0_1_885*', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  152. self.assertResourceCalled('Package', 'snappy', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  153. self.assertResourceCalled('Package', 'snappy-devel', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  154. self.assertResourceCalled('Package', 'lzo', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  155. self.assertResourceCalled('Package', 'hadooplzo_2_2_0_1_885*', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  156. self.assertResourceCalled('Package', 'hadoop_2_2_0_1_885*-libhdfs', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  157. self.assertResourceCalled('Package', 'ambari-log4j', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  158. self.assertNoMoreResources()
  159. @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
  160. @patch("ambari_commons.os_check.OSCheck.is_redhat_family")
  161. @patch("resource_management.libraries.script.Script.put_structured_out")
  162. @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
  163. @patch("resource_management.libraries.functions.hdp_select.get_hdp_versions")
  164. @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
  165. @patch("resource_management.libraries.functions.repo_version_history.write_actual_version_to_history_file")
  166. def test_exclude_existing_repo(self, write_actual_version_to_history_file_mock,
  167. read_actual_version_from_history_file_mock,
  168. hdp_versions_mock,
  169. allInstalledPackages_mock, put_structured_out_mock,
  170. is_redhat_family_mock, list_ambari_managed_repos_mock):
  171. read_actual_version_from_history_file_mock.return_value = VERSION_STUB
  172. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  173. list_ambari_managed_repos_mock.return_value=["HDP-UTILS-2.2.0.1-885"]
  174. is_redhat_family_mock.return_value = True
  175. self.executeScript("scripts/install_packages.py",
  176. classname="InstallPackages",
  177. command="actionexecute",
  178. config_file="install_packages_config.json",
  179. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  180. os_type=('Redhat', '6.4', 'Final'),
  181. )
  182. self.assertTrue(put_structured_out_mock.called)
  183. self.assertEquals(put_structured_out_mock.call_args[0][0],
  184. {'package_installation_result': 'SUCCESS',
  185. 'installed_repository_version': VERSION_STUB,
  186. 'stack_id': 'HDP-2.2',
  187. 'actual_version': VERSION_STUB,
  188. 'ambari_repositories': ["HDP-UTILS-2.2.0.1-885"]})
  189. self.assertResourceCalled('Repository', 'HDP-UTILS-2.2.0.1-885',
  190. base_url=u'http://repo1/HDP/centos5/2.x/updates/2.2.0.0',
  191. action=['create'],
  192. components=[u'HDP-UTILS', 'main'],
  193. repo_template=u'[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0',
  194. repo_file_name='HDP-2.2.0.1-885',
  195. mirror_list=None,
  196. append_to_file=False,
  197. )
  198. self.assertResourceCalled('Repository', 'HDP-2.2.0.1-885',
  199. base_url='http://repo1/HDP/centos5/2.x/updates/2.2.0.0',
  200. action=['create'],
  201. components=[u'HDP', 'main'],
  202. repo_template=u'[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0',
  203. repo_file_name=u'HDP-2.2.0.1-885',
  204. mirror_list=None,
  205. append_to_file=True,
  206. )
  207. self.assertResourceCalled('Package', 'hadoop_2_2_*', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  208. self.assertResourceCalled('Package', 'snappy', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  209. self.assertResourceCalled('Package', 'snappy-devel', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  210. self.assertResourceCalled('Package', 'lzo', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  211. self.assertResourceCalled('Package', 'hadooplzo_2_2_*', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  212. self.assertResourceCalled('Package', 'hadoop_2_2_*-libhdfs', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  213. self.assertResourceCalled('Package', 'ambari-log4j', use_repos=['HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=['HDP-*'])
  214. self.assertNoMoreResources()
  215. _install_failed = False
  216. @staticmethod
  217. def _add_packages_with_fail(arg):
  218. arg.append(["pkg1_2_2_0_1_885_pack", "1.0", "repo"])
  219. arg.append(["pkg2_2_2_0_1_885_pack2", "2.0", "repo2"])
  220. if TestInstallPackages._install_failed:
  221. arg.append(["should_not_be_removed_pkg1", "1.0", "repo"])
  222. arg.append(["hadoop_2_2_0_1_885fake_pkg", "1.0", "repo"])
  223. arg.append(["snappy__2_2_0_1_885_fake_pkg", "3.0", "repo2"])
  224. arg.append(["ubuntu-like-2-2-0-1-885-fake-pkg", "3.0", "repo2"])
  225. arg.append(["should_not_be_removed_pkg2", "3.0", "repo2"])
  226. @staticmethod
  227. def _new_with_exception(cls, name, env=None, provider=None, **kwargs):
  228. if (name != "snappy-devel"):
  229. return Resource.__new__(cls, name, env, provider, **kwargs)
  230. else:
  231. TestInstallPackages._install_failed = True
  232. raise Exception()
  233. @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
  234. @patch("ambari_commons.os_check.OSCheck.is_redhat_family")
  235. @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
  236. @patch("resource_management.core.resources.packaging.Package.__new__")
  237. @patch("resource_management.libraries.script.Script.put_structured_out")
  238. def test_fail(self, put_structured_out_mock, Package__mock, allInstalledPackages_mock,
  239. is_redhat_family_mock, list_ambari_managed_repos_mock):
  240. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages_with_fail
  241. is_redhat_family_mock.return_value = True
  242. list_ambari_managed_repos_mock.return_value = []
  243. def side_effect(retcode):
  244. TestInstallPackages._install_failed = True
  245. raise Exception()
  246. Package__mock.side_effect = side_effect
  247. self.assertRaises(Fail, self.executeScript, "scripts/install_packages.py",
  248. classname="InstallPackages",
  249. command="actionexecute",
  250. config_file="install_packages_config.json",
  251. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  252. os_type=('Redhat', '6.4', 'Final'))
  253. self.assertTrue(put_structured_out_mock.called)
  254. self.assertEquals(put_structured_out_mock.call_args[0][0],
  255. {'stack_id': 'HDP-2.2',
  256. 'actual_version': VERSION_STUB,
  257. 'installed_repository_version': VERSION_STUB,
  258. 'ambari_repositories': [],
  259. 'package_installation_result': 'FAIL'})
  260. self.assertResourceCalled('Repository', 'HDP-UTILS-2.2.0.1-885',
  261. base_url=u'http://repo1/HDP/centos5/2.x/updates/2.2.0.0',
  262. action=['create'],
  263. components=[u'HDP-UTILS', 'main'],
  264. repo_template=u'[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0',
  265. repo_file_name=u'HDP-2.2.0.1-885',
  266. mirror_list=None,
  267. append_to_file=False,
  268. )
  269. self.assertResourceCalled('Repository', 'HDP-2.2.0.1-885',
  270. base_url=u'http://repo1/HDP/centos5/2.x/updates/2.2.0.0',
  271. action=['create'],
  272. components=[u'HDP', 'main'],
  273. repo_template=u'[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0',
  274. repo_file_name=u'HDP-2.2.0.1-885',
  275. mirror_list=None,
  276. append_to_file=True,
  277. )
  278. self.assertNoMoreResources()
  279. TestInstallPackages._install_failed = False
  280. @patch("ambari_commons.os_check.OSCheck.is_suse_family")
  281. @patch("resource_management.core.resources.packaging.Package")
  282. @patch("resource_management.libraries.script.Script.put_structured_out")
  283. @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
  284. @patch("resource_management.libraries.functions.hdp_select.get_hdp_versions")
  285. @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
  286. @patch("resource_management.libraries.functions.repo_version_history.write_actual_version_to_history_file")
  287. def test_format_package_name(self, write_actual_version_to_history_file_mock,
  288. read_actual_version_from_history_file_mock,
  289. hdp_versions_mock,
  290. allInstalledPackages_mock, put_structured_out_mock,
  291. package_mock, is_suse_family_mock):
  292. read_actual_version_from_history_file_mock.return_value = VERSION_STUB
  293. allInstalledPackages_mock = MagicMock(side_effect = TestInstallPackages._add_packages)
  294. is_suse_family_mock.return_value = True
  295. self.executeScript("scripts/install_packages.py",
  296. classname="InstallPackages",
  297. command="actionexecute",
  298. config_file="install_packages_config.json",
  299. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  300. os_type=('Suse', '11', 'Final'),
  301. )
  302. self.assertTrue(put_structured_out_mock.called)
  303. self.assertEquals(put_structured_out_mock.call_args[0][0],
  304. {'package_installation_result': 'SUCCESS',
  305. 'installed_repository_version': VERSION_STUB,
  306. 'stack_id': 'HDP-2.2',
  307. 'actual_version': VERSION_STUB,
  308. 'ambari_repositories': []})
  309. self.assertResourceCalled('Repository', 'HDP-UTILS-2.2.0.1-885',
  310. base_url=u'http://repo1/HDP/centos5/2.x/updates/2.2.0.0',
  311. action=['create'],
  312. components=[u'HDP-UTILS', 'main'],
  313. repo_template=u'[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0',
  314. repo_file_name=u'HDP-2.2.0.1-885',
  315. mirror_list=None,
  316. append_to_file=False,
  317. )
  318. self.assertResourceCalled('Repository', 'HDP-2.2.0.1-885',
  319. base_url=u'http://repo1/HDP/centos5/2.x/updates/2.2.0.0',
  320. action=['create'],
  321. components=[u'HDP', 'main'],
  322. repo_template=u'[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0',
  323. repo_file_name=u'HDP-2.2.0.1-885',
  324. mirror_list=None,
  325. append_to_file=True,
  326. )
  327. self.assertResourceCalled('Package', 'hadoop_2_2_0_1_885*', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  328. self.assertResourceCalled('Package', 'snappy', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  329. self.assertResourceCalled('Package', 'snappy-devel', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  330. self.assertResourceCalled('Package', 'lzo', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  331. self.assertResourceCalled('Package', 'hadooplzo_2_2_0_1_885*', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  332. self.assertResourceCalled('Package', 'hadoop_2_2_0_1_885*-libhdfs', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  333. self.assertResourceCalled('Package', 'ambari-log4j', use_repos=['base', 'HDP-UTILS-2.2.0.1-885', 'HDP-2.2.0.1-885'], skip_repos=[])
  334. self.assertNoMoreResources()
  335. @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
  336. @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
  337. @patch("resource_management.libraries.script.Script.put_structured_out")
  338. @patch("resource_management.libraries.functions.hdp_select.get_hdp_versions")
  339. @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
  340. @patch("resource_management.libraries.functions.repo_version_history.write_actual_version_to_history_file")
  341. def test_version_reporting__build_number_defined__usr_hdp_present(self,
  342. write_actual_version_to_history_file_mock,
  343. read_actual_version_from_history_file_mock,
  344. hdp_versions_mock,
  345. put_structured_out_mock, allInstalledPackages_mock, list_ambari_managed_repos_mock):
  346. hdp_versions_mock.side_effect = [
  347. [OLD_VERSION_STUB], # before installation attempt
  348. [OLD_VERSION_STUB, VERSION_STUB]
  349. ]
  350. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  351. with open(config_file, "r") as f:
  352. command_json = json.load(f)
  353. command_json['roleParams']['repository_version'] = VERSION_STUB
  354. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  355. list_ambari_managed_repos_mock.return_value = []
  356. self.executeScript("scripts/install_packages.py",
  357. classname="InstallPackages",
  358. command="actionexecute",
  359. config_dict=command_json,
  360. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  361. os_type=('Redhat', '6.4', 'Final'),
  362. )
  363. self.assertTrue(put_structured_out_mock.called)
  364. self.assertEquals(put_structured_out_mock.call_args[0][0],
  365. {'package_installation_result': 'SUCCESS',
  366. 'installed_repository_version': VERSION_STUB,
  367. 'stack_id': 'HDP-2.2',
  368. 'actual_version': VERSION_STUB,
  369. 'ambari_repositories': []})
  370. self.assertTrue(write_actual_version_to_history_file_mock.called)
  371. self.assertEquals(write_actual_version_to_history_file_mock.call_args[0], (VERSION_STUB_WITHOUT_BUILD_NUMBER, VERSION_STUB))
  372. hdp_versions_mock.reset_mock()
  373. write_actual_version_to_history_file_mock.reset_mock()
  374. put_structured_out_mock.reset_mock()
  375. # Test retrying install again
  376. hdp_versions_mock.side_effect = [
  377. [OLD_VERSION_STUB, VERSION_STUB],
  378. [OLD_VERSION_STUB, VERSION_STUB]
  379. ]
  380. read_actual_version_from_history_file_mock.return_value = VERSION_STUB
  381. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  382. with open(config_file, "r") as f:
  383. command_json = json.load(f)
  384. command_json['roleParams']['repository_version'] = VERSION_STUB
  385. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  386. list_ambari_managed_repos_mock.return_value = []
  387. self.executeScript("scripts/install_packages.py",
  388. classname="InstallPackages",
  389. command="actionexecute",
  390. config_dict=command_json,
  391. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  392. os_type=('Redhat', '6.4', 'Final'),
  393. )
  394. self.assertTrue(put_structured_out_mock.called)
  395. self.assertEquals(put_structured_out_mock.call_args[0][0],
  396. {'package_installation_result': 'SUCCESS',
  397. 'installed_repository_version': VERSION_STUB,
  398. 'stack_id': 'HDP-2.2',
  399. 'actual_version': VERSION_STUB,
  400. 'ambari_repositories': []})
  401. self.assertFalse(write_actual_version_to_history_file_mock.called)
  402. @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
  403. @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
  404. @patch("resource_management.libraries.script.Script.put_structured_out")
  405. @patch("resource_management.libraries.functions.hdp_select.get_hdp_versions")
  406. @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
  407. @patch("resource_management.libraries.functions.repo_version_history.write_actual_version_to_history_file")
  408. @patch("os.path.exists")
  409. def test_version_reporting__build_number_defined__usr_hdp_not_present(self,
  410. exists_mock,
  411. write_actual_version_to_history_file_mock,
  412. read_actual_version_from_history_file_mock,
  413. hdp_versions_mock,
  414. put_structured_out_mock, allInstalledPackages_mock, list_ambari_managed_repos_mock):
  415. exists_mock.return_value = False
  416. hdp_versions_mock.side_effect = [
  417. [], # before installation attempt
  418. []
  419. ]
  420. read_actual_version_from_history_file_mock.return_value = None
  421. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  422. with open(config_file, "r") as f:
  423. command_json = json.load(f)
  424. command_json['roleParams']['repository_version'] = VERSION_STUB
  425. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  426. list_ambari_managed_repos_mock.return_value = []
  427. self.executeScript("scripts/install_packages.py",
  428. classname="InstallPackages",
  429. command="actionexecute",
  430. config_dict=command_json,
  431. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  432. os_type=('Redhat', '6.4', 'Final'),
  433. )
  434. self.assertTrue(put_structured_out_mock.called)
  435. self.assertEquals(put_structured_out_mock.call_args[0][0],
  436. {'package_installation_result': 'SUCCESS',
  437. 'stack_id': u'HDP-2.2',
  438. 'installed_repository_version': VERSION_STUB,
  439. 'actual_version': VERSION_STUB,
  440. 'ambari_repositories': []})
  441. self.assertFalse(write_actual_version_to_history_file_mock.called)
  442. hdp_versions_mock.reset_mock()
  443. write_actual_version_to_history_file_mock.reset_mock()
  444. put_structured_out_mock.reset_mock()
  445. # Test retrying install again
  446. hdp_versions_mock.side_effect = [
  447. [], # before installation attempt
  448. []
  449. ]
  450. read_actual_version_from_history_file_mock.return_value = None
  451. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  452. with open(config_file, "r") as f:
  453. command_json = json.load(f)
  454. command_json['roleParams']['repository_version'] = VERSION_STUB
  455. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  456. list_ambari_managed_repos_mock.return_value = []
  457. self.executeScript("scripts/install_packages.py",
  458. classname="InstallPackages",
  459. command="actionexecute",
  460. config_dict=command_json,
  461. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  462. os_type=('Redhat', '6.4', 'Final'),
  463. )
  464. self.assertTrue(put_structured_out_mock.called)
  465. self.assertEquals(put_structured_out_mock.call_args[0][0],
  466. {'package_installation_result': 'SUCCESS',
  467. 'stack_id': u'HDP-2.2',
  468. 'installed_repository_version': VERSION_STUB,
  469. 'actual_version': VERSION_STUB,
  470. 'ambari_repositories': []})
  471. self.assertFalse(write_actual_version_to_history_file_mock.called)
  472. @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
  473. @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
  474. @patch("resource_management.libraries.script.Script.put_structured_out")
  475. @patch("resource_management.libraries.functions.hdp_select.get_hdp_versions")
  476. @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
  477. @patch("resource_management.libraries.functions.repo_version_history.write_actual_version_to_history_file")
  478. @patch("os.path.exists")
  479. def test_version_reporting__build_number_not_defined__usr_hdp_present__no_components_installed(self,
  480. exists_mock,
  481. write_actual_version_to_history_file_mock,
  482. read_actual_version_from_history_file_mock,
  483. hdp_versions_mock,
  484. put_structured_out_mock, allInstalledPackages_mock, list_ambari_managed_repos_mock):
  485. exists_mock.return_value = True
  486. hdp_versions_mock.side_effect = [
  487. [], # before installation attempt
  488. []
  489. ]
  490. read_actual_version_from_history_file_mock.return_value = None
  491. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  492. with open(config_file, "r") as f:
  493. command_json = json.load(f)
  494. command_json['roleParams']['repository_version'] = VERSION_STUB_WITHOUT_BUILD_NUMBER
  495. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  496. list_ambari_managed_repos_mock.return_value = []
  497. try:
  498. self.executeScript("scripts/install_packages.py",
  499. classname="InstallPackages",
  500. command="actionexecute",
  501. config_dict=command_json,
  502. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  503. os_type=('Redhat', '6.4', 'Final'),
  504. )
  505. self.fail("Should throw exception")
  506. except Fail:
  507. pass # Expected
  508. self.assertTrue(put_structured_out_mock.called)
  509. self.assertEquals(put_structured_out_mock.call_args_list[-1][0][0],
  510. { 'ambari_repositories': [],
  511. 'package_installation_result': 'FAIL',
  512. 'installed_repository_version': '2.2.0.1',
  513. 'stack_id': u'HDP-2.2'})
  514. self.assertFalse(write_actual_version_to_history_file_mock.called)
  515. hdp_versions_mock.reset_mock()
  516. write_actual_version_to_history_file_mock.reset_mock()
  517. put_structured_out_mock.reset_mock()
  518. @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
  519. @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
  520. @patch("resource_management.libraries.script.Script.put_structured_out")
  521. @patch("resource_management.libraries.functions.hdp_select.get_hdp_versions")
  522. @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
  523. @patch("resource_management.libraries.functions.repo_version_history.write_actual_version_to_history_file")
  524. @patch("os.path.exists")
  525. def test_version_reporting__build_number_not_defined__usr_hdp_not_present(self,
  526. exists_mock,
  527. write_actual_version_to_history_file_mock,
  528. read_actual_version_from_history_file_mock,
  529. hdp_versions_mock,
  530. put_structured_out_mock, allInstalledPackages_mock, list_ambari_managed_repos_mock):
  531. exists_mock.return_value = False
  532. hdp_versions_mock.side_effect = [
  533. [], # before installation attempt
  534. []
  535. ]
  536. read_actual_version_from_history_file_mock.return_value = None
  537. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  538. with open(config_file, "r") as f:
  539. command_json = json.load(f)
  540. command_json['roleParams']['repository_version'] = VERSION_STUB_WITHOUT_BUILD_NUMBER
  541. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  542. list_ambari_managed_repos_mock.return_value = []
  543. self.executeScript("scripts/install_packages.py",
  544. classname="InstallPackages",
  545. command="actionexecute",
  546. config_dict=command_json,
  547. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  548. os_type=('Redhat', '6.4', 'Final'),
  549. )
  550. self.assertTrue(put_structured_out_mock.called)
  551. self.assertEquals(put_structured_out_mock.call_args_list[-1][0][0],
  552. {'package_installation_result': 'SUCCESS',
  553. 'stack_id': u'HDP-2.2',
  554. 'installed_repository_version': '2.2.0.1',
  555. 'ambari_repositories': []})
  556. self.assertFalse(write_actual_version_to_history_file_mock.called)
  557. hdp_versions_mock.reset_mock()
  558. write_actual_version_to_history_file_mock.reset_mock()
  559. put_structured_out_mock.reset_mock()
  560. # Test retrying install again
  561. hdp_versions_mock.side_effect = [
  562. [], # before installation attempt
  563. []
  564. ]
  565. read_actual_version_from_history_file_mock.return_value = None
  566. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  567. with open(config_file, "r") as f:
  568. command_json = json.load(f)
  569. command_json['roleParams']['repository_version'] = VERSION_STUB
  570. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  571. list_ambari_managed_repos_mock.return_value = []
  572. self.executeScript("scripts/install_packages.py",
  573. classname="InstallPackages",
  574. command="actionexecute",
  575. config_dict=command_json,
  576. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  577. os_type=('Redhat', '6.4', 'Final'),
  578. )
  579. self.assertTrue(put_structured_out_mock.called)
  580. self.assertEquals(put_structured_out_mock.call_args[0][0],
  581. {'package_installation_result': 'SUCCESS',
  582. 'stack_id': u'HDP-2.2',
  583. 'installed_repository_version': VERSION_STUB,
  584. 'actual_version': VERSION_STUB,
  585. 'ambari_repositories': []})
  586. self.assertFalse(write_actual_version_to_history_file_mock.called)
  587. @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
  588. @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
  589. @patch("resource_management.libraries.script.Script.put_structured_out")
  590. @patch("resource_management.libraries.functions.hdp_select.get_hdp_versions")
  591. @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
  592. @patch("resource_management.libraries.functions.repo_version_history.write_actual_version_to_history_file")
  593. def test_version_reporting__build_number_not_defined__usr_hdp_present(self,
  594. write_actual_version_to_history_file_mock,
  595. read_actual_version_from_history_file_mock,
  596. hdp_versions_mock,
  597. put_structured_out_mock, allInstalledPackages_mock, list_ambari_managed_repos_mock):
  598. hdp_versions_mock.side_effect = [
  599. [OLD_VERSION_STUB], # before installation attempt
  600. [OLD_VERSION_STUB, VERSION_STUB]
  601. ]
  602. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  603. with open(config_file, "r") as f:
  604. command_json = json.load(f)
  605. command_json['roleParams']['repository_version'] = VERSION_STUB_WITHOUT_BUILD_NUMBER
  606. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  607. list_ambari_managed_repos_mock.return_value = []
  608. self.executeScript("scripts/install_packages.py",
  609. classname="InstallPackages",
  610. command="actionexecute",
  611. config_dict=command_json,
  612. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  613. os_type=('Redhat', '6.4', 'Final'),
  614. )
  615. self.assertTrue(put_structured_out_mock.called)
  616. self.assertEquals(put_structured_out_mock.call_args[0][0],
  617. {'package_installation_result': 'SUCCESS',
  618. 'installed_repository_version': VERSION_STUB_WITHOUT_BUILD_NUMBER,
  619. 'stack_id': 'HDP-2.2',
  620. 'actual_version': VERSION_STUB,
  621. 'ambari_repositories': []})
  622. self.assertTrue(write_actual_version_to_history_file_mock.called)
  623. self.assertEquals(write_actual_version_to_history_file_mock.call_args[0], (VERSION_STUB_WITHOUT_BUILD_NUMBER, VERSION_STUB))
  624. hdp_versions_mock.reset_mock()
  625. write_actual_version_to_history_file_mock.reset_mock()
  626. put_structured_out_mock.reset_mock()
  627. # Test retrying install again
  628. hdp_versions_mock.side_effect = [
  629. [OLD_VERSION_STUB, VERSION_STUB],
  630. [OLD_VERSION_STUB, VERSION_STUB]
  631. ]
  632. read_actual_version_from_history_file_mock.return_value = VERSION_STUB
  633. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  634. with open(config_file, "r") as f:
  635. command_json = json.load(f)
  636. command_json['roleParams']['repository_version'] = VERSION_STUB_WITHOUT_BUILD_NUMBER
  637. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  638. list_ambari_managed_repos_mock.return_value = []
  639. self.executeScript("scripts/install_packages.py",
  640. classname="InstallPackages",
  641. command="actionexecute",
  642. config_dict=command_json,
  643. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  644. os_type=('Redhat', '6.4', 'Final'),
  645. )
  646. self.assertTrue(put_structured_out_mock.called)
  647. self.assertEquals(put_structured_out_mock.call_args[0][0],
  648. {'package_installation_result': 'SUCCESS',
  649. 'installed_repository_version': VERSION_STUB_WITHOUT_BUILD_NUMBER,
  650. 'stack_id': 'HDP-2.2',
  651. 'actual_version': VERSION_STUB,
  652. 'ambari_repositories': []})
  653. self.assertFalse(write_actual_version_to_history_file_mock.called)
  654. @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
  655. @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
  656. @patch("resource_management.libraries.script.Script.put_structured_out")
  657. @patch("resource_management.libraries.functions.hdp_select.get_hdp_versions")
  658. @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
  659. @patch("resource_management.libraries.functions.repo_version_history.write_actual_version_to_history_file")
  660. def test_version_reporting__wrong_build_number_specified__usr_hdp_present(self,
  661. write_actual_version_to_history_file_mock,
  662. read_actual_version_from_history_file_mock,
  663. hdp_versions_mock,
  664. put_structured_out_mock, allInstalledPackages_mock, list_ambari_managed_repos_mock):
  665. hdp_versions_mock.side_effect = [
  666. [OLD_VERSION_STUB], # before installation attempt
  667. [OLD_VERSION_STUB, VERSION_STUB]
  668. ]
  669. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  670. with open(config_file, "r") as f:
  671. command_json = json.load(f)
  672. command_json['roleParams']['repository_version'] = '2.2.0.1-500' # User specified wrong build number
  673. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  674. list_ambari_managed_repos_mock.return_value = []
  675. self.executeScript("scripts/install_packages.py",
  676. classname="InstallPackages",
  677. command="actionexecute",
  678. config_dict=command_json,
  679. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  680. os_type=('Redhat', '6.4', 'Final'),
  681. )
  682. self.assertTrue(put_structured_out_mock.called)
  683. self.assertEquals(put_structured_out_mock.call_args[0][0],
  684. {'package_installation_result': 'SUCCESS',
  685. 'installed_repository_version': '2.2.0.1-500',
  686. 'stack_id': 'HDP-2.2',
  687. 'actual_version': VERSION_STUB,
  688. 'ambari_repositories': []})
  689. self.assertTrue(write_actual_version_to_history_file_mock.called)
  690. self.assertEquals(write_actual_version_to_history_file_mock.call_args[0], ('2.2.0.1', VERSION_STUB))
  691. hdp_versions_mock.reset_mock()
  692. write_actual_version_to_history_file_mock.reset_mock()
  693. put_structured_out_mock.reset_mock()
  694. # Test retrying install again
  695. hdp_versions_mock.side_effect = [
  696. [OLD_VERSION_STUB, VERSION_STUB],
  697. [OLD_VERSION_STUB, VERSION_STUB]
  698. ]
  699. read_actual_version_from_history_file_mock.return_value = VERSION_STUB
  700. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  701. with open(config_file, "r") as f:
  702. command_json = json.load(f)
  703. command_json['roleParams']['repository_version'] = '2.2.0.1-500' # User specified wrong build number
  704. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  705. list_ambari_managed_repos_mock.return_value = []
  706. self.executeScript("scripts/install_packages.py",
  707. classname="InstallPackages",
  708. command="actionexecute",
  709. config_dict=command_json,
  710. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  711. os_type=('Redhat', '6.4', 'Final'),
  712. )
  713. self.assertTrue(put_structured_out_mock.called)
  714. self.assertEquals(put_structured_out_mock.call_args[0][0],
  715. {'package_installation_result': 'SUCCESS',
  716. 'installed_repository_version': '2.2.0.1-500',
  717. 'stack_id': 'HDP-2.2',
  718. 'actual_version': VERSION_STUB,
  719. 'ambari_repositories': []})
  720. self.assertFalse(write_actual_version_to_history_file_mock.called)
  721. @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
  722. @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
  723. @patch("resource_management.libraries.script.Script.put_structured_out")
  724. @patch("resource_management.libraries.functions.hdp_select.get_hdp_versions")
  725. @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
  726. @patch("resource_management.libraries.functions.repo_version_history.write_actual_version_to_history_file")
  727. @patch("os.path.exists")
  728. def test_version_reporting__wrong_build_number_specified__usr_hdp_absent(self,
  729. exists_mock,
  730. write_actual_version_to_history_file_mock,
  731. read_actual_version_from_history_file_mock,
  732. hdp_versions_mock,
  733. put_structured_out_mock, allInstalledPackages_mock, list_ambari_managed_repos_mock):
  734. exists_mock.return_value = False
  735. hdp_versions_mock.side_effect = [
  736. [], # before installation attempt
  737. []
  738. ]
  739. read_actual_version_from_history_file_mock.return_value = None
  740. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  741. with open(config_file, "r") as f:
  742. command_json = json.load(f)
  743. command_json['roleParams']['repository_version'] = VERSION_STUB_WITHOUT_BUILD_NUMBER
  744. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  745. list_ambari_managed_repos_mock.return_value = []
  746. self.executeScript("scripts/install_packages.py",
  747. classname="InstallPackages",
  748. command="actionexecute",
  749. config_dict=command_json,
  750. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  751. os_type=('Redhat', '6.4', 'Final'),
  752. )
  753. self.assertTrue(put_structured_out_mock.called)
  754. self.assertEquals(put_structured_out_mock.call_args_list[-1][0][0],
  755. {'package_installation_result': 'SUCCESS',
  756. 'stack_id': u'HDP-2.2',
  757. 'installed_repository_version': '2.2.0.1',
  758. 'ambari_repositories': []})
  759. self.assertFalse(write_actual_version_to_history_file_mock.called)
  760. hdp_versions_mock.reset_mock()
  761. write_actual_version_to_history_file_mock.reset_mock()
  762. put_structured_out_mock.reset_mock()
  763. # Test retrying install again
  764. hdp_versions_mock.side_effect = [
  765. [], # before installation attempt
  766. []
  767. ]
  768. read_actual_version_from_history_file_mock.return_value = None
  769. config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
  770. with open(config_file, "r") as f:
  771. command_json = json.load(f)
  772. command_json['roleParams']['repository_version'] = VERSION_STUB
  773. allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
  774. list_ambari_managed_repos_mock.return_value = []
  775. self.executeScript("scripts/install_packages.py",
  776. classname="InstallPackages",
  777. command="actionexecute",
  778. config_dict=command_json,
  779. target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
  780. os_type=('Redhat', '6.4', 'Final'),
  781. )
  782. self.assertTrue(put_structured_out_mock.called)
  783. self.assertEquals(put_structured_out_mock.call_args[0][0],
  784. {'package_installation_result': 'SUCCESS',
  785. 'stack_id': u'HDP-2.2',
  786. 'installed_repository_version': VERSION_STUB,
  787. 'actual_version': VERSION_STUB,
  788. 'ambari_repositories': []})
  789. self.assertFalse(write_actual_version_to_history_file_mock.called)