test_mysql_server.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. def test_configure_default(self):
  21. self.executeScript("2.1.1/services/HIVE/package/scripts/mysql_server.py",
  22. classname = "MysqlServer",
  23. command = "configure",
  24. config_file="default.json"
  25. )
  26. self.assert_configure_default()
  27. self.assertNoMoreResources()
  28. def test_start_default(self):
  29. self.executeScript("2.1.1/services/HIVE/package/scripts/mysql_server.py",
  30. classname = "MysqlServer",
  31. command = "start",
  32. config_file="default.json"
  33. )
  34. self.assertResourceCalled('Execute', 'service mysql start',
  35. logoutput = True,
  36. path = ['/usr/local/bin/:/bin/:/sbin/'],
  37. tries = 1,
  38. )
  39. self.assertNoMoreResources()
  40. def test_stop_default(self):
  41. self.executeScript("2.1.1/services/HIVE/package/scripts/mysql_server.py",
  42. classname = "MysqlServer",
  43. command = "stop",
  44. config_file="default.json"
  45. )
  46. self.assertResourceCalled('Execute', 'service mysql stop',
  47. logoutput = True,
  48. path = ['/usr/local/bin/:/bin/:/sbin/'],
  49. tries = 1,
  50. )
  51. self.assertNoMoreResources()
  52. def test_configure_secured(self):
  53. self.executeScript("2.1.1/services/HIVE/package/scripts/mysql_server.py",
  54. classname = "MysqlServer",
  55. command = "configure",
  56. config_file="secured.json"
  57. )
  58. self.assert_configure_secured()
  59. self.assertNoMoreResources()
  60. def test_start_secured(self):
  61. self.executeScript("2.1.1/services/HIVE/package/scripts/mysql_server.py",
  62. classname = "MysqlServer",
  63. command = "start",
  64. config_file="secured.json"
  65. )
  66. self.assertResourceCalled('Execute', 'service mysql start',
  67. logoutput = True,
  68. path = ['/usr/local/bin/:/bin/:/sbin/'],
  69. tries = 1,
  70. )
  71. self.assertNoMoreResources()
  72. def test_stop_secured(self):
  73. self.executeScript("2.1.1/services/HIVE/package/scripts/mysql_server.py",
  74. classname = "MysqlServer",
  75. command = "stop",
  76. config_file="secured.json"
  77. )
  78. self.assertResourceCalled('Execute', 'service mysql stop',
  79. logoutput = True,
  80. path = ['/usr/local/bin/:/bin/:/sbin/'],
  81. tries = 1,
  82. )
  83. self.assertNoMoreResources()
  84. def assert_configure_default(self):
  85. self.assertResourceCalled('Execute', 'service mysql start',
  86. logoutput = True,
  87. path = ['/usr/local/bin/:/bin/:/sbin/'],
  88. tries = 1,
  89. )
  90. self.assertResourceCalled('File', '/tmp/addMysqlUser.sh',
  91. content = StaticFile('addMysqlUser.sh'),
  92. mode = 493,
  93. )
  94. self.assertResourceCalled('Execute', ('bash', '-x', '/tmp/addMysqlUser.sh', 'mysql', u'hive', 'asd', u'c6402.ambari.apache.org'),
  95. logoutput = True,
  96. path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
  97. tries = 3,
  98. try_sleep = 5,
  99. )
  100. self.assertResourceCalled('Execute', 'service mysql stop',
  101. logoutput = True,
  102. path = ['/usr/local/bin/:/bin/:/sbin/'],
  103. tries = 1,
  104. )
  105. def assert_configure_secured(self):
  106. self.assertResourceCalled('Execute', 'service mysql start',
  107. logoutput = True,
  108. path = ['/usr/local/bin/:/bin/:/sbin/'],
  109. tries = 1,
  110. )
  111. self.assertResourceCalled('File', '/tmp/addMysqlUser.sh',
  112. content = StaticFile('addMysqlUser.sh'),
  113. mode = 493,
  114. )
  115. self.assertResourceCalled('Execute', ('bash', '-x', '/tmp/addMysqlUser.sh', 'mysql', u'hive', 'asd', u'c6402.ambari.apache.org'),
  116. logoutput = True,
  117. path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
  118. tries = 3,
  119. try_sleep = 5,
  120. )
  121. self.assertResourceCalled('Execute', 'service mysql stop',
  122. logoutput = True,
  123. path = ['/usr/local/bin/:/bin/:/sbin/'],
  124. tries = 1,
  125. )