TestMonitorWebserverResource.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. '''
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. '''
  16. from stacks.utils.RMFTestCase import *
  17. from unittest import TestCase
  18. from mock.mock import patch, MagicMock
  19. from resource_management import *
  20. from resource_management.libraries.providers.monitor_webserver\
  21. import MonitorWebserverProvider
  22. from resource_management.libraries.resources.monitor_webserver\
  23. import MonitorWebserver
  24. class TestMonitorWebserverResource(TestCase):
  25. @patch.object(System, "os_family", new='redhat')
  26. def test_setup_redhat(self):
  27. with Environment(test_mode=True) as env:
  28. MonitorWebserverProvider(MonitorWebserver("start")).action_start()
  29. defined_resources = env.resource_list
  30. expected_resources = "[MonitorWebserver['start'], " \
  31. "Execute['grep -E 'KeepAlive (On|Off)' /etc/httpd/conf/httpd.conf" \
  32. " && sed -i 's/KeepAlive Off/KeepAlive On/' /etc/httpd/conf/httpd.conf" \
  33. " || echo 'KeepAlive On' >> /etc/httpd/conf/httpd.conf']," \
  34. " Execute['/etc/init.d/httpd start']]"
  35. self.assertEqual(str(defined_resources), expected_resources)
  36. @patch.object(System, "os_family", new='suse')
  37. def test_setup_suse(self):
  38. with Environment(test_mode=True) as env:
  39. MonitorWebserverProvider(MonitorWebserver("start")).action_start()
  40. defined_resources = env.resource_list
  41. expected_resources = "[MonitorWebserver['start'], " \
  42. "Execute['grep -E 'KeepAlive (On|Off)' /etc/apache2/httpd.conf " \
  43. "&& sed -i 's/KeepAlive Off/KeepAlive On/' /etc/apache2/httpd.conf " \
  44. "|| echo 'KeepAlive On' >> /etc/apache2/httpd.conf']," \
  45. " Execute['/etc/init.d/apache2 start']]"
  46. self.assertEqual(str(defined_resources), expected_resources)
  47. @patch.object(System, "os_family", new='redhat')
  48. def test_stop_redhat(self):
  49. with Environment(test_mode=True) as env:
  50. MonitorWebserverProvider(MonitorWebserver("stop")).action_stop()
  51. defined_resources = env.resource_list
  52. expected_resources = "[MonitorWebserver['stop'], " \
  53. "Execute['/etc/init.d/httpd stop']]"
  54. self.assertEqual(str(defined_resources), expected_resources)
  55. @patch.object(System, "os_family", new='suse')
  56. def test_stop_suse(self):
  57. with Environment(test_mode=True) as env:
  58. MonitorWebserverProvider(MonitorWebserver("stop")).action_stop()
  59. defined_resources = env.resource_list
  60. expected_resources = "[MonitorWebserver['stop'], " \
  61. "Execute['/etc/init.d/apache2 stop']]"
  62. self.assertEqual(str(defined_resources), expected_resources)