Skip to content

Commit 961ebce

Browse files
committed
Applying review comments
1 parent eaeedc1 commit 961ebce

File tree

3 files changed

+56
-57
lines changed

3 files changed

+56
-57
lines changed

tests/test_scenario/fault_injector_client.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import json
2+
import logging
3+
import time
24
import urllib.request
3-
from typing import Dict, Any, Optional, Union
5+
from typing import Dict, Any, Optional, Tuple, Union
46
from enum import Enum
57

8+
import pytest
69

10+
class TaskStatuses:
11+
"""Class to hold completed statuses constants."""
12+
13+
FAILED = "failed"
14+
FINISHED = "finished"
15+
SUCCESS = "success"
16+
RUNNING = "running"
17+
18+
COMPLETED_STATUSES = [FAILED, FINISHED, SUCCESS]
719
class ActionType(str, Enum):
820
DMC_RESTART = "dmc_restart"
921
FAILOVER = "failover"
@@ -103,3 +115,34 @@ def execute_rladmin_command(
103115
error_body = json.loads(e.read().decode("utf-8"))
104116
raise ValueError(f"Validation Error: {error_body}")
105117
raise
118+
119+
def get_operation_result(
120+
self,
121+
action_id: str,
122+
timeout: int = 60,
123+
) -> Dict[str, Any]:
124+
"""Get the result of a specific action"""
125+
start_time = time.time()
126+
check_interval = 3
127+
while time.time() - start_time < timeout:
128+
try:
129+
status_result = self.get_action_status(action_id)
130+
operation_status = status_result.get("status", "unknown")
131+
132+
if operation_status in TaskStatuses.COMPLETED_STATUSES:
133+
logging.debug(
134+
f"Operation {action_id} completed with status: "
135+
f"{operation_status}"
136+
)
137+
if operation_status != TaskStatuses.SUCCESS:
138+
pytest.fail(
139+
f"Operation {action_id} failed: {status_result}"
140+
)
141+
return status_result
142+
143+
time.sleep(check_interval)
144+
except Exception as e:
145+
logging.warning(f"Error checking operation status: {e}")
146+
time.sleep(check_interval)
147+
else:
148+
raise TimeoutError(f"Timeout waiting for operation {action_id}")

tests/test_scenario/hitless_upgrade_helpers.py

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,10 @@
99
ActionRequest,
1010
ActionType,
1111
FaultInjectorClient,
12+
TaskStatuses,
1213
)
1314

1415

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-
2616
class ClientValidations:
2717
@staticmethod
2818
def wait_push_notification(
@@ -32,15 +22,15 @@ def wait_push_notification(
3222
):
3323
"""Wait for a push notification to be received."""
3424
start_time = time.time()
35-
check_interval = 1 # Check more frequently during operations
25+
check_interval = 0.2 # Check more frequently during operations
3626
test_conn = (
3727
connection if connection else redis_client.connection_pool.get_connection()
3828
)
3929

4030
try:
4131
while time.time() - start_time < timeout:
4232
try:
43-
if test_conn.can_read(timeout=0.5):
33+
if test_conn.can_read(timeout=0.2):
4434
# reading is important, it triggers the push notification
4535
push_response = test_conn.read_response(push_request=True)
4636
logging.debug(
@@ -61,33 +51,6 @@ def wait_push_notification(
6151

6252

6353
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}")
9154

9255
@staticmethod
9356
def get_cluster_nodes_info(
@@ -113,16 +76,11 @@ def get_cluster_nodes_info(
11376
f"Failed to trigger get cluster status action for bdb_id {bdb_id}: {trigger_action_result}"
11477
)
11578

116-
status, action_status_check_response = (
117-
ClusterOperations.get_operation_result(
118-
fault_injector, action_id, timeout=timeout
79+
action_status_check_response = (
80+
fault_injector.get_operation_result(
81+
action_id, timeout=timeout
11982
)
12083
)
121-
122-
if status != TaskStatuses.SUCCESS:
123-
pytest.fail(
124-
f"Failed to get cluster nodes info: {action_status_check_response}"
125-
)
12684
logging.info(
12785
f"Completed cluster nodes info reading: {action_status_check_response}"
12886
)

tests/test_scenario/test_hitless_upgrade.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,10 @@ def _execute_migration(
135135

136136
self._migration_executed = True
137137

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

144143
def _execute_bind(
145144
self,
@@ -153,11 +152,10 @@ def _execute_bind(
153152

154153
self._bind_executed = True
155154

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

162160
def _execute_migrate_bind_flow(
163161
self,

0 commit comments

Comments
 (0)