Skip to content

Commit 015550b

Browse files
committed
Applying review comments
1 parent eaeedc1 commit 015550b

File tree

3 files changed

+54
-59
lines changed

3 files changed

+54
-59
lines changed

tests/test_scenario/fault_injector_client.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
import json
2+
import logging
3+
import time
24
import urllib.request
35
from typing import Dict, Any, Optional, Union
46
from enum import Enum
57

8+
import pytest
9+
10+
11+
class TaskStatuses:
12+
"""Class to hold completed statuses constants."""
13+
14+
FAILED = "failed"
15+
FINISHED = "finished"
16+
SUCCESS = "success"
17+
RUNNING = "running"
18+
19+
COMPLETED_STATUSES = [FAILED, FINISHED, SUCCESS]
20+
621

722
class ActionType(str, Enum):
823
DMC_RESTART = "dmc_restart"
@@ -103,3 +118,32 @@ def execute_rladmin_command(
103118
error_body = json.loads(e.read().decode("utf-8"))
104119
raise ValueError(f"Validation Error: {error_body}")
105120
raise
121+
122+
def get_operation_result(
123+
self,
124+
action_id: str,
125+
timeout: int = 60,
126+
) -> Dict[str, Any]:
127+
"""Get the result of a specific action"""
128+
start_time = time.time()
129+
check_interval = 3
130+
while time.time() - start_time < timeout:
131+
try:
132+
status_result = self.get_action_status(action_id)
133+
operation_status = status_result.get("status", "unknown")
134+
135+
if operation_status in TaskStatuses.COMPLETED_STATUSES:
136+
logging.debug(
137+
f"Operation {action_id} completed with status: "
138+
f"{operation_status}"
139+
)
140+
if operation_status != TaskStatuses.SUCCESS:
141+
pytest.fail(f"Operation {action_id} failed: {status_result}")
142+
return status_result
143+
144+
time.sleep(check_interval)
145+
except Exception as e:
146+
logging.warning(f"Error checking operation status: {e}")
147+
time.sleep(check_interval)
148+
else:
149+
raise TimeoutError(f"Timeout waiting for operation {action_id}")

tests/test_scenario/hitless_upgrade_helpers.py

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@
1212
)
1313

1414

15-
class TaskStatuses:
16-
"""Class to hold completed statuses constants."""
17-
18-
FAILED = "failed"
19-
FINISHED = "finished"
20-
SUCCESS = "success"
21-
RUNNING = "running"
22-
23-
COMPLETED_STATUSES = [FAILED, FINISHED, SUCCESS]
24-
25-
2615
class ClientValidations:
2716
@staticmethod
2817
def wait_push_notification(
@@ -32,15 +21,15 @@ def wait_push_notification(
3221
):
3322
"""Wait for a push notification to be received."""
3423
start_time = time.time()
35-
check_interval = 1 # Check more frequently during operations
24+
check_interval = 0.2 # Check more frequently during operations
3625
test_conn = (
3726
connection if connection else redis_client.connection_pool.get_connection()
3827
)
3928

4029
try:
4130
while time.time() - start_time < timeout:
4231
try:
43-
if test_conn.can_read(timeout=0.5):
32+
if test_conn.can_read(timeout=0.2):
4433
# reading is important, it triggers the push notification
4534
push_response = test_conn.read_response(push_request=True)
4635
logging.debug(
@@ -61,34 +50,6 @@ def wait_push_notification(
6150

6251

6352
class ClusterOperations:
64-
@staticmethod
65-
def get_operation_result(
66-
fault_injector: FaultInjectorClient,
67-
action_id: str,
68-
timeout: int = 60,
69-
) -> Tuple[str, dict]:
70-
"""Get the result of a specific action"""
71-
start_time = time.time()
72-
check_interval = 3
73-
while time.time() - start_time < timeout:
74-
try:
75-
status_result = fault_injector.get_action_status(action_id)
76-
operation_status = status_result.get("status", "unknown")
77-
78-
if operation_status in TaskStatuses.COMPLETED_STATUSES:
79-
logging.debug(
80-
f"Operation {action_id} completed with status: "
81-
f"{operation_status}"
82-
)
83-
return operation_status, status_result
84-
85-
time.sleep(check_interval)
86-
except Exception as e:
87-
logging.warning(f"Error checking operation status: {e}")
88-
time.sleep(check_interval)
89-
else:
90-
raise TimeoutError(f"Timeout waiting for operation {action_id}")
91-
9253
@staticmethod
9354
def get_cluster_nodes_info(
9455
fault_injector: FaultInjectorClient,
@@ -113,16 +74,9 @@ def get_cluster_nodes_info(
11374
f"Failed to trigger get cluster status action for bdb_id {bdb_id}: {trigger_action_result}"
11475
)
11576

116-
status, action_status_check_response = (
117-
ClusterOperations.get_operation_result(
118-
fault_injector, action_id, timeout=timeout
119-
)
77+
action_status_check_response = fault_injector.get_operation_result(
78+
action_id, timeout=timeout
12079
)
121-
122-
if status != TaskStatuses.SUCCESS:
123-
pytest.fail(
124-
f"Failed to get cluster nodes info: {action_status_check_response}"
125-
)
12680
logging.info(
12781
f"Completed cluster nodes info reading: {action_status_check_response}"
12882
)

tests/test_scenario/test_hitless_upgrade.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from tests.test_scenario.hitless_upgrade_helpers import (
2323
ClientValidations,
2424
ClusterOperations,
25-
TaskStatuses,
2625
)
2726

2827
logging.basicConfig(
@@ -135,11 +134,10 @@ def _execute_migration(
135134

136135
self._migration_executed = True
137136

138-
migrate_status, migrate_result = ClusterOperations.get_operation_result(
139-
fault_injector_client, migrate_action_id, timeout=MIGRATE_TIMEOUT
137+
migrate_result = fault_injector_client.get_operation_result(
138+
migrate_action_id, timeout=MIGRATE_TIMEOUT
140139
)
141-
if migrate_status != TaskStatuses.SUCCESS:
142-
pytest.fail(f"Failed to execute rladmin migrate: {migrate_result}")
140+
logging.debug(f"Migration result: {migrate_result}")
143141

144142
def _execute_bind(
145143
self,
@@ -153,11 +151,10 @@ def _execute_bind(
153151

154152
self._bind_executed = True
155153

156-
bind_status, bind_result = ClusterOperations.get_operation_result(
157-
fault_injector_client, bind_action_id, timeout=BIND_TIMEOUT
154+
bind_result = fault_injector_client.get_operation_result(
155+
bind_action_id, timeout=BIND_TIMEOUT
158156
)
159-
if bind_status != TaskStatuses.SUCCESS:
160-
pytest.fail(f"Failed to execute rladmin bind endpoint: {bind_result}")
157+
logging.debug(f"Bind result: {bind_result}")
161158

162159
def _execute_migrate_bind_flow(
163160
self,

0 commit comments

Comments
 (0)