Skip to content

Commit 9471bef

Browse files
committed
more fixups
1 parent 1a4c5a5 commit 9471bef

5 files changed

Lines changed: 22 additions & 15 deletions

File tree

metrics_utility/library/collectors/others/total_workers_vcpu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def total_workers_vcpu(*, cluster_name=None, metering_enabled=False, prometheus_
2525

2626
if not metering_enabled:
2727
info['total_workers_vcpu'] = 1
28-
return info
28+
return output.dict(info)
2929

3030
prom = PrometheusClient(url=prometheus_url, ca_cert_path=ca_cert_path, token=token)
3131

metrics_utility/test/gather/test_jobhostsummary_gather.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def test_job_host_summary_case_insensitive_disable(cleanup_glob):
285285
def test_job_host_summary_invalid_values_still_enabled(cleanup_glob):
286286
"""Test that job_host_summary.csv is still generated when METRICS_UTILITY_DISABLE_JOB_HOST_SUMMARY_COLLECTOR is set to invalid values."""
287287

288-
invalid_values = ['yes', 'no', '1', '0', 'enabled', 'disabled', 'random_text', '']
288+
invalid_values = ['yes', 'no', '0', 'enabled', 'disabled', 'random_text', '']
289289

290290
for test_value in invalid_values:
291291
# Create environment variables with collector set to invalid value

metrics_utility/test/gather/test_total_workers_vcpu.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
from datetime import datetime, timezone
3-
from unittest.mock import MagicMock, patch
2+
from unittest.mock import MagicMock, mock_open, patch
43

54
import pytest
65

@@ -64,11 +63,10 @@ def test_raises_exception_when_total_workers_vcpu_is_none(self):
6463
with (
6564
patch('metrics_utility.automation_controller_billing.collectors.get_optional_collectors') as mock_get,
6665
patch('metrics_utility.automation_controller_billing.collectors.total_workers_vcpu') as mock_tw_vcpu,
67-
patch('metrics_utility.automation_controller_billing.collectors.os.path.exists') as mock_exists,
68-
patch('builtins.open', MagicMock(return_value=MagicMock(__enter__=MagicMock(return_value=MagicMock(read=MagicMock(return_value='test-token\n')))))),
66+
patch('metrics_utility.automation_controller_billing.collectors.os.path.exists', return_value=True),
67+
patch('builtins.open', mock_open(read_data='test-token\n')),
6968
):
7069
mock_get.return_value = ['total_workers_vcpu']
71-
mock_exists.return_value = True # token and ca_cert files exist
7270

7371
# Mock the collector to return None for total_workers_vcpu
7472
mock_collector = MagicMock()
@@ -91,11 +89,10 @@ def test_successful_call_with_metering_enabled(self):
9189
with (
9290
patch('metrics_utility.automation_controller_billing.collectors.get_optional_collectors') as mock_get,
9391
patch('metrics_utility.automation_controller_billing.collectors.total_workers_vcpu') as mock_tw_vcpu,
94-
patch('metrics_utility.automation_controller_billing.collectors.os.path.exists') as mock_exists,
95-
patch('builtins.open', MagicMock(return_value=MagicMock(__enter__=MagicMock(return_value=MagicMock(read=MagicMock(return_value='test-token\n')))))),
92+
patch('metrics_utility.automation_controller_billing.collectors.os.path.exists', return_value=True),
93+
patch('builtins.open', mock_open(read_data='test-token\n')),
9694
):
9795
mock_get.return_value = ['total_workers_vcpu']
98-
mock_exists.return_value = True # token and ca_cert files exist
9996

10097
# Mock the collector
10198
mock_collector = MagicMock()

metrics_utility/test/library/test_collectors_total_workers_vcpu_helpers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ def test_get_cpu_timeline_query_parameters(self):
150150

151151
get_cpu_timeline(mock_prom, start_ts, end_ts)
152152

153-
mock_prom.query_range.assert_called_once_with(
154-
query='sum(machine_cpu_cores)', start_time=start_ts, end_time=end_ts, step='5m'
155-
)
153+
mock_prom.query_range.assert_called_once_with(query='sum(machine_cpu_cores)', start_time=start_ts, end_time=end_ts, step='5m')
156154

157155
def test_get_cpu_timeline_empty_result(self):
158156
"""Test handling of empty result."""

metrics_utility/test/test_collectors.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ def test_main_indirectmanagednodeaudit_table_not_in_optional_collectors(self, mo
5353
@patch('metrics_utility.automation_controller_billing.collectors.main_indirectmanagednodeaudit')
5454
@patch('metrics_utility.automation_controller_billing.collectors.get_optional_collectors')
5555
@patch('metrics_utility.automation_controller_billing.collectors.connection')
56-
def test_main_indirectmanagednodeaudit_table_programming_error(self, mock_connection, mock_get_optional_collectors, mock_main_indirectmanagednodeaudit, mock_logger):
56+
def test_main_indirectmanagednodeaudit_table_programming_error(
57+
self,
58+
mock_connection,
59+
mock_get_optional_collectors,
60+
mock_main_indirectmanagednodeaudit,
61+
mock_logger,
62+
):
5763
"""Test graceful handling when table doesn't exist (ProgrammingError)"""
5864
# Setup
5965
mock_get_optional_collectors.return_value = {'main_indirectmanagednodeaudit'}
@@ -80,7 +86,13 @@ def test_main_indirectmanagednodeaudit_table_programming_error(self, mock_connec
8086
@patch('metrics_utility.automation_controller_billing.collectors.main_indirectmanagednodeaudit')
8187
@patch('metrics_utility.automation_controller_billing.collectors.get_optional_collectors')
8288
@patch('metrics_utility.automation_controller_billing.collectors.connection')
83-
def test_main_indirectmanagednodeaudit_table_logs_specific_error(self, mock_connection, mock_get_optional_collectors, mock_main_indirectmanagednodeaudit, mock_logger):
89+
def test_main_indirectmanagednodeaudit_table_logs_specific_error(
90+
self,
91+
mock_connection,
92+
mock_get_optional_collectors,
93+
mock_main_indirectmanagednodeaudit,
94+
mock_logger,
95+
):
8496
"""Test that the specific error message is logged correctly"""
8597
# Setup
8698
mock_get_optional_collectors.return_value = {'main_indirectmanagednodeaudit'}

0 commit comments

Comments
 (0)