#NEWLINE# @ mock . patch ( 'sahara.plugins.ambari.client.AmbariClient.__init__' ) #NEWLINE# @ mock . patch ( 'sahara.plugins.ambari.client.AmbariClient.close' ) #NEWLINE# @ mock . patch ( 'sahara.plugins.ambari.client.AmbariClient.get_alerts_data' ) #NEWLINE# @ mock . patch ( 'sahara.plugins.utils.get_instance' ) #NEWLINE# def test_check_health( self , get_instance , alerts_response , close , init ) : #NEWLINE# #INDENT# init . return_value = None #NEWLINE# alerts_response . return_value = [ { #NEWLINE# #INDENT# 'Alert' : { #NEWLINE# #INDENT# 'state' : 'OK' , #NEWLINE# 'service_name' : 'ZOOKEEPER' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] #NEWLINE# result = health . AmbariServiceHealthCheck ( mock . Mock ( extra = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) , health . AlertsProvider ( mock . Mock ( ) ) , 'ZOOKEEPER' ) . check_health ( ) #NEWLINE# self . assertEqual ( 'No alerts found' , result ) #NEWLINE# self . _standard_negative_test ( self , [ { #NEWLINE# #INDENT# 'Alert' : { #NEWLINE# #INDENT# 'state' : 'WARNING' , #NEWLINE# 'service_name' : 'ZOOKEEPER' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , 'YELLOW' , '1 warning' ) #NEWLINE# self . _standard_negative_test ( alerts_response , [ { #NEWLINE# #INDENT# 'Alert' : { #NEWLINE# #INDENT# 'state' : 'CRITICAL' , #NEWLINE# 'service_name' : 'ZOOKEEPER' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , 'RED' , '1 critical' ) #NEWLINE# self . _standard_negative_test ( alerts_response , [ { #NEWLINE# #INDENT# 'Alert' : { #NEWLINE# #INDENT# 'state' : 'CRITICAL' , #NEWLINE# 'service_name' : 'Kafka' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , 'YELLOW' , '1 warning' ) #NEWLINE# self . _standard_negative_test ( alerts_response , [ { #NEWLINE# #INDENT# 'Alert' : { #NEWLINE# #INDENT# 'state' : 'CRITICAL' , #NEWLINE# 'service_name' : 'ZOOKEEPER' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'Alert' : { #NEWLINE# #INDENT# 'state' : 'WARNING' , #NEWLINE# 'service_name' : 'ZOOKEEPER' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , 'RED' , '1 critical and 1 warning' ) #NEWLINE# alerts_response . side_effect = [ ValueError ( 'OOUCH!' ) ] #NEWLINE# with testtools . ExpectedException ( health_check_base . RedHealthError ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# health . AmbariHealthCheck ( mock . Mock ( extra = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) , health . AlertsProvider ( mock . Mock ( ) ) ) . check_health ( ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# self . assertEqual ( "Cluster health is RED. Reason: Can't get response from Ambari Monitor: OOUCH!" , six . text_type ( e ) ) #NEWLINE# raise