Skip to content

Commit 24b71b4

Browse files
fix: Engine service improvements (#313)
1 parent 894eda3 commit 24b71b4

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

src/firebolt/model/engine.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ def update(
213213
parameters are set to None, old engine parameter values remain.
214214
"""
215215

216-
if not any((name, scale, spec, auto_stop, warmup, engine_type)):
216+
if not any(
217+
x is not None for x in (name, scale, spec, auto_stop, warmup, engine_type)
218+
):
217219
# Nothing to be updated
218220
return self
219221

@@ -231,7 +233,7 @@ def update(
231233
self.ALTER_PARAMETER_NAMES,
232234
(scale, spec, auto_stop, name, warmup, engine_type),
233235
):
234-
if value:
236+
if value is not None:
235237
sql += f"{param} = ? "
236238
parameters.append(str(value))
237239

src/firebolt/service/engine.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,15 @@ def create(
156156
("" if fail_if_exists else self.IF_NOT_EXISTS_SQL), name
157157
)
158158
parameters = []
159-
if any((region, engine_type, spec, scale, auto_stop, warmup)):
159+
if any(
160+
x is not None for x in (region, engine_type, spec, scale, auto_stop, warmup)
161+
):
160162
sql += self.CREATE_WITH_SQL
161163
for param, value in zip(
162164
self.CREATE_PARAMETER_NAMES,
163165
(region, engine_type, spec, scale, auto_stop, warmup),
164166
):
165-
if value:
167+
if value is not None:
166168
sql += f"{param} = ? "
167169
parameters.append(str(value))
168170
with self._connection.cursor() as c:

src/firebolt/service/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class EngineStatus(Enum):
4747
STOPPED = "Stopped"
4848
DROPPING = "Dropping"
4949
REPAIRING = "Repairing"
50+
FAILED = "Failed"
5051

5152
def __str__(self) -> str:
5253
return self.value

tests/unit/service/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,18 @@ def updated_engine_type() -> EngineType:
307307
return EngineType.DATA_ANALYTICS
308308

309309

310+
@fixture
311+
def updated_auto_stop() -> EngineType:
312+
return 0
313+
314+
310315
@fixture
311316
def update_engine_callback(
312317
system_engine_no_db_query_url: str,
313318
mock_engine: Engine,
314319
updated_engine_scale: int,
315320
updated_engine_type: EngineType,
321+
updated_auto_stop: int,
316322
) -> Callable:
317323
def do_mock(
318324
request: httpx.Request = None,
@@ -321,6 +327,7 @@ def do_mock(
321327
assert request.url == system_engine_no_db_query_url
322328
mock_engine.scale = updated_engine_scale
323329
mock_engine.type = updated_engine_type
330+
mock_engine.auto_stop = updated_auto_stop
324331
return Response(
325332
status_code=httpx.codes.OK,
326333
json=empty_response,

tests/unit/service/test_engine.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,32 @@ def test_engine_update(
149149

150150
assert mock_engine.scale == updated_engine_scale
151151
assert mock_engine.type == updated_engine_type
152+
153+
mock_engine.update(scale=updated_engine_scale, engine_type=updated_engine_type)
154+
155+
assert mock_engine.scale == updated_engine_scale
156+
assert mock_engine.type == updated_engine_type
157+
158+
159+
def test_engine_update_auto_stop_zero(
160+
httpx_mock: HTTPXMock,
161+
resource_manager: ResourceManager,
162+
instance_type_callback: Callable,
163+
instance_type_url: str,
164+
mock_engine: Engine,
165+
get_engine_callback: Callable,
166+
update_engine_callback: Callable,
167+
system_engine_no_db_query_url: str,
168+
updated_auto_stop: int,
169+
):
170+
httpx_mock.add_callback(instance_type_callback, url=instance_type_url)
171+
httpx_mock.add_callback(get_engine_callback, url=system_engine_no_db_query_url)
172+
httpx_mock.add_callback(update_engine_callback, url=system_engine_no_db_query_url)
173+
httpx_mock.add_callback(get_engine_callback, url=system_engine_no_db_query_url)
174+
175+
mock_engine.auto_stop = updated_auto_stop + 100
176+
# auto_stop = 0 is not considered an empty parameter value
177+
mock_engine._service = resource_manager.engines
178+
mock_engine.update(auto_stop=0)
179+
180+
assert mock_engine.auto_stop == updated_auto_stop

0 commit comments

Comments
 (0)