def test_skipped_alert(self): definition_json = self._get_script_alert_definition() # 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']['host_scripts_directory'] = os.path.join( 'ambari_agent', 'host_scripts') configuration = {'foo-site': {'skip': 'true'}} collector = AlertCollector() cluster_configuration = self.__get_cluster_configuration() self.__update_cluster_configuration(cluster_configuration, configuration) alert = ScriptAlert(definition_json, definition_json['source'], None) # instruct the test alert script to be skipped 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']['common_services_directory'], alert.common_services_dir) self.assertEquals(definition_json['source']['host_scripts_directory'], alert.host_scripts_dir) # ensure that it was skipped self.assertEquals(0, len(collector.alerts()))
def test_skipped_alert(self): definition_json = self._get_script_alert_definition() # 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']['host_scripts_directory'] = os.path.join('ambari_agent', 'host_scripts') configuration = {'foo-site' : { 'skip': 'true' } } collector = AlertCollector() cluster_configuration = self.__get_cluster_configuration() self.__update_cluster_configuration(cluster_configuration, configuration) alert = ScriptAlert(definition_json, definition_json['source'], None) # instruct the test alert script to be skipped 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']['common_services_directory'], alert.common_services_dir) self.assertEquals(definition_json['source']['host_scripts_directory'], alert.host_scripts_dir) # ensure that it was skipped self.assertEquals(0,len(collector.alerts()))
def test_script_alert(self): definition_json = self._get_script_alert_definition() # 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']['host_scripts_directory'] = os.path.join('ambari_agent', 'host_scripts') configuration = {'foo-site' : { 'bar': 'rendered-bar', 'baz' : 'rendered-baz' } } collector = AlertCollector() cluster_configuration = self.__get_cluster_configuration() self.__update_cluster_configuration(cluster_configuration, configuration) 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']['common_services_directory'], alert.common_services_dir) self.assertEquals(definition_json['source']['host_scripts_directory'], alert.host_scripts_dir) alert.collect() alerts = collector.alerts() self.assertEquals(0, len(collector.alerts())) self.assertEquals('WARNING', alerts[0]['state']) self.assertEquals('bar is rendered-bar, baz is rendered-baz', alerts[0]['text'])
def test_configuration_updates(self): definition_json = self._get_script_alert_definition() # 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']['host_scripts_directory'] = os.path.join( 'ambari_agent', 'host_scripts') configuration = { 'foo-site': { 'bar': 'rendered-bar', 'baz': 'rendered-baz' } } # populate the configuration cache with the initial configs collector = AlertCollector() cluster_configuration = self.__get_cluster_configuration() self.__update_cluster_configuration(cluster_configuration, configuration) # run the alert and verify the output alert = ScriptAlert(definition_json, definition_json['source'], MagicMock()) 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('bar is rendered-bar, baz is rendered-baz', alerts[0]['text']) # now update only the configs and run the same alert again and check # for different output configuration = { 'foo-site': { 'bar': 'rendered-bar2', 'baz': 'rendered-baz2' } } # populate the configuration cache with the initial configs self.__update_cluster_configuration(cluster_configuration, configuration) alert.collect() alerts = collector.alerts() self.assertEquals(0, len(collector.alerts())) self.assertEquals('WARNING', alerts[0]['state']) self.assertEquals('bar is rendered-bar2, baz is rendered-baz2', alerts[0]['text'])
def test_configuration_updates(self): definition_json = self._get_script_alert_definition() # 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']['host_scripts_directory'] = os.path.join('ambari_agent', 'host_scripts') configuration = {'foo-site' : { 'bar': 'rendered-bar', 'baz' : 'rendered-baz' } } # populate the configuration cache with the initial configs collector = AlertCollector() cluster_configuration = self.__get_cluster_configuration() self.__update_cluster_configuration(cluster_configuration, configuration) # run the alert and verify the output alert = ScriptAlert(definition_json, definition_json['source'], MagicMock()) 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('bar is rendered-bar, baz is rendered-baz', alerts[0]['text']) # now update only the configs and run the same alert again and check # for different output configuration = {'foo-site' : { 'bar': 'rendered-bar2', 'baz' : 'rendered-baz2' } } # populate the configuration cache with the initial configs self.__update_cluster_configuration(cluster_configuration, configuration) alert.collect() alerts = collector.alerts() self.assertEquals(0, len(collector.alerts())) self.assertEquals('WARNING', alerts[0]['state']) self.assertEquals('bar is rendered-bar2, baz is rendered-baz2', alerts[0]['text'])