Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 f941c6f49 -> d146df7ee


AMBARI-19283 - Ambari agent doesn't find alert scripts in a stack extension 
(Diego Santesteban via tthorpe)


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

Branch: refs/heads/branch-2.5
Commit: d146df7ee8639d5586bd3545adfcafafd5e01d86
Parents: f941c6f
Author: Tim Thorpe <ttho...@apache.org>
Authored: Fri Dec 23 09:36:03 2016 -0800
Committer: Tim Thorpe <ttho...@apache.org>
Committed: Fri Dec 23 09:36:03 2016 -0800

----------------------------------------------------------------------
 .../ambari_agent/AlertSchedulerHandler.py       | 17 +++---
 .../src/main/python/ambari_agent/Controller.py  | 12 ++--
 .../src/main/python/ambari_agent/FileCache.py   |  1 +
 .../python/ambari_agent/alerts/script_alert.py  |  8 +++
 .../ambari_agent/TestAlertSchedulerHandler.py   | 51 +++++++++++-----
 .../src/test/python/ambari_agent/TestAlerts.py  | 61 ++++++++++++--------
 6 files changed, 99 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d146df7e/ambari-agent/src/main/python/ambari_agent/AlertSchedulerHandler.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/AlertSchedulerHandler.py 
b/ambari-agent/src/main/python/ambari_agent/AlertSchedulerHandler.py
index 65cc8b0..026a5ed 100644
--- a/ambari-agent/src/main/python/ambari_agent/AlertSchedulerHandler.py
+++ b/ambari-agent/src/main/python/ambari_agent/AlertSchedulerHandler.py
@@ -48,12 +48,14 @@ class AlertSchedulerHandler():
   TYPE_WEB = 'WEB'
   TYPE_RECOVERY = 'RECOVERY'
 
-  def __init__(self, cachedir, stacks_dir, common_services_dir, 
host_scripts_dir,
-      cluster_configuration, config, recovery_manager, in_minutes=True):
+  def __init__(self, cachedir, stacks_dir, common_services_dir, extensions_dir,
+      host_scripts_dir, cluster_configuration, config, recovery_manager,
+      in_minutes=True):
 
     self.cachedir = cachedir
     self.stacks_dir = stacks_dir
     self.common_services_dir = common_services_dir
+    self.extensions_dir = extensions_dir
     self.host_scripts_dir = host_scripts_dir
 
     self._cluster_configuration = cluster_configuration
@@ -308,6 +310,7 @@ class AlertSchedulerHandler():
       elif source_type == AlertSchedulerHandler.TYPE_SCRIPT:
         source['stacks_directory'] = self.stacks_dir
         source['common_services_directory'] = self.common_services_dir
+        source['extensions_directory'] = self.extensions_dir
         source['host_scripts_directory'] = self.host_scripts_dir
         alert = ScriptAlert(json_definition, source, self.config)
       elif source_type == AlertSchedulerHandler.TYPE_WEB:
@@ -401,10 +404,10 @@ def main():
   args = list(sys.argv)
   del args[0]
 
-  
+
   ash = AlertSchedulerHandler(args[0], args[1], args[2], False)
   ash.start()
-  
+
   i = 0
   try:
     while i < 10:
@@ -412,12 +415,10 @@ def main():
       i += 1
   except KeyboardInterrupt:
     pass
-    
+
   print str(ash.collector().alerts())
-      
+
   ash.stop()
 
 if __name__ == "__main__":
   main()
-  
-      

http://git-wip-us.apache.org/repos/asf/ambari/blob/d146df7e/ambari-agent/src/main/python/ambari_agent/Controller.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/Controller.py 
b/ambari-agent/src/main/python/ambari_agent/Controller.py
index 090938a..672885e 100644
--- a/ambari-agent/src/main/python/ambari_agent/Controller.py
+++ b/ambari-agent/src/main/python/ambari_agent/Controller.py
@@ -99,6 +99,7 @@ class Controller(threading.Thread):
 
     stacks_cache_dir = os.path.join(cache_dir, 
FileCache.STACKS_CACHE_DIRECTORY)
     common_services_cache_dir = os.path.join(cache_dir, 
FileCache.COMMON_SERVICES_DIRECTORY)
+    extensions_cache_dir = os.path.join(cache_dir, 
FileCache.EXTENSIONS_CACHE_DIRECTORY)
     host_scripts_cache_dir = os.path.join(cache_dir, 
FileCache.HOST_SCRIPTS_CACHE_DIRECTORY)
     alerts_cache_dir = os.path.join(cache_dir, 
FileCache.ALERTS_CACHE_DIRECTORY)
     cluster_config_cache_dir = os.path.join(cache_dir, 
FileCache.CLUSTER_CONFIGURATION_CACHE_DIRECTORY)
@@ -122,8 +123,9 @@ class Controller(threading.Thread):
     self.move_data_dir_mount_file()
 
     self.alert_scheduler_handler = AlertSchedulerHandler(alerts_cache_dir,
-      stacks_cache_dir, common_services_cache_dir, host_scripts_cache_dir,
-      self.cluster_configuration, config, self.recovery_manager)
+      stacks_cache_dir, common_services_cache_dir, extensions_cache_dir,
+      host_scripts_cache_dir, self.cluster_configuration, config,
+      self.recovery_manager)
 
     self.alert_scheduler_handler.start()
 
@@ -447,10 +449,10 @@ class Controller(threading.Thread):
       self.actionQueue.start()
       self.register = Register(self.config)
       self.heartbeat = Heartbeat(self.actionQueue, self.config, 
self.alert_scheduler_handler.collector())
-  
+ 
       opener = urllib2.build_opener()
       urllib2.install_opener(opener)
-  
+ 
       while True:
         self.repeatRegistration = False
         self.registerAndHeartbeat()
@@ -460,7 +462,7 @@ class Controller(threading.Thread):
     except:
       logger.exception("Controller thread failed with exception:")
       raise
-    
+
     logger.info("Controller thread has successfully finished")
 
   def registerAndHeartbeat(self):

http://git-wip-us.apache.org/repos/asf/ambari/blob/d146df7e/ambari-agent/src/main/python/ambari_agent/FileCache.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/FileCache.py 
b/ambari-agent/src/main/python/ambari_agent/FileCache.py
index 0cd629b..d0c8bdb 100644
--- a/ambari-agent/src/main/python/ambari_agent/FileCache.py
+++ b/ambari-agent/src/main/python/ambari_agent/FileCache.py
@@ -45,6 +45,7 @@ class FileCache():
   STACKS_CACHE_DIRECTORY="stacks"
   COMMON_SERVICES_DIRECTORY="common-services"
   CUSTOM_ACTIONS_CACHE_DIRECTORY="custom_actions"
+  EXTENSIONS_CACHE_DIRECTORY="extensions"
   HOST_SCRIPTS_CACHE_DIRECTORY="host_scripts"
   HASH_SUM_FILE=".hash"
   ARCHIVE_NAME="archive.zip"

http://git-wip-us.apache.org/repos/asf/ambari/blob/d146df7e/ambari-agent/src/main/python/ambari_agent/alerts/script_alert.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/alerts/script_alert.py 
b/ambari-agent/src/main/python/ambari_agent/alerts/script_alert.py
index 8dfa73e..945a222 100644
--- a/ambari-agent/src/main/python/ambari_agent/alerts/script_alert.py
+++ b/ambari-agent/src/main/python/ambari_agent/alerts/script_alert.py
@@ -48,6 +48,7 @@ class ScriptAlert(BaseAlert):
     self.stacks_dir = None
     self.common_services_dir = None
     self.host_scripts_dir = None
+    self.extensions_dir = None
     self.path_to_script = None
     self.parameters = {}
 
@@ -66,6 +67,9 @@ class ScriptAlert(BaseAlert):
     if 'host_scripts_directory' in alert_source_meta:
       self.host_scripts_dir = alert_source_meta['host_scripts_directory']
 
+    if 'extensions_directory' in alert_source_meta:
+      self.extensions_dir = alert_source_meta['extensions_directory']
+
     # convert a list of script parameters, like timeouts, into a dictionary
     # so the the scripts can easily lookup the data
     if 'parameters' in alert_source_meta:
@@ -144,6 +148,10 @@ class ScriptAlert(BaseAlert):
     if not os.path.exists(self.path_to_script) and self.host_scripts_dir is 
not None:
       self.path_to_script = os.path.join(self.host_scripts_dir, *paths)
 
+    # if the path doesn't exist and the extensions dir is defined, try that
+    if not os.path.exists(self.path_to_script) and self.extensions_dir is not 
None:
+      self.path_to_script = os.path.join(self.extensions_dir, *paths)
+
     # if the path can't be evaluated, throw exception
     if not os.path.exists(self.path_to_script) or not 
os.path.isfile(self.path_to_script):
       raise Exception(

http://git-wip-us.apache.org/repos/asf/ambari/blob/d146df7e/ambari-agent/src/test/python/ambari_agent/TestAlertSchedulerHandler.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/test/python/ambari_agent/TestAlertSchedulerHandler.py 
b/ambari-agent/src/test/python/ambari_agent/TestAlertSchedulerHandler.py
index 1202c81..e396a3e 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestAlertSchedulerHandler.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestAlertSchedulerHandler.py
@@ -40,14 +40,14 @@ class TestAlertSchedulerHandler(TestCase):
     self.config = AmbariConfig()
 
   def test_load_definitions(self):
-    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, None)
+    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, TEST_PATH, None)
 
     definitions = scheduler._AlertSchedulerHandler__load_definitions()
 
     self.assertEquals(len(definitions), 1)
 
   def test_json_to_callable_metric(self):
-    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, None, self.config, None)
+    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, TEST_PATH, None, self.config, None)
     json_definition = {
       'source': {
         'type': 'METRIC'
@@ -62,7 +62,7 @@ class TestAlertSchedulerHandler(TestCase):
     self.assertEquals(callable_result.alert_source_meta, 
json_definition['source'])
 
   def test_json_to_callable_ams(self):
-    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, None, self.config, None)
+    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, TEST_PATH, None, self.config, None)
     json_definition = {
       'source': {
         'type': 'AMS'
@@ -83,7 +83,7 @@ class TestAlertSchedulerHandler(TestCase):
       }
     }
 
-    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, None, self.config, None)
+    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, TEST_PATH, None, self.config, None)
     callable_result = 
scheduler._AlertSchedulerHandler__json_to_callable('cluster', 'host', 
copy.deepcopy(json_definition))
 
     self.assertTrue(callable_result is not None)
@@ -99,7 +99,7 @@ class TestAlertSchedulerHandler(TestCase):
       }
     }
 
-    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, None, self.config, None)
+    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, TEST_PATH, None, self.config, None)
     callable_result = 
scheduler._AlertSchedulerHandler__json_to_callable('cluster', 'host', 
copy.deepcopy(json_definition))
 
     self.assertTrue(callable_result is not None)
@@ -114,7 +114,7 @@ class TestAlertSchedulerHandler(TestCase):
       }
     }
 
-    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, None, self.config, None)
+    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, TEST_PATH, None, self.config, None)
     callable_result = 
scheduler._AlertSchedulerHandler__json_to_callable('cluster', 'host', 
copy.deepcopy(json_definition))
 
     self.assertTrue(callable_result is None)
@@ -122,7 +122,7 @@ class TestAlertSchedulerHandler(TestCase):
   def test_execute_alert_noneScheduler(self):
     execution_commands = []
 
-    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, None, self.config, None)
+    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, TEST_PATH, None, self.config, None)
     scheduler._AlertSchedulerHandler__scheduler = None
     alert_mock = Mock()
     scheduler._AlertSchedulerHandler__json_to_callable = 
Mock(return_value=alert_mock)
@@ -134,7 +134,7 @@ class TestAlertSchedulerHandler(TestCase):
   def test_execute_alert_noneCommands(self):
     execution_commands = None
 
-    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, None, self.config, None)
+    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, TEST_PATH, None, self.config, None)
     alert_mock = Mock()
     scheduler._AlertSchedulerHandler__json_to_callable = 
Mock(return_value=alert_mock)
 
@@ -145,7 +145,7 @@ class TestAlertSchedulerHandler(TestCase):
   def test_execute_alert_emptyCommands(self):
     execution_commands = []
 
-    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, None, self.config, None)
+    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, TEST_PATH, None, self.config, None)
     alert_mock = Mock()
     scheduler._AlertSchedulerHandler__json_to_callable = 
Mock(return_value=alert_mock)
 
@@ -164,7 +164,32 @@ class TestAlertSchedulerHandler(TestCase):
       }
     ]
 
-    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, None, self.config, None)
+    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, TEST_PATH, None, self.config, None)
+    alert_mock = MagicMock()
+    alert_mock.collect = Mock()
+    alert_mock.set_helpers = Mock()
+    scheduler._AlertSchedulerHandler__json_to_callable = 
Mock(return_value=alert_mock)
+    scheduler._AlertSchedulerHandler__config_maps = {
+      'cluster': {}
+    }
+
+    scheduler.execute_alert(execution_commands)
+
+    
scheduler._AlertSchedulerHandler__json_to_callable.assert_called_with('cluster',
 'host', {'name': 'alert1'})
+    self.assertTrue(alert_mock.collect.called)
+
+  def test_execute_alert_from_extension(self):
+    execution_commands = [
+      {
+        'clusterName': 'cluster',
+        'hostName': 'host',
+        'alertDefinition': {
+          'name': 'alert1'
+        }
+      }
+    ]
+
+    scheduler = AlertSchedulerHandler('wrong_path', 'wrong_path', 
'wrong_path', TEST_PATH, 'wrong_path', None, self.config, None)
     alert_mock = MagicMock()
     alert_mock.collect = Mock()
     alert_mock.set_helpers = Mock()
@@ -179,7 +204,7 @@ class TestAlertSchedulerHandler(TestCase):
     self.assertTrue(alert_mock.collect.called)
 
   def test_load_definitions(self):
-    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, None, self.config, None)
+    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, TEST_PATH, None, self.config, None)
     scheduler._AlertSchedulerHandler__config_maps = {
       'cluster': {}
     }
@@ -190,7 +215,7 @@ class TestAlertSchedulerHandler(TestCase):
     self.assertTrue(isinstance(alert_def, PortAlert))
 
   def test_load_definitions_noFile(self):
-    scheduler = AlertSchedulerHandler('wrong_path', 'wrong_path', 
'wrong_path', 'wrong_path', None, self.config, None)
+    scheduler = AlertSchedulerHandler('wrong_path', 'wrong_path', 
'wrong_path', 'wrong_path', 'wrong_path', None, self.config, None)
     scheduler._AlertSchedulerHandler__config_maps = {
       'cluster': {}
     }
@@ -210,7 +235,7 @@ class TestAlertSchedulerHandler(TestCase):
       }
     ]
 
-    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, None, self.config, None)
+    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, 
TEST_PATH, TEST_PATH, None, self.config, None)
     alert_mock = MagicMock()
     alert_mock.interval = Mock(return_value=5)
     alert_mock.collect = Mock()

http://git-wip-us.apache.org/repos/asf/ambari/blob/d146df7e/ambari-agent/src/test/python/ambari_agent/TestAlerts.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestAlerts.py 
b/ambari-agent/src/test/python/ambari_agent/TestAlerts.py
index 2bddc43..64479a2 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestAlerts.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestAlerts.py
@@ -62,12 +62,13 @@ class TestAlerts(TestCase):
     test_file_path = os.path.join('ambari_agent', 'dummy_files')
     test_stack_path = os.path.join('ambari_agent', 'dummy_files')
     test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
+    test_extensions_path = os.path.join('ambari_agent', 'dummy_files')
     test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')
 
     cluster_configuration = self.__get_cluster_configuration()
 
     ash = AlertSchedulerHandler(test_file_path, test_stack_path,
-      test_common_services_path, test_host_scripts_path, cluster_configuration,
+      test_common_services_path, test_extensions_path, test_host_scripts_path, 
cluster_configuration,
       self.config, None)
 
     ash.start()
@@ -236,10 +237,10 @@ class TestAlerts(TestCase):
     self.assertEquals(6, alert.interval())
 
     alert.collect()
-    
+
     alerts = collector.alerts()
     self.assertEquals(0, len(collector.alerts()))
-    
+
     self.assertEquals('OK', alerts[0]['state'])
     self.assertTrue('(Unit Tests)' in alerts[0]['text'])
     self.assertTrue('response time on port 2181' in alerts[0]['text'])
@@ -286,6 +287,7 @@ class TestAlerts(TestCase):
     # normally set by AlertSchedulerHandler
     definition_json['source']['stacks_directory'] = 
os.path.join('ambari_agent', 'dummy_files')
     definition_json['source']['common_services_directory'] = 
os.path.join('ambari_agent', 'common-services')
+    definition_json['source']['extensions_directory'] = 
os.path.join('ambari_agent', 'extensions')
     definition_json['source']['host_scripts_directory'] = 
os.path.join('ambari_agent', 'host_scripts')
 
     configuration = {'foo-site' :
@@ -299,9 +301,10 @@ class TestAlerts(TestCase):
     alert = ScriptAlert(definition_json, definition_json['source'], 
MagicMock())
     alert.set_helpers(collector, cluster_configuration )
     alert.set_cluster("c1", "c6401.ambari.apache.org")
-    
+
     self.assertEquals(definition_json['source']['path'], alert.path)
     self.assertEquals(definition_json['source']['stacks_directory'], 
alert.stacks_dir)
+    self.assertEquals(definition_json['source']['extensions_directory'], 
alert.extensions_dir)
     self.assertEquals(definition_json['source']['common_services_directory'], 
alert.common_services_dir)
     self.assertEquals(definition_json['source']['host_scripts_directory'], 
alert.host_scripts_dir)
 
@@ -320,6 +323,7 @@ class TestAlerts(TestCase):
     # normally set by AlertSchedulerHandler
     definition_json['source']['stacks_directory'] = 
os.path.join('ambari_agent', 'dummy_files')
     definition_json['source']['common_services_directory'] = 
os.path.join('ambari_agent', 'common-services')
+    definition_json['source']['extensions_directory'] = 
os.path.join('ambari_agent', 'extensions')
     definition_json['source']['host_scripts_directory'] = 
os.path.join('ambari_agent', 'host_scripts')
 
     configuration = {'foo-site' :
@@ -337,6 +341,7 @@ class TestAlerts(TestCase):
     self.assertEquals(definition_json['source']['path'], alert.path)
     self.assertEquals(definition_json['source']['stacks_directory'], 
alert.stacks_dir)
     self.assertEquals(definition_json['source']['common_services_directory'], 
alert.common_services_dir)
+    self.assertEquals(definition_json['source']['extensions_directory'], 
alert.extensions_dir)
     self.assertEquals(definition_json['source']['host_scripts_directory'], 
alert.host_scripts_dir)
 
     alert.collect()
@@ -454,7 +459,7 @@ class TestAlerts(TestCase):
     definition_json = self._get_metric_alert_definition()
 
     ma_load_jmx_mock.return_value = ([0,0], None)
-    
+
     # run the alert without specifying any keys; an exception should be thrown
     # indicating that there was no URI and the result is UNKNOWN
     collector = AlertCollector()
@@ -479,9 +484,9 @@ class TestAlerts(TestCase):
     alert.set_helpers(collector, cluster_configuration)
     alert.set_cluster("c1", "c6401.ambari.apache.org")
     alert.collect()
-    
+
     self.assertEquals('UNKNOWN', collector.alerts()[0]['state'])
-    
+
     # set an actual property key (http)
     configuration = {'hdfs-site' :
       { 'dfs.http.policy' : 'HTTP_ONLY',
@@ -495,9 +500,9 @@ class TestAlerts(TestCase):
     alert.set_helpers(collector, cluster_configuration)
     alert.set_cluster("c1", "c6401.ambari.apache.org")
     alert.collect()
-    
+
     self.assertEquals('OK', collector.alerts()[0]['state'])
-    
+
     # set an actual property key (https)
     configuration = {'hdfs-site' :
       { 'dfs.http.policy' : 'HTTP_ONLY',
@@ -511,7 +516,7 @@ class TestAlerts(TestCase):
     alert.set_helpers(collector, cluster_configuration)
     alert.set_cluster("c1", "c6401.ambari.apache.org")
     alert.collect()
-    
+
     self.assertEquals('OK', collector.alerts()[0]['state'])
 
     # set both (http and https)
@@ -528,8 +533,8 @@ class TestAlerts(TestCase):
     alert.set_helpers(collector, cluster_configuration)
     alert.set_cluster("c1", "c6401.ambari.apache.org")
     alert.collect()
-    
-    self.assertEquals('OK', collector.alerts()[0]['state'])    
+
+    self.assertEquals('OK', collector.alerts()[0]['state'])
 
 
   @patch.object(WebAlert, "_make_web_request")
@@ -539,7 +544,7 @@ class TestAlerts(TestCase):
     WebResponse = namedtuple('WebResponse', 'status_code time_millis 
error_msg')
     wa_make_web_request_mock.return_value = WebResponse(200,1.234,None)
 
-    # run the alert and check HTTP 200    
+    # run the alert and check HTTP 200
     configuration = {'hdfs-site' :
       { 'dfs.datanode.http.address' : 'c6401.ambari.apache.org:80' }
     }
@@ -566,25 +571,25 @@ class TestAlerts(TestCase):
     alert.set_helpers(collector, cluster_configuration)
     alert.set_cluster("c1", "c6401.ambari.apache.org")
     alert.collect()
-    
+
     alerts = collector.alerts()
     self.assertEquals(0, len(collector.alerts()))
-    
+
     self.assertEquals('WARNING', alerts[0]['state'])
     self.assertEquals('(Unit Tests) warning: 500 (Internal Server Error)', 
alerts[0]['text'])
 
     # run the alert and check critical
     wa_make_web_request_mock.return_value = WebResponse(0,0,'error message')
-     
+
     collector = AlertCollector()
     alert = WebAlert(definition_json, definition_json['source'], self.config)
     alert.set_helpers(collector, cluster_configuration)
     alert.set_cluster("c1", "c6401.ambari.apache.org")
     alert.collect()
-    
+
     alerts = collector.alerts()
-    self.assertEquals(0, len(collector.alerts()))    
-    
+    self.assertEquals(0, len(collector.alerts()))
+
     # http assertion indicating that we properly determined non-SSL
     self.assertEquals('CRITICAL', alerts[0]['state'])
     self.assertEquals('(Unit Tests) critical: 
http://c6401.ambari.apache.org:80. error message', alerts[0]['text'])
@@ -603,10 +608,10 @@ class TestAlerts(TestCase):
     alert.set_cluster("c1", "c6401.ambari.apache.org")
 
     alert.collect()
-    
+
     alerts = collector.alerts()
-    self.assertEquals(0, len(collector.alerts()))    
-    
+    self.assertEquals(0, len(collector.alerts()))
+
     # SSL assertion
     self.assertEquals('CRITICAL', alerts[0]['state'])
     self.assertEquals('(Unit Tests) critical: 
https://c6401.ambari.apache.org:443/test/path. error message', 
alerts[0]['text'])
@@ -615,12 +620,13 @@ class TestAlerts(TestCase):
     test_file_path = os.path.join('ambari_agent', 'dummy_files')
     test_stack_path = os.path.join('ambari_agent', 'dummy_files')
     test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
+    test_extensions_path = os.path.join('ambari_agent', 'dummy_files')
     test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')
 
     cluster_configuration = self.__get_cluster_configuration()
 
     ash = AlertSchedulerHandler(test_file_path, test_stack_path,
-      test_common_services_path, test_host_scripts_path, cluster_configuration,
+      test_common_services_path, test_extensions_path, test_host_scripts_path, 
cluster_configuration,
       self.config, None)
 
     ash.start()
@@ -662,12 +668,13 @@ class TestAlerts(TestCase):
     test_file_path = os.path.join('ambari_agent', 'dummy_files')
     test_stack_path = os.path.join('ambari_agent', 'dummy_files')
     test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
+    test_extensions_path = os.path.join('ambari_agent', 'dummy_files')
     test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')
 
     cluster_configuration = self.__get_cluster_configuration()
 
     ash = AlertSchedulerHandler(test_file_path, test_stack_path,
-      test_common_services_path, test_host_scripts_path, cluster_configuration,
+      test_common_services_path, test_extensions_path, test_host_scripts_path, 
cluster_configuration,
       self.config, None)
 
     ash.start()
@@ -699,11 +706,12 @@ class TestAlerts(TestCase):
     test_file_path = os.path.join('ambari_agent', 'dummy_files')
     test_stack_path = os.path.join('ambari_agent', 'dummy_files')
     test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
+    test_extensions_path = os.path.join('ambari_agent', 'dummy_files')
     test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')
 
     cluster_configuration = self.__get_cluster_configuration()
     ash = AlertSchedulerHandler(test_file_path, test_stack_path,
-      test_common_services_path, test_host_scripts_path, cluster_configuration,
+      test_common_services_path, test_extensions_path, test_host_scripts_path, 
cluster_configuration,
       self.config, None)
 
     ash.start()
@@ -728,6 +736,7 @@ class TestAlerts(TestCase):
     # normally set by AlertSchedulerHandler
     definition_json['source']['stacks_directory'] = 
os.path.join('ambari_agent', 'dummy_files')
     definition_json['source']['common_services_directory'] = 
os.path.join('ambari_agent', 'common-services')
+    definition_json['source']['extensions_directory'] = 
os.path.join('ambari_agent', 'extensions')
     definition_json['source']['host_scripts_directory'] = 
os.path.join('ambari_agent', 'host_scripts')
 
     configuration = {'foo-site' :
@@ -748,6 +757,7 @@ class TestAlerts(TestCase):
 
     self.assertEquals(definition_json['source']['path'], alert.path)
     self.assertEquals(definition_json['source']['stacks_directory'], 
alert.stacks_dir)
+    self.assertEquals(definition_json['source']['extensions_directory'], 
alert.extensions_dir)
     self.assertEquals(definition_json['source']['common_services_directory'], 
alert.common_services_dir)
     self.assertEquals(definition_json['source']['host_scripts_directory'], 
alert.host_scripts_dir)
 
@@ -796,6 +806,7 @@ class TestAlerts(TestCase):
     # normally set by AlertSchedulerHandler
     definition_json['source']['stacks_directory'] = 
os.path.join('ambari_agent', 'dummy_files')
     definition_json['source']['common_services_directory'] = 
os.path.join('ambari_agent', 'common-services')
+    definition_json['source']['extensions_directory'] = 
os.path.join('ambari_agent', 'extensions')
     definition_json['source']['host_scripts_directory'] = 
os.path.join('ambari_agent', 'host_scripts')
 
     configuration = {'foo-site' :

Reply via email to