test_phoenix_queryserver.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. from stacks.utils.RMFTestCase import *
  20. from unittest import skip
  21. @patch("platform.linux_distribution", new = MagicMock(return_value = "Linux"))
  22. @patch("os.path.exists", new = MagicMock(return_value = True))
  23. class TestPhoenixQueryServer(RMFTestCase):
  24. COMMON_SERVICES_PACKAGE_DIR = "HBASE/0.96.0.2.0/package"
  25. STACK_VERSION = "2.3"
  26. TMP_PATH = "/hadoop"
  27. def test_configure_default(self):
  28. self.executeScript(
  29. self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/phoenix_queryserver.py",
  30. classname = "PhoenixQueryServer",
  31. command = "configure",
  32. config_file = "hbase_default.json",
  33. hdp_stack_version = self.STACK_VERSION,
  34. target = RMFTestCase.TARGET_COMMON_SERVICES
  35. )
  36. self.assert_configure_default()
  37. self.assertNoMoreResources()
  38. def test_start_default(self):
  39. self.executeScript(
  40. self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/phoenix_queryserver.py",
  41. classname = "PhoenixQueryServer",
  42. command = "start",
  43. config_file = "hbase_default.json",
  44. hdp_stack_version = self.STACK_VERSION,
  45. target = RMFTestCase.TARGET_COMMON_SERVICES
  46. )
  47. self.assert_configure_default()
  48. self.assertResourceCalled('Execute',
  49. '/usr/hdp/current/phoenix-server/bin/queryserver.py start',
  50. environment = {'JAVA_HOME':'/usr/jdk64/jdk1.8.0_40',
  51. 'HBASE_CONF_DIR':'/usr/hdp/current/hbase-regionserver/conf'},
  52. user = 'hbase'
  53. )
  54. self.assertNoMoreResources()
  55. def test_stop_default(self):
  56. self.executeScript(
  57. self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/phoenix_queryserver.py",
  58. classname = "PhoenixQueryServer",
  59. command = "stop",
  60. config_file = "hbase_default.json",
  61. hdp_stack_version = self.STACK_VERSION,
  62. target = RMFTestCase.TARGET_COMMON_SERVICES
  63. )
  64. self.assertResourceCalled('Execute',
  65. '/usr/hdp/current/phoenix-server/bin/queryserver.py stop',
  66. on_timeout = '! ( ls /var/run/hbase/phoenix-hbase-server.pid >/dev/null 2>&1 && ps -p `cat /var/run/hbase/phoenix-hbase-server.pid` >/dev/null 2>&1 ) || ambari-sudo.sh -H -E kill -9 `cat /var/run/hbase/phoenix-hbase-server.pid`',
  67. timeout = 30,
  68. environment = {'JAVA_HOME':'/usr/jdk64/jdk1.8.0_40',
  69. 'HBASE_CONF_DIR':'/usr/hdp/current/hbase-regionserver/conf'},
  70. user = 'hbase'
  71. )
  72. self.assertResourceCalled('Execute',
  73. 'rm -f /var/run/hbase/phoenix-hbase-server.pid',
  74. )
  75. self.assertNoMoreResources()
  76. def test_configure_secured(self):
  77. self.executeScript(
  78. self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/phoenix_queryserver.py",
  79. classname = "PhoenixQueryServer",
  80. command = "configure",
  81. config_file = "hbase_secure.json",
  82. hdp_stack_version = self.STACK_VERSION,
  83. target = RMFTestCase.TARGET_COMMON_SERVICES
  84. )
  85. self.assert_configure_secured()
  86. self.assertNoMoreResources()
  87. def test_start_secured(self):
  88. self.executeScript(
  89. self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/phoenix_queryserver.py",
  90. classname = "PhoenixQueryServer",
  91. command = "start",
  92. config_file = "hbase_secure.json",
  93. hdp_stack_version = self.STACK_VERSION,
  94. target = RMFTestCase.TARGET_COMMON_SERVICES
  95. )
  96. self.assert_configure_secured()
  97. self.assertResourceCalled('Execute',
  98. '/usr/hdp/current/phoenix-server/bin/queryserver.py start',
  99. environment = {'JAVA_HOME':'/usr/jdk64/jdk1.8.0_40',
  100. 'HBASE_CONF_DIR':'/usr/hdp/current/hbase-regionserver/conf'},
  101. user = 'hbase'
  102. )
  103. self.assertNoMoreResources()
  104. def test_stop_secured(self):
  105. self.executeScript(
  106. self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/phoenix_queryserver.py",
  107. classname = "PhoenixQueryServer",
  108. command = "stop",
  109. config_file = "hbase_secure.json",
  110. hdp_stack_version = self.STACK_VERSION,
  111. target = RMFTestCase.TARGET_COMMON_SERVICES
  112. )
  113. self.assertResourceCalled('Execute',
  114. '/usr/hdp/current/phoenix-server/bin/queryserver.py stop',
  115. on_timeout = '! ( ls /var/run/hbase/phoenix-hbase-server.pid >/dev/null 2>&1 && ps -p `cat /var/run/hbase/phoenix-hbase-server.pid` >/dev/null 2>&1 ) || ambari-sudo.sh -H -E kill -9 `cat /var/run/hbase/phoenix-hbase-server.pid`',
  116. timeout = 30,
  117. environment = {'JAVA_HOME':'/usr/jdk64/jdk1.8.0_40',
  118. 'HBASE_CONF_DIR':'/usr/hdp/current/hbase-regionserver/conf'},
  119. user = 'hbase'
  120. )
  121. self.assertResourceCalled('Execute',
  122. 'rm -f /var/run/hbase/phoenix-hbase-server.pid',
  123. )
  124. self.assertNoMoreResources()
  125. @skip("there's nothing to upgrade to yet")
  126. def test_start_default_24(self):
  127. self.executeScript(
  128. self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/phoenix_queryserver.py",
  129. classname = "PhoenixQueryServer",
  130. command = "start",
  131. config_file = "hbase-rs-2.4.json",
  132. hdp_stack_version = self.STACK_VERSION,
  133. target = RMFTestCase.TARGET_COMMON_SERVICES)
  134. self.assertResourceCalled('Directory', '/etc/hbase',
  135. mode = 0755)
  136. self.assertResourceCalled('Directory',
  137. '/usr/hdp/current/hbase-regionserver/conf',
  138. owner = 'hbase',
  139. group = 'hadoop',
  140. recursive = True)
  141. self.assertResourceCalled('XmlConfig', 'hbase-site.xml',
  142. owner = 'hbase',
  143. group = 'hadoop',
  144. conf_dir = '/usr/hdp/current/hbase-regionserver/conf',
  145. configurations = self.getConfig()['configurations']['hbase-site'],
  146. configuration_attributes = self.getConfig()['configuration_attributes'][
  147. 'hbase-site'])
  148. self.assertResourceCalled('XmlConfig', 'core-site.xml',
  149. owner = 'hbase',
  150. group = 'hadoop',
  151. conf_dir = '/usr/hdp/current/hbase-regionserver/conf',
  152. configurations = self.getConfig()['configurations']['core-site'],
  153. configuration_attributes = self.getConfig()['configuration_attributes'][
  154. 'core-site']
  155. )
  156. self.assertResourceCalled('File',
  157. '/usr/hdp/current/hbase-regionserver/conf/hbase-env.sh',
  158. owner = 'hbase',
  159. content = InlineTemplate(
  160. self.getConfig()['configurations']['hbase-env']['content']))
  161. self.assertResourceCalled('Directory', '/var/run/hbase',
  162. owner = 'hbase',
  163. recursive = True)
  164. self.assertResourceCalled('Directory', '/var/log/hbase',
  165. owner = 'hbase',
  166. recursive = True)
  167. self.assertResourceCalled('File',
  168. '/usr/lib/phoenix/bin/log4j.properties',
  169. mode = 0644,
  170. group = 'hadoop',
  171. owner = 'hbase',
  172. content = 'log4jproperties\nline2')
  173. self.assertResourceCalled('Execute',
  174. '/usr/hdp/current/phoenix-server/bin/queryserver.py start',
  175. not_if = 'ls /var/run/hbase/phoenix-hbase-server.pid >/dev/null 2>&1 && ps -p `cat /var/run/hbase/phoenix-hbase-server.pid` >/dev/null 2>&1',
  176. user = 'hbase')
  177. self.assertNoMoreResources()
  178. def assert_configure_default(self):
  179. self.assertResourceCalled('Directory', '/etc/hbase',
  180. mode = 0755
  181. )
  182. self.assertResourceCalled('Directory',
  183. '/usr/hdp/current/hbase-regionserver/conf',
  184. owner = 'hbase',
  185. group = 'hadoop',
  186. recursive = True,
  187. )
  188. self.assertResourceCalled('Directory', '/hadoop',
  189. recursive = True,
  190. cd_access = 'a',
  191. )
  192. self.assertResourceCalled('Execute', ('chmod', '1777', u'/hadoop'),
  193. sudo = True,
  194. )
  195. self.assertResourceCalled('XmlConfig', 'hbase-site.xml',
  196. owner = 'hbase',
  197. group = 'hadoop',
  198. conf_dir = '/usr/hdp/current/hbase-regionserver/conf',
  199. configurations = self.getConfig()['configurations']['hbase-site'],
  200. configuration_attributes = self.getConfig()['configuration_attributes'][
  201. 'hbase-site']
  202. )
  203. self.assertResourceCalled('XmlConfig', 'core-site.xml',
  204. owner = 'hbase',
  205. group = 'hadoop',
  206. conf_dir = '/usr/hdp/current/hbase-regionserver/conf',
  207. configurations = self.getConfig()['configurations']['core-site'],
  208. configuration_attributes = self.getConfig()['configuration_attributes'][
  209. 'core-site']
  210. )
  211. self.assertResourceCalled('XmlConfig', 'hdfs-site.xml',
  212. owner = 'hbase',
  213. group = 'hadoop',
  214. conf_dir = '/usr/hdp/current/hbase-regionserver/conf',
  215. configurations = self.getConfig()['configurations']['hdfs-site'],
  216. configuration_attributes = self.getConfig()['configuration_attributes'][
  217. 'hdfs-site']
  218. )
  219. self.assertResourceCalled('XmlConfig', 'hdfs-site.xml',
  220. owner = 'hdfs',
  221. group = 'hadoop',
  222. conf_dir = '/usr/hdp/current/hadoop-client/conf',
  223. configurations = self.getConfig()['configurations']['hdfs-site'],
  224. configuration_attributes = self.getConfig()['configuration_attributes'][
  225. 'hdfs-site']
  226. )
  227. self.assertResourceCalled('XmlConfig', 'hbase-policy.xml',
  228. owner = 'hbase',
  229. group = 'hadoop',
  230. conf_dir = '/usr/hdp/current/hbase-regionserver/conf',
  231. configurations = self.getConfig()['configurations']['hbase-policy'],
  232. configuration_attributes = self.getConfig()['configuration_attributes'][
  233. 'hbase-policy']
  234. )
  235. self.assertResourceCalled('File',
  236. '/usr/hdp/current/hbase-regionserver/conf/hbase-env.sh',
  237. owner = 'hbase',
  238. content = InlineTemplate(
  239. self.getConfig()['configurations']['hbase-env']['content']),
  240. )
  241. self.assertResourceCalled('TemplateConfig',
  242. '/usr/hdp/current/hbase-regionserver/conf/hadoop-metrics2-hbase.properties',
  243. owner = 'hbase',
  244. template_tag = 'GANGLIA-RS',
  245. )
  246. self.assertResourceCalled('TemplateConfig',
  247. '/usr/hdp/current/hbase-regionserver/conf/regionservers',
  248. owner = 'hbase',
  249. template_tag = None,
  250. )
  251. self.assertResourceCalled('Directory', '/var/run/hbase',
  252. owner = 'hbase',
  253. recursive = True,
  254. )
  255. self.assertResourceCalled('Directory', '/var/log/hbase',
  256. owner = 'hbase',
  257. recursive = True,
  258. )
  259. self.assertResourceCalled('File',
  260. '/usr/hdp/current/hbase-regionserver/conf/log4j.properties',
  261. mode = 0644,
  262. group = 'hadoop',
  263. owner = 'hbase',
  264. content = 'log4jproperties\nline2'
  265. )
  266. def assert_configure_secured(self):
  267. self.assertResourceCalled('Directory', '/etc/hbase',
  268. mode = 0755
  269. )
  270. self.assertResourceCalled('Directory',
  271. '/usr/hdp/current/hbase-regionserver/conf',
  272. owner = 'hbase',
  273. group = 'hadoop',
  274. recursive = True,
  275. )
  276. self.assertResourceCalled('Directory', '/hadoop',
  277. recursive = True,
  278. cd_access = 'a',
  279. )
  280. self.assertResourceCalled('Execute', ('chmod', '1777', u'/hadoop'),
  281. sudo = True,
  282. )
  283. self.assertResourceCalled('XmlConfig', 'hbase-site.xml',
  284. owner = 'hbase',
  285. group = 'hadoop',
  286. conf_dir = '/usr/hdp/current/hbase-regionserver/conf',
  287. configurations = self.getConfig()['configurations']['hbase-site'],
  288. configuration_attributes = self.getConfig()['configuration_attributes'][
  289. 'hbase-site']
  290. )
  291. self.assertResourceCalled('XmlConfig', 'core-site.xml',
  292. owner = 'hbase',
  293. group = 'hadoop',
  294. conf_dir = '/usr/hdp/current/hbase-regionserver/conf',
  295. configurations = self.getConfig()['configurations']['core-site'],
  296. configuration_attributes = self.getConfig()['configuration_attributes'][
  297. 'core-site']
  298. )
  299. self.assertResourceCalled('XmlConfig', 'hdfs-site.xml',
  300. owner = 'hbase',
  301. group = 'hadoop',
  302. conf_dir = '/usr/hdp/current/hbase-regionserver/conf',
  303. configurations = self.getConfig()['configurations']['hdfs-site'],
  304. configuration_attributes = self.getConfig()['configuration_attributes'][
  305. 'hdfs-site']
  306. )
  307. self.assertResourceCalled('XmlConfig', 'hdfs-site.xml',
  308. owner = 'hdfs',
  309. group = 'hadoop',
  310. conf_dir = '/usr/hdp/current/hadoop-client/conf',
  311. configurations = self.getConfig()['configurations']['hdfs-site'],
  312. configuration_attributes = self.getConfig()['configuration_attributes'][
  313. 'hdfs-site']
  314. )
  315. self.assertResourceCalled('XmlConfig', 'hbase-policy.xml',
  316. owner = 'hbase',
  317. group = 'hadoop',
  318. conf_dir = '/usr/hdp/current/hbase-regionserver/conf',
  319. configurations = self.getConfig()['configurations']['hbase-policy'],
  320. configuration_attributes = self.getConfig()['configuration_attributes'][
  321. 'hbase-policy']
  322. )
  323. self.assertResourceCalled('File',
  324. '/usr/hdp/current/hbase-regionserver/conf/hbase-env.sh',
  325. owner = 'hbase',
  326. content = InlineTemplate(
  327. self.getConfig()['configurations']['hbase-env']['content']),
  328. )
  329. self.assertResourceCalled('TemplateConfig',
  330. '/usr/hdp/current/hbase-regionserver/conf/hadoop-metrics2-hbase.properties',
  331. owner = 'hbase',
  332. template_tag = 'GANGLIA-RS',
  333. )
  334. self.assertResourceCalled('TemplateConfig',
  335. '/usr/hdp/current/hbase-regionserver/conf/regionservers',
  336. owner = 'hbase',
  337. template_tag = None,
  338. )
  339. self.assertResourceCalled('TemplateConfig',
  340. '/usr/hdp/current/hbase-regionserver/conf/hbase_queryserver_jaas.conf',
  341. owner = 'hbase',
  342. template_tag = None,
  343. )
  344. self.assertResourceCalled('Directory', '/var/run/hbase',
  345. owner = 'hbase',
  346. recursive = True,
  347. )
  348. self.assertResourceCalled('Directory', '/var/log/hbase',
  349. owner = 'hbase',
  350. recursive = True,
  351. )
  352. self.assertResourceCalled('File',
  353. '/usr/hdp/current/hbase-regionserver/conf/log4j.properties',
  354. mode = 0644,
  355. group = 'hadoop',
  356. owner = 'hbase',
  357. content = 'log4jproperties\nline2'
  358. )
  359. def test_upgrade_restart(self):
  360. config_file = self.get_src_folder()+"/test/python/stacks/2.3/configs/hbase_default.json"
  361. with open(config_file, "r") as f:
  362. json_content = json.load(f)
  363. json_content['commandParams']['version'] = '2.3.0.0-1234'
  364. self.executeScript(
  365. self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/phoenix_queryserver.py",
  366. classname = "PhoenixQueryServer",
  367. command = "pre_rolling_restart",
  368. config_dict = json_content,
  369. hdp_stack_version = self.STACK_VERSION,
  370. target = RMFTestCase.TARGET_COMMON_SERVICES)
  371. self.assertResourceCalled('Execute', 'hdp-select set phoenix-server 2.3.0.0-1234')
  372. self.assertNoMoreResources()