test_service_check.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 stacks.utils.RMFTestCase import *
  18. import resource_management.libraries.functions
  19. from mock.mock import MagicMock, call, patch
  20. @patch.object(resource_management.libraries.functions, "get_unique_id_and_date", new = MagicMock(return_value=''))
  21. class TestServiceCheck(RMFTestCase):
  22. COMMON_SERVICES_PACKAGE_DIR = "HDFS/2.1.0.2.0/package"
  23. STACK_VERSION = "2.0.6"
  24. def test_service_check_default(self):
  25. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/service_check.py",
  26. classname = "HdfsServiceCheck",
  27. command = "service_check",
  28. config_file = "default.json",
  29. hdp_stack_version = self.STACK_VERSION,
  30. target = RMFTestCase.TARGET_COMMON_SERVICES
  31. )
  32. self.assert_service_check()
  33. self.assertNoMoreResources()
  34. def test_service_check_secured(self):
  35. self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/service_check.py",
  36. classname = "HdfsServiceCheck",
  37. command = "service_check",
  38. config_file = "default.json",
  39. hdp_stack_version = self.STACK_VERSION,
  40. target = RMFTestCase.TARGET_COMMON_SERVICES
  41. )
  42. self.assert_service_check()
  43. self.assertNoMoreResources()
  44. def assert_service_check(self):
  45. self.assertResourceCalled('ExecuteHadoop', 'dfsadmin -fs hdfs://c6401.ambari.apache.org:8020 -safemode get | grep OFF',
  46. logoutput = True,
  47. tries = 20,
  48. conf_dir = '/etc/hadoop/conf',
  49. try_sleep = 3,
  50. bin_dir = '/usr/bin',
  51. user = 'hdfs',
  52. )
  53. self.assertResourceCalled('ExecuteHadoop', 'fs -mkdir /tmp',
  54. conf_dir = '/etc/hadoop/conf',
  55. logoutput = True,
  56. not_if = "ambari-sudo.sh su hdfs -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]/usr/bin/hadoop --config /etc/hadoop/conf fs -test -e /tmp'",
  57. try_sleep = 3,
  58. tries = 5,
  59. bin_dir = '/usr/bin',
  60. user = 'hdfs',
  61. )
  62. self.assertResourceCalled('ExecuteHadoop', 'fs -chmod 777 /tmp',
  63. conf_dir = '/etc/hadoop/conf',
  64. logoutput = True,
  65. try_sleep = 3,
  66. tries = 5,
  67. bin_dir = '/usr/bin',
  68. user = 'hdfs',
  69. )
  70. self.assertResourceCalled('ExecuteHadoop', 'fs -rm /tmp/; hadoop --config /etc/hadoop/conf fs -put /etc/passwd /tmp/',
  71. logoutput = True,
  72. tries = 5,
  73. conf_dir = '/etc/hadoop/conf',
  74. bin_dir = '/usr/bin',
  75. try_sleep = 3,
  76. user = 'hdfs',
  77. )
  78. self.assertResourceCalled('ExecuteHadoop', 'fs -test -e /tmp/',
  79. logoutput = True,
  80. tries = 5,
  81. conf_dir = '/etc/hadoop/conf',
  82. bin_dir = '/usr/bin',
  83. try_sleep = 3,
  84. user = 'hdfs',
  85. )