Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicaj committed Mar 4, 2025
1 parent f109ec8 commit c30b049
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,59 @@
from middlewared.plugins.reporting.utils import get_metrics_approximation, calculate_disk_space_for_netdata


@pytest.mark.parametrize('disk_count,core_count,interface_count,services_count,vms_count,expected_output', [
(4, 2, 1, 10, 2, {1: 699, 60: 4}),
(1600, 32, 4, 10, 1, {1: 8754, 60: 1600}),
(10, 16, 2, 12, 3, {1: 838, 60: 10}),
@pytest.mark.parametrize('disk_count,core_count,interface_count,pool_count,services_count,vms_count,expected_output', [
(4, 2, 1, 2, 10, 2, {1: 703, 60: 4}),
(1600, 32, 4, 4, 10, 1, {1: 8762, 60: 1600}),
(10, 16, 2, 2, 12, 3, {1: 842, 60: 10}),
])
def test_netdata_metrics_count_approximation(
disk_count, core_count, interface_count, services_count, vms_count, expected_output
disk_count, core_count, interface_count, pool_count, services_count, vms_count, expected_output
):
assert get_metrics_approximation(
disk_count, core_count, interface_count, vms_count, services_count
disk_count, core_count, interface_count, pool_count, vms_count, services_count
) == expected_output


@pytest.mark.parametrize(
'disk_count,core_count,interface_count,services_count,vms_count,days,'
'disk_count,core_count,interface_count,pool_count,services_count,vms_count,days,'
'bytes_per_point,tier_interval,expected_output', [
(4, 2, 1, 10, 2, 7, 1, 1, 403),
(4, 2, 1, 10, 1, 7, 4, 60, 25),
(1600, 32, 4, 2, 4, 4, 1, 1, 2925),
(1600, 32, 4, 1, 4, 4, 4, 900, 12),
(10, 16, 2, 12, 1, 3, 1, 1, 183),
(10, 16, 2, 10, 3, 3, 4, 60, 13),
(1600, 32, 4, 12, 3, 18, 1, 1, 13183),
(1600, 32, 4, 12, 1, 18, 4, 900, 57),
(4, 2, 1, 2, 10, 2, 7, 1, 1, 405),
(4, 2, 1, 2, 10, 1, 7, 4, 60, 25),
(1600, 32, 4, 12, 2, 4, 4, 1, 1, 2933),
(1600, 32, 4, 10, 1, 4, 4, 4, 900, 13),
(10, 16, 2, 2, 12, 1, 3, 1, 1, 184),
(10, 16, 2, 2, 10, 3, 3, 4, 60, 13),
(1600, 32, 4, 4, 12, 3, 18, 1, 1, 13195),
(1600, 32, 4, 4, 12, 1, 18, 4, 900, 58),
],
)
def test_netdata_disk_space_approximation(
disk_count, core_count, interface_count, services_count,
vms_count, days, bytes_per_point, tier_interval, expected_output
disk_count, core_count, interface_count, pool_count, services_count,
vms_count, days, bytes_per_point, tier_interval, expected_output
):
assert calculate_disk_space_for_netdata(get_metrics_approximation(
disk_count, core_count, interface_count, vms_count, services_count
disk_count, core_count, interface_count, pool_count, vms_count, services_count
), days, bytes_per_point, tier_interval) == expected_output


@pytest.mark.parametrize(
'disk_count,core_count,interface_count,services_count,vms_count,days,bytes_per_point,tier_interval', [
(4, 2, 1, 10, 2, 7, 1, 1),
(4, 2, 1, 12, 2, 7, 4, 60),
(1600, 32, 4, 10, 3, 4, 1, 1),
(1600, 32, 4, 12, 3, 4, 4, 900),
(10, 16, 2, 10, 4, 3, 1, 1),
(10, 16, 2, 12, 4, 3, 4, 60),
(1600, 32, 4, 10, 5, 18, 1, 1),
(1600, 32, 4, 12, 5, 18, 4, 900),
'disk_count,core_count,interface_count,pool_count,services_count,vms_count,days,bytes_per_point,tier_interval',
[
(4, 2, 1, 2, 10, 2, 7, 1, 1),
(4, 2, 1, 2, 12, 2, 7, 4, 60),
(1600, 32, 4, 4, 10, 3, 4, 1, 1),
(1600, 32, 4, 4, 12, 3, 4, 4, 900),
(10, 16, 2, 2, 10, 4, 3, 1, 1),
(10, 16, 2, 2, 12, 4, 3, 4, 60),
(1600, 32, 4, 4, 10, 5, 18, 1, 1),
(1600, 32, 4, 4, 12, 5, 18, 4, 900),
],
)
def test_netdata_days_approximation(
disk_count, core_count, interface_count, services_count, vms_count, days, bytes_per_point, tier_interval
):
disk_count, core_count, interface_count, pool_count, services_count, vms_count, days, bytes_per_point,
tier_interval):
metric_intervals = get_metrics_approximation(
disk_count, core_count, interface_count, vms_count, services_count
disk_count, core_count, interface_count, pool_count, vms_count, services_count
)
disk_size = calculate_disk_space_for_netdata(metric_intervals, days, bytes_per_point, tier_interval)
total_metrics = metric_intervals[1] + (metric_intervals[60] / 60)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from middlewared.plugins.reporting.netdata.utils import NETDATA_UPDATE_EVERY
from middlewared.plugins.reporting.realtime_reporting import (
get_arc_stats, get_cpu_stats, get_disk_stats, get_interface_stats, get_memory_info,
get_arc_stats, get_cpu_stats, get_disk_stats, get_interface_stats, get_memory_info, get_pool_stats
)
from middlewared.plugins.reporting.realtime_reporting.utils import normalize_value, safely_retrieve_dimension

Expand Down Expand Up @@ -653,10 +653,51 @@
}
}
},
'truenas_pool.usage': {
'name': 'truenas_pool.usage',
'family': 'pool.usage',
'context': 'pool.usage',
'units': 'bytes',
'last_updated': 1741023952,
'dimensions': {
'boot-pool.available': {
'name': 'available',
'value': 16053874688
},
'boot-pool.used': {
'name': 'used',
'value': 3730903040
},
'tank.available': {
'name': 'available',
'value': 7181352960
},
'tank.used': {
'name': 'used',
'value': 13102555136
}
}
},

}


def test_get_pool_stats():
pool_stats = get_pool_stats(NETDATA_ALL_METRICS)
assert pool_stats['tank']['available'] == safely_retrieve_dimension(
NETDATA_ALL_METRICS, 'truenas_pool.usage', 'tank.available'
)
assert pool_stats['tank']['used'] == safely_retrieve_dimension(
NETDATA_ALL_METRICS, 'truenas_pool.usage', 'tank.used'
)
assert pool_stats['boot-pool']['available'] == safely_retrieve_dimension(
NETDATA_ALL_METRICS, 'truenas_pool.usage', 'boot-pool.available'
)
assert pool_stats['boot-pool']['used'] == safely_retrieve_dimension(
NETDATA_ALL_METRICS, 'truenas_pool.usage', 'boot-pool.used'
)


def test_arc_stats():
arc_stats = get_arc_stats(NETDATA_ALL_METRICS)

Expand Down

0 comments on commit c30b049

Please sign in to comment.