Skip to content

Commit

Permalink
Fix hypervisor sensor
Browse files Browse the repository at this point in the history
Change current state to use the name of hypervisorstate enum as expected
  • Loading branch information
gmatthews20 committed Dec 16, 2024
1 parent 1243bb0 commit 8a78c64
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions sensors/src/hypervisor_state_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ def poll(self):
name=hypervisor["hypervisor_name"]
)

if not prev_state == current_state:
if not prev_state == current_state.name:
payload = {
"hypervisor_name": hypervisor["hypervisor_name"],
"previous_state": prev_state,
"current_state": current_state,
"current_state": current_state.name,
}
self.sensor_service.dispatch(
trigger="stackstorm_openstack.hypervisor.state_change",
payload=payload,
)

self.sensor_service.set_value(
name=hypervisor["hypervisor_name"], value=current_state
name=hypervisor["hypervisor_name"], value=current_state.name
)

def cleanup(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/sensors/test_hypervisor_state_sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from unittest.mock import MagicMock, patch
from enums.hypervisor_states import HypervisorState
from sensors.src.hypervisor_state_sensor import HypervisorStateSensor


Expand Down Expand Up @@ -36,7 +37,7 @@ def test_poll(self, mock_query_hypervisor_state, mock_get_hypervisor_state):
]

self.sensor_service.get_value.return_value = "RUNNING"
mock_get_hypervisor_state.return_value = "PENDING_MAINTENANCE"
mock_get_hypervisor_state.return_value = HypervisorState.PENDING_MAINTENANCE

self.sensor.poll()

Expand Down

0 comments on commit 8a78c64

Please sign in to comment.