ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject git commit: AMBARI-4573. Write unnitests for NAGIOS install script on HDP1 and HDP2 (Iryna Kuzmenko via aonishuk)
Date Mon, 10 Feb 2014 11:59:50 GMT
Updated Branches:
  refs/heads/trunk 9d07f72a5 -> 9b7f183cb


AMBARI-4573. Write unnitests for NAGIOS install script on HDP1 and HDP2
(Iryna Kuzmenko via aonishuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9b7f183c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9b7f183c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9b7f183c

Branch: refs/heads/trunk
Commit: 9b7f183cb04290c04761afdea12e7c8a9880c132
Parents: 9d07f72
Author: Andrew Onischuk <aonishuk@hortonworks.com>
Authored: Mon Feb 10 03:27:50 2014 -0800
Committer: Andrew Onischuk <aonishuk@hortonworks.com>
Committed: Mon Feb 10 03:27:50 2014 -0800

----------------------------------------------------------------------
 .../package/scripts/nagios_server_config.py     |   2 +-
 .../package/scripts/nagios_server_config.py     |   2 +-
 .../stacks/1.3.2/NAGIOS/test_nagios_server.py   | 261 +++++++++++++++++++
 .../stacks/2.0.6/NAGIOS/test_nagios_server.py   | 259 ++++++++++++++++++
 4 files changed, 522 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9b7f183c/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/NAGIOS/package/scripts/nagios_server_config.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/NAGIOS/package/scripts/nagios_server_config.py
b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/NAGIOS/package/scripts/nagios_server_config.py
index 9f6c884..275c9c4 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/NAGIOS/package/scripts/nagios_server_config.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/NAGIOS/package/scripts/nagios_server_config.py
@@ -42,7 +42,7 @@ def nagios_server_config():
   
   if System.get_instance().os_family != "suse":
     nagios_server_configfile( 'nagios',
-                              config_dir = '/etc/init.d/', 
+                              config_dir = '/etc/init.d',
                               mode = 0755, 
                               owner = 'root', 
                               group = 'root'

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b7f183c/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_server_config.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_server_config.py
b/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_server_config.py
index 9f6c884..275c9c4 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_server_config.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_server_config.py
@@ -42,7 +42,7 @@ def nagios_server_config():
   
   if System.get_instance().os_family != "suse":
     nagios_server_configfile( 'nagios',
-                              config_dir = '/etc/init.d/', 
+                              config_dir = '/etc/init.d',
                               mode = 0755, 
                               owner = 'root', 
                               group = 'root'

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b7f183c/ambari-server/src/test/python/stacks/1.3.2/NAGIOS/test_nagios_server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/1.3.2/NAGIOS/test_nagios_server.py b/ambari-server/src/test/python/stacks/1.3.2/NAGIOS/test_nagios_server.py
new file mode 100644
index 0000000..d89f6f3
--- /dev/null
+++ b/ambari-server/src/test/python/stacks/1.3.2/NAGIOS/test_nagios_server.py
@@ -0,0 +1,261 @@
+#!/usr/bin/env python
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+'''
+
+from mock.mock import MagicMock, patch
+from stacks.utils.RMFTestCase import *
+
+
+class TestNagiosServer(RMFTestCase):
+  def test_configure_default(self):
+    self.executeScript("1.3.2/services/NAGIOS/package/scripts/nagios_server.py",
+                       classname="NagiosServer",
+                       command="configure",
+                       config_file="default.json"
+    )
+    self.assert_configure_default()
+    self.assertNoMoreResources()
+
+
+  def test_start_default(self):
+    self.executeScript(
+      "1.3.2/services/NAGIOS/package/scripts/nagios_service.py",
+      classname="NagiosServer",
+      command="start",
+      config_file="default.json"
+    )
+    self.assert_configure_default()
+    self.assertResourceCalled('Execute', 'service nagios start',
+                              path=['/usr/local/bin/:/bin/:/sbin/']
+    )
+    self.assertResourceCalled('MonitorWebserver', 'restart',
+    )
+    self.assertNoMoreResources()
+
+
+  def test_stop_default(self):
+    self.executeScript(
+      "1.3.2/services/NAGIOS/package/scripts/nagios_service.py",
+      classname="NagiosServer",
+      command="stop",
+      config_file="default.json"
+    )
+    self.assertResourceCalled('Execute',
+                              'service nagios stop && rm -f /var/run/nagios/nagios.pid',
+                              path=['/usr/local/bin/:/bin/:/sbin/']
+    )
+    self.assertResourceCalled('MonitorWebserver', 'restart',
+    )
+    self.assertNoMoreResources()
+
+
+  def assert_configure_default(self):
+    self.assertResourceCalled('File', '/etc/httpd/conf.d/nagios.conf',
+                              owner='nagios',
+                              group='nagios',
+                              content=Template("nagios.conf.j2"),
+                              mode=0644
+    )
+    self.assertResourceCalled('Execute',
+                              'service snmpd start; chkconfig snmpd on',
+                              path=['/usr/local/bin/:/bin/:/sbin/']
+    )
+    self.assertResourceCalled('Directory', '/etc/nagios',
+                              owner='nagios',
+                              group='nagios',
+    )
+    self.assertResourceCalled('Directory', '/usr/lib64/nagios/plugins'
+    )
+    self.assertResourceCalled('Directory', '/etc/nagios/objects'
+    )
+    self.assertResourceCalled('Directory', '/var/run/nagios',
+                              owner='nagios',
+                              group='nagios',
+                              mode=0755,
+                              recursive=True
+    )
+    self.assertResourceCalled('Directory', '/var/nagios',
+                              owner='nagios',
+                              group='nagios',
+                              recursive=True
+    )
+    self.assertResourceCalled('Directory', '/var/nagios/spool/checkresults',
+                              owner='nagios',
+                              group='nagios',
+                              recursive=True
+    )
+    self.assertResourceCalled('Directory', '/var/nagios/rw',
+                              owner='nagios',
+                              group='nagios',
+                              recursive=True
+    )
+    self.assertResourceCalled('Directory', '/var/log/nagios',
+                              owner='nagios',
+                              group='nagios',
+                              mode=0755
+    )
+    self.assertResourceCalled('Directory', '/var/log/nagios/archives',
+                              owner='nagios',
+                              group='nagios',
+                              mode=0755
+    )
+    self.assertResourceCalled('TemplateConfig', '/etc/nagios/nagios.cfg',
+                              owner='nagios',
+                              group='nagios',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig', '/etc/nagios/resource.cfg',
+                              owner='nagios',
+                              group='nagios',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig',
+                              '/etc/nagios/objects/hadoop-hosts.cfg',
+                              owner='nagios',
+                              group='hadoop',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig',
+                              '/etc/nagios/objects/hadoop-hostgroups.cfg',
+                              owner='nagios',
+                              group='hadoop',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig',
+                              '/etc/nagios/objects/hadoop-servicegroups.cfg',
+                              owner='nagios',
+                              group='hadoop',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig',
+                              '/etc/nagios/objects/hadoop-services.cfg',
+                              owner='nagios',
+                              group='hadoop',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig',
+                              '/etc/nagios/objects/hadoop-commands.cfg',
+                              owner='nagios',
+                              group='hadoop',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig',
+                              '/etc/nagios/objects/contacts.cfg',
+                              owner='nagios',
+                              group='hadoop',
+                              mode=None
+    )
+    self.assertResourceCalled('File', '/usr/lib64/nagios/plugins/check_cpu.pl',
+                              content=StaticFile('check_cpu.pl'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_datanode_storage.php',
+                              content=StaticFile('check_datanode_storage.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_aggregate.php',
+                              content=StaticFile('check_aggregate.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_hdfs_blocks.php',
+                              content=StaticFile('check_hdfs_blocks.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_hdfs_capacity.php',
+                              content=StaticFile('check_hdfs_capacity.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_rpcq_latency.php',
+                              content=StaticFile('check_rpcq_latency.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_webui.sh',
+                              content=StaticFile('check_webui.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_name_dir_status.php',
+                              content=StaticFile('check_name_dir_status.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_oozie_status.sh',
+                              content=StaticFile('check_oozie_status.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_templeton_status.sh',
+                              content=StaticFile('check_templeton_status.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_hive_metastore_status.sh',
+                              content=StaticFile(
+                                'check_hive_metastore_status.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_hue_status.sh',
+                              content=StaticFile('check_hue_status.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_mapred_local_dir_used.sh',
+                              content=StaticFile(
+                                'check_mapred_local_dir_used.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_nodemanager_health.sh',
+                              content=StaticFile('check_nodemanager_health.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_namenodes_ha.sh',
+                              content=StaticFile('check_namenodes_ha.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/hdp_nagios_init.php',
+                              content=StaticFile('hdp_nagios_init.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('Execute',
+                              'htpasswd2 -c -b  /etc/nagios/htpasswd.users nagiosadmin q',
+                              not_if="grep nagiosadmin /etc/nagios/htpasswd.users"
+    )
+
+    self.assertResourceCalled('File', '/etc/nagios/htpasswd.users',
+                              owner='nagios',
+                              group='nagios',
+                              mode=0640
+    )
+    self.assertResourceCalled('Execute', 'usermod -G nagios wwwrun'
+    )
+
+    self.assertResourceCalled('File', '/etc/nagios/command.cfg',
+                              owner='nagios',
+                              group='nagios'
+    )
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b7f183c/ambari-server/src/test/python/stacks/2.0.6/NAGIOS/test_nagios_server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/NAGIOS/test_nagios_server.py b/ambari-server/src/test/python/stacks/2.0.6/NAGIOS/test_nagios_server.py
new file mode 100644
index 0000000..8682a48
--- /dev/null
+++ b/ambari-server/src/test/python/stacks/2.0.6/NAGIOS/test_nagios_server.py
@@ -0,0 +1,259 @@
+#!/usr/bin/env python
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+'''
+
+from mock.mock import MagicMock, patch
+from stacks.utils.RMFTestCase import *
+
+
+class TestNagiosServer(RMFTestCase):
+  def test_configure_default(self):
+    self.executeScript("2.0.6/services/NAGIOS/package/scripts/nagios_server.py",
+                       classname="NagiosServer",
+                       command="configure",
+                       config_file="default.json"
+    )
+    self.assert_configure_default()
+    self.assertNoMoreResources()
+
+
+  def test_start_default(self):
+    self.executeScript(
+      "2.0.6/services/NAGIOS/package/scripts/nagios_service.py",
+      classname="NagiosServer",
+      command="start",
+      config_file="default.json"
+    )
+    self.assert_configure_default()
+    self.assertResourceCalled('Execute', 'service nagios start',
+                              path=['/usr/local/bin/:/bin/:/sbin/']
+    )
+    self.assertResourceCalled('MonitorWebserver', 'restart',
+    )
+    self.assertNoMoreResources()
+
+
+  def test_stop_default(self):
+    self.executeScript(
+      "2.0.6/services/NAGIOS/package/scripts/nagios_service.py",
+      classname="NagiosServer",
+      command="stop",
+      config_file="default.json"
+    )
+    self.assertResourceCalled('Execute',
+                              'service nagios stop && rm -f /var/run/nagios/nagios.pid',
+                              path=['/usr/local/bin/:/bin/:/sbin/']
+    )
+    self.assertResourceCalled('MonitorWebserver', 'restart',
+    )
+    self.assertNoMoreResources()
+
+
+  def assert_configure_default(self):
+    self.assertResourceCalled('File', '/etc/httpd/conf.d/nagios.conf',
+                              owner='nagios',
+                              group='nagios',
+                              content=Template("nagios.conf.j2"),
+                              mode=0644
+    )
+    self.assertResourceCalled('Execute',
+                              'service snmpd start; chkconfig snmpd on',
+                              path=['/usr/local/bin/:/bin/:/sbin/']
+    )
+    self.assertResourceCalled('Directory', '/etc/nagios',
+                              owner='nagios',
+                              group='nagios',
+    )
+    self.assertResourceCalled('Directory', '/usr/lib64/nagios/plugins'
+    )
+    self.assertResourceCalled('Directory', '/etc/nagios/objects'
+    )
+    self.assertResourceCalled('Directory', '/var/run/nagios',
+                              owner='nagios',
+                              group='nagios',
+                              mode=0755,
+                              recursive=True
+    )
+    self.assertResourceCalled('Directory', '/var/nagios',
+                              owner='nagios',
+                              group='nagios',
+                              recursive=True
+    )
+    self.assertResourceCalled('Directory', '/var/nagios/spool/checkresults',
+                              owner='nagios',
+                              group='nagios',
+                              recursive=True
+    )
+    self.assertResourceCalled('Directory', '/var/nagios/rw',
+                              owner='nagios',
+                              group='nagios',
+                              recursive=True
+    )
+    self.assertResourceCalled('Directory', '/var/log/nagios',
+                              owner='nagios',
+                              group='nagios',
+                              mode=0755
+    )
+    self.assertResourceCalled('Directory', '/var/log/nagios/archives',
+                              owner='nagios',
+                              group='nagios',
+                              mode=0755
+    )
+    self.assertResourceCalled('TemplateConfig', '/etc/nagios/nagios.cfg',
+                              owner='nagios',
+                              group='nagios',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig', '/etc/nagios/resource.cfg',
+                              owner='nagios',
+                              group='nagios',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig',
+                              '/etc/nagios/objects/hadoop-hosts.cfg',
+                              owner='nagios',
+                              group='hadoop',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig',
+                              '/etc/nagios/objects/hadoop-hostgroups.cfg',
+                              owner='nagios',
+                              group='hadoop',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig',
+                              '/etc/nagios/objects/hadoop-servicegroups.cfg',
+                              owner='nagios',
+                              group='hadoop',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig',
+                              '/etc/nagios/objects/hadoop-services.cfg',
+                              owner='nagios',
+                              group='hadoop',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig',
+                              '/etc/nagios/objects/hadoop-commands.cfg',
+                              owner='nagios',
+                              group='hadoop',
+                              mode=None
+    )
+    self.assertResourceCalled('TemplateConfig',
+                              '/etc/nagios/objects/contacts.cfg',
+                              owner='nagios',
+                              group='hadoop',
+                              mode=None
+    )
+    self.assertResourceCalled('File', '/usr/lib64/nagios/plugins/check_cpu.pl',
+                              content=StaticFile('check_cpu.pl'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_datanode_storage.php',
+                              content=StaticFile('check_datanode_storage.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_aggregate.php',
+                              content=StaticFile('check_aggregate.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_hdfs_blocks.php',
+                              content=StaticFile('check_hdfs_blocks.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_hdfs_capacity.php',
+                              content=StaticFile('check_hdfs_capacity.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_rpcq_latency.php',
+                              content=StaticFile('check_rpcq_latency.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_webui.sh',
+                              content=StaticFile('check_webui.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_name_dir_status.php',
+                              content=StaticFile('check_name_dir_status.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_oozie_status.sh',
+                              content=StaticFile('check_oozie_status.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_templeton_status.sh',
+                              content=StaticFile('check_templeton_status.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_hive_metastore_status.sh',
+                              content=StaticFile(
+                                'check_hive_metastore_status.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_hue_status.sh',
+                              content=StaticFile('check_hue_status.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_mapred_local_dir_used.sh',
+                              content=StaticFile(
+                                'check_mapred_local_dir_used.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_nodemanager_health.sh',
+                              content=StaticFile('check_nodemanager_health.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/check_namenodes_ha.sh',
+                              content=StaticFile('check_namenodes_ha.sh'),
+                              mode=0755
+    )
+    self.assertResourceCalled('File',
+                              '/usr/lib64/nagios/plugins/hdp_nagios_init.php',
+                              content=StaticFile('hdp_nagios_init.php'),
+                              mode=0755
+    )
+    self.assertResourceCalled('Execute',
+                              'htpasswd2 -c -b  /etc/nagios/htpasswd.users nagiosadmin asd',
+                              not_if="grep nagiosadmin /etc/nagios/htpasswd.users"
+    )
+    self.assertResourceCalled('File', '/etc/nagios/htpasswd.users',
+                              owner='nagios',
+                              group='nagios',
+                              mode=0640
+    )
+    self.assertResourceCalled('Execute', 'usermod -G nagios wwwrun'
+    )
+    self.assertResourceCalled('File', '/etc/nagios/command.cfg',
+                              owner='nagios',
+                              group='nagios'
+    )
\ No newline at end of file


Mime
View raw message