test_mysql_server.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #!/usr/bin/env python
  2. '''
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. '''
  17. from mock.mock import MagicMock, call, patch
  18. from stacks.utils.RMFTestCase import *
  19. class TestMySqlServer(RMFTestCase):
  20. COMMON_SERVICES_PACKAGE_DIR = "HIVE/0.12.0.2.0/package"
  21. STACK_VERSION = "2.0.6"
  22. def test_configure_default(self):
  23. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/mysql_server.py",
  24. classname = "MysqlServer",
  25. command = "configure",
  26. config_file="default.json",
  27. hdp_stack_version = self.STACK_VERSION,
  28. target = RMFTestCase.TARGET_COMMON_SERVICES
  29. )
  30. self.assert_configure_default()
  31. self.assertNoMoreResources()
  32. def test_start_default(self):
  33. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/mysql_server.py",
  34. classname = "MysqlServer",
  35. command = "start",
  36. config_file="default.json",
  37. hdp_stack_version = self.STACK_VERSION,
  38. target = RMFTestCase.TARGET_COMMON_SERVICES
  39. )
  40. self.assertResourceCalled('Execute', ('service','mysql','start'),
  41. logoutput = True,
  42. not_if = 'pgrep -l \'^mysqld$\'',
  43. sudo = True,
  44. )
  45. self.assertNoMoreResources()
  46. def test_stop_default(self):
  47. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/mysql_server.py",
  48. classname = "MysqlServer",
  49. command = "stop",
  50. config_file="default.json",
  51. hdp_stack_version = self.STACK_VERSION,
  52. target = RMFTestCase.TARGET_COMMON_SERVICES
  53. )
  54. self.assertResourceCalled('Execute', ('service','mysql','stop'),
  55. logoutput = True,
  56. only_if = 'pgrep -l \'^mysqld$\'',
  57. sudo = True,
  58. )
  59. self.assertNoMoreResources()
  60. def test_configure_secured(self):
  61. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/mysql_server.py",
  62. classname = "MysqlServer",
  63. command = "configure",
  64. config_file="secured.json",
  65. hdp_stack_version = self.STACK_VERSION,
  66. target = RMFTestCase.TARGET_COMMON_SERVICES
  67. )
  68. self.assert_configure_secured()
  69. self.assertNoMoreResources()
  70. def test_start_secured(self):
  71. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/mysql_server.py",
  72. classname = "MysqlServer",
  73. command = "start",
  74. config_file="secured.json",
  75. hdp_stack_version = self.STACK_VERSION,
  76. target = RMFTestCase.TARGET_COMMON_SERVICES
  77. )
  78. self.assertResourceCalled('Execute', ('service','mysql','start'),
  79. logoutput = True,
  80. not_if = 'pgrep -l \'^mysqld$\'',
  81. sudo = True,
  82. )
  83. self.assertNoMoreResources()
  84. def test_stop_secured(self):
  85. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/mysql_server.py",
  86. classname = "MysqlServer",
  87. command = "stop",
  88. config_file="secured.json",
  89. hdp_stack_version = self.STACK_VERSION,
  90. target = RMFTestCase.TARGET_COMMON_SERVICES
  91. )
  92. self.assertResourceCalled('Execute', ('service','mysql','stop'),
  93. logoutput = True,
  94. only_if = 'pgrep -l \'^mysqld$\'',
  95. sudo = True,
  96. )
  97. self.assertNoMoreResources()
  98. def test_clean_default(self):
  99. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/mysql_server.py",
  100. classname = "MysqlServer",
  101. command = "clean",
  102. config_file="default.json",
  103. hdp_stack_version = self.STACK_VERSION,
  104. target = RMFTestCase.TARGET_COMMON_SERVICES
  105. )
  106. self.assert_clean_default()
  107. self.assertNoMoreResources()
  108. def test_clean_secured(self):
  109. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/mysql_server.py",
  110. classname = "MysqlServer",
  111. command = "clean",
  112. config_file="secured.json",
  113. hdp_stack_version = self.STACK_VERSION,
  114. target = RMFTestCase.TARGET_COMMON_SERVICES
  115. )
  116. self.assert_clean_secured()
  117. self.assertNoMoreResources()
  118. def assert_configure_default(self):
  119. self.assertResourceCalled('Execute', ('sed',
  120. '-i',
  121. 's|^bind-address[ \t]*=.*|bind-address = 0.0.0.0|',
  122. '/etc/my.cnf'),
  123. sudo = True,
  124. )
  125. self.assertResourceCalled('File', '/tmp/addMysqlUser.sh',
  126. content = StaticFile('addMysqlUser.sh'),
  127. mode = 0755,
  128. )
  129. self.assertResourceCalled('Execute', 'bash -x /tmp/addMysqlUser.sh mysql hive \'!`"\'"\'"\' 1\' c6402.ambari.apache.org',
  130. path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
  131. logoutput = False,
  132. tries = 3,
  133. try_sleep = 5
  134. )
  135. def assert_configure_secured(self):
  136. self.assertResourceCalled('Execute', ('sed',
  137. '-i',
  138. 's|^bind-address[ \t]*=.*|bind-address = 0.0.0.0|',
  139. '/etc/my.cnf'),
  140. sudo = True,
  141. )
  142. self.assertResourceCalled('File', '/tmp/addMysqlUser.sh',
  143. content = StaticFile('addMysqlUser.sh'),
  144. mode = 0755,
  145. )
  146. self.assertResourceCalled('Execute', 'bash -x /tmp/addMysqlUser.sh mysql hive \'!`"\'"\'"\' 1\' c6402.ambari.apache.org',
  147. path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
  148. logoutput = False,
  149. tries = 3,
  150. try_sleep = 5
  151. )
  152. def assert_clean_default(self):
  153. self.assertResourceCalled('File', '/tmp/removeMysqlUser.sh',
  154. content = StaticFile('removeMysqlUser.sh'),
  155. mode = 0755,
  156. )
  157. self.assertResourceCalled('Execute', 'bash -x /tmp/removeMysqlUser.sh mysql hive c6402.ambari.apache.org',
  158. path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
  159. tries = 3,
  160. try_sleep = 5
  161. )
  162. def assert_clean_secured(self):
  163. self.assertResourceCalled('File', '/tmp/removeMysqlUser.sh',
  164. content = StaticFile('removeMysqlUser.sh'),
  165. mode = 0755,
  166. )
  167. self.assertResourceCalled('Execute', 'bash -x /tmp/removeMysqlUser.sh mysql hive c6402.ambari.apache.org',
  168. path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
  169. tries = 3,
  170. try_sleep = 5
  171. )