77
88from metrics_utility .automation_controller_billing .collectors import total_workers_vcpu
99from metrics_utility .exceptions import MissingRequiredEnvVar
10- from metrics_utility .library .collectors .total_workers_vcpu import get_hour_boundaries
10+ from metrics_utility .library .collectors .others . total_workers_vcpu import get_hour_boundaries
1111from metrics_utility .test .util import temporary_env
1212
1313
@@ -39,7 +39,7 @@ def test_returns_hardcoded_value_when_usage_based_billing_disabled(self):
3939 """Test that the function returns hardcoded value when METRICS_UTILITY_USAGE_BASED_METERING_ENABLED is not set or false (default behavior)."""
4040 with (
4141 patch ('metrics_utility.automation_controller_billing.collectors.get_optional_collectors' ) as mock_get ,
42- patch ('metrics_utility.library.collectors.total_workers_vcpu.logger' ) as mock_logger ,
42+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.logger' ) as mock_logger ,
4343 patch ('metrics_utility.automation_controller_billing.collectors.os.path.exists' , return_value = True ),
4444 patch ('builtins.open' , mock_open (read_data = 'fake-token' )),
4545 ):
@@ -75,7 +75,7 @@ def test_usage_based_billing_enabled_case_insensitive(self):
7575 """Test that METRICS_UTILITY_USAGE_BASED_METERING_ENABLED is case insensitive."""
7676 with (
7777 patch ('metrics_utility.automation_controller_billing.collectors.get_optional_collectors' ) as mock_get ,
78- patch ('metrics_utility.library.collectors.total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
78+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
7979 patch ('metrics_utility.automation_controller_billing.collectors.os.path.exists' , return_value = True ),
8080 patch ('builtins.open' , mock_open (read_data = 'fake-token' )),
8181 ):
@@ -102,10 +102,10 @@ def test_uses_default_prometheus_url_when_not_set(self):
102102 """Test that the function uses default Prometheus URL when METRICS_UTILITY_PROMETHEUS_URL is not set."""
103103 with (
104104 patch ('metrics_utility.automation_controller_billing.collectors.get_optional_collectors' ) as mock_get ,
105- patch ('metrics_utility.library.collectors.total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
106- patch ('metrics_utility.library.collectors.total_workers_vcpu.get_total_workers_cpu' ) as mock_get_cpu ,
107- patch ('metrics_utility.library.collectors.total_workers_vcpu.get_cpu_timeline' ) as mock_get_timeline ,
108- patch ('metrics_utility.library.collectors.total_workers_vcpu.logger' ) as mock_logger ,
105+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
106+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.get_total_workers_cpu' ) as mock_get_cpu ,
107+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.get_cpu_timeline' ) as mock_get_timeline ,
108+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.logger' ) as mock_logger ,
109109 patch ('metrics_utility.automation_controller_billing.collectors.logger' ) as mock_collectors_logger ,
110110 patch ('metrics_utility.automation_controller_billing.collectors.os.path.exists' , return_value = True ),
111111 patch ('builtins.open' , mock_open (read_data = 'fake-token' )),
@@ -172,7 +172,7 @@ def test_prometheus_client_creation_failure_raises_exception(self):
172172 """Test that PrometheusClient creation failure raises an exception."""
173173 with (
174174 patch ('metrics_utility.automation_controller_billing.collectors.get_optional_collectors' ) as mock_get ,
175- patch ('metrics_utility.library.collectors.total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
175+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
176176 patch ('metrics_utility.automation_controller_billing.collectors.os.path.exists' , return_value = True ),
177177 patch ('builtins.open' , mock_open (read_data = 'fake-token' )),
178178 ):
@@ -195,7 +195,7 @@ def test_prometheus_query_failure_raises_exception(self):
195195 """Test that Prometheus query failure raises an exception."""
196196 with (
197197 patch ('metrics_utility.automation_controller_billing.collectors.get_optional_collectors' ) as mock_get ,
198- patch ('metrics_utility.library.collectors.total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
198+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
199199 patch ('metrics_utility.automation_controller_billing.collectors.os.path.exists' , return_value = True ),
200200 patch ('builtins.open' , mock_open (read_data = 'fake-token' )),
201201 ):
@@ -222,8 +222,8 @@ def test_prometheus_query_returns_none_when_no_data_available(self):
222222 """Test that the function returns None when Prometheus query returns None (no data available)."""
223223 with (
224224 patch ('metrics_utility.automation_controller_billing.collectors.get_optional_collectors' ) as mock_get ,
225- patch ('metrics_utility.library.collectors.total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
226- patch ('metrics_utility.library.collectors.total_workers_vcpu.logger' ) as mock_logger ,
225+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
226+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.logger' ) as mock_logger ,
227227 patch ('metrics_utility.automation_controller_billing.collectors.os.path.exists' , return_value = True ),
228228 patch ('builtins.open' , mock_open (read_data = 'fake-token' )),
229229 ):
@@ -254,8 +254,8 @@ def test_successful_prometheus_query_with_vcpu_calculation(self):
254254 """Test successful Prometheus query with vCPU calculation."""
255255 with (
256256 patch ('metrics_utility.automation_controller_billing.collectors.get_optional_collectors' ) as mock_get ,
257- patch ('metrics_utility.library.collectors.total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
258- patch ('metrics_utility.library.collectors.total_workers_vcpu.logger' ) as mock_logger ,
257+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
258+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.logger' ) as mock_logger ,
259259 patch ('metrics_utility.automation_controller_billing.collectors.os.path.exists' , return_value = True ),
260260 patch ('builtins.open' , mock_open (read_data = 'fake-token' )),
261261 ):
@@ -303,7 +303,7 @@ def test_prometheus_client_initialized_correctly(self):
303303 """Test that PrometheusClient is initialized correctly."""
304304 with (
305305 patch ('metrics_utility.automation_controller_billing.collectors.get_optional_collectors' ) as mock_get ,
306- patch ('metrics_utility.library.collectors.total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
306+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
307307 patch ('metrics_utility.automation_controller_billing.collectors.os.path.exists' , return_value = True ),
308308 patch ('builtins.open' , mock_open (read_data = 'fake-token' )),
309309 ):
@@ -334,8 +334,8 @@ def test_prometheus_query_uses_correct_promql_with_hour_boundaries(self):
334334 """Test that the Prometheus query uses correct PromQL with hour boundaries."""
335335 with (
336336 patch ('metrics_utility.automation_controller_billing.collectors.get_optional_collectors' ) as mock_get ,
337- patch ('metrics_utility.library.collectors.total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
338- patch ('metrics_utility.library.collectors.total_workers_vcpu.datetime' ) as mock_datetime ,
337+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
338+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.datetime' ) as mock_datetime ,
339339 patch ('metrics_utility.automation_controller_billing.collectors.os.path.exists' , return_value = True ),
340340 patch ('builtins.open' , mock_open (read_data = 'fake-token' )),
341341 ):
@@ -375,7 +375,7 @@ def test_vcpu_value_converted_to_int(self):
375375 """Test that vCPU values from Prometheus (floats) are properly converted to integers."""
376376 with (
377377 patch ('metrics_utility.automation_controller_billing.collectors.get_optional_collectors' ) as mock_get ,
378- patch ('metrics_utility.library.collectors.total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
378+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
379379 patch ('metrics_utility.automation_controller_billing.collectors.os.path.exists' , return_value = True ),
380380 patch ('builtins.open' , mock_open (read_data = 'fake-token' )),
381381 ):
@@ -398,7 +398,7 @@ def test_vcpu_value_converted_to_int(self):
398398 assert result ['total_workers_vcpu' ] == 15 # Should be truncated to int
399399 assert isinstance (result ['total_workers_vcpu' ], int )
400400
401- @patch ('metrics_utility.library.collectors.total_workers_vcpu.datetime' )
401+ @patch ('metrics_utility.library.collectors.others. total_workers_vcpu.datetime' )
402402 def test_timestamp_in_output_with_hour_boundaries (self , mock_datetime ):
403403 """Test that the function includes proper timestamp based on hour boundaries."""
404404 # Mock the datetime.now() call
@@ -409,8 +409,8 @@ def test_timestamp_in_output_with_hour_boundaries(self, mock_datetime):
409409
410410 with (
411411 patch ('metrics_utility.automation_controller_billing.collectors.get_optional_collectors' ) as mock_get ,
412- patch ('metrics_utility.library.collectors.total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
413- patch ('metrics_utility.library.collectors.total_workers_vcpu.logger' ) as mock_logger ,
412+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.PrometheusClient' ) as mock_prom_client_class ,
413+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.logger' ) as mock_logger ,
414414 patch ('metrics_utility.automation_controller_billing.collectors.os.path.exists' , return_value = True ),
415415 patch ('builtins.open' , mock_open (read_data = 'fake-token' )),
416416 ):
@@ -451,7 +451,7 @@ def test_usage_based_billing_disabled_unset_returns_hardcoded_value(self):
451451 """Test that when METRICS_UTILITY_USAGE_BASED_METERING_ENABLED is unset, it returns hardcoded value."""
452452 with (
453453 patch ('metrics_utility.automation_controller_billing.collectors.get_optional_collectors' ) as mock_get ,
454- patch ('metrics_utility.library.collectors.total_workers_vcpu.logger' ) as mock_logger ,
454+ patch ('metrics_utility.library.collectors.others. total_workers_vcpu.logger' ) as mock_logger ,
455455 patch ('metrics_utility.automation_controller_billing.collectors.os.path.exists' , return_value = True ),
456456 patch ('builtins.open' , mock_open (read_data = 'fake-token' )),
457457 ):
0 commit comments