Skip to content

Commit 6595b6f

Browse files
Copilotalvarolopez
andcommitted
Fix import style and regenerate config file
- Changed import from `from prometheus_api_client import PrometheusConnect` to `import prometheus_api_client` to match codebase style - Updated usage to `prometheus_api_client.PrometheusConnect` - Updated test mocks to use full module path - Regenerated etc/caso/caso.conf.sample using oslo-config-generator - All tests pass (6/6 energy-related tests) Co-authored-by: alvarolopez <468751+alvarolopez@users.noreply.github.com>
1 parent 018e419 commit 6595b6f

File tree

3 files changed

+471
-6
lines changed

3 files changed

+471
-6
lines changed

caso/extract/prometheus.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import uuid
2020

21-
from prometheus_api_client import PrometheusConnect
21+
import prometheus_api_client
2222
from oslo_config import cfg
2323
from oslo_log import log
2424

@@ -100,7 +100,9 @@ def _energy_consumed_wh(self, vm_uuid):
100100
query_range = CONF.prometheus.prometheus_query_range
101101
verify_ssl = CONF.prometheus.prometheus_verify_ssl
102102

103-
prom = PrometheusConnect(url=prom_url, disable_ssl=not verify_ssl)
103+
prom = prometheus_api_client.PrometheusConnect(
104+
url=prom_url, disable_ssl=not verify_ssl
105+
)
104106

105107
# factor = step_seconds / 3600 converts µW·s to µWh
106108
factor = step_seconds / 3600

caso/tests/extract/test_prometheus.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def mock_prometheus_result_empty():
9393
class TestEnergyConsumptionExtractor:
9494
"""Test the energy consumption extractor."""
9595

96-
@mock.patch("caso.extract.prometheus.PrometheusConnect")
96+
@mock.patch("caso.extract.prometheus.prometheus_api_client.PrometheusConnect")
9797
def test_extract_with_results(
9898
self,
9999
mock_prom_connect,
@@ -144,7 +144,7 @@ def test_extract_with_no_vms(self, configured_extractor, extract_dates):
144144
# Verify - no VMs, no records
145145
assert len(records) == 0
146146

147-
@mock.patch("caso.extract.prometheus.PrometheusConnect")
147+
@mock.patch("caso.extract.prometheus.prometheus_api_client.PrometheusConnect")
148148
def test_extract_with_no_energy_data(
149149
self,
150150
mock_prom_connect,
@@ -170,7 +170,7 @@ def test_extract_with_no_energy_data(
170170
assert len(records) == 0
171171

172172
@mock.patch("caso.extract.prometheus.LOG")
173-
@mock.patch("caso.extract.prometheus.PrometheusConnect")
173+
@mock.patch("caso.extract.prometheus.prometheus_api_client.PrometheusConnect")
174174
def test_extract_with_prometheus_exception(
175175
self,
176176
mock_prom_connect,

0 commit comments

Comments
 (0)