Skip to content

Commit 880b4cc

Browse files
fix: Fir 31676 python sdk resource manager errors when referencing engines (#366)
1 parent 77e260e commit 880b4cc

File tree

6 files changed

+114
-2
lines changed

6 files changed

+114
-2
lines changed

src/firebolt/common/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
DEFAULT_TIMEOUT_SECONDS: int = 60
44

55
# Running statuses in infromation schema
6-
ENGINE_STATUS_RUNNING_LIST = ["Running", "ENGINE_STATE_RUNNING"]
6+
ENGINE_STATUS_RUNNING_LIST = ["RUNNING", "Running", "ENGINE_STATE_RUNNING"]

src/firebolt/service/V2/types.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from enum import Enum
2+
from typing import Optional
23

34

45
class EngineType(Enum):
@@ -50,9 +51,20 @@ class EngineStatus(Enum):
5051
FAILED = "Failed"
5152
DELETING = "Deleting"
5253

54+
@classmethod
55+
def _missing_(cls, value: object) -> Optional["EngineStatus"]:
56+
"""Handle case-insensitive string values."""
57+
if isinstance(value, str):
58+
return cls(value.capitalize())
59+
return super()._missing_(value)
60+
5361
def __str__(self) -> str:
5462
return self.value
5563

64+
@classmethod
65+
def from_string(cls, value: str) -> "EngineStatus":
66+
return cls(value.capitalize())
67+
5668

5769
class DatabaseOrder(Enum):
5870
DATABASE_ORDER_UNSPECIFIED = "DATABASE_ORDER_UNSPECIFIED"

tests/unit/async_db/V2/test_connection.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,40 @@ async def test_connect_engine_name(
136136
assert await connection.cursor().execute("select*") == len(python_query_data)
137137

138138

139+
async def test_connect_engine_running(
140+
httpx_mock: HTTPXMock,
141+
db_name: str,
142+
auth_url: str,
143+
server: str,
144+
auth: Auth,
145+
account_name: str,
146+
get_system_engine_url: str,
147+
get_system_engine_callback: Callable,
148+
account_id_url: str,
149+
account_id_callback: Callable,
150+
check_credentials_callback: Callable,
151+
engine_name: str,
152+
system_engine_query_url: str,
153+
get_engine_url_callback_test_status: Callable,
154+
) -> None:
155+
httpx_mock.add_callback(check_credentials_callback, url=auth_url)
156+
httpx_mock.add_callback(get_system_engine_callback, url=get_system_engine_url)
157+
httpx_mock.add_callback(account_id_callback, url=account_id_url)
158+
httpx_mock.add_callback(
159+
get_engine_url_callback_test_status, url=system_engine_query_url
160+
)
161+
162+
async with await connect(
163+
engine_name=engine_name,
164+
database=db_name,
165+
auth=auth,
166+
account_name=account_name,
167+
api_endpoint=server,
168+
):
169+
# Engine is running, no exception should be raised
170+
pass
171+
172+
139173
async def test_connect_database(
140174
db_name: str,
141175
auth_url: str,

tests/unit/db/V2/test_connection.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,40 @@ def test_connect_engine_name(
141141
assert connection.cursor().execute("select*") == len(python_query_data)
142142

143143

144+
def test_connect_engine_running(
145+
httpx_mock: HTTPXMock,
146+
db_name: str,
147+
auth_url: str,
148+
server: str,
149+
auth: Auth,
150+
account_name: str,
151+
get_system_engine_url: str,
152+
get_system_engine_callback: Callable,
153+
account_id_url: str,
154+
account_id_callback: Callable,
155+
check_credentials_callback: Callable,
156+
engine_name: str,
157+
system_engine_query_url: str,
158+
get_engine_url_callback_test_status: Callable,
159+
) -> None:
160+
httpx_mock.add_callback(check_credentials_callback, url=auth_url)
161+
httpx_mock.add_callback(get_system_engine_callback, url=get_system_engine_url)
162+
httpx_mock.add_callback(account_id_callback, url=account_id_url)
163+
httpx_mock.add_callback(
164+
get_engine_url_callback_test_status, url=system_engine_query_url
165+
)
166+
167+
with connect(
168+
engine_name=engine_name,
169+
database=db_name,
170+
auth=auth,
171+
account_name=account_name,
172+
api_endpoint=server,
173+
):
174+
# Engine is running, no exception should be raised
175+
pass
176+
177+
144178
def test_connect_database(
145179
db_name: str,
146180
auth_url: str,

tests/unit/db_conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ def get_engine_url_not_running_callback(
303303
return _get_engine_url_callback(engine_name, db_name, query_statistics, "Stopped")
304304

305305

306+
@fixture(params=["Running", "RUNNING", "ENGINE_STATE_RUNNING"])
307+
def get_engine_url_callback_test_status(
308+
server: str, db_name: str, query_statistics: Dict[str, Any], request: Any
309+
) -> Callable:
310+
return _get_engine_url_callback(server, db_name, query_statistics, request.param)
311+
312+
306313
@fixture
307314
def get_engine_url_invalid_db_callback(
308315
engine_name,

tests/unit/service/V2/test_engine.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Callable
22

33
from httpx import Request
4-
from pytest import raises
4+
from pytest import mark, raises
55
from pytest_httpx import HTTPXMock
66

77
from firebolt.model.V2.database import Database
@@ -228,3 +228,28 @@ def test_engine_deleteting(
228228
engine = resource_manager.engines.get_by_name(mock_engine.name)
229229

230230
assert engine.current_status == EngineStatus.DELETING
231+
232+
233+
@mark.parametrize(
234+
"engine_status, expected_status",
235+
[(status.value.upper(), status) for status in EngineStatus],
236+
)
237+
def test_engine_new_status(
238+
engine_status: str,
239+
expected_status: EngineStatus,
240+
httpx_mock: HTTPXMock,
241+
resource_manager: ResourceManager,
242+
instance_type_callback: Callable,
243+
instance_type_url: str,
244+
system_engine_no_db_query_url: str,
245+
mock_engine: Engine,
246+
):
247+
mock_engine.current_status = engine_status
248+
get_engine_callback = get_objects_from_db_callback([mock_engine])
249+
250+
httpx_mock.add_callback(instance_type_callback, url=instance_type_url)
251+
httpx_mock.add_callback(get_engine_callback, url=system_engine_no_db_query_url)
252+
253+
engine = resource_manager.engines.get_by_name(mock_engine.name)
254+
255+
assert engine.current_status == expected_status

0 commit comments

Comments
 (0)