def test_get_global_statistics_non_integer(self):
        bigip = mock.MagicMock()
        bigip.tm.sys.performances.all_stats.load().__dict__ = ALL_STATS_1

        sh = StatHelper()
        stats = sh.get_global_statistics(bigip)
        rc_util = stats['Sys::Performance Ramcache']['RAM Cache Utilization']
        assert isinstance(rc_util['Hit Rate']['current'], int)
        assert isinstance(rc_util['Hit Rate']['average'], int)
        assert isinstance(rc_util['Hit Rate']['max'], int)
    def test_get_outbound_throughput_gs(self):
        bigip = mock.MagicMock()
        gs = {
            'Sys::Performance Throughput': {
                'Throughput(bits)': {
                    'Out': {
                        'current': 100
                    }
                }
            }
        }

        sh = StatHelper()
        conns = sh.get_outbound_throughput(bigip, global_stats=gs)
        assert(conns == 100)
    def test_get_active_SSL_TPS_gs(self):
        bigip = mock.MagicMock()
        gs = {
            'Sys::Performance Throughput': {
                'SSL Transactions': {
                    'SSL TPS': {
                        'current': 100
                    }
                }
            }
        }

        sh = StatHelper()
        conns = sh.get_active_SSL_TPS(bigip, global_stats=gs)
        assert(conns == 100)
    def test_get_active_connection_count_gs(self):
        bigip = mock.MagicMock()
        gs = {
            'Sys::Performance Connections': {
                'Active Connections': {
                    'Connections': {
                        'current': 100
                    }
                }
            }
        }

        sh = StatHelper()
        conns = sh.get_active_connection_count(bigip, global_stats=gs)
        assert(conns == 100)
 def test_get_throughput_bigip(self):
     bigip = mock.MagicMock()
     bigip.tm.sys.performances.all_stats.load().__dict__ = ALL_STATS_1
     sh = StatHelper()
     conns = sh.get_throughput(bigip)
     assert(conns == 24820)
 def test_get_active_SSL_TPS_bigip(self):
     bigip = mock.MagicMock()
     bigip.tm.sys.performances.all_stats.load().__dict__ = ALL_STATS_1
     sh = StatHelper()
     conns = sh.get_active_SSL_TPS(bigip)
     assert(conns == 0)
    def test_get_global_statistics_api_raw_values(self):
        bigip = mock.MagicMock()
        bigip.tm.sys.performances.all_stats.load().__dict__ = ALL_STATS_1
        sh = StatHelper()
        stats = sh.get_global_statistics(bigip)
        assert isinstance(stats, dict)
        assert stats['since'] == "2016-09-01T14:53:10Z"

        # Validate the sections' stats
        perf_sys_cpu = stats['Sys::Performance System']['System CPU Usage']
        assert(perf_sys_cpu['Utilization']['current'] == 2)
        assert(perf_sys_cpu['Utilization']['average'] == 2)
        assert(perf_sys_cpu['Utilization']['max'] == 28)

        perf_sys_mem = stats['Sys::Performance System']['Memory Used']
        assert(perf_sys_mem['TMM Memory Used']['current'] == 41)
        assert(perf_sys_mem['TMM Memory Used']['average'] == 41)
        assert(perf_sys_mem['TMM Memory Used']['max'] == 41)

        perf_conns_active =\
            stats['Sys::Performance Connections']['Active Connections']
        assert(perf_conns_active['Connections']['current'] == 0)
        assert(perf_conns_active['Connections']['average'] == 0)
        assert(perf_conns_active['Connections']['max'] == 0)

        perf_conns_new =\
            stats['Sys::Performance Connections']['Total New Connections']
        assert(perf_conns_new['Client Connections']['current'] == 0)
        assert(perf_conns_new['Client Connections']['average'] == 0)
        assert(perf_conns_new['Client Connections']['max'] == 0)
        assert(perf_conns_new['Server Connections']['current'] == 0)
        assert(perf_conns_new['Server Connections']['average'] == 0)
        assert(perf_conns_new['Server Connections']['max'] == 0)

        perf_conns_http =\
            stats['Sys::Performance Connections']['HTTP Requests']
        assert(perf_conns_http['HTTP Requests']['current'] == 0)
        assert(perf_conns_http['HTTP Requests']['average'] == 0)
        assert(perf_conns_http['HTTP Requests']['max'] == 0)

        perf_tp_bits =\
            stats['Sys::Performance Throughput']['Throughput(bits)']
        assert(perf_tp_bits['In']['current'] == 16995)
        assert(perf_tp_bits['In']['average'] == 14108)
        assert(perf_tp_bits['In']['max'] == 52077)
        assert(perf_tp_bits['Out']['current'] == 7825)
        assert(perf_tp_bits['Out']['average'] == 2782)
        assert(perf_tp_bits['Out']['max'] == 197391)

        perf_tp_ssl =\
            stats['Sys::Performance Throughput']['SSL Transactions']
        assert(perf_tp_ssl['SSL TPS']['current'] == 0)
        assert(perf_tp_ssl['SSL TPS']['average'] == 0)
        assert(perf_tp_ssl['SSL TPS']['max'] == 0)

        perf_tp_pkts =\
            stats['Sys::Performance Throughput']['Throughput(packets)']
        assert(perf_tp_pkts['In']['current'] == 20)
        assert(perf_tp_pkts['In']['average'] == 18)
        assert(perf_tp_pkts['In']['max'] == 43)
        assert(perf_tp_pkts['Out']['current'] == 3)
        assert(perf_tp_pkts['Out']['average'] == 1)
        assert(perf_tp_pkts['Out']['max'] == 26)

        # The input has 'nan' for these values so they should be cast as 0
        perf_ram_util =\
            stats['Sys::Performance Ramcache']['RAM Cache Utilization']
        assert(perf_ram_util['Hit Rate']['current'] == 0)
        assert(perf_ram_util['Hit Rate']['average'] == 0)
        assert(perf_ram_util['Hit Rate']['max'] == 0)
        assert(perf_ram_util['Byte Rate']['current'] == 0)
        assert(perf_ram_util['Byte Rate']['average'] == 0)
        assert(perf_ram_util['Byte Rate']['max'] == 0)
        assert(perf_ram_util['Eviction Rate']['current'] == 0)
        assert(perf_ram_util['Eviction Rate']['average'] == 0)
        assert(perf_ram_util['Eviction Rate']['max'] == 0)
 def test_get_global_statistics_no_api_raw_values(self):
     bigip = mock.MagicMock()
     bigip.tm.sys.performances.all_stats.load().__dict__ = {}
     sh = StatHelper()
     assert sh.get_global_statistics(bigip) is None