<s> import logging <EOL> import sys <EOL> import unittest <EOL> from checks . system . unix import ( <EOL> IO , <EOL> Load , <EOL> Memory , <EOL> System , <EOL> ) <EOL> from config import get_system_stats <EOL> from tests . checks . common import get_check <EOL> from utils . platform import Platform <EOL> logging . basicConfig ( level = logging . DEBUG ) <EOL> logger = logging . getLogger ( __file__ ) <EOL> class TestSystem ( unittest . TestCase ) : <EOL> def testUptime ( self ) : <EOL> global logger <EOL> system = System ( logger ) <EOL> metrics = system . check ( { } ) <EOL> self . assertTrue ( "<STR_LIT>" in metrics ) <EOL> self . assertTrue ( metrics [ "<STR_LIT>" ] > <NUM_LIT:0> ) <EOL> def testLoad ( self ) : <EOL> global logger <EOL> load = Load ( logger ) <EOL> res = load . check ( { '<STR_LIT>' : get_system_stats ( ) } ) <EOL> assert '<STR_LIT>' in res <EOL> if Platform . is_linux ( ) : <EOL> cores = int ( get_system_stats ( ) . get ( '<STR_LIT>' ) ) <EOL> assert '<STR_LIT>' in res <EOL> assert abs ( res [ '<STR_LIT>' ] - cores * res [ '<STR_LIT>' ] ) <= <NUM_LIT:0.1> , ( res [ '<STR_LIT>' ] , cores * res [ '<STR_LIT>' ] ) <EOL> res = load . check ( { } ) <EOL> assert '<STR_LIT>' in res <EOL> assert '<STR_LIT>' not in res <EOL> def testMemory ( self ) : <EOL> global logger <EOL> res = Memory ( logger ) . check ( { } ) <EOL> if Platform . is_linux ( ) : <EOL> MEM_METRICS = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> for k in MEM_METRICS : <EOL> if k == '<STR_LIT>' and res [ '<STR_LIT>' ] == <NUM_LIT:0> : <EOL> continue <EOL> assert k in res , res <EOL> assert res [ "<STR_LIT>" ] == res [ "<STR_LIT>" ] + res [ "<STR_LIT>" ] <EOL> assert res [ "<STR_LIT>" ] == res [ "<STR_LIT>" ] + res [ "<STR_LIT>" ] <EOL> elif sys . platform == '<STR_LIT>' : <EOL> for k in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> assert k in res , res <EOL> def testDiskLatency ( self ) : <EOL> debian_iostat_output = """<STR_LIT>""" <EOL> global logger <EOL> checker = IO ( logger ) <EOL> results = checker . _parse_linux2 ( debian_iostat_output ) <EOL> self . assertTrue ( '<STR_LIT>' in results ) <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertTrue ( key in results [ '<STR_LIT>' ] , '<STR_LIT>' % key ) <EOL> self . assertEqual ( results [ '<STR_LIT>' ] [ key ] , '<STR_LIT>' ) <EOL> centos_iostat_output = """<STR_LIT>""" <EOL> checker = IO ( logger ) <EOL> results = checker . _parse_linux2 ( centos_iostat_output ) <EOL> self . assertTrue ( '<STR_LIT>' in results ) <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertTrue ( key in results [ '<STR_LIT>' ] , '<STR_LIT>' % key ) <EOL> self . assertEqual ( results [ '<STR_LIT>' ] [ key ] , '<STR_LIT>' ) <EOL> darwin_iostat_output = """<STR_LIT>""" <EOL> checker = IO ( logger ) <EOL> results = checker . _parse_darwin ( darwin_iostat_output ) <EOL> self . assertTrue ( "<STR_LIT>" in results . keys ( ) ) <EOL> self . assertTrue ( "<STR_LIT>" in results . keys ( ) ) <EOL> self . assertEqual ( <EOL> results [ "<STR_LIT>" ] , <EOL> { '<STR_LIT>' : float ( <NUM_LIT> * <NUM_LIT:10> ** <NUM_LIT:6> ) , } <EOL> ) <EOL> self . assertEqual ( <EOL> results [ "<STR_LIT>" ] , <EOL> { '<STR_LIT>' : float ( <NUM_LIT:0> ) , } <EOL> ) <EOL> def testNetwork ( self ) : <EOL> config = """<STR_LIT>""" <EOL> check , instances = get_check ( '<STR_LIT>' , config ) <EOL> check . check ( instances [ <NUM_LIT:0> ] ) <EOL> check . get_metrics ( ) <EOL> metric_names = [ m [ <NUM_LIT:0> ] for m in check . aggregator . metrics ] <EOL> assert '<STR_LIT>' in metric_names <EOL> assert '<STR_LIT>' in metric_names <EOL> if Platform . is_linux ( ) : <EOL> assert '<STR_LIT>' in metric_names <EOL> assert '<STR_LIT>' in metric_names <EOL> assert '<STR_LIT>' in metric_names <EOL> elif Platform . is_bsd ( ) : <EOL> assert '<STR_LIT>' in metric_names <EOL> assert '<STR_LIT>' in metric_names <EOL> assert '<STR_LIT>' in metric_names </s>
